You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by na...@apache.org on 2016/08/12 02:47:13 UTC
[2/5] incubator-fineract git commit: address_module
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/exception/AddressNotFoundException.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/exception/AddressNotFoundException.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/exception/AddressNotFoundException.java
new file mode 100644
index 0000000..9935192
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/exception/AddressNotFoundException.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.exception;
+
+import org.apache.fineract.infrastructure.core.exception.AbstractPlatformResourceNotFoundException;
+
+public class AddressNotFoundException extends AbstractPlatformResourceNotFoundException {
+
+ public AddressNotFoundException(final long clientId) {
+ super("error.msg.address.client.Identifier.not.found",
+ "Client with client ID `" + clientId + "` is not mapped with any address", clientId);
+ }
+
+ public AddressNotFoundException(final long clientId, final long addressTypeId) {
+ super("error.msg.address.client.addresstype.not.found",
+ "Client with client ID`" + clientId + "` does not have address" + " type with id", addressTypeId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/serialization/AddressCommandFromApiJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/serialization/AddressCommandFromApiJsonDeserializer.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/serialization/AddressCommandFromApiJsonDeserializer.java
new file mode 100644
index 0000000..dd054e1
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/serialization/AddressCommandFromApiJsonDeserializer.java
@@ -0,0 +1,272 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.serialization;
+
+import java.lang.reflect.Type;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.fineract.infrastructure.core.data.ApiParameterError;
+import org.apache.fineract.infrastructure.core.data.DataValidatorBuilder;
+import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
+import org.apache.fineract.infrastructure.core.exception.PlatformApiDataValidationException;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.portfolio.address.data.FieldConfigurationData;
+import org.apache.fineract.portfolio.address.service.FieldConfigurationReadPlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.JsonElement;
+import com.google.gson.reflect.TypeToken;
+
+@Component
+public class AddressCommandFromApiJsonDeserializer {
+ private final FromJsonHelper fromApiJsonHelper;
+ private final FieldConfigurationReadPlatformService readservice;
+
+ @Autowired
+ public AddressCommandFromApiJsonDeserializer(final FromJsonHelper fromApiJsonHelper,
+ final FieldConfigurationReadPlatformService readservice) {
+ this.fromApiJsonHelper = fromApiJsonHelper;
+ this.readservice = readservice;
+ }
+
+ public void validateForUpdate(final String json) {
+ validate(json, false);
+ }
+
+ public void validateForCreate(final String json, final boolean fromNewClient) {
+ validate(json, fromNewClient);
+ }
+
+ public void validate(final String json, final boolean fromNewClient) {
+ if (StringUtils.isBlank(json)) {
+ throw new InvalidJsonException();
+ }
+
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {
+ }.getType();
+
+ final List<ApiParameterError> dataValidationErrors = new ArrayList<>();
+ final DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors)
+ .resource("Address");
+
+ final JsonElement element = this.fromApiJsonHelper.parse(json);
+ Set<String> supportedParameters = new HashSet<>();
+
+ final List<FieldConfigurationData> configurationData = new ArrayList<>(
+ this.readservice.retrieveFieldConfigurationList("ADDRESS"));
+ final List<String> enabledFieldList = new ArrayList<>();
+
+ final Map<String, Boolean> madatoryFieldsMap = new HashMap<String, Boolean>();
+ final Map<String, Boolean> enabledFieldsMap = new HashMap<String, Boolean>();
+ final Map<String, String> regexFieldsMap = new HashMap<String, String>();
+
+ // validate the json fields from the configuration data fields
+
+ for (final FieldConfigurationData data : configurationData) {
+ madatoryFieldsMap.put(data.getField(), data.isIs_mandatory());
+ enabledFieldsMap.put(data.getField(), data.isIs_enabled());
+ regexFieldsMap.put(data.getField(), data.getValidation_regex());
+ if (data.isIs_enabled()) {
+ enabledFieldList.add(data.getField());
+ }
+ }
+ if (fromNewClient) {
+
+ enabledFieldList.add("addressTypeId");
+ enabledFieldList.add("locale");
+ enabledFieldList.add("dateFormat");
+ supportedParameters = new HashSet<>(enabledFieldList);
+ // enabledFieldList.add("address");
+
+ madatoryFieldsMap.put("addressTypeId", true);
+
+ }
+ if (!fromNewClient) {
+ enabledFieldList.add("locale");
+ enabledFieldList.add("dateFormat");
+ enabledFieldList.add("addressId");
+ madatoryFieldsMap.put("addressId", true);
+ supportedParameters = new HashSet<>(enabledFieldList);
+ }
+ // final Set<String> supportedParameters = new
+ // HashSet<>(enabledFieldList);
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParameters);
+
+ final String street = this.fromApiJsonHelper.extractStringNamed("street", element);
+
+ if (enabledFieldsMap.get("street")) {
+ if (madatoryFieldsMap.get("street") && fromNewClient) {
+
+ baseDataValidator.reset().parameter("street").value(street).notBlank();
+
+ }
+ if (!regexFieldsMap.get("street").isEmpty()) {
+ baseDataValidator.reset().parameter("street").value(street)
+ .matchesRegularExpression(regexFieldsMap.get("street"));
+ }
+
+ }
+ final String addressLine1 = this.fromApiJsonHelper.extractStringNamed("addressLine1", element);
+ if (enabledFieldsMap.get("addressLine1")) {
+ if (madatoryFieldsMap.get("addressLine1") && fromNewClient) {
+ baseDataValidator.reset().parameter("addressLine1").value(addressLine1).notBlank();
+ }
+ if (!regexFieldsMap.get("addressLine1").isEmpty()) {
+ baseDataValidator.reset().parameter("addressLine1").value(addressLine1)
+ .matchesRegularExpression(regexFieldsMap.get("addressLine1"));
+ }
+
+ }
+ final String addressLine2 = this.fromApiJsonHelper.extractStringNamed("addressLine2", element);
+ if (enabledFieldsMap.get("addressLine2")) {
+ if (madatoryFieldsMap.get("addressLine2") && fromNewClient) {
+ baseDataValidator.reset().parameter("addressLine2").value(addressLine2).notBlank();
+ }
+ if (!regexFieldsMap.get("addressLine2").isEmpty()) {
+ baseDataValidator.reset().parameter("addressLine2").value(addressLine2)
+ .matchesRegularExpression(regexFieldsMap.get("addressLine2"));
+ }
+ }
+ final String addressLine3 = this.fromApiJsonHelper.extractStringNamed("addressLine3", element);
+ if (enabledFieldsMap.get("addressLine3")) {
+ if (madatoryFieldsMap.get("addressLine3") && fromNewClient) {
+ baseDataValidator.reset().parameter("addressLine3").value(addressLine3).notBlank();
+ }
+ if (!regexFieldsMap.get("addressLine3").isEmpty()) {
+ baseDataValidator.reset().parameter("addressLine3").value(addressLine3)
+ .matchesRegularExpression(regexFieldsMap.get("addressLine3"));
+ }
+ }
+ final String townVillage = this.fromApiJsonHelper.extractStringNamed("townVillage", element);
+ if (enabledFieldsMap.get("townVillage")) {
+ if (madatoryFieldsMap.get("townVillage") && fromNewClient) {
+ baseDataValidator.reset().parameter("townVillage").value(townVillage).notBlank();
+ }
+ if (!regexFieldsMap.get("townVillage").isEmpty()) {
+ baseDataValidator.reset().parameter("townVillage").value(townVillage)
+ .matchesRegularExpression(regexFieldsMap.get("townVillage"));
+ }
+ }
+ final String city = this.fromApiJsonHelper.extractStringNamed("city", element);
+
+ if (enabledFieldsMap.get("city")) {
+ if (madatoryFieldsMap.get("city") && fromNewClient) {
+ baseDataValidator.reset().parameter("city").value(city).notBlank();
+ }
+ if (!regexFieldsMap.get("city").isEmpty()) {
+ baseDataValidator.reset().parameter("city").value(city)
+ .matchesRegularExpression(regexFieldsMap.get("city"));
+ }
+ }
+ final String countyDistrict = this.fromApiJsonHelper.extractStringNamed("countyDistrict", element);
+ if (enabledFieldsMap.get("countyDistrict")) {
+ if (madatoryFieldsMap.get("countyDistrict") && fromNewClient) {
+ baseDataValidator.reset().parameter("countyDistrict").value(countyDistrict).notBlank();
+ }
+ if (!regexFieldsMap.get("countyDistrict").isEmpty()) {
+ baseDataValidator.reset().parameter("countyDistrict").value(countyDistrict)
+ .matchesRegularExpression(regexFieldsMap.get("countyDistrict"));
+ }
+ }
+
+ if (this.fromApiJsonHelper.extractLongNamed("stateProvinceId", element) != null) {
+
+ final long stateProvinceId = this.fromApiJsonHelper.extractLongNamed("stateProvinceId", element);
+ if (enabledFieldsMap.get("stateProvinceId")) {
+ if (madatoryFieldsMap.get("stateProvinceId") && fromNewClient) {
+ baseDataValidator.reset().parameter("stateProvinceId").value(stateProvinceId).notBlank();
+ }
+ if (!regexFieldsMap.get("stateProvinceId").isEmpty()) {
+ baseDataValidator.reset().parameter("stateProvinceId").value(stateProvinceId)
+ .matchesRegularExpression(regexFieldsMap.get("stateProvinceId"));
+ }
+ }
+ }
+
+ if (this.fromApiJsonHelper.extractLongNamed("countryId", element) != null) {
+ final long countryId = this.fromApiJsonHelper.extractLongNamed("countryId", element);
+ if (enabledFieldsMap.get("countryId")) {
+ if (madatoryFieldsMap.get("countryId") && fromNewClient) {
+ baseDataValidator.reset().parameter("countryId").value(countryId).notBlank();
+ }
+ if (!regexFieldsMap.get("countryId").isEmpty()) {
+ baseDataValidator.reset().parameter("countryId").value(countryId)
+ .matchesRegularExpression(regexFieldsMap.get("countryId"));
+ }
+ }
+ }
+
+ final String postalCode = this.fromApiJsonHelper.extractStringNamed("postalCode", element);
+ if (enabledFieldsMap.get("postalCode")) {
+ if (madatoryFieldsMap.get("postalCode") && fromNewClient) {
+ baseDataValidator.reset().parameter("postalCode").value(postalCode).notBlank();
+ }
+ if (!regexFieldsMap.get("postalCode").isEmpty()) {
+ baseDataValidator.reset().parameter("postalCode").value(postalCode)
+ .matchesRegularExpression(regexFieldsMap.get("postalCode"));
+ }
+ }
+
+ if (this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("latitude", element) != null) {
+ final BigDecimal latitude = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("latitude", element);
+ if (enabledFieldsMap.get("latitude")) {
+ if (madatoryFieldsMap.get("latitude") && fromNewClient) {
+ baseDataValidator.reset().parameter("latitude").value(latitude).notBlank();
+ }
+ if (!regexFieldsMap.get("latitude").isEmpty()) {
+ baseDataValidator.reset().parameter("latitude").value(latitude)
+ .matchesRegularExpression(regexFieldsMap.get("latitude"));
+ }
+ }
+ }
+
+ if (this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("longitude", element) != null) {
+ final BigDecimal longitude = this.fromApiJsonHelper.extractBigDecimalWithLocaleNamed("longitude", element);
+ if (enabledFieldsMap.get("longitude")) {
+ if (madatoryFieldsMap.get("longitude") && fromNewClient) {
+ baseDataValidator.reset().parameter("longitude").value(longitude).notBlank();
+ }
+ if (!regexFieldsMap.get("longitude").isEmpty()) {
+ baseDataValidator.reset().parameter("longitude").value(longitude)
+ .matchesRegularExpression(regexFieldsMap.get("longitude"));
+ }
+ }
+ }
+
+ throwExceptionIfValidationWarningsExist(dataValidationErrors);
+
+ }
+
+ private void throwExceptionIfValidationWarningsExist(final List<ApiParameterError> dataValidationErrors) {
+ if (!dataValidationErrors.isEmpty()) {
+ throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
+ "Validation errors exist.", dataValidationErrors);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformService.java
new file mode 100644
index 0000000..0a45e7a
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformService.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import java.util.Collection;
+
+import org.apache.fineract.portfolio.address.data.AddressData;
+
+public interface AddressReadPlatformService {
+ public Collection<AddressData> retrieveAddressFields(long clientid);
+
+ public Collection<AddressData> retrieveAllClientAddress(long clientid);
+
+ public Collection<AddressData> retrieveAddressbyType(long clientid, long typeid);
+
+ Collection<AddressData> retrieveAddressbyTypeAndStatus(long clientid, long typeid, String status);
+
+ Collection<AddressData> retrieveAddressbyStatus(long clientid, String status);
+
+ AddressData retrieveTemplate();
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java
new file mode 100644
index 0000000..dc88318
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressReadPlatformServiceImpl.java
@@ -0,0 +1,246 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import java.math.BigDecimal;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.fineract.infrastructure.codes.data.CodeValueData;
+import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.address.data.AddressData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AddressReadPlatformServiceImpl implements AddressReadPlatformService {
+
+ private final JdbcTemplate jdbcTemplate;
+ private final PlatformSecurityContext context;
+ private final CodeValueReadPlatformService readService;
+
+ @Autowired
+ public AddressReadPlatformServiceImpl(final PlatformSecurityContext context, final RoutingDataSource dataSource,
+ final CodeValueReadPlatformService readService) {
+ this.context = context;
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ this.readService = readService;
+ }
+
+ private static final class AddFieldsMapper implements RowMapper<AddressData> {
+ public String schema() {
+ return "addr.id as id,client.id as client_id,addr.street as street,addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,"
+ + "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district,"
+ + "addr.state_province_id as state_province_id, addr.country_id as country_id,addr.postal_code as postal_code,addr.latitude as latitude,"
+ + "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by,"
+ + "addr.updated_on as updated_on from m_address as addr,m_client client";
+ }
+
+ @Override
+ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
+ throws SQLException {
+
+ final long addressId = rs.getLong("id");
+
+ final long clientId = rs.getLong("client_id");
+
+ final String street = rs.getString("street");
+
+ final String address_line_1 = rs.getString("address_line_1");
+
+ final String address_line_2 = rs.getString("address_line_2");
+
+ final String address_line_3 = rs.getString("address_line_3");
+
+ final String town_village = rs.getString("town_village");
+
+ final String city = rs.getString("city");
+
+ final String county_district = rs.getString("county_district");
+
+ final long state_province_id = rs.getLong("state_province_id");
+
+ final long country_id = rs.getLong("country_id");
+
+ final String postal_code = rs.getString("postal_code");
+
+ final BigDecimal latitude = rs.getBigDecimal("latitude");
+
+ final BigDecimal longitude = rs.getBigDecimal("longitude");
+
+ final String created_by = rs.getString("created_by");
+
+ final Date created_on = rs.getDate("created_on");
+
+ final String updated_by = rs.getString("updated_by");
+
+ final Date updated_on = rs.getDate("updated_on");
+
+ return AddressData.instance1(addressId, street, address_line_1, address_line_2, address_line_3,
+ town_village, city, county_district, state_province_id, country_id, postal_code, latitude,
+ longitude, created_by, created_on, updated_by, updated_on);
+
+ }
+ }
+
+ private static final class AddMapper implements RowMapper<AddressData> {
+ public String schema() {
+ return "cv2.code_value as addressType,ca.client_id as client_id,addr.id as id,ca.address_type_id as addresstyp,ca.is_active as is_active,addr.street as street,addr.address_line_1 as address_line_1,addr.address_line_2 as address_line_2,"
+ + "addr.address_line_3 as address_line_3,addr.town_village as town_village, addr.city as city,addr.county_district as county_district,"
+ + "addr.state_province_id as state_province_id,cv.code_value as state_name, addr.country_id as country_id,c.code_value as country_name,addr.postal_code as postal_code,addr.latitude as latitude,"
+ + "addr.longitude as longitude,addr.created_by as created_by,addr.created_on as created_on,addr.updated_by as updated_by,"
+ + "addr.updated_on as updated_on"
+ + " from m_address addr left join m_code_value cv on addr.state_province_id=cv.id"
+ + " left join m_code_value c on addr.country_id=c.id"
+ + " join m_client_address ca on addr.id= ca.address_id"
+ + " join m_code_value cv2 on ca.address_type_id=cv2.id";
+
+ }
+
+ @Override
+ public AddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
+ throws SQLException {
+
+ final String addressType = rs.getString("addressType");
+ final long addressId = rs.getLong("id");
+
+ final long client_id = rs.getLong("client_id");
+
+ final String street = rs.getString("street");
+
+ final long address_type_id = rs.getLong("addresstyp");
+
+ final boolean is_active = rs.getBoolean("is_active");
+
+ final String address_line_1 = rs.getString("address_line_1");
+
+ final String address_line_2 = rs.getString("address_line_2");
+
+ final String address_line_3 = rs.getString("address_line_3");
+
+ final String town_village = rs.getString("town_village");
+
+ final String city = rs.getString("city");
+
+ final String county_district = rs.getString("county_district");
+
+ final long state_province_id = rs.getLong("state_province_id");
+
+ final long country_id = rs.getLong("country_id");
+
+ final String country_name = rs.getString("country_name");
+
+ final String state_name = rs.getString("state_name");
+
+ final String postal_code = rs.getString("postal_code");
+
+ final BigDecimal latitude = rs.getBigDecimal("latitude");
+
+ final BigDecimal longitude = rs.getBigDecimal("longitude");
+
+ final String created_by = rs.getString("created_by");
+
+ final Date created_on = rs.getDate("created_on");
+
+ final String updated_by = rs.getString("updated_by");
+
+ final Date updated_on = rs.getDate("updated_on");
+
+ return AddressData.instance(addressType, client_id, addressId, address_type_id, is_active, street,
+ address_line_1, address_line_2, address_line_3, town_village, city, county_district,
+ state_province_id, country_id, state_name, country_name, postal_code, latitude, longitude,
+ created_by, created_on, updated_by, updated_on);
+
+ }
+ }
+
+ @Override
+ public Collection<AddressData> retrieveAddressFields(final long clientid) {
+ this.context.authenticatedUser();
+
+ final AddFieldsMapper rm = new AddFieldsMapper();
+ final String sql = "select " + rm.schema() + " where client.id=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { clientid });
+ }
+
+ @Override
+ public Collection<AddressData> retrieveAllClientAddress(final long clientid) {
+ this.context.authenticatedUser();
+ final AddMapper rm = new AddMapper();
+ final String sql = "select " + rm.schema() + " and ca.client_id=?";
+ return this.jdbcTemplate.query(sql, rm, new Object[] { clientid });
+ }
+
+ @Override
+ public Collection<AddressData> retrieveAddressbyType(final long clientid, final long typeid) {
+ this.context.authenticatedUser();
+
+ final AddMapper rm = new AddMapper();
+ final String sql = "select " + rm.schema() + " and ca.client_id=? and ca.address_type_id=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { clientid, typeid });
+ }
+
+ @Override
+ public Collection<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, final long typeid,
+ final String status) {
+ this.context.authenticatedUser();
+ Boolean temp = false;
+ temp = Boolean.parseBoolean(status);
+
+ final AddMapper rm = new AddMapper();
+ final String sql = "select " + rm.schema() + " and ca.client_id=? and ca.address_type_id=? and ca.is_active=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { clientid, typeid, temp });
+ }
+
+ @Override
+ public Collection<AddressData> retrieveAddressbyStatus(final long clientid, final String status) {
+ this.context.authenticatedUser();
+ Boolean temp = false;
+ temp = Boolean.parseBoolean(status);
+
+ final AddMapper rm = new AddMapper();
+ final String sql = "select " + rm.schema() + " and ca.client_id=? and ca.is_active=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { clientid, temp });
+ }
+
+ @Override
+ public AddressData retrieveTemplate() {
+ final List<CodeValueData> countryoptions = new ArrayList<>(
+ this.readService.retrieveCodeValuesByCode("COUNTRY"));
+
+ final List<CodeValueData> StateOptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("STATES"));
+
+ final List<CodeValueData> addressTypeOptions = new ArrayList<>(
+ this.readService.retrieveCodeValuesByCode("ADDRESS_TYPE"));
+
+ return AddressData.template(countryoptions, StateOptions, addressTypeOptions);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformService.java
new file mode 100644
index 0000000..fa1219a
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformService.java
@@ -0,0 +1,31 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.client.domain.Client;
+
+public interface AddressWritePlatformService {
+ CommandProcessingResult addClientAddress(Long clientId, Long addressTypeId, JsonCommand command);
+
+ CommandProcessingResult addNewClientAddress(Client client, JsonCommand command);
+
+ CommandProcessingResult updateClientAddress(Long clientId, JsonCommand command);
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
new file mode 100644
index 0000000..847b20d
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/AddressWritePlatformServiceImpl.java
@@ -0,0 +1,284 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import java.math.BigDecimal;
+
+import org.apache.fineract.infrastructure.codes.domain.CodeValue;
+import org.apache.fineract.infrastructure.codes.domain.CodeValueRepository;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.address.domain.Address;
+import org.apache.fineract.portfolio.address.domain.AddressRepository;
+import org.apache.fineract.portfolio.address.serialization.AddressCommandFromApiJsonDeserializer;
+import org.apache.fineract.portfolio.client.domain.Client;
+import org.apache.fineract.portfolio.client.domain.ClientAddress;
+import org.apache.fineract.portfolio.client.domain.ClientAddressRepository;
+import org.apache.fineract.portfolio.client.domain.ClientAddressRepositoryWrapper;
+import org.apache.fineract.portfolio.client.domain.ClientRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+
+@Service
+public class AddressWritePlatformServiceImpl implements AddressWritePlatformService {
+ private final PlatformSecurityContext context;
+ private final CodeValueRepository codeValueRepository;
+ private final ClientAddressRepository clientAddressRepository;
+ private final ClientRepository clientRepository;
+ private final AddressRepository addressRepository;
+ private final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper;
+ private final AddressCommandFromApiJsonDeserializer fromApiJsonDeserializer;
+
+ @Autowired
+ public AddressWritePlatformServiceImpl(final PlatformSecurityContext context,
+ final CodeValueRepository codeValueRepository, final ClientAddressRepository clientAddressRepository,
+ final ClientRepository clientRepository, final AddressRepository addressRepository,
+ final ClientAddressRepositoryWrapper clientAddressRepositoryWrapper,
+ final AddressCommandFromApiJsonDeserializer fromApiJsonDeserializer) {
+ this.context = context;
+ this.codeValueRepository = codeValueRepository;
+ this.clientAddressRepository = clientAddressRepository;
+ this.clientRepository = clientRepository;
+ this.addressRepository = addressRepository;
+ this.clientAddressRepositoryWrapper = clientAddressRepositoryWrapper;
+ this.fromApiJsonDeserializer = fromApiJsonDeserializer;
+
+ }
+
+ @Override
+ public CommandProcessingResult addClientAddress(final Long clientId, final Long addressTypeId,
+ final JsonCommand command) {
+ CodeValue stateIdobj = null;
+ CodeValue countryIdObj = null;
+ long stateId;
+ long countryId;
+
+ this.context.authenticatedUser();
+ this.fromApiJsonDeserializer.validateForCreate(command.json(), true);
+
+ System.out.println("request " + command.json());
+
+ if (command.longValueOfParameterNamed("stateProvinceId") != null) {
+ stateId = command.longValueOfParameterNamed("stateProvinceId");
+ stateIdobj = this.codeValueRepository.getOne(stateId);
+ }
+
+ if (command.longValueOfParameterNamed("countryId") != null) {
+ countryId = command.longValueOfParameterNamed("countryId");
+ countryIdObj = this.codeValueRepository.getOne(countryId);
+ }
+
+ final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId);
+
+ final Address add = Address.fromJson(command, stateIdobj, countryIdObj);
+ this.addressRepository.save(add);
+ final Long addressid = add.getId();
+ final Address addobj = this.addressRepository.getOne(addressid);
+
+ final Client client = this.clientRepository.getOne(clientId);
+ final boolean isActive = command.booleanPrimitiveValueOfParameterNamed("isActive");
+
+ final ClientAddress clientAddressobj = ClientAddress.fromJson(isActive, client, addobj, addressTypeIdObj);
+ this.clientAddressRepository.save(clientAddressobj);
+
+ return new CommandProcessingResultBuilder().withCommandId(command.commandId())
+ .withEntityId(clientAddressobj.getId()).build();
+ }
+
+ // following method is used for adding multiple addresses while creating new
+ // client
+
+ @Override
+ public CommandProcessingResult addNewClientAddress(final Client client, final JsonCommand command) {
+ CodeValue stateIdobj = null;
+ CodeValue countryIdObj = null;
+ long stateId;
+ long countryId;
+ ClientAddress clientAddressobj = new ClientAddress();
+ final JsonArray addressArray = command.arrayOfParameterNamed("address");
+
+ for (int i = 0; i < addressArray.size(); i++) {
+ final JsonObject jsonObject = addressArray.get(i).getAsJsonObject();
+
+ // validate every address
+ this.fromApiJsonDeserializer.validateForCreate(jsonObject.toString(), true);
+
+ if (jsonObject.get("stateProvinceId") != null) {
+ stateId = jsonObject.get("stateProvinceId").getAsLong();
+ stateIdobj = this.codeValueRepository.getOne(stateId);
+ }
+
+ if (jsonObject.get("countryId") != null) {
+ countryId = jsonObject.get("countryId").getAsLong();
+ countryIdObj = this.codeValueRepository.getOne(countryId);
+ }
+
+ final long addressTypeId = jsonObject.get("addressTypeId").getAsLong();
+ final CodeValue addressTypeIdObj = this.codeValueRepository.getOne(addressTypeId);
+
+ final Address add = Address.fromJsonObject(jsonObject, stateIdobj, countryIdObj);
+ this.addressRepository.save(add);
+ final Long addressid = add.getId();
+ final Address addobj = this.addressRepository.getOne(addressid);
+
+ final boolean isActive = jsonObject.get("isActive").getAsBoolean();
+
+ clientAddressobj = ClientAddress.fromJson(isActive, client, addobj, addressTypeIdObj);
+ this.clientAddressRepository.save(clientAddressobj);
+
+ }
+
+ return new CommandProcessingResultBuilder().withCommandId(command.commandId())
+ .withEntityId(clientAddressobj.getId()).build();
+ }
+
+ @Override
+ public CommandProcessingResult updateClientAddress(final Long clientId, final JsonCommand command) {
+ this.context.authenticatedUser();
+
+ long stateId;
+
+ long countryId;
+
+ CodeValue stateIdobj;
+
+ CodeValue countryIdObj;
+
+ boolean is_address_update = false;
+
+ this.fromApiJsonDeserializer.validateForUpdate(command.json());
+
+ final long addressId = command.longValueOfParameterNamed("addressId");
+
+ final ClientAddress clientAddressObj = this.clientAddressRepositoryWrapper
+ .findOneByClientIdAndAddressId(clientId, addressId);
+
+ final Address addobj = this.addressRepository.getOne(addressId);
+
+ if (!(command.stringValueOfParameterNamed("street").isEmpty())) {
+
+ is_address_update = true;
+ final String street = command.stringValueOfParameterNamed("street");
+ addobj.setStreet(street);
+ }
+
+ if (!(command.stringValueOfParameterNamed("addressLine1").isEmpty())) {
+
+ is_address_update = true;
+ final String addressLine1 = command.stringValueOfParameterNamed("addressLine1");
+ addobj.setAddressLine1(addressLine1);
+
+ }
+
+ if (!(command.stringValueOfParameterNamed("addressLine2").isEmpty())) {
+
+ is_address_update = true;
+ final String addressLine2 = command.stringValueOfParameterNamed("addressLine2");
+ addobj.setAddressLine2(addressLine2);
+
+ }
+
+ if (!(command.stringValueOfParameterNamed("addressLine3").isEmpty())) {
+ is_address_update = true;
+ final String addressLine3 = command.stringValueOfParameterNamed("addressLine3");
+ addobj.setAddressLine3(addressLine3);
+
+ }
+
+ if (!(command.stringValueOfParameterNamed("townVillage").isEmpty())) {
+
+ is_address_update = true;
+ final String townVillage = command.stringValueOfParameterNamed("townVillage");
+ addobj.setTownVillage(townVillage);
+ }
+
+ if (!(command.stringValueOfParameterNamed("city").isEmpty())) {
+ is_address_update = true;
+ final String city = command.stringValueOfParameterNamed("city");
+ addobj.setCity(city);
+ }
+
+ if (!(command.stringValueOfParameterNamed("countyDistrict").isEmpty())) {
+ is_address_update = true;
+ final String countyDistrict = command.stringValueOfParameterNamed("countyDistrict");
+ addobj.setCountyDistrict(countyDistrict);
+ }
+
+ if ((command.longValueOfParameterNamed("stateProvinceId") != null)) {
+ if ((command.longValueOfParameterNamed("stateProvinceId") != 0)) {
+ is_address_update = true;
+ stateId = command.longValueOfParameterNamed("stateProvinceId");
+ stateIdobj = this.codeValueRepository.getOne(stateId);
+ addobj.setStateProvince(stateIdobj);
+ }
+
+ }
+ if ((command.longValueOfParameterNamed("countryId") != null)) {
+ if ((command.longValueOfParameterNamed("countryId") != 0)) {
+ is_address_update = true;
+ countryId = command.longValueOfParameterNamed("countryId");
+ countryIdObj = this.codeValueRepository.getOne(countryId);
+ addobj.setCountry(countryIdObj);
+ }
+
+ }
+
+ if (!(command.stringValueOfParameterNamed("postalCode").isEmpty())) {
+ is_address_update = true;
+ final String postalCode = command.stringValueOfParameterNamed("postalCode");
+ addobj.setPostalCode(postalCode);
+ }
+
+ if (command.bigDecimalValueOfParameterNamed("latitude") != null) {
+
+ is_address_update = true;
+ final BigDecimal latitude = command.bigDecimalValueOfParameterNamed("latitude");
+
+ addobj.setLatitude(latitude);
+ }
+ if (command.bigDecimalValueOfParameterNamed("longitude") != null) {
+ is_address_update = true;
+ final BigDecimal longitude = command.bigDecimalValueOfParameterNamed("longitude");
+ addobj.setLongitude(longitude);
+
+ }
+
+ if (is_address_update) {
+
+ this.addressRepository.save(addobj);
+
+ }
+
+ final Boolean testActive = command.booleanPrimitiveValueOfParameterNamed("isActive");
+ if (testActive != null) {
+
+ final boolean active = command.booleanPrimitiveValueOfParameterNamed("isActive");
+ clientAddressObj.setIs_active(active);
+
+ }
+
+ return new CommandProcessingResultBuilder().withCommandId(command.commandId())
+ .withEntityId(clientAddressObj.getId()).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformService.java
new file mode 100644
index 0000000..c3403f4
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformService.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.fineract.portfolio.address.data.FieldConfigurationData;
+
+public interface FieldConfigurationReadPlatformService {
+ public Collection<FieldConfigurationData> retrieveFieldConfiguration(String entity);
+
+ List<FieldConfigurationData> retrieveFieldConfigurationList(String entity);
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformServiceImpl.java
new file mode 100644
index 0000000..946a96f
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/service/FieldConfigurationReadPlatformServiceImpl.java
@@ -0,0 +1,89 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.address.service;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.address.data.FieldConfigurationData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class FieldConfigurationReadPlatformServiceImpl implements FieldConfigurationReadPlatformService {
+ private final JdbcTemplate jdbcTemplate;
+ private final PlatformSecurityContext context;
+
+ @Autowired
+ public FieldConfigurationReadPlatformServiceImpl(final PlatformSecurityContext context,
+ final RoutingDataSource dataSource) {
+ this.context = context;
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ private static final class FieldMapper implements RowMapper<FieldConfigurationData> {
+ public String schema() {
+ return "fld.id as fieldConfigurationId,fld.entity as entity,fld.subentity as subentity,fld.field as field,fld.is_enabled as is_enabled,"
+ + "fld.is_mandatory as is_mandatory,fld.validation_regex as validation_regex from m_field_configuration fld";
+ }
+
+ @Override
+ public FieldConfigurationData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
+ throws SQLException {
+ final long fieldConfigurationId = rs.getLong("fieldConfigurationId");
+ final String entity = rs.getString("entity");
+ final String subentity = rs.getString("subentity");
+ final String field = rs.getString("field");
+ final boolean is_enabled = rs.getBoolean("is_enabled");
+ final boolean is_mandatory = rs.getBoolean("is_mandatory");
+ final String validation_regex = rs.getString("validation_regex");
+
+ return FieldConfigurationData.instance(fieldConfigurationId, entity, subentity, field, is_enabled,
+ is_mandatory, validation_regex);
+
+ }
+ }
+
+ @Override
+ public Collection<FieldConfigurationData> retrieveFieldConfiguration(final String entity) {
+ this.context.authenticatedUser();
+
+ final FieldMapper rm = new FieldMapper();
+ final String sql = "select " + rm.schema() + " where fld.entity=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { entity });
+ }
+
+ @Override
+ public List<FieldConfigurationData> retrieveFieldConfigurationList(final String entity) {
+ this.context.authenticatedUser();
+
+ final FieldMapper rm = new FieldMapper();
+ final String sql = "select " + rm.schema() + " where fld.entity=?";
+
+ return this.jdbcTemplate.query(sql, new Object[] { entity }, rm);
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResources.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResources.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResources.java
new file mode 100644
index 0000000..67c72b4
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResources.java
@@ -0,0 +1,151 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.api;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.apache.fineract.commands.service.CommandWrapperBuilder;
+import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
+import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
+import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.address.data.AddressData;
+import org.apache.fineract.portfolio.address.service.AddressReadPlatformServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+@Path("/client")
+@Component
+@Scope("singleton")
+public class ClientAddressApiResources {
+ private final Set<String> RESPONSE_DATA_PARAMETERS = new HashSet<>(Arrays.asList("addressId", "street",
+ "addressLine1", "addressLine2", "addressLine3", "townVillage", "city", "countyDistrict", "stateProvinceId",
+ "countryId", "postalCode", "latitude", "longitude", "createdBy", "createdOn", "updatedBy", "updatedOn",
+ "clientAddressId", "client_id", "address_id", "address_type_id", "isActive", "fieldConfigurationId",
+ "entity", "table", "field", "is_enabled", "is_mandatory", "validation_regex"));
+ private final String resourceNameForPermissions = "Address";
+ private final PlatformSecurityContext context;
+ private final AddressReadPlatformServiceImpl readPlatformService;
+ private final DefaultToApiJsonSerializer<AddressData> toApiJsonSerializer;
+ private final ApiRequestParameterHelper apiRequestParameterHelper;
+ private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
+
+ @Autowired
+ public ClientAddressApiResources(final PlatformSecurityContext context,
+ final AddressReadPlatformServiceImpl readPlatformService,
+ final DefaultToApiJsonSerializer<AddressData> toApiJsonSerializer,
+ final ApiRequestParameterHelper apiRequestParameterHelper,
+ final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService) {
+ this.context = context;
+ this.readPlatformService = readPlatformService;
+ this.toApiJsonSerializer = toApiJsonSerializer;
+ this.apiRequestParameterHelper = apiRequestParameterHelper;
+ this.commandsSourceWritePlatformService = commandsSourceWritePlatformService;
+ }
+
+ @GET
+ @Path("addresses/template")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String getAddressesTemplate(@Context final UriInfo uriInfo) {
+ this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
+
+ final AddressData template = this.readPlatformService.retrieveTemplate();
+
+ final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper
+ .process(uriInfo.getQueryParameters());
+ return this.toApiJsonSerializer.serialize(settings, template, this.RESPONSE_DATA_PARAMETERS);
+
+ }
+
+ @GET
+ @Path("/{clientid}/addresses")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String getAddresses(@QueryParam("status") final String status, @QueryParam("type") final long addressTypeId,
+ @PathParam("clientid") final long clientid, @Context final UriInfo uriInfo) {
+ Collection<AddressData> address;
+
+ this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
+
+ if (addressTypeId == 0 && status == null) {
+ address = this.readPlatformService.retrieveAllClientAddress(clientid);
+ } else if (addressTypeId != 0 && status == null) {
+ address = this.readPlatformService.retrieveAddressbyType(clientid, addressTypeId);
+ } else if (addressTypeId != 0 && status != null) {
+ address = this.readPlatformService.retrieveAddressbyTypeAndStatus(clientid, addressTypeId, status);
+ } else {
+ address = this.readPlatformService.retrieveAddressbyStatus(clientid, status);
+ }
+
+ final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper
+ .process(uriInfo.getQueryParameters());
+ return this.toApiJsonSerializer.serialize(settings, address, this.RESPONSE_DATA_PARAMETERS);
+
+ }
+
+ @POST
+ @Path("/{clientid}/addresses")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String AddClientAddress(@QueryParam("type") final long addressTypeId,
+ @PathParam("clientid") final long clientid, final String apiRequestBodyAsJson) {
+
+ final CommandWrapper commandRequest = new CommandWrapperBuilder().addClientAddress(clientid, addressTypeId)
+ .withJson(apiRequestBodyAsJson).build();
+
+ final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+
+ return this.toApiJsonSerializer.serialize(result);
+ }
+
+ @PUT
+ @Path("/{clientid}/addresses")
+ @Consumes({ MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_JSON })
+ public String UpdateClientAddress(@PathParam("clientid") final long clientid, final String apiRequestBodyAsJson) {
+
+ final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClientAddress(clientid)
+ .withJson(apiRequestBodyAsJson).build();
+
+ final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
+
+ return this.toApiJsonSerializer.serialize(result);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java
index 861358a..fb07c0e 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientApiConstants.java
@@ -68,6 +68,7 @@ public class ClientApiConstants {
// general
public static final String localeParamName = "locale";
public static final String dateFormatParamName = "dateFormat";
+ public static final String address = "address";
public static final String CLIENT_TYPE_INDIVIDUAL = "Individual";
@@ -175,14 +176,14 @@ public class ClientApiConstants {
public static final String staffOptionsParamName = "staffOptions";
public static final Set<String> CLIENT_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<>(
- Arrays.asList(localeParamName, dateFormatParamName, groupIdParamName, accountNoParamName, externalIdParamName,
+ Arrays.asList(address,localeParamName, dateFormatParamName, groupIdParamName, accountNoParamName, externalIdParamName,
mobileNoParamName, firstnameParamName, middlenameParamName, lastnameParamName, fullnameParamName, officeIdParamName,
activeParamName, activationDateParamName, staffIdParamName, submittedOnDateParamName, savingsProductIdParamName,
dateOfBirthParamName, genderIdParamName, clientTypeIdParamName, clientClassificationIdParamName,
clientNonPersonDetailsParamName, displaynameParamName, legalFormIdParamName));
public static final Set<String> CLIENT_NON_PERSON_CREATE_REQUEST_DATA_PARAMETERS = new HashSet<>(
- Arrays.asList(localeParamName, dateFormatParamName, incorpNumberParamName, remarksParamName, incorpValidityTillParamName,
+ Arrays.asList(address,localeParamName, dateFormatParamName, incorpNumberParamName, remarksParamName, incorpValidityTillParamName,
constitutionIdParamName, mainBusinessLineIdParamName));
public static final Set<String> CLIENT_UPDATE_REQUEST_DATA_PARAMETERS = new HashSet<>(Arrays.asList(localeParamName,
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java
index 1984417..bcba0fc 100644
--- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientData.java
@@ -29,6 +29,7 @@ import org.apache.fineract.infrastructure.codes.data.CodeValueData;
import org.apache.fineract.infrastructure.core.data.EnumOptionData;
import org.apache.fineract.organisation.office.data.OfficeData;
import org.apache.fineract.organisation.staff.data.StaffData;
+import org.apache.fineract.portfolio.address.data.AddressData;
import org.apache.fineract.portfolio.group.data.GroupGeneralData;
import org.apache.fineract.portfolio.savings.data.SavingsAccountData;
import org.apache.fineract.portfolio.savings.data.SavingsProductData;
@@ -95,13 +96,17 @@ final public class ClientData implements Comparable<ClientData> {
private final List<EnumOptionData> clientLegalFormOptions;
private final ClientNonPersonData clientNonPersonDetails;
+
+ private final AddressData address;
+
+ private final Boolean isAddressEnabled;
public static ClientData template(final Long officeId, final LocalDate joinedDate, final Collection<OfficeData> officeOptions,
final Collection<StaffData> staffOptions, final Collection<CodeValueData> narrations,
final Collection<CodeValueData> genderOptions, final Collection<SavingsProductData> savingProductOptions,
final Collection<CodeValueData> clientTypeOptions, final Collection<CodeValueData> clientClassificationOptions,
final Collection<CodeValueData> clientNonPersonConstitutionOptions, final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions,
- final List<EnumOptionData> clientLegalFormOptions) {
+ final List<EnumOptionData> clientLegalFormOptions, final AddressData address,final Boolean isAddressEnabled) {
final String accountNo = null;
final EnumOptionData status = null;
final CodeValueData subStatus = null;
@@ -136,7 +141,7 @@ final public class ClientData implements Comparable<ClientData> {
staffName, officeOptions, groups, staffOptions, narrations, genderOptions, timeline, savingProductOptions,
savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification,
clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions,
- clientNonPersonDetails, clientLegalFormOptions, legalForm);
+ clientNonPersonDetails, clientLegalFormOptions, legalForm,address, isAddressEnabled);
}
@@ -151,7 +156,7 @@ final public class ClientData implements Comparable<ClientData> {
clientData.savingsProductName, clientData.savingsAccountId, clientData.savingAccountOptions, clientData.clientType,
clientData.clientClassification, templateData.clientTypeOptions, templateData.clientClassificationOptions,
templateData.clientNonPersonConstitutionOptions, templateData.clientNonPersonMainBusinessLineOptions, clientData.clientNonPersonDetails,
- templateData.clientLegalFormOptions, clientData.legalForm);
+ templateData.clientLegalFormOptions, clientData.legalForm, clientData.address,clientData.isAddressEnabled);
}
@@ -167,7 +172,7 @@ final public class ClientData implements Comparable<ClientData> {
clientData.savingsProductName, clientData.savingsAccountId, savingAccountOptions, clientData.clientType,
clientData.clientClassification, clientData.clientTypeOptions, clientData.clientClassificationOptions,
clientData.clientNonPersonConstitutionOptions, clientData.clientNonPersonMainBusinessLineOptions, clientData.clientNonPersonDetails,
- clientData.clientLegalFormOptions, clientData.legalForm);
+ clientData.clientLegalFormOptions, clientData.legalForm,clientData.address, clientData.isAddressEnabled);
}
@@ -180,7 +185,8 @@ final public class ClientData implements Comparable<ClientData> {
clientData.savingProductOptions, clientData.savingsProductId, clientData.savingsProductName, clientData.savingsAccountId,
clientData.savingAccountOptions, clientData.clientType, clientData.clientClassification, clientData.clientTypeOptions,
clientData.clientClassificationOptions, clientData.clientNonPersonConstitutionOptions, clientData.clientNonPersonMainBusinessLineOptions,
- clientData.clientNonPersonDetails, clientData.clientLegalFormOptions, clientData.legalForm);
+ clientData.clientNonPersonDetails, clientData.clientLegalFormOptions, clientData.legalForm,clientData.address,
+ clientData.isAddressEnabled);
}
@@ -224,7 +230,7 @@ final public class ClientData implements Comparable<ClientData> {
staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions,
savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification,
clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions,
- clientNonPerson, clientLegalFormOptions, legalForm);
+ clientNonPerson, clientLegalFormOptions, legalForm,null,null);
}
public static ClientData lookup(final Long id, final String displayName, final Long officeId, final String officeName) {
@@ -270,7 +276,7 @@ final public class ClientData implements Comparable<ClientData> {
staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions,
savingsProductId, savingsProductName, savingsAccountId, savingAccountOptions, clientType, clientClassification,
clientTypeOptions, clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions,
- clientNonPerson, clientLegalFormOptions, legalForm);
+ clientNonPerson, clientLegalFormOptions, legalForm,null,null);
}
@@ -298,7 +304,7 @@ final public class ClientData implements Comparable<ClientData> {
staffName, allowedOffices, groups, staffOptions, closureReasons, genderOptions, timeline, savingProductOptions,
savingsProductId, savingsProductName, savingsAccountId, null, clientType, clientClassification, clientTypeOptions,
clientClassificationOptions, clientNonPersonConstitutionOptions, clientNonPersonMainBusinessLineOptions, clientNonPerson,
- clientLegalFormOptions, legalForm);
+ clientLegalFormOptions, legalForm,null,null);
}
@@ -315,7 +321,7 @@ final public class ClientData implements Comparable<ClientData> {
final CodeValueData clientClassification, final Collection<CodeValueData> clientTypeOptions,
final Collection<CodeValueData> clientClassificationOptions, final Collection<CodeValueData> clientNonPersonConstitutionOptions,
final Collection<CodeValueData> clientNonPersonMainBusinessLineOptions, final ClientNonPersonData clientNonPerson,
- final List<EnumOptionData> clientLegalFormOptions, final EnumOptionData legalForm) {
+ final List<EnumOptionData> clientLegalFormOptions, final EnumOptionData legalForm,final AddressData address, final Boolean isAddressEnabled) {
this.accountNo = accountNo;
this.status = status;
if (status != null) {
@@ -374,6 +380,9 @@ final public class ClientData implements Comparable<ClientData> {
this.savingAccountOptions = savingAccountOptions;
this.legalForm = legalForm;
this.clientNonPersonDetails = clientNonPerson;
+
+ this.address = address;
+ this.isAddressEnabled = isAddressEnabled;
}
@@ -455,4 +464,8 @@ final public class ClientData implements Comparable<ClientData> {
public LocalDate getActivationDate() {
return this.activationDate;
}
+
+ public Boolean getIsAddressEnabled() {
+ return this.isAddressEnabled;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
new file mode 100644
index 0000000..1dbe0b9
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddress.java
@@ -0,0 +1,100 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.domain;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.Table;
+
+import org.apache.fineract.infrastructure.codes.domain.CodeValue;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.portfolio.address.domain.Address;
+import org.springframework.data.jpa.domain.AbstractPersistable;
+
+@Entity
+@Table(name = "m_client_address")
+public class ClientAddress extends AbstractPersistable<Long> {
+
+ @ManyToOne
+ private Client client;
+
+ @ManyToOne
+ private Address address;
+
+ @ManyToOne
+ @JoinColumn(name = "address_type_id")
+ private CodeValue addressType;
+
+ @Column(name = "is_active")
+ private boolean isActive;
+
+ private ClientAddress(final Client client, final Address address, final CodeValue addressType,
+ final boolean isActive) {
+ this.client = client;
+ this.address = address;
+ this.addressType = addressType;
+ this.isActive = isActive;
+
+ }
+
+ public ClientAddress() {
+
+ }
+
+ public static ClientAddress fromJson(final boolean isActive, final Client client, final Address address,
+ final CodeValue address_type) {
+
+ return new ClientAddress(client, address, address_type, isActive);
+ }
+
+ public Client getClient() {
+ return this.client;
+ }
+
+ public Address getAddress() {
+ return this.address;
+ }
+
+ public CodeValue getAddressType() {
+ return this.addressType;
+ }
+
+ public void setAddressType(final CodeValue addressType) {
+ this.addressType = addressType;
+ }
+
+ public boolean isIs_active() {
+ return this.isActive;
+ }
+
+ public void setClient(final Client client) {
+ this.client = client;
+ }
+
+ public void setAddress(final Address address) {
+ this.address = address;
+ }
+
+ public void setIs_active(final boolean isActive) {
+ this.isActive = isActive;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepository.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepository.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepository.java
new file mode 100644
index 0000000..984b2ea
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepository.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.domain;
+
+import org.apache.fineract.infrastructure.codes.domain.CodeValue;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ClientAddressRepository
+ extends JpaRepository<ClientAddress, Long>, JpaSpecificationExecutor<ClientAddress> {
+ ClientAddress findByClientId(String clientId);
+
+ // ClientAddress findByAddressId(long addressId);
+
+ ClientAddress findByClientIdAndAddressTypeAndIsActive(final long clientId, final CodeValue addressTypeId,
+ final boolean isActive);
+
+ ClientAddress findByClientIdAndAddressId(final long clientId, final long addressId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepositoryWrapper.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepositoryWrapper.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepositoryWrapper.java
new file mode 100644
index 0000000..fbe7cd2
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/domain/ClientAddressRepositoryWrapper.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.domain;
+
+import org.apache.fineract.infrastructure.codes.domain.CodeValue;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ClientAddressRepositoryWrapper {
+ private final ClientAddressRepository clientAddressRepository;
+
+ @Autowired
+ public ClientAddressRepositoryWrapper(final ClientAddressRepository clientAddressRepository) {
+ this.clientAddressRepository = clientAddressRepository;
+ }
+
+ public ClientAddress findOneByClientIdAndAddressTypeAndIsActive(final long clientId, final CodeValue addressType,
+ final boolean isActive) {
+ final ClientAddress clientAddress = this.clientAddressRepository
+ .findByClientIdAndAddressTypeAndIsActive(clientId, addressType, isActive);
+ // if (clientAddress == null) { throw new
+ // AddressNotFoundException(clientId, addressType); }
+ return clientAddress;
+ }
+
+ public ClientAddress findOneByClientIdAndAddressId(final long clientId, final long addressId) {
+ final ClientAddress clientAddress = this.clientAddressRepository.findByClientIdAndAddressId(clientId,
+ addressId);
+
+ return clientAddress;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/AddClientAddressCommandHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/AddClientAddressCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/AddClientAddressCommandHandler.java
new file mode 100644
index 0000000..2e9d844
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/AddClientAddressCommandHandler.java
@@ -0,0 +1,45 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.handler;
+
+import org.apache.fineract.commands.annotation.CommandType;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.address.service.AddressWritePlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+@CommandType(entity = "ADDRESS", action = "CREATE")
+public class AddClientAddressCommandHandler implements NewCommandSourceHandler {
+ private final AddressWritePlatformService writePlatformService;
+
+ @Autowired
+ public AddClientAddressCommandHandler(final AddressWritePlatformService writePlatformService) {
+ this.writePlatformService = writePlatformService;
+ }
+
+ @Override
+ public CommandProcessingResult processCommand(final JsonCommand command) {
+ return this.writePlatformService.addClientAddress(command.getClientId(), command.entityId(), command);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/UpdateClientAddressCommandHandler.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/UpdateClientAddressCommandHandler.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/UpdateClientAddressCommandHandler.java
new file mode 100644
index 0000000..a7892c9
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/handler/UpdateClientAddressCommandHandler.java
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.handler;
+
+import org.apache.fineract.commands.annotation.CommandType;
+import org.apache.fineract.commands.handler.NewCommandSourceHandler;
+import org.apache.fineract.infrastructure.core.api.JsonCommand;
+import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
+import org.apache.fineract.portfolio.address.service.AddressWritePlatformService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+@CommandType(entity = "ADDRESS", action = "UPDATE")
+public class UpdateClientAddressCommandHandler implements NewCommandSourceHandler {
+
+ private final AddressWritePlatformService writePlatformService;
+
+ @Autowired
+ public UpdateClientAddressCommandHandler(final AddressWritePlatformService writePlatformService) {
+ this.writePlatformService = writePlatformService;
+ }
+
+ @Override
+ public CommandProcessingResult processCommand(final JsonCommand command) {
+ /*
+ * return
+ * this.writePlatformService.updateClientAddress(command.getClientId(),
+ * command.entityId(), command.getStatus(), command);
+ */
+ return this.writePlatformService.updateClientAddress(command.getClientId(), command);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformService.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformService.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformService.java
new file mode 100644
index 0000000..d33635f
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformService.java
@@ -0,0 +1,29 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.service;
+
+import java.util.Collection;
+
+import org.apache.fineract.portfolio.address.data.ClientAddressData;
+
+public interface ClientAddressReadPlatformService {
+
+ public Collection<ClientAddressData> retrieveClientAddrConfiguration(String entity);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b086e005/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformServiceImpl.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformServiceImpl.java
new file mode 100644
index 0000000..63079ed
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/service/ClientAddressReadPlatformServiceImpl.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.client.service;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Collection;
+
+import org.apache.fineract.infrastructure.core.service.RoutingDataSource;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.portfolio.address.data.ClientAddressData;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.stereotype.Service;
+
+@Service
+public class ClientAddressReadPlatformServiceImpl implements ClientAddressReadPlatformService {
+
+ private final JdbcTemplate jdbcTemplate;
+ private final PlatformSecurityContext context;
+
+ @Autowired
+ public ClientAddressReadPlatformServiceImpl(final PlatformSecurityContext context,
+ final RoutingDataSource dataSource) {
+ this.context = context;
+ this.jdbcTemplate = new JdbcTemplate(dataSource);
+ }
+
+ private static final class ClientAddrMapper implements RowMapper<ClientAddressData> {
+ public String schema() {
+ return "fld.id as fieldConfigurationId,fld.entity as entity,fld.table as entitytable,fld.field as field,fld.is_enabled as is_enabled,"
+ + "fld.is_mandatory as is_mandatory,fld.validation_regex as validation_regex from m_field_configuration fld";
+ }
+
+ @Override
+ public ClientAddressData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
+ throws SQLException {
+ final long clientAddressId = rs.getLong("clientAddressId");
+ final long client_id = rs.getLong("client_id");
+ final long address_id = rs.getLong("address_id");
+ final long address_type_id = rs.getLong("address_type_id");
+ final boolean is_active = rs.getBoolean("is_active");
+
+ return ClientAddressData.instance(clientAddressId, client_id, address_id, address_type_id, is_active);
+
+ }
+ }
+
+ @Override
+ public Collection<ClientAddressData> retrieveClientAddrConfiguration(final String entity) {
+ this.context.authenticatedUser();
+
+ final ClientAddrMapper rm = new ClientAddrMapper();
+ final String sql = "select " + rm.schema() + " where fld.entity=?";
+
+ return this.jdbcTemplate.query(sql, rm, new Object[] { entity });
+ }
+
+}