FINERACT-2169: Refactor client address controller;
This commit is contained in:
committed by
Adam Saghy
parent
99f12d6091
commit
30543fd72e
+38
@@ -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<P, R> {
|
||||
|
||||
private final Predicate<P> condition;
|
||||
private final Function<P, R> action;
|
||||
|
||||
public boolean matches(P params) {
|
||||
return condition.test(params);
|
||||
}
|
||||
|
||||
public R execute(P params) {
|
||||
return action.apply(params);
|
||||
}
|
||||
}
|
||||
+2
@@ -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 {
|
||||
|
||||
|
||||
+5
-5
@@ -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<PostClientsResponse> response = clientApi.create6(clientsRequest).execute();
|
||||
ErrorHelper.checkSuccessfulApiCall(response);
|
||||
|
||||
+35
@@ -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;
|
||||
}
|
||||
+9
-6
@@ -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<AddressData> retrieveAddressFields(long clientid);
|
||||
List<AddressData> retrieveAddressFields(long clientid);
|
||||
|
||||
Collection<AddressData> retrieveAllClientAddress(long clientid);
|
||||
List<AddressData> retrieveAllClientAddress(long clientid);
|
||||
|
||||
Collection<AddressData> retrieveAddressbyType(long clientid, long typeid);
|
||||
List<AddressData> retrieveAddressbyType(long clientid, long typeid);
|
||||
|
||||
Collection<AddressData> retrieveAddressbyTypeAndStatus(long clientid, long typeid, String status);
|
||||
List<AddressData> retrieveAddressbyTypeAndStatus(long clientid, long typeid, String status);
|
||||
|
||||
Collection<AddressData> retrieveAddressbyStatus(long clientid, String status);
|
||||
List<AddressData> retrieveAddressbyStatus(long clientid, String status);
|
||||
|
||||
List<AddressData> retrieveBySearchParam(ClientAddressSearchParam searchFilter);
|
||||
|
||||
AddressData retrieveTemplate();
|
||||
}
|
||||
|
||||
+27
-19
@@ -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<AddressData> {
|
||||
|
||||
public String schema() {
|
||||
@@ -178,7 +171,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AddressData> retrieveAddressFields(final long clientid) {
|
||||
public List<AddressData> retrieveAddressFields(final long clientid) {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
final AddFieldsMapper rm = new AddFieldsMapper();
|
||||
@@ -188,7 +181,7 @@ public class AddressReadPlatformServiceImpl implements AddressReadPlatformServic
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AddressData> retrieveAllClientAddress(final long clientid) {
|
||||
public List<AddressData> 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<AddressData> retrieveAddressbyType(final long clientid, final long typeid) {
|
||||
public List<AddressData> 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<AddressData> retrieveAddressbyTypeAndStatus(final long clientid, final long typeid, final String status) {
|
||||
public List<AddressData> 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<AddressData> retrieveAddressbyStatus(final long clientid, final String status) {
|
||||
public List<AddressData> 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<AddressData> 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<CodeValueData> countryoptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("COUNTRY"));
|
||||
final List<CodeValueData> countryoptions = this.readService.retrieveCodeValuesByCode("COUNTRY");
|
||||
|
||||
final List<CodeValueData> StateOptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("STATE"));
|
||||
final List<CodeValueData> StateOptions = this.readService.retrieveCodeValuesByCode("STATE");
|
||||
|
||||
final List<CodeValueData> addressTypeOptions = new ArrayList<>(this.readService.retrieveCodeValuesByCode("ADDRESS_TYPE"));
|
||||
final List<CodeValueData> addressTypeOptions = this.readService.retrieveCodeValuesByCode("ADDRESS_TYPE");
|
||||
|
||||
return AddressData.template(countryoptions, StateOptions, addressTypeOptions);
|
||||
}
|
||||
|
||||
private List<FetcherRule<ClientAddressSearchParam, List<AddressData>>> 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())));
|
||||
}
|
||||
}
|
||||
|
||||
+21
-63
@@ -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<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 static final String RESOURCE_NAME_FOR_PERMISSIONS = "Address";
|
||||
private final PlatformSecurityContext context;
|
||||
private final AddressReadPlatformServiceImpl readPlatformService;
|
||||
private final DefaultToApiJsonSerializer<AddressData> 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<AddressData> 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<AddressData> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-81
@@ -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 {
|
||||
|
||||
|
||||
+2
-1
@@ -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<PostClientsDatatable> datatables;
|
||||
@Schema(description = "Address requests")
|
||||
public List<PostClientsAddressRequest> address;
|
||||
public List<ClientAddressRequest> address;
|
||||
@Schema(example = "test@test.com")
|
||||
public String emailAddress;
|
||||
}
|
||||
|
||||
+52
@@ -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;
|
||||
}
|
||||
+11
-12
@@ -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<GetClientClientIdAddressesResponse> clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId);
|
||||
GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0);
|
||||
List<AddressData> 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<GetClientClientIdAddressesResponse> clientAddresses = ClientHelper.getClientAddresses(requestSpec, responseSpec, clientId);
|
||||
GetClientClientIdAddressesResponse addressResponse = clientAddresses.get(0);
|
||||
List<AddressData> 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);
|
||||
|
||||
+6
-6
@@ -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<GetClientClientIdAddressesResponse> getClientAddresses(final RequestSpecification requestSpec,
|
||||
final ResponseSpecification responseSpec, final int clientId) {
|
||||
public static List<AddressData> 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<List<GetClientClientIdAddressesResponse>>() {}.getType());
|
||||
return GSON.fromJson(clientResponseStr, new TypeToken<List<AddressData>>() {}.getType());
|
||||
}
|
||||
|
||||
// TODO: Rewrite to use fineract-client instead!
|
||||
|
||||
Reference in New Issue
Block a user