Skip to content

Commit 510b485

Browse files
oleksmaadamsaghy
authored andcommitted
FINERACT-2169: Apply dto in CollateralManagementApiResource
1 parent 957666d commit 510b485

File tree

8 files changed

+98
-155
lines changed

8 files changed

+98
-155
lines changed

fineract-core/src/main/java/org/apache/fineract/organisation/monetary/service/CurrencyReadPlatformService.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
*/
1919
package org.apache.fineract.organisation.monetary.service;
2020

21-
import java.util.Collection;
21+
import java.util.List;
2222
import org.apache.fineract.organisation.monetary.data.CurrencyData;
2323

2424
public interface CurrencyReadPlatformService {
2525

26-
Collection<CurrencyData> retrieveAllowedCurrencies();
26+
List<CurrencyData> retrieveAllowedCurrencies();
2727

28-
Collection<CurrencyData> retrieveAllPlatformCurrencies();
28+
List<CurrencyData> retrieveAllPlatformCurrencies();
2929

3030
CurrencyData retrieveCurrency(String code);
3131
}

fineract-core/src/main/java/org/apache/fineract/organisation/monetary/service/CurrencyReadPlatformServiceImpl.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import java.sql.ResultSet;
2222
import java.sql.SQLException;
23-
import java.util.Collection;
23+
import java.util.List;
2424
import lombok.RequiredArgsConstructor;
2525
import org.apache.fineract.infrastructure.core.domain.JdbcSupport;
2626
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -36,7 +36,7 @@ public class CurrencyReadPlatformServiceImpl implements CurrencyReadPlatformServ
3636
private final CurrencyMapper currencyRowMapper = new CurrencyMapper();
3737

3838
@Override
39-
public Collection<CurrencyData> retrieveAllowedCurrencies() {
39+
public List<CurrencyData> retrieveAllowedCurrencies() {
4040

4141
this.context.authenticatedUser();
4242

@@ -46,7 +46,7 @@ public Collection<CurrencyData> retrieveAllowedCurrencies() {
4646
}
4747

4848
@Override
49-
public Collection<CurrencyData> retrieveAllPlatformCurrencies() {
49+
public List<CurrencyData> retrieveAllPlatformCurrencies() {
5050

5151
final String sql = "select " + this.currencyRowMapper.schema() + " from m_currency c order by c.name";
5252

fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/ClientCollateralManagementApiResource.java

-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.apache.fineract.commands.service.CommandWrapperBuilder;
4949
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
5050
import org.apache.fineract.infrastructure.codes.service.CodeValueReadPlatformService;
51-
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
5251
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
5352
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
5453
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
@@ -67,7 +66,6 @@ public class ClientCollateralManagementApiResource {
6766
private final DefaultToApiJsonSerializer<ClientCollateralManagement> apiJsonSerializerService;
6867
private final DefaultToApiJsonSerializer<ClientCollateralManagementData> apiJsonSerializerDataService;
6968
private final DefaultToApiJsonSerializer<LoanCollateralTemplateData> apiJsonSerializerForLoanCollateralTemplateService;
70-
private final ApiRequestParameterHelper apiRequestParameterHelper;
7169
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
7270
private final PlatformSecurityContext context;
7371
private final CodeValueReadPlatformService codeValueReadPlatformService;

fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralManagementApiResource.java

+26-40
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import io.swagger.v3.oas.annotations.Operation;
2222
import io.swagger.v3.oas.annotations.Parameter;
23-
import io.swagger.v3.oas.annotations.media.ArraySchema;
2423
import io.swagger.v3.oas.annotations.media.Content;
2524
import io.swagger.v3.oas.annotations.media.Schema;
2625
import io.swagger.v3.oas.annotations.parameters.RequestBody;
@@ -35,10 +34,8 @@
3534
import jakarta.ws.rs.Path;
3635
import jakarta.ws.rs.PathParam;
3736
import jakarta.ws.rs.Produces;
38-
import jakarta.ws.rs.core.Context;
3937
import jakarta.ws.rs.core.MediaType;
40-
import jakarta.ws.rs.core.UriInfo;
41-
import java.util.Collection;
38+
import java.util.List;
4239
import lombok.RequiredArgsConstructor;
4340
import org.apache.fineract.commands.domain.CommandWrapper;
4441
import org.apache.fineract.commands.service.CommandWrapperBuilder;
@@ -49,6 +46,8 @@
4946
import org.apache.fineract.organisation.monetary.data.CurrencyData;
5047
import org.apache.fineract.organisation.monetary.service.CurrencyReadPlatformService;
5148
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementData;
49+
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralManagementProductRequest;
50+
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductRequest;
5251
import org.apache.fineract.portfolio.collateralmanagement.service.CollateralManagementReadPlatformService;
5352
import org.springframework.stereotype.Component;
5453

@@ -69,76 +68,64 @@ public class CollateralManagementApiResource {
6968
@Consumes({ MediaType.APPLICATION_JSON })
7069
@Produces({ MediaType.APPLICATION_JSON })
7170
@Operation(summary = "Create a new collateral", description = "Collateral Creation")
72-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PostCollateralManagementProductRequest.class)))
71+
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementProductRequest.class)))
7372
@ApiResponses({
7473
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PostCollateralManagementProductResponse.class))) })
75-
public String createCollateral(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
76-
final CommandWrapper commandWrapper = new CommandWrapperBuilder().createCollateral().withJson(apiRequestBodyAsJson).build();
77-
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
78-
return this.apiJsonSerializerService.serialize(commandProcessingResult);
74+
public CommandProcessingResult createCollateral(
75+
@Parameter(hidden = true) final CollateralManagementProductRequest collateralManagementProductRequest) {
76+
final CommandWrapper commandWrapper = new CommandWrapperBuilder().createCollateral()
77+
.withJson(apiJsonSerializerService.serialize(collateralManagementProductRequest)).build();
78+
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
7979
}
8080

8181
@GET
8282
@Path("{collateralId}")
8383
@Consumes({ MediaType.APPLICATION_JSON })
8484
@Produces({ MediaType.APPLICATION_JSON })
8585
@Operation(summary = "Get Collateral", description = "Fetch Collateral")
86-
@ApiResponses({
87-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.class))) })
88-
public String getCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
89-
@Context final UriInfo uriInfo) {
86+
public CollateralManagementData getCollateral(
87+
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
9088

9189
this.context.authenticatedUser()
9290
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
9391

94-
final CollateralManagementData collateralManagementData = this.collateralManagementReadPlatformService
95-
.getCollateralProduct(collateralId);
96-
97-
return this.apiJsonSerializerService.serialize(collateralManagementData);
92+
return this.collateralManagementReadPlatformService.getCollateralProduct(collateralId);
9893
}
9994

10095
@GET
10196
@Consumes({ MediaType.APPLICATION_JSON })
10297
@Produces({ MediaType.APPLICATION_JSON })
10398
@Operation(summary = "Get All Collaterals", description = "Fetch all Collateral Products")
104-
@ApiResponses({
105-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.class)))) })
106-
public String getAllCollaterals(@Context final UriInfo uriInfo) {
99+
public List<CollateralManagementData> getAllCollaterals() {
107100
this.context.authenticatedUser()
108101
.validateHasReadPermission(CollateralManagementJsonInputParams.COLLATERAL_PRODUCT_READ_PERMISSION.getValue());
109-
Collection<CollateralManagementData> collateralManagementDataList = this.collateralManagementReadPlatformService
110-
.getAllCollateralProducts();
111-
return this.apiJsonSerializerService.serialize(collateralManagementDataList);
102+
return this.collateralManagementReadPlatformService.getAllCollateralProducts();
112103
}
113104

114105
@GET
115106
@Path("template")
116107
@Consumes({ MediaType.APPLICATION_JSON })
117108
@Produces({ MediaType.APPLICATION_JSON })
118109
@Operation(summary = "Get Collateral Template", description = "Get Collateral Template")
119-
@ApiResponses({
120-
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.GetCollateralProductTemplate.class)))) })
121-
public String getCollateralTemplate(@Context final UriInfo uriInfo) {
122-
Collection<CurrencyData> currencyDataCollection = this.currencyReadPlatformService.retrieveAllPlatformCurrencies();
123-
return this.apiJsonSerializerServiceForCurrency.serialize(currencyDataCollection);
110+
public List<CurrencyData> getCollateralTemplate() {
111+
return currencyReadPlatformService.retrieveAllPlatformCurrencies();
124112
}
125113

126114
@PUT
127115
@Path("{collateralId}")
128116
@Consumes({ MediaType.APPLICATION_JSON })
129117
@Produces({ MediaType.APPLICATION_JSON })
130118
@Operation(summary = "Update Collateral", description = "Update Collateral")
131-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PutCollateralProductRequest.class)))
119+
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = CollateralProductRequest.class)))
132120
@ApiResponses({
133121
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.PutCollateralProductResponse.class))) })
134-
public String updateCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
135-
@Parameter(hidden = true) final String jsonBody) {
136-
final CommandWrapper commandWrapper = new CommandWrapperBuilder().updateCollateralProduct(collateralId).withJson(jsonBody).build();
137-
138-
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
139-
140-
return this.apiJsonSerializerService.serialize(commandProcessingResult);
122+
public CommandProcessingResult updateCollateral(
123+
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId,
124+
@Parameter(hidden = true) final CollateralProductRequest collateralProductRequest) {
125+
final CommandWrapper commandWrapper = new CommandWrapperBuilder().updateCollateralProduct(collateralId)
126+
.withJson(apiJsonSerializerService.serialize(collateralProductRequest)).build();
141127

128+
return this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
142129
}
143130

144131
@DELETE
@@ -148,13 +135,12 @@ public String updateCollateral(@PathParam("collateralId") @Parameter(description
148135
@Operation(summary = "Delete a Collateral", description = "Delete Collateral")
149136
@ApiResponses({
150137
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = CollateralManagementApiResourceSwagger.DeleteCollateralProductResponse.class))) })
151-
public String deleteCollateral(@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
138+
public CommandProcessingResult deleteCollateral(
139+
@PathParam("collateralId") @Parameter(description = "collateralId") final Long collateralId) {
152140

153141
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteCollateralProduct(collateralId).build();
154142

155-
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
156-
157-
return this.apiJsonSerializerService.serialize(commandProcessingResult);
143+
return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
158144
}
159145

160146
}

fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/api/CollateralManagementApiResourceSwagger.java

+2-106
Original file line numberDiff line numberDiff line change
@@ -19,96 +19,12 @@
1919
package org.apache.fineract.portfolio.collateralmanagement.api;
2020

2121
import io.swagger.v3.oas.annotations.media.Schema;
22-
import java.math.BigDecimal;
22+
import org.apache.fineract.portfolio.collateralmanagement.data.CollateralProductRequest;
2323

2424
final class CollateralManagementApiResourceSwagger {
2525

2626
private CollateralManagementApiResourceSwagger() {}
2727

28-
@Schema(description = "GetCollateralManagementsResponse")
29-
public static final class GetCollateralManagementsResponse {
30-
31-
private GetCollateralManagementsResponse() {}
32-
33-
static final class GetCollateralTypeResponse {
34-
35-
private GetCollateralTypeResponse() {}
36-
37-
@Schema(example = "22kt")
38-
public String quality;
39-
40-
}
41-
42-
static final class GetCollateralCurrencyResponse {
43-
44-
private GetCollateralCurrencyResponse() {}
45-
46-
@Schema(example = "USD")
47-
public String code;
48-
}
49-
50-
@Schema(example = "8")
51-
public Long id;
52-
@Schema(example = "Gold")
53-
public String name;
54-
private CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.GetCollateralTypeResponse quality;
55-
@Schema(example = "20000")
56-
public BigDecimal basePrice;
57-
@Schema(example = "gm")
58-
public String unitType;
59-
@Schema(example = "80")
60-
public BigDecimal pctToBase;
61-
public CollateralManagementApiResourceSwagger.GetCollateralManagementsResponse.GetCollateralCurrencyResponse currency;
62-
}
63-
64-
@Schema(description = "GetCollateralProductTemplate")
65-
public static final class GetCollateralProductTemplate {
66-
67-
private GetCollateralProductTemplate() {}
68-
69-
static final class GetCurrencyData {
70-
71-
private GetCurrencyData() {}
72-
73-
@Schema(example = "USD")
74-
public String code;
75-
@Schema(example = "Dollars")
76-
public String name;
77-
@Schema(example = "10")
78-
public int decimalPlaces;
79-
@Schema(example = "2")
80-
public Integer inMultiplesOf;
81-
@Schema(example = "USD")
82-
public String displaySymbol;
83-
@Schema(example = "Dollars")
84-
public String nameCode;
85-
@Schema(example = "Dollars")
86-
public String displayLabel;
87-
88-
}
89-
90-
public GetCurrencyData currency;
91-
}
92-
93-
@Schema(description = "PostCollateralManagementProductRequest")
94-
public static final class PostCollateralManagementProductRequest {
95-
96-
private PostCollateralManagementProductRequest() {}
97-
98-
@Schema(example = "22kt")
99-
public String quality;
100-
@Schema(example = "4500")
101-
public BigDecimal basePrice;
102-
@Schema(example = "80")
103-
public BigDecimal pctToBase;
104-
@Schema(example = "gm")
105-
public String unitType;
106-
@Schema(example = "gold")
107-
public String name;
108-
@Schema(example = "USD")
109-
public String currency;
110-
}
111-
11228
@Schema(description = "PostCollateralManagementProductResponse")
11329
public static final class PostCollateralManagementProductResponse {
11430

@@ -118,34 +34,14 @@ private PostCollateralManagementProductResponse() {}
11834
public Long resourceId;
11935
}
12036

121-
@Schema(description = "PutCollateralProductRequest")
122-
public static final class PutCollateralProductRequest {
123-
124-
private PutCollateralProductRequest() {}
125-
126-
@Schema(example = "22kt")
127-
public String quality;
128-
@Schema(example = "4500")
129-
public BigDecimal basePrice;
130-
@Schema(example = "80")
131-
public BigDecimal pctToBase;
132-
@Schema(example = "gm")
133-
public String unitType;
134-
@Schema(example = "gold")
135-
public String name;
136-
@Schema(example = "USD")
137-
public String currency;
138-
139-
}
140-
14137
@Schema(description = "PutCollateralProductResponse")
14238
public static final class PutCollateralProductResponse {
14339

14440
private PutCollateralProductResponse() {}
14541

14642
@Schema(example = "12")
14743
public Long resourceId;
148-
public CollateralManagementApiResourceSwagger.PutCollateralProductRequest changes;
44+
public CollateralProductRequest changes;
14945
}
15046

15147
@Schema(description = "DeleteCollateralProductResponse")

fineract-provider/src/main/java/org/apache/fineract/portfolio/collateralmanagement/data/CollateralManagementData.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
*/
1919
package org.apache.fineract.portfolio.collateralmanagement.data;
2020

21+
import java.io.Serializable;
2122
import java.math.BigDecimal;
23+
import lombok.Getter;
2224
import org.apache.fineract.portfolio.collateralmanagement.domain.CollateralManagementDomain;
2325

24-
public final class CollateralManagementData {
26+
@Getter
27+
public final class CollateralManagementData implements Serializable {
2528

2629
private String quality;
2730

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.portfolio.collateralmanagement.data;
20+
21+
import java.io.Serial;
22+
import java.io.Serializable;
23+
import java.math.BigDecimal;
24+
25+
public record CollateralManagementProductRequest(String quality, BigDecimal basePrice, BigDecimal pctToBase, String unitType, String name,
26+
String currency, String locale) implements Serializable {
27+
28+
@Serial
29+
private static final long serialVersionUID = 1L;
30+
}

0 commit comments

Comments
 (0)