Skip to content

Commit 477ae7f

Browse files
committed
MX-263: Create Offices Self Service endpoints
1 parent c93e2b2 commit 477ae7f

3 files changed

Lines changed: 148 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.savings.office.data;
20+
21+
public final class OfficeAddressData {
22+
23+
private final long officeAddressID;
24+
25+
private final long officeID;
26+
27+
private final long addressID;
28+
29+
private final long addressTypeID;
30+
31+
private final boolean isActive;
32+
33+
private OfficeAddressData(final long officeAddressID, final long office_id, final long address_id, final long address_type_id,
34+
final boolean isActive) {
35+
this.officeAddressID = officeAddressID;
36+
this.officeID = office_id;
37+
this.addressID = address_id;
38+
this.addressTypeID = address_type_id;
39+
this.isActive = isActive;
40+
}
41+
42+
public static OfficeAddressData instance(final long officeAddressID, final long office_id, final long address_id,
43+
final long address_type_id, final boolean isActive) {
44+
return new OfficeAddressData(officeAddressID, office_id, address_id, address_type_id, isActive);
45+
}
46+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.savings.office.service;
20+
21+
import java.util.Collection;
22+
import org.apache.fineract.savings.office.data.OfficeAddressData;
23+
24+
25+
public interface OfficeAddressReadPlatformService {
26+
27+
Collection<OfficeAddressData> retrieveOfficeAddrConfiguration(String entity);
28+
29+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.savings.office.service;
20+
21+
import java.sql.ResultSet;
22+
import java.sql.SQLException;
23+
import java.util.Collection;
24+
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
25+
import org.apache.fineract.savings.office.data.OfficeAddressData;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.jdbc.core.JdbcTemplate;
28+
import org.springframework.jdbc.core.RowMapper;
29+
import org.springframework.stereotype.Service;
30+
31+
@Service
32+
public class OfficeAddressReadPlatformServiceImpl implements OfficeAddressReadPlatformService {
33+
34+
private final JdbcTemplate jdbcTemplate;
35+
private final PlatformSecurityContext context;
36+
37+
@Autowired
38+
public OfficeAddressReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate) {
39+
this.context = context;
40+
this.jdbcTemplate = jdbcTemplate;
41+
}
42+
43+
private static final class OfficeAddrMapper implements RowMapper<OfficeAddressData> {
44+
45+
public String schema() {
46+
return "fld.id as fieldConfigurationId,fld.entity as entity,fld.table as entitytable,fld.field as field,fld.is_enabled as is_enabled,"
47+
+ "fld.is_mandatory as is_mandatory,fld.validation_regex as validation_regex from m_field_configuration fld";
48+
}
49+
50+
@Override
51+
public OfficeAddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
52+
final long officeAddressId = rs.getLong("officeAddressId");
53+
final long office_id = rs.getLong("office_id");
54+
final long address_id = rs.getLong("address_id");
55+
final long address_type_id = rs.getLong("address_type_id");
56+
final boolean is_active = rs.getBoolean("is_active");
57+
58+
return OfficeAddressData.instance(officeAddressId, office_id, address_id, address_type_id, is_active);
59+
60+
}
61+
}
62+
63+
@Override
64+
public Collection<OfficeAddressData> retrieveOfficeAddrConfiguration(final String entity) {
65+
this.context.authenticatedUser();
66+
67+
final OfficeAddrMapper rm = new OfficeAddrMapper();
68+
final String sql = "select " + rm.schema() + " where fld.entity=?";
69+
70+
return this.jdbcTemplate.query(sql, rm, entity); // NOSONAR
71+
}
72+
73+
}

0 commit comments

Comments
 (0)