Skip to content

Commit bb5078b

Browse files
VictorPavfuriousadamsaghy
authored andcommitted
FINERACT-2169: Refactor account transfer api controller;
1 parent e584e26 commit bb5078b

File tree

8 files changed

+305
-218
lines changed

8 files changed

+305
-218
lines changed

fineract-provider/src/main/java/org/apache/fineract/infrastructure/dataqueries/api/RunreportsApiResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
@Path("/v1/runreports")
5555
@Component
56-
@Tag(name = "Run Reports", description = "")
56+
@Tag(name = "Run Reports")
5757
@RequiredArgsConstructor
5858
public class RunreportsApiResource {
5959

@@ -69,7 +69,7 @@ public class RunreportsApiResource {
6969
@Produces({ MediaType.APPLICATION_JSON })
7070
@Operation(summary = "Return all available export types for the specific report", description = "Returns the list of all available export types.")
7171
@ApiResponses({
72-
@ApiResponse(responseCode = "200", description = "", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ReportExportType.class)))) })
72+
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ReportExportType.class)))) })
7373
public Response retrieveAllAvailableExports(@PathParam("reportName") @Parameter(description = "reportName") final String reportName,
7474
@Context final UriInfo uriInfo,
7575
@DefaultValue("false") @QueryParam(IS_SELF_SERVICE_USER_REPORT_PARAMETER) @Parameter(description = IS_SELF_SERVICE_USER_REPORT_PARAMETER) final boolean isSelfServiceUserReport) {

fineract-provider/src/main/java/org/apache/fineract/portfolio/account/api/AccountTransfersApiResource.java

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,27 @@
2626
import io.swagger.v3.oas.annotations.responses.ApiResponse;
2727
import io.swagger.v3.oas.annotations.responses.ApiResponses;
2828
import io.swagger.v3.oas.annotations.tags.Tag;
29+
import jakarta.ws.rs.BeanParam;
2930
import jakarta.ws.rs.Consumes;
3031
import jakarta.ws.rs.GET;
3132
import jakarta.ws.rs.POST;
3233
import jakarta.ws.rs.Path;
3334
import jakarta.ws.rs.PathParam;
3435
import jakarta.ws.rs.Produces;
3536
import jakarta.ws.rs.QueryParam;
36-
import jakarta.ws.rs.core.Context;
3737
import jakarta.ws.rs.core.MediaType;
38-
import jakarta.ws.rs.core.UriInfo;
3938
import lombok.RequiredArgsConstructor;
4039
import org.apache.fineract.commands.domain.CommandWrapper;
4140
import org.apache.fineract.commands.service.CommandWrapperBuilder;
4241
import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService;
43-
import org.apache.fineract.infrastructure.core.api.ApiRequestParameterHelper;
4442
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
45-
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
4643
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
4744
import org.apache.fineract.infrastructure.core.service.Page;
4845
import org.apache.fineract.infrastructure.core.service.SearchParameters;
4946
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
50-
import org.apache.fineract.infrastructure.security.service.SqlValidator;
5147
import org.apache.fineract.portfolio.account.data.AccountTransferData;
48+
import org.apache.fineract.portfolio.account.data.request.AccountTransSearchParam;
49+
import org.apache.fineract.portfolio.account.data.request.AccountTransferRequest;
5250
import org.apache.fineract.portfolio.account.service.AccountTransfersReadPlatformService;
5351
import org.springframework.stereotype.Component;
5452

@@ -61,9 +59,7 @@ public class AccountTransfersApiResource {
6159
private final PlatformSecurityContext context;
6260
private final DefaultToApiJsonSerializer<AccountTransferData> toApiJsonSerializer;
6361
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
64-
private final ApiRequestParameterHelper apiRequestParameterHelper;
6562
private final AccountTransfersReadPlatformService accountTransfersReadPlatformService;
66-
private final SqlValidator sqlValidator;
6763

6864
@GET
6965
@Path("template")
@@ -76,38 +72,28 @@ public class AccountTransfersApiResource {
7672
+ "accounttransfers/template?fromClientId=1&fromAccountType=2&fromAccountId=1")
7773
@ApiResponses({
7874
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.GetAccountTransfersTemplateResponse.class))) })
79-
public String template(@QueryParam("fromOfficeId") @Parameter(description = "fromOfficeId") final Long fromOfficeId,
80-
@QueryParam("fromClientId") @Parameter(description = "fromClientId") final Long fromClientId,
81-
@QueryParam("fromAccountId") @Parameter(description = "fromAccountId") final Long fromAccountId,
82-
@QueryParam("fromAccountType") @Parameter(description = "fromAccountType") final Integer fromAccountType,
83-
@QueryParam("toOfficeId") @Parameter(description = "toOfficeId") final Long toOfficeId,
84-
@QueryParam("toClientId") @Parameter(description = "toClientId") final Long toClientId,
85-
@QueryParam("toAccountId") @Parameter(description = "toAccountId") final Long toAccountId,
86-
@QueryParam("toAccountType") @Parameter(description = "toAccountType") final Integer toAccountType,
87-
@Context final UriInfo uriInfo) {
75+
public AccountTransferData template(@BeanParam AccountTransSearchParam accountTransSearchParam) {
8876

89-
this.context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
77+
context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
9078

91-
final AccountTransferData transferData = this.accountTransfersReadPlatformService.retrieveTemplate(fromOfficeId, fromClientId,
92-
fromAccountId, fromAccountType, toOfficeId, toClientId, toAccountId, toAccountType);
93-
94-
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
95-
return this.toApiJsonSerializer.serialize(settings, transferData, AccountTransfersApiConstants.RESPONSE_DATA_PARAMETERS);
79+
return accountTransfersReadPlatformService.retrieveTemplate(accountTransSearchParam.getFromAccountId(),
80+
accountTransSearchParam.getFromClientId(), accountTransSearchParam.getFromAccountId(),
81+
accountTransSearchParam.getFromAccountType(), accountTransSearchParam.getToOfficeId(),
82+
accountTransSearchParam.getToClientId(), accountTransSearchParam.getToAccountId(),
83+
accountTransSearchParam.getToAccountType());
9684
}
9785

9886
@POST
9987
@Consumes({ MediaType.APPLICATION_JSON })
10088
@Produces({ MediaType.APPLICATION_JSON })
10189
@Operation(summary = "Create new Transfer", description = "Ability to create new transfer of monetary funds from one account to another.")
102-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.PostAccountTransfersRequest.class)))
90+
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccountTransferRequest.class)))
10391
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.PostAccountTransfersResponse.class)))
104-
public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
105-
106-
final CommandWrapper commandRequest = new CommandWrapperBuilder().createAccountTransfer().withJson(apiRequestBodyAsJson).build();
92+
public CommandProcessingResult create(@Parameter(hidden = true) AccountTransferRequest accountTransferRequest) {
93+
final CommandWrapper commandRequest = new CommandWrapperBuilder().createAccountTransfer()
94+
.withJson(toApiJsonSerializer.serialize(accountTransferRequest)).build();
10795

108-
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
109-
110-
return this.toApiJsonSerializer.serialize(result);
96+
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
11197
}
11298

11399
@GET
@@ -117,26 +103,19 @@ public String create(@Parameter(hidden = true) final String apiRequestBodyAsJson
117103
+ "accounttransfers")
118104
@ApiResponses({
119105
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.GetAccountTransfersResponse.class))) })
120-
public String retrieveAll(@Context final UriInfo uriInfo,
121-
@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
106+
public Page<AccountTransferData> retrieveAll(@QueryParam("externalId") @Parameter(description = "externalId") final String externalId,
122107
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
123108
@QueryParam("limit") @Parameter(example = "limit") final Integer limit,
124109
@QueryParam("orderBy") @Parameter(description = "orderBy") final String orderBy,
125110
@QueryParam("sortOrder") @Parameter(description = "sortOrder") final String sortOrder,
126111
@QueryParam("accountDetailId") @Parameter(description = "accountDetailId") final Long accountDetailId) {
127112

128-
this.context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
113+
context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
129114

130-
sqlValidator.validate(orderBy);
131-
sqlValidator.validate(sortOrder);
132-
sqlValidator.validate(externalId);
133115
final SearchParameters searchParameters = SearchParameters.builder().limit(limit).externalId(externalId).offset(offset)
134116
.orderBy(orderBy).sortOrder(sortOrder).build();
135117

136-
final Page<AccountTransferData> transfers = this.accountTransfersReadPlatformService.retrieveAll(searchParameters, accountDetailId);
137-
138-
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
139-
return this.toApiJsonSerializer.serialize(settings, transfers, AccountTransfersApiConstants.RESPONSE_DATA_PARAMETERS);
118+
return accountTransfersReadPlatformService.retrieveAll(searchParameters, accountDetailId);
140119
}
141120

142121
@GET
@@ -147,15 +126,9 @@ public String retrieveAll(@Context final UriInfo uriInfo,
147126
+ "accounttransfers/1")
148127
@ApiResponses({
149128
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.GetAccountTransfersResponse.GetAccountTransfersPageItems.class))) })
150-
public String retrieveOne(@PathParam("transferId") @Parameter(description = "transferId") final Long transferId,
151-
@Context final UriInfo uriInfo) {
152-
153-
this.context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
154-
155-
final AccountTransferData transfer = this.accountTransfersReadPlatformService.retrieveOne(transferId);
156-
157-
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
158-
return this.toApiJsonSerializer.serialize(settings, transfer, AccountTransfersApiConstants.RESPONSE_DATA_PARAMETERS);
129+
public AccountTransferData retrieveOne(@PathParam("transferId") @Parameter(description = "transferId") final Long transferId) {
130+
context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
131+
return accountTransfersReadPlatformService.retrieveOne(transferId);
159132
}
160133

161134
@GET
@@ -167,39 +140,26 @@ public String retrieveOne(@PathParam("transferId") @Parameter(description = "tra
167140
+ "accounttransfers/templateRefundByTransfer?fromAccountId=2&fromAccountType=1& toAccountId=1&toAccountType=2&toClientId=1&toOfficeId=1")
168141
@ApiResponses({
169142
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.GetAccountTransfersTemplateRefundByTransferResponse.class))) })
170-
public String templateRefundByTransfer(@QueryParam("fromOfficeId") @Parameter(description = "fromOfficeId") final Long fromOfficeId,
171-
@QueryParam("fromClientId") @Parameter(description = "fromClientId") final Long fromClientId,
172-
@QueryParam("fromAccountId") @Parameter(description = "fromAccountId") final Long fromAccountId,
173-
@QueryParam("fromAccountType") @Parameter(description = "fromAccountType") final Integer fromAccountType,
174-
@QueryParam("toOfficeId") @Parameter(description = "toOfficeId") final Long toOfficeId,
175-
@QueryParam("toClientId") @Parameter(description = "toClientId") final Long toClientId,
176-
@QueryParam("toAccountId") @Parameter(description = "toAccountId") final Long toAccountId,
177-
@QueryParam("toAccountType") @Parameter(description = "toAccountType") final Integer toAccountType,
178-
@Context final UriInfo uriInfo) {
179-
180-
this.context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
181-
182-
final AccountTransferData transferData = this.accountTransfersReadPlatformService.retrieveRefundByTransferTemplate(fromOfficeId,
183-
fromClientId, fromAccountId, fromAccountType, toOfficeId, toClientId, toAccountId, toAccountType);
184-
185-
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
186-
return this.toApiJsonSerializer.serialize(settings, transferData, AccountTransfersApiConstants.RESPONSE_DATA_PARAMETERS);
143+
public AccountTransferData templateRefundByTransfer(@BeanParam AccountTransSearchParam accountTransSearchParam) {
144+
context.authenticatedUser().validateHasReadPermission(AccountTransfersApiConstants.ACCOUNT_TRANSFER_RESOURCE_NAME);
145+
return accountTransfersReadPlatformService.retrieveRefundByTransferTemplate(accountTransSearchParam.getFromAccountId(),
146+
accountTransSearchParam.getFromClientId(), accountTransSearchParam.getFromAccountId(),
147+
accountTransSearchParam.getFromAccountType(), accountTransSearchParam.getToOfficeId(),
148+
accountTransSearchParam.getToClientId(), accountTransSearchParam.getToAccountId(),
149+
accountTransSearchParam.getToAccountType());
187150
}
188151

189152
@POST
190153
@Path("refundByTransfer")
191154
@Consumes({ MediaType.APPLICATION_JSON })
192155
@Produces({ MediaType.APPLICATION_JSON })
193156
@Operation(summary = "Refund of an Active Loan by Transfer", description = "Ability to refund an active loan by transferring to a savings account.")
194-
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.PostAccountTransfersRefundByTransferRequest.class)))
157+
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = AccountTransferRequest.class)))
195158
@ApiResponses({
196159
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = AccountTransfersApiResourceSwagger.PostAccountTransfersRefundByTransferResponse.class))) })
197-
public String templateRefundByTransferPost(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
198-
199-
final CommandWrapper commandRequest = new CommandWrapperBuilder().refundByTransfer().withJson(apiRequestBodyAsJson).build();
200-
201-
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
202-
203-
return this.toApiJsonSerializer.serialize(result);
160+
public CommandProcessingResult templateRefundByTransferPost(@Parameter(hidden = true) AccountTransferRequest accountTransferRequest) {
161+
final CommandWrapper commandRequest = new CommandWrapperBuilder().refundByTransfer()
162+
.withJson(toApiJsonSerializer.serialize(accountTransferRequest)).build();
163+
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
204164
}
205165
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.account.data.request;
20+
21+
import jakarta.ws.rs.QueryParam;
22+
import java.io.Serial;
23+
import java.io.Serializable;
24+
import lombok.AllArgsConstructor;
25+
import lombok.Data;
26+
import lombok.NoArgsConstructor;
27+
28+
@Data
29+
@NoArgsConstructor
30+
@AllArgsConstructor
31+
public class AccountTransSearchParam implements Serializable {
32+
33+
@Serial
34+
private static final long serialVersionUID = 1L;
35+
36+
@QueryParam("fromOfficeId")
37+
private Long fromOfficeId;
38+
@QueryParam("fromClientId")
39+
private Long fromClientId;
40+
@QueryParam("fromAccountId")
41+
private Long fromAccountId;
42+
@QueryParam("fromAccountType")
43+
private Integer fromAccountType;
44+
@QueryParam("toOfficeId")
45+
private Long toOfficeId;
46+
@QueryParam("toClientId")
47+
private Long toClientId;
48+
@QueryParam("toAccountId")
49+
private Long toAccountId;
50+
@QueryParam("toAccountType")
51+
private Integer toAccountType;
52+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.account.data.request;
20+
21+
import java.io.Serial;
22+
import java.io.Serializable;
23+
import lombok.Data;
24+
import lombok.NoArgsConstructor;
25+
26+
@Data
27+
@NoArgsConstructor
28+
public class AccountTransferRequest implements Serializable {
29+
30+
@Serial
31+
private static final long serialVersionUID = 1L;
32+
33+
private String transferDescription;
34+
private String toOfficeId;
35+
private String toAccountType;
36+
private String dateFormat;
37+
private String transferAmount;
38+
private String toAccountId;
39+
private String fromClientId;
40+
private String locale;
41+
private String transferDate;
42+
private String fromAccountType;
43+
private String toClientId;
44+
private String fromAccountId;
45+
private String fromOfficeId;
46+
}

0 commit comments

Comments
 (0)