FINERACT-2169: Apply dto in CollateralManagementApiResource

This commit is contained in:
oleksandr.masliuk
2025-04-01 10:02:47 +02:00
committed by Adam Saghy
parent 957666df18
commit 510b4853e7
8 changed files with 98 additions and 155 deletions
@@ -18,14 +18,14 @@
*/
package org.apache.fineract.organisation.monetary.service;
import java.util.Collection;
import java.util.List;
import org.apache.fineract.organisation.monetary.data.CurrencyData;
public interface CurrencyReadPlatformService {
Collection<CurrencyData> retrieveAllowedCurrencies();
List<CurrencyData> retrieveAllowedCurrencies();
Collection<CurrencyData> retrieveAllPlatformCurrencies();
List<CurrencyData> retrieveAllPlatformCurrencies();
CurrencyData retrieveCurrency(String code);
}
@@ -20,7 +20,7 @@ package org.apache.fineract.organisation.monetary.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -36,7 +36,7 @@ public class CurrencyReadPlatformServiceImpl implements CurrencyReadPlatformServ
private final CurrencyMapper currencyRowMapper = new CurrencyMapper();
@Override
public Collection<CurrencyData> retrieveAllowedCurrencies() {
public List<CurrencyData> retrieveAllowedCurrencies() {
this.context.authenticatedUser();
@@ -46,7 +46,7 @@ public class CurrencyReadPlatformServiceImpl implements CurrencyReadPlatformServ
}
@Override
public Collection<CurrencyData> retrieveAllPlatformCurrencies() {
public List<CurrencyData> retrieveAllPlatformCurrencies() {
final String sql = "select " + this.currencyRowMapper.schema() + " from m_currency c order by c.name";
@@ -48,7 +48,6 @@ 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.codes.service.CodeValueReadPlatformService;
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -67,7 +66,6 @@ public class ClientCollateralManagementApiResource {
private final DefaultToApiJsonSerializer<ClientCollateralManagement> apiJsonSerializerService;
private final DefaultToApiJsonSerializer<ClientCollateralManagementData> apiJsonSerializerDataService;
private final DefaultToApiJsonSerializer<LoanCollateralTemplateData> apiJsonSerializerForLoanCollateralTemplateService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final PlatformSecurityContext context;
private final CodeValueReadPlatformService codeValueReadPlatformService;
@@ -20,7 +20,6 @@ package org.apache.fineract.portfolio.collateralmanagement.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,10 +34,8 @@ import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
@@ -49,6 +46,8 @@ import org.apache.fineract.infrastructure.security.service.PlatformSecurityConte
import org.apache.fineract.organisation.monetary.data.CurrencyData;
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementData;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementProductRequest;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductRequest;
import org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadPlatformService;
import org.springframework.stereotype.Component;
@@ -69,13 +68,14 @@ public class CollateralManagementApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a new collateral", description = "Collateral Creation")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PostCollateralManagementProductRequest.class)))
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementProductRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PostCollateralManagementProductResponse.class))) })
public String createCollateral(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().createCollateral().withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.apiJsonSerializerService.serialize(commandProcessingResult);
public CommandProcessingResult createCollateral(
@Parameter(hidden = true) final CollateralManagementProductRequest collateralManagementProductRequest) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().createCollateral()
.withJson(apiJsonSerializerService.serialize(collateralManagementProductRequest)).build();
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
}
@GET
@@ -83,32 +83,23 @@ public class CollateralManagementApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get Collateral", description = "Fetch Collateral")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.class))) })
public String getCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
@Context final UriInfo uriInfo) {
public CollateralManagementData getCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
this.context.authenticatedUser()
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
final CollateralManagementData collateralManagementData = this.collateralManagementReadPlatformService
.getCollateralProduct(collateralId);
return this.apiJsonSerializerService.serialize(collateralManagementData);
return this.collateralManagementReadPlatformService.getCollateralProduct(collateralId);
}
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get All Collaterals", description = "Fetch all Collateral Products")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.class)))) })
public String getAllCollaterals(@Context final UriInfo uriInfo) {
public List<CollateralManagementData> getAllCollaterals() {
this.context.authenticatedUser()
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
Collection<CollateralManagementData> collateralManagementDataList = this.collateralManagementReadPlatformService
.getAllCollateralProducts();
return this.apiJsonSerializerService.serialize(collateralManagementDataList);
return this.collateralManagementReadPlatformService.getAllCollateralProducts();
}
@GET
@@ -116,11 +107,8 @@ public class CollateralManagementApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Get Collateral Template", description = "Get Collateral Template")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralProductTemplate.class)))) })
public String getCollateralTemplate(@Context final UriInfo uriInfo) {
Collection<CurrencyData> currencyDataCollection = this.currencyReadPlatformService.retrieveAllPlatformCurrencies();
return this.apiJsonSerializerServiceForCurrency.serialize(currencyDataCollection);
public List<CurrencyData> getCollateralTemplate() {
return currencyReadPlatformService.retrieveAllPlatformCurrencies();
}
@PUT
@@ -128,17 +116,16 @@ public class CollateralManagementApiResource {
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update Collateral", description = "Update Collateral")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PutCollateralProductRequest.class)))
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralProductRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PutCollateralProductResponse.class))) })
public String updateCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
@Parameter(hidden = true) final String jsonBody) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().updateCollateralProduct(collateralId).withJson(jsonBody).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
return this.apiJsonSerializerService.serialize(commandProcessingResult);
public CommandProcessingResult updateCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
@Parameter(hidden = true) final CollateralProductRequest collateralProductRequest) {
final CommandWrapper commandWrapper = new CommandWrapperBuilder().updateCollateralProduct(collateralId)
.withJson(apiJsonSerializerService.serialize(collateralProductRequest)).build();
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
}
@DELETE
@@ -148,13 +135,12 @@ public class CollateralManagementApiResource {
@Operation(summary = "Delete a Collateral", description = "Delete Collateral")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.DeleteCollateralProductResponse.class))) })
public String deleteCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
public CommandProcessingResult deleteCollateral(
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteCollateralProduct(collateralId).build();
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.apiJsonSerializerService.serialize(commandProcessingResult);
return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
@@ -19,96 +19,12 @@
package org.apache.fineract.portfolio.collateralmanagement.api;
import io.swagger.v3.oas.annotations.media.Schema;
import java.math.BigDecimal;
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductRequest;
final class CollateralManagementApiResourceSwagger {
private CollateralManagementApiResourceSwagger() {}
@Schema(description = "GetCollateralManagementsResponse")
public static final class GetCollateralManagementsResponse {
private GetCollateralManagementsResponse() {}
static final class GetCollateralTypeResponse {
private GetCollateralTypeResponse() {}
@Schema(example = "22kt")
public String quality;
}
static final class GetCollateralCurrencyResponse {
private GetCollateralCurrencyResponse() {}
@Schema(example = "USD")
public String code;
}
@Schema(example = "8")
public Long id;
@Schema(example = "Gold")
public String name;
private CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.GetCollateralTypeResponse quality;
@Schema(example = "20000")
public BigDecimal basePrice;
@Schema(example = "gm")
public String unitType;
@Schema(example = "80")
public BigDecimal pctToBase;
public CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.GetCollateralCurrencyResponse currency;
}
@Schema(description = "GetCollateralProductTemplate")
public static final class GetCollateralProductTemplate {
private GetCollateralProductTemplate() {}
static final class GetCurrencyData {
private GetCurrencyData() {}
@Schema(example = "USD")
public String code;
@Schema(example = "Dollars")
public String name;
@Schema(example = "10")
public int decimalPlaces;
@Schema(example = "2")
public Integer inMultiplesOf;
@Schema(example = "USD")
public String displaySymbol;
@Schema(example = "Dollars")
public String nameCode;
@Schema(example = "Dollars")
public String displayLabel;
}
public GetCurrencyData currency;
}
@Schema(description = "PostCollateralManagementProductRequest")
public static final class PostCollateralManagementProductRequest {
private PostCollateralManagementProductRequest() {}
@Schema(example = "22kt")
public String quality;
@Schema(example = "4500")
public BigDecimal basePrice;
@Schema(example = "80")
public BigDecimal pctToBase;
@Schema(example = "gm")
public String unitType;
@Schema(example = "gold")
public String name;
@Schema(example = "USD")
public String currency;
}
@Schema(description = "PostCollateralManagementProductResponse")
public static final class PostCollateralManagementProductResponse {
@@ -118,26 +34,6 @@ final class CollateralManagementApiResourceSwagger {
public Long resourceId;
}
@Schema(description = "PutCollateralProductRequest")
public static final class PutCollateralProductRequest {
private PutCollateralProductRequest() {}
@Schema(example = "22kt")
public String quality;
@Schema(example = "4500")
public BigDecimal basePrice;
@Schema(example = "80")
public BigDecimal pctToBase;
@Schema(example = "gm")
public String unitType;
@Schema(example = "gold")
public String name;
@Schema(example = "USD")
public String currency;
}
@Schema(description = "PutCollateralProductResponse")
public static final class PutCollateralProductResponse {
@@ -145,7 +41,7 @@ final class CollateralManagementApiResourceSwagger {
@Schema(example = "12")
public Long resourceId;
public CollateralManagementApiResourceSwagger.PutCollateralProductRequest changes;
public CollateralProductRequest changes;
}
@Schema(description = "DeleteCollateralProductResponse")
@@ -18,10 +18,13 @@
*/
package org.apache.fineract.portfolio.collateralmanagement.data;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Getter;
import org.apache.fineract.portfolio.collateralmanagement.domain.CollateralManagementDomain;
public final class CollateralManagementData {
@Getter
public final class CollateralManagementData implements Serializable {
private String quality;
@@ -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.collateralmanagement.data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
public record CollateralManagementProductRequest(String quality, BigDecimal basePrice, BigDecimal pctToBase, String unitType, String name,
String currency, String locale) implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}
@@ -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.collateralmanagement.data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
public record CollateralProductRequest(String quality, BigDecimal basePrice, BigDecimal pctToBase, String unitType, String name,
String currency) implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
}