From 30543fd72e8e986a7bc8270f00f6fbd96a3dddf3 Mon Sep 17 00:00:00 2001 From: viktorpavlenko Date: Wed, 9 Apr 2025 16:38:17 +0300 Subject: [PATCH] FINERACT-2169: Refactor client address controller; --- .../core/component/FetcherRule.java | 38 +++++++++ .../portfolio/address/data/AddressData.java | 2 + .../test/stepdef/common/ClientStepDef.java | 10 +-- .../filter/ClientAddressSearchParam.java | 35 ++++++++ .../service/AddressReadPlatformService.java | 15 ++-- .../AddressReadPlatformServiceImpl.java | 46 +++++----- .../client/api/ClientAddressApiResource.java | 84 +++++-------------- .../api/ClientAddressApiResourcesSwagger.java | 81 ------------------ .../client/api/ClientsApiResourceSwagger.java | 3 +- .../client/data/ClientAddressRequest.java | 52 ++++++++++++ .../fineract/integrationtests/ClientTest.java | 23 +++-- .../integrationtests/common/ClientHelper.java | 12 +-- 12 files changed, 208 insertions(+), 193 deletions(-) create mode 100644 fineract-core/src/main/java/org/apache/fineract/infrastructure/core/component/FetcherRule.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/address/filter/ClientAddressSearchParam.java create mode 100644 fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAddressRequest.java diff --git a/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/component/FetcherRule.java b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/component/FetcherRule.java new file mode 100644 index 000000000..746d88531 --- /dev/null +++ b/fineract-core/src/main/java/org/apache/fineract/infrastructure/core/component/FetcherRule.java @@ -0,0 +1,38 @@ +/** + * 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.infrastructure.core.component; + +import java.util.function.Function; +import java.util.function.Predicate; +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public class FetcherRule { + + private final Predicate

condition; + private final Function action; + + public boolean matches(P params) { + return condition.test(params); + } + + public R execute(P params) { + return action.apply(params); + } +} diff --git a/fineract-core/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java b/fineract-core/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java index 4742b5608..8e96cacc9 100644 --- a/fineract-core/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java +++ b/fineract-core/src/main/java/org/apache/fineract/portfolio/address/data/AddressData.java @@ -22,8 +22,10 @@ import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDate; import java.util.Collection; +import lombok.Getter; import org.apache.fineract.infrastructure.codes.data.CodeValueData; +@Getter @SuppressWarnings("unused") public class AddressData implements Serializable { diff --git a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java index 7777afb81..622d43e69 100644 --- a/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java +++ b/fineract-e2e-tests-core/src/test/java/org/apache/fineract/test/stepdef/common/ClientStepDef.java @@ -23,8 +23,8 @@ import static org.assertj.core.api.Assertions.assertThat; import io.cucumber.java.en.Then; import io.cucumber.java.en.When; import java.io.IOException; -import java.util.Arrays; -import org.apache.fineract.client.models.PostClientsAddressRequest; +import java.util.Collections; +import org.apache.fineract.client.models.ClientAddressRequest; import org.apache.fineract.client.models.PostClientsRequest; import org.apache.fineract.client.models.PostClientsResponse; import org.apache.fineract.client.services.ClientApi; @@ -92,13 +92,13 @@ public class ClientStepDef extends AbstractStepDef { Long stateId = codeHelper.createStateCodeValue(Utils.randomNameGenerator("Budapest", 4)).body().getResourceId(); String city = "Budapest"; boolean addressIsActive = true; - long postalCode = 1000L; + String postalCode = "1000"; - PostClientsAddressRequest addressRequest = new PostClientsAddressRequest().postalCode(postalCode).city(city).countryId(countryId) + ClientAddressRequest addressRequest = new ClientAddressRequest().postalCode(postalCode).city(city).countryId(countryId) .stateProvinceId(stateId).addressTypeId(addressTypeId).isActive(addressIsActive); PostClientsRequest clientsRequest = clientRequestFactory.defaultClientCreationRequest().firstname(firstName).lastname(lastName) - .address(Arrays.asList(addressRequest)); + .address(Collections.singletonList(addressRequest)); Response response = clientApi.create6(clientsRequest).execute(); ErrorHelper.checkSuccessfulApiCall(response); diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/filter/ClientAddressSearchParam.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/filter/ClientAddressSearchParam.java new file mode 100644 index 000000000..5fb399083 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/address/filter/ClientAddressSearchParam.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.address.filter; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.FieldNameConstants; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@FieldNameConstants +public class ClientAddressSearchParam { + + private Long clientId; + private Long addressTypeId; + private String status; +} 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 index cc9b22d38..49cf27eab 100644 --- 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 @@ -18,20 +18,23 @@ */ package org.apache.fineract.portfolio.address.service; -import java.util.Collection; +import java.util.List; import org.apache.fineract.portfolio.address.data.AddressData; +import org.apache.fineract.portfolio.address.filter.ClientAddressSearchParam; public interface AddressReadPlatformService { - Collection retrieveAddressFields(long clientid); + List retrieveAddressFields(long clientid); - Collection retrieveAllClientAddress(long clientid); + List retrieveAllClientAddress(long clientid); - Collection retrieveAddressbyType(long clientid, long typeid); + List retrieveAddressbyType(long clientid, long typeid); - Collection retrieveAddressbyTypeAndStatus(long clientid, long typeid, String status); + List retrieveAddressbyTypeAndStatus(long clientid, long typeid, String status); - Collection retrieveAddressbyStatus(long clientid, String status); + List retrieveAddressbyStatus(long clientid, String status); + + List retrieveBySearchParam(ClientAddressSearchParam searchFilter); AddressData retrieveTemplate(); } 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 index 5e0a60f4d..249d60c1c 100644 --- 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 @@ -23,33 +23,26 @@ import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDate; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; +import lombok.RequiredArgsConstructor; import org.apache.fineract.infrastructure.codes.data.CodeValueData; import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService; +import org.apache.fineract.infrastructure.core.component.FetcherRule; 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.apache.fineract.portfolio.address.filter.ClientAddressSearchParam; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.stereotype.Service; @Service +@RequiredArgsConstructor public class AddressReadPlatformServiceImpl implements AddressReadPlatformService { private final JdbcTemplate jdbcTemplate; private final PlatformSecurityContext context; private final CodeValueReadPlatformService readService; - @Autowired - public AddressReadPlatformServiceImpl(final PlatformSecurityContext context, final JdbcTemplate jdbcTemplate, - final CodeValueReadPlatformService readService) { - this.context = context; - this.jdbcTemplate = jdbcTemplate; - this.readService = readService; - } - private static final class AddFieldsMapper implements RowMapper { public String schema() { @@ -178,7 +171,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic } @Override - public Collection retrieveAddressFields(final long clientid) { + public List retrieveAddressFields(final long clientid) { this.context.authenticatedUser(); final AddFieldsMapper rm = new AddFieldsMapper(); @@ -188,7 +181,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic } @Override - public Collection retrieveAllClientAddress(final long clientid) { + public List retrieveAllClientAddress(final long clientid) { this.context.authenticatedUser(); final AddMapper rm = new AddMapper(); final String sql = "select " + rm.schema() + " and ca.client_id=?"; @@ -196,7 +189,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic } @Override - public Collection retrieveAddressbyType(final long clientid, final long typeid) { + public List retrieveAddressbyType(final long clientid, final long typeid) { this.context.authenticatedUser(); final AddMapper rm = new AddMapper(); @@ -206,7 +199,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic } @Override - public Collection retrieveAddressbyTypeAndStatus(final long clientid, final long typeid, final String status) { + public List retrieveAddressbyTypeAndStatus(final long clientid, final long typeid, final String status) { this.context.authenticatedUser(); boolean temp = Boolean.parseBoolean(status); @@ -217,7 +210,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic } @Override - public Collection retrieveAddressbyStatus(final long clientid, final String status) { + public List retrieveAddressbyStatus(final long clientid, final String status) { this.context.authenticatedUser(); boolean temp = Boolean.parseBoolean(status); @@ -227,14 +220,29 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic return this.jdbcTemplate.query(sql, rm, new Object[] { clientid, temp }); // NOSONAR } + @Override + public List retrieveBySearchParam(ClientAddressSearchParam params) { + return getFilterRules().stream().filter(rule -> rule.matches(params)).map(r -> r.execute(params)).findFirst() + .orElse(retrieveAddressbyStatus(params.getClientId(), params.getStatus())); + } + @Override public AddressData retrieveTemplate() { - final List countryoptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("COUNTRY")); + final List countryoptions = this.readService.retrieveCodeValuesByCode("COUNTRY"); - final List StateOptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("STATE")); + final List StateOptions = this.readService.retrieveCodeValuesByCode("STATE"); - final List addressTypeOptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("ADDRESS_TYPE")); + final List addressTypeOptions = this.readService.retrieveCodeValuesByCode("ADDRESS_TYPE"); return AddressData.template(countryoptions, StateOptions, addressTypeOptions); } + + private List>> getFilterRules() { + return List.of( + new FetcherRule<>(p -> p.getAddressTypeId() == 0 && p.getStatus() == null, p -> retrieveAllClientAddress(p.getClientId())), + new FetcherRule<>(p -> p.getAddressTypeId() != 0 && p.getStatus() == null, + p -> retrieveAddressbyType(p.getClientId(), p.getAddressTypeId())), + new FetcherRule<>(p -> p.getAddressTypeId() != 0 && p.getStatus() != null, + p -> retrieveAddressbyTypeAndStatus(p.getClientId(), p.getAddressTypeId(), p.getStatus()))); + } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResource.java index 01f4d964c..b496f0691 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResource.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResource.java @@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.client.api; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.parameters.RequestBody; @@ -35,24 +34,19 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.QueryParam; -import jakarta.ws.rs.core.Context; import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.UriInfo; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; +import java.util.List; import lombok.RequiredArgsConstructor; 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.filter.ClientAddressSearchParam; import org.apache.fineract.portfolio.address.service.AddressReadPlatformServiceImpl; +import org.apache.fineract.portfolio.client.data.ClientAddressRequest; import org.springframework.stereotype.Component; @Path("/v1/client") @@ -61,29 +55,19 @@ import org.springframework.stereotype.Component; @RequiredArgsConstructor public class ClientAddressApiResource { - private static final Set 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 static final String RESOURCE_NAME_FOR_PERMISSIONS = "Address"; private final PlatformSecurityContext context; private final AddressReadPlatformServiceImpl readPlatformService; private final DefaultToApiJsonSerializer toApiJsonSerializer; - private final ApiRequestParameterHelper apiRequestParameterHelper; private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService; @GET @Path("addresses/template") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public String getAddressesTemplate(@Context final UriInfo uriInfo) { - this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); - - final AddressData template = this.readPlatformService.retrieveTemplate(); - - final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters()); - return this.toApiJsonSerializer.serialize(settings, template, RESPONSE_DATA_PARAMETERS); + public AddressData getAddressesTemplate() { + context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); + return readPlatformService.retrieveTemplate(); } @@ -92,19 +76,16 @@ public class ClientAddressApiResource { @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "Create an address for a Client", description = "Mandatory Fields : \n" + "type and clientId") - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = ClientAddressApiResourcesSwagger.PostClientClientIdAddressesRequest.class))) + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = ClientAddressRequest.class))) @ApiResponses({ @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ClientAddressApiResourcesSwagger.PostClientClientIdAddressesResponse.class))) }) - public String addClientAddress(@QueryParam("type") @Parameter(description = "type") final long addressTypeId, + public CommandProcessingResult addClientAddress(@QueryParam("type") @Parameter(description = "type") final long addressTypeId, @PathParam("clientid") @Parameter(description = "clientId") final long clientid, - @Parameter(hidden = true) final String apiRequestBodyAsJson) { - + @Parameter(hidden = true) ClientAddressRequest clientAddressRequest) { final CommandWrapper commandRequest = new CommandWrapperBuilder().addClientAddress(clientid, addressTypeId) - .withJson(apiRequestBodyAsJson).build(); + .withJson(toApiJsonSerializer.serialize(clientAddressRequest)).build(); - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); - - return this.toApiJsonSerializer.serialize(result); + return commandsSourceWritePlatformService.logCommandSource(commandRequest); } @GET @@ -113,30 +94,11 @@ public class ClientAddressApiResource { @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "List all addresses for a Client", description = "Example Requests:\n" + "\n" + "client/1/addresses\n" + "\n" + "\n" + "clients/1/addresses?status=false,true&&type=1,2,3") - @ApiResponses({ - @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ClientAddressApiResourcesSwagger.GetClientClientIdAddressesResponse.class)))) }) - public String getAddresses(@QueryParam("status") @Parameter(description = "status") final String status, + public List getAddresses(@QueryParam("status") @Parameter(description = "status") final String status, @QueryParam("type") @Parameter(description = "type") final long addressTypeId, - @PathParam("clientid") @Parameter(description = "clientId") final long clientid, @Context final UriInfo uriInfo) { - Collection address; - - this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); - - // TODO: This is quite a confusing implementation with all these checks - // These have to be considered as filtering criterias instead - 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, RESPONSE_DATA_PARAMETERS); - + @PathParam("clientid") @Parameter(description = "clientId") final long clientid) { + context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); + return readPlatformService.retrieveBySearchParam(new ClientAddressSearchParam(clientid, addressTypeId, status)); } @PUT @@ -145,18 +107,14 @@ public class ClientAddressApiResource { @Produces({ MediaType.APPLICATION_JSON }) @Operation(summary = "Update an address for a Client", description = "All the address fields can be updated by using update client address API\n" + "\n" + "Mandatory Fields\n" + "type and addressId") - @RequestBody(required = true, content = @Content(schema = @Schema(implementation = ClientAddressApiResourcesSwagger.PutClientClientIdAddressesRequest.class))) + @RequestBody(required = true, content = @Content(schema = @Schema(implementation = ClientAddressRequest.class))) @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ClientAddressApiResourcesSwagger.PutClientClientIdAddressesResponse.class))) }) - public String updateClientAddress(@PathParam("clientid") @Parameter(description = "clientId") final long clientid, - @Parameter(hidden = true) final String apiRequestBodyAsJson) { + public CommandProcessingResult updateClientAddress(@PathParam("clientid") @Parameter(description = "clientId") final long clientid, + @Parameter(hidden = true) ClientAddressRequest clientAddressRequest) { - final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClientAddress(clientid).withJson(apiRequestBodyAsJson) - .build(); - - final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest); - - return this.toApiJsonSerializer.serialize(result); + final CommandWrapper commandRequest = new CommandWrapperBuilder().updateClientAddress(clientid) + .withJson(toApiJsonSerializer.serialize(clientAddressRequest)).build(); + return commandsSourceWritePlatformService.logCommandSource(commandRequest); } - } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResourcesSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResourcesSwagger.java index 5b557fc0a..2bb2d1832 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResourcesSwagger.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientAddressApiResourcesSwagger.java @@ -28,31 +28,6 @@ final class ClientAddressApiResourcesSwagger { private ClientAddressApiResourcesSwagger() {} - @Schema(description = "PostClientClientIdAddressesRequest") - public static final class PostClientClientIdAddressesRequest { - - private PostClientClientIdAddressesRequest() {} - - @Schema(example = "Ipca") - public String street; - @Schema(example = "Kandivali") - public String addressLine1; - @Schema(example = "plot47") - public String addressLine2; - @Schema(example = "charkop") - public String addressLine3; - @Schema(example = "Mumbai") - public String city; - @Schema(example = "800") - public Long stateProvinceId; - @Schema(example = "802") - public Long countryId; - @Schema(example = "400064") - public Long postalCode; - @Schema(example = "true") - public Boolean isActive; - } - @Schema(description = "PostClientClientIdAddressesResponse") public static final class PostClientClientIdAddressesResponse { @@ -62,62 +37,6 @@ final class ClientAddressApiResourcesSwagger { public Long resourceId; } - @Schema(description = "GetClientClientIdAddressesResponse") - public static final class GetClientClientIdAddressesResponse { - - private GetClientClientIdAddressesResponse() {} - - @Schema(example = "111755") - public Long client_id; - @Schema(example = "PERMANENT ADDRESS") - public String addressType; - @Schema(example = "14") - public Long addressId; - @Schema(example = "804") - public Long addressTypeId; - @Schema(example = "false") - public Boolean isActive; - @Schema(example = "anki's home") - public String street; - @Schema(example = "test123") - public String addressLine1; - @Schema(example = "iuyt") - public String addressLine2; - @Schema(example = " ") - public String addressLine3; - @Schema(example = " ") - public String townVillage; - @Schema(example = "mumbai") - public String city; - @Schema(example = " ") - public String countyDistrict; - @Schema(example = "801") - public Long stateProvinceId; - @Schema(example = "UNITED STATES") - public String countryName; - @Schema(example = "GUJRAT") - public String stateName; - @Schema(example = "807") - public Long countryId; - @Schema(example = "400095") - public Long postalCode; - @Schema(example = " ") - public String createdBy; - @Schema(example = " ") - public String updatedBy; - } - - @Schema(description = "PutClientClientIdAddressesRequest") - public static final class PutClientClientIdAddressesRequest { - - private PutClientClientIdAddressesRequest() {} - - @Schema(example = "67") - public Long addressId; - @Schema(example = "goldensource") - public String street; - } - @Schema(description = "PutClientClientIdAddressesResponse") public static final class PutClientClientIdAddressesResponse { diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResourceSwagger.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResourceSwagger.java index b93d6612c..7ab477c00 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResourceSwagger.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/api/ClientsApiResourceSwagger.java @@ -23,6 +23,7 @@ import java.time.LocalDate; import java.util.HashMap; import java.util.List; import java.util.Set; +import org.apache.fineract.portfolio.client.data.ClientAddressRequest; /** * Created by Chirag Gupta on 01/13/18. @@ -327,7 +328,7 @@ final class ClientsApiResourceSwagger { @Schema(description = "List of PostClientsDatatable") public List datatables; @Schema(description = "Address requests") - public List address; + public List address; @Schema(example = "test@test.com") public String emailAddress; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAddressRequest.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAddressRequest.java new file mode 100644 index 000000000..5df556aa9 --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/client/data/ClientAddressRequest.java @@ -0,0 +1,52 @@ +/** + * 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.data; + +import java.io.Serial; +import java.io.Serializable; +import java.math.BigDecimal; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +public class ClientAddressRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private String city; + private Long countryId; + private Boolean isActive; + private String postalCode; + private Long addressTypeId; + private String addressLine1; + private String addressLine2; + private String addressLine3; + private String townVillage; + private String countyDistrict; + private Long stateProvinceId; + private BigDecimal latitude; + private BigDecimal longitude; + private String createdBy; + private String createdOn; + private String updatedBy; + private String updatedOn; + private Long addressId; +} diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientTest.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientTest.java index 1a992c812..7e44cbfc3 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientTest.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/ClientTest.java @@ -35,12 +35,11 @@ import java.security.SecureRandom; import java.util.HashMap; import java.util.List; import java.util.UUID; -import org.apache.fineract.client.models.GetClientClientIdAddressesResponse; +import org.apache.fineract.client.models.AddressData; +import org.apache.fineract.client.models.ClientAddressRequest; import org.apache.fineract.client.models.GetClientsClientIdResponse; import org.apache.fineract.client.models.GlobalConfigurationPropertyData; -import org.apache.fineract.client.models.PostClientClientIdAddressesRequest; import org.apache.fineract.client.models.PostClientClientIdAddressesResponse; -import org.apache.fineract.client.models.PostClientsAddressRequest; import org.apache.fineract.client.models.PostClientsRequest; import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; @@ -218,10 +217,10 @@ public class ClientTest { Integer stateId = CodeHelper.createStateCodeValue(requestSpec, responseSpec, Utils.randomStringGenerator("Budapest", 4), 0); String city = "Budapest"; boolean addressIsActive = true; - long postalCode = 1000L; + String postalCode = "1000"; // when - PostClientsAddressRequest addressRequest = new PostClientsAddressRequest().postalCode(postalCode).city(city) + ClientAddressRequest addressRequest = new ClientAddressRequest().postalCode(postalCode).city(city) .countryId(Long.valueOf(countryId)).stateProvinceId(Long.valueOf(stateId)).addressTypeId(addressTypeId.longValue()) .isActive(addressIsActive); PostClientsRequest request = ClientHelper.defaultClientCreationRequest().address(List.of(addressRequest)); @@ -229,8 +228,8 @@ public class ClientTest { // then ClientHelper.verifyClientCreatedOnServer(requestSpec, responseSpec, clientId); - List clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId); - GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0); + List clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId); + AddressData addressResponse = clientAddresses.get(0); assertThat(addressResponse.getCity()).isEqualTo(city); assertThat(addressResponse.getCountryId()).isEqualTo((long) countryId); assertThat(addressResponse.getStateProvinceId()).isEqualTo((long) stateId); @@ -248,19 +247,19 @@ public class ClientTest { Integer stateId = CodeHelper.createStateCodeValue(requestSpec, responseSpec, Utils.randomStringGenerator("Budapest", 4), 0); String city = "Budapest"; boolean addressIsActive = true; - long postalCode = 1000L; + String postalCode = "1000"; PostClientsRequest clientRequest = ClientHelper.defaultClientCreationRequest(); final Integer clientId = ClientHelper.createClient(requestSpec, responseSpec, clientRequest); // when - PostClientClientIdAddressesRequest request = new PostClientClientIdAddressesRequest().postalCode(postalCode).city(city) - .countryId(Long.valueOf(countryId)).stateProvinceId(Long.valueOf(stateId)).isActive(addressIsActive); + ClientAddressRequest request = new ClientAddressRequest().postalCode(postalCode).city(city).countryId(Long.valueOf(countryId)) + .stateProvinceId(Long.valueOf(stateId)).isActive(addressIsActive); PostClientClientIdAddressesResponse response = ClientHelper.createClientAddress(requestSpec, responseSpec, clientId.longValue(), addressTypeId, request); // then assertThat(response.getResourceId()).isNotNull(); - List clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId); - GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0); + List clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId); + AddressData addressResponse = clientAddresses.get(0); assertThat(addressResponse.getCity()).isEqualTo(city); assertThat(addressResponse.getCountryId()).isEqualTo((long) countryId); assertThat(addressResponse.getStateProvinceId()).isEqualTo((long) stateId); diff --git a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java index 0a1e7aaf9..7b573576f 100644 --- a/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java +++ b/integration-tests/src/test/java/org/apache/fineract/integrationtests/common/ClientHelper.java @@ -38,9 +38,10 @@ import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.apache.fineract.client.models.AddressData; +import org.apache.fineract.client.models.ClientAddressRequest; import org.apache.fineract.client.models.ClientTextSearch; import org.apache.fineract.client.models.DeleteClientsClientIdResponse; -import org.apache.fineract.client.models.GetClientClientIdAddressesResponse; import org.apache.fineract.client.models.GetClientTransferProposalDateResponse; import org.apache.fineract.client.models.GetClientsClientIdAccountsResponse; import org.apache.fineract.client.models.GetClientsClientIdResponse; @@ -50,7 +51,6 @@ import org.apache.fineract.client.models.GetObligeeData; import org.apache.fineract.client.models.LoanAccountLockResponseDTO; import org.apache.fineract.client.models.PageClientSearchData; import org.apache.fineract.client.models.PagedRequestClientTextSearch; -import org.apache.fineract.client.models.PostClientClientIdAddressesRequest; import org.apache.fineract.client.models.PostClientClientIdAddressesResponse; import org.apache.fineract.client.models.PostClientsClientIdIdentifiersRequest; import org.apache.fineract.client.models.PostClientsClientIdIdentifiersResponse; @@ -263,7 +263,7 @@ public class ClientHelper { // org.apache.fineract.client.models.PostLoansLoanIdRequest) @Deprecated(forRemoval = true) public static PostClientClientIdAddressesResponse createClientAddress(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, long clientId, long addressTypeId, PostClientClientIdAddressesRequest request) { + final ResponseSpecification responseSpec, long clientId, long addressTypeId, ClientAddressRequest request) { final String CREATE_CLIENT_ADDRESS_URL = "/fineract-provider/api/v1/client/" + clientId + "/addresses?type=" + addressTypeId + "&" + Utils.TENANT_IDENTIFIER; log.info("---------------------------------CREATING A CLIENT ADDRESS ---------------------------------------------"); @@ -659,12 +659,12 @@ public class ClientHelper { // Example: org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper.disburseLoan(java.lang.Long, // org.apache.fineract.client.models.PostLoansLoanIdRequest) @Deprecated(forRemoval = true) - public static List getClientAddresses(final RequestSpecification requestSpec, - final ResponseSpecification responseSpec, final int clientId) { + public static List getClientAddresses(final RequestSpecification requestSpec, final ResponseSpecification responseSpec, + final int clientId) { final String GET_CLIENT_ADDRESSES_URL = "/fineract-provider/api/v1/client/" + clientId + "/addresses?" + Utils.TENANT_IDENTIFIER; log.info("---------------------------------GET A CLIENT'S ADDRESSES ---------------------------------------------"); String clientResponseStr = Utils.performServerGet(requestSpec, responseSpec, GET_CLIENT_ADDRESSES_URL); - return GSON.fromJson(clientResponseStr, new TypeToken>() {}.getType()); + return GSON.fromJson(clientResponseStr, new TypeToken>() {}.getType()); } // TODO: Rewrite to use fineract-client instead!