|
41 | 41 | import jakarta.ws.rs.core.Context; |
42 | 42 | import jakarta.ws.rs.core.MediaType; |
43 | 43 | import jakarta.ws.rs.core.UriInfo; |
| 44 | +import java.time.LocalDate; |
44 | 45 | import lombok.RequiredArgsConstructor; |
| 46 | +import org.apache.commons.lang3.StringUtils; |
45 | 47 | import org.apache.fineract.commands.domain.CommandWrapper; |
46 | 48 | import org.apache.fineract.commands.service.CommandWrapperBuilder; |
47 | 49 | import org.apache.fineract.commands.service.PortfolioCommandSourceWritePlatformService; |
| 50 | +import org.apache.fineract.infrastructure.core.api.DateParam; |
48 | 51 | import org.apache.fineract.infrastructure.core.api.jersey.Pagination; |
49 | 52 | import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; |
| 53 | +import org.apache.fineract.infrastructure.core.data.DateFormat; |
50 | 54 | import org.apache.fineract.infrastructure.core.domain.ExternalId; |
51 | 55 | import org.apache.fineract.infrastructure.core.exception.UnrecognizedQueryParamException; |
52 | 56 | import org.apache.fineract.infrastructure.core.service.CommandParameterUtil; |
| 57 | +import org.apache.fineract.infrastructure.core.service.DateUtils; |
53 | 58 | import org.apache.fineract.infrastructure.core.service.ExternalIdFactory; |
54 | 59 | import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext; |
55 | 60 | import org.apache.fineract.portfolio.workingcapitalloan.WorkingCapitalLoanConstants; |
56 | 61 | import org.apache.fineract.portfolio.workingcapitalloan.data.WorkingCapitalLoanCommandTemplateData; |
57 | 62 | import org.apache.fineract.portfolio.workingcapitalloan.data.WorkingCapitalLoanTransactionData; |
| 63 | +import org.apache.fineract.portfolio.workingcapitalloan.data.WorkingCapitalLoanTransactionTemplateData; |
58 | 64 | import org.apache.fineract.portfolio.workingcapitalloan.domain.WorkingCapitalLoanTransaction; |
59 | 65 | import org.apache.fineract.portfolio.workingcapitalloan.exception.WorkingCapitalLoanNotFoundException; |
60 | 66 | import org.apache.fineract.portfolio.workingcapitalloan.exception.WorkingCapitalLoanTransactionNotFoundException; |
@@ -287,6 +293,55 @@ public CommandProcessingResult executeWorkingCapitalLoanTransactionCommandByLoan |
287 | 293 | return executeWorkingCapitalLoanTransactionCommand(loanId, null, null, transactionExternalId, command, apiRequestBodyAsJson); |
288 | 294 | } |
289 | 295 |
|
| 296 | + @GET |
| 297 | + @Produces({ MediaType.APPLICATION_JSON }) |
| 298 | + @Operation(operationId = "getWorkingCapitalLoanTransactionTemplateById", summary = "Get Working Capital Loan transaction template by loan id", description = "Supported command query parameter: prepayLoan.") |
| 299 | + @Path("{loanId}/transactions/template") |
| 300 | + @ApiResponses({ |
| 301 | + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = WorkingCapitalLoanTransactionsApiResourceSwagger.WorkingCapitalLoanTransactionTemplateResponse.class))) }) |
| 302 | + public WorkingCapitalLoanTransactionTemplateData getWorkingCapitalLoanTransactionTemplateById( |
| 303 | + @PathParam("loanId") @Parameter(description = "loanId", required = true) final Long loanId, |
| 304 | + @QueryParam("command") @Parameter(description = "command") final String commandParam, |
| 305 | + @QueryParam("dateFormat") @Parameter(description = "dateFormat") final String rawDateFormat, |
| 306 | + @QueryParam("transactionDate") @Parameter(description = "transactionDate") final DateParam transactionDateParam, |
| 307 | + @QueryParam("locale") @Parameter(description = "locale") final String locale) { |
| 308 | + |
| 309 | + return getWorkingCapitalLoanTransactionTemplate(commandParam, loanId, null, locale, rawDateFormat, transactionDateParam); |
| 310 | + } |
| 311 | + |
| 312 | + @GET |
| 313 | + @Produces({ MediaType.APPLICATION_JSON }) |
| 314 | + @Operation(operationId = "getWorkingCapitalLoanTransactionTemplateByExternalId", summary = "Get Working Capital Loan transaction template by loan external id", description = "Supported command query parameter: prepayLoan.") |
| 315 | + @Path("external-id/{loanExternalId}/transactions/template") |
| 316 | + @ApiResponses({ |
| 317 | + @ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = WorkingCapitalLoanTransactionsApiResourceSwagger.WorkingCapitalLoanTransactionTemplateResponse.class))) }) |
| 318 | + public WorkingCapitalLoanTransactionTemplateData getWorkingCapitalLoanTransactionTemplateByExternalId( |
| 319 | + @PathParam("loanExternalId") @Parameter(description = "loanExternalId", required = true) final String loanExternalId, |
| 320 | + @QueryParam("command") @Parameter(description = "command") final String commandParam, |
| 321 | + @QueryParam("dateFormat") @Parameter(description = "dateFormat") final String rawDateFormat, |
| 322 | + @QueryParam("transactionDate") @Parameter(description = "transactionDate") final DateParam transactionDateParam, |
| 323 | + @QueryParam("locale") @Parameter(description = "locale") final String locale) { |
| 324 | + return getWorkingCapitalLoanTransactionTemplate(commandParam, null, loanExternalId, locale, rawDateFormat, transactionDateParam); |
| 325 | + } |
| 326 | + |
| 327 | + private WorkingCapitalLoanTransactionTemplateData getWorkingCapitalLoanTransactionTemplate(String commandParam, Long loanId, |
| 328 | + String externalId, String locale, String rawDateFormat, DateParam transactionDateParam) { |
| 329 | + final Long resolvedLoanId = resolveLoanId(loanId, externalId); |
| 330 | + this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS); |
| 331 | + final DateFormat dateFormat = StringUtils.isBlank(rawDateFormat) ? null : new DateFormat(rawDateFormat); |
| 332 | + if (CommandParameterUtil.is(commandParam, "prepayLoan")) { |
| 333 | + LocalDate transactionDate; |
| 334 | + if (transactionDateParam == null) { |
| 335 | + transactionDate = DateUtils.getBusinessLocalDate(); |
| 336 | + } else { |
| 337 | + transactionDate = transactionDateParam.getDate("transactionDate", dateFormat, locale); |
| 338 | + } |
| 339 | + return this.loanReadPlatformService.retrieveLoanPrePaymentTemplate(resolvedLoanId, transactionDate); |
| 340 | + } else { |
| 341 | + throw new UnrecognizedQueryParamException("command", commandParam); |
| 342 | + } |
| 343 | + } |
| 344 | + |
290 | 345 | @POST |
291 | 346 | @Consumes({ MediaType.APPLICATION_JSON }) |
292 | 347 | @Produces({ MediaType.APPLICATION_JSON }) |
|
0 commit comments