FINERACT-2169: Provision entries api refactor;
This commit is contained in:
committed by
Adam Saghy
parent
d96e78a4f7
commit
056b3edaad
+44
-62
@@ -18,9 +18,11 @@
|
||||
*/
|
||||
package org.apache.fineract.accounting.provisioning.api;
|
||||
|
||||
import static org.apache.fineract.accounting.provisioning.constant.ProvisioningEntriesApiConstants.CREATE_JOURNAL_ENTRY;
|
||||
import static org.apache.fineract.accounting.provisioning.constant.ProvisioningEntriesApiConstants.RECREATE_PROVISION_IN_ENTRY;
|
||||
|
||||
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;
|
||||
@@ -33,24 +35,17 @@ 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.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.accounting.provisioning.constant.ProvisioningEntriesApiConstants;
|
||||
import org.apache.fineract.accounting.provisioning.data.LoanProductProvisioningEntryData;
|
||||
import org.apache.fineract.accounting.provisioning.data.ProvisioningEntryData;
|
||||
import org.apache.fineract.accounting.provisioning.data.request.ProvisionEntryRequest;
|
||||
import org.apache.fineract.accounting.provisioning.service.ProvisioningEntriesReadPlatformService;
|
||||
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.exception.UnrecognizedQueryParamException;
|
||||
import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSerializationSettings;
|
||||
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
|
||||
import org.apache.fineract.infrastructure.core.service.Page;
|
||||
import org.apache.fineract.infrastructure.core.service.SearchParameters;
|
||||
@@ -71,17 +66,10 @@ import org.springframework.stereotype.Component;
|
||||
@RequiredArgsConstructor
|
||||
public class ProvisioningEntriesApiResource {
|
||||
|
||||
private static final Set<String> PROVISIONING_ENTRY_PARAMETERS = new HashSet<>(
|
||||
Arrays.asList(ProvisioningEntriesApiConstants.PROVISIONINGENTRY_PARAM, ProvisioningEntriesApiConstants.ENTRIES_PARAM));
|
||||
private static final Set<String> ALL_PROVISIONING_ENTRIES = new HashSet<>(
|
||||
Arrays.asList(ProvisioningEntriesApiConstants.PROVISIONINGENTRY_PARAM));
|
||||
|
||||
private final PlatformSecurityContext platformSecurityContext;
|
||||
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
|
||||
private final DefaultToApiJsonSerializer<ProvisioningEntryData> toApiJsonSerializer;
|
||||
private final DefaultToApiJsonSerializer<Object> entriesApiJsonSerializer;
|
||||
private final ProvisioningEntriesReadPlatformService provisioningEntriesReadPlatformService;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@@ -95,14 +83,13 @@ public class ProvisioningEntriesApiResource {
|
||||
locale
|
||||
Optional Fields
|
||||
createjournalentries""")
|
||||
@RequestBody(content = @Content(schema = @Schema(implementation = ProvisioningEntriesApiResourceSwagger.PostProvisioningEntriesRequest.class)))
|
||||
@RequestBody(content = @Content(schema = @Schema(implementation = ProvisionEntryRequest.class)))
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ProvisioningEntriesApiResourceSwagger.PostProvisioningEntriesResponse.class)))
|
||||
public String createProvisioningEntries(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
||||
CommandWrapper commandWrapper = null;
|
||||
this.platformSecurityContext.authenticatedUser();
|
||||
commandWrapper = new CommandWrapperBuilder().createProvisioningEntries().withJson(apiRequestBodyAsJson).build();
|
||||
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService.logCommandSource(commandWrapper);
|
||||
return this.toApiJsonSerializer.serialize(commandProcessingResult);
|
||||
public CommandProcessingResult createProvisioningEntries(@Parameter(hidden = true) ProvisionEntryRequest provisionEntryRequest) {
|
||||
platformSecurityContext.authenticatedUser();
|
||||
CommandWrapper commandWrapper = new CommandWrapperBuilder().createProvisioningEntries()
|
||||
.withJson(toApiJsonSerializer.serialize(provisionEntryRequest)).build();
|
||||
return commandsSourceWritePlatformService.logCommandSource(commandWrapper);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -112,23 +99,11 @@ public class ProvisioningEntriesApiResource {
|
||||
@Operation(summary = "Recreates Provisioning Entry", description = "Recreates Provisioning Entry | createjournalentry.")
|
||||
@RequestBody(content = @Content(schema = @Schema(implementation = ProvisioningEntriesApiResourceSwagger.PutProvisioningEntriesRequest.class)))
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ProvisioningEntriesApiResourceSwagger.PutProvisioningEntriesResponse.class)))
|
||||
public String modifyProvisioningEntry(@PathParam("entryId") @Parameter(description = "entryId") final Long entryId,
|
||||
public CommandProcessingResult modifyProvisioningEntry(@PathParam("entryId") @Parameter(description = "entryId") final Long entryId,
|
||||
@QueryParam("command") @Parameter(description = "command=createjournalentry\ncommand=recreateprovisioningentry") final String commandParam,
|
||||
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
|
||||
CommandWrapper commandWrapper = null;
|
||||
this.platformSecurityContext.authenticatedUser();
|
||||
if ("createjournalentry".equals(commandParam)) {
|
||||
commandWrapper = new CommandWrapperBuilder().createProvisioningJournalEntries(entryId).withJson(apiRequestBodyAsJson).build();
|
||||
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService
|
||||
.logCommandSource(commandWrapper);
|
||||
return this.toApiJsonSerializer.serialize(commandProcessingResult);
|
||||
} else if ("recreateprovisioningentry".equals(commandParam)) {
|
||||
commandWrapper = new CommandWrapperBuilder().reCreateProvisioningEntries(entryId).withJson(apiRequestBodyAsJson).build();
|
||||
final CommandProcessingResult commandProcessingResult = this.commandsSourceWritePlatformService
|
||||
.logCommandSource(commandWrapper);
|
||||
return this.toApiJsonSerializer.serialize(commandProcessingResult);
|
||||
}
|
||||
throw new UnrecognizedQueryParamException("command", commandParam);
|
||||
@Parameter(hidden = true) String provisionCommandRequest) {
|
||||
platformSecurityContext.authenticatedUser();
|
||||
return getResultByCommandParam(commandParam, entryId, provisionCommandRequest);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -136,42 +111,49 @@ public class ProvisioningEntriesApiResource {
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Retrieves a Provisioning Entry", description = "Returns the details of a generated Provisioning Entry.")
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ProvisioningEntryData.class)))
|
||||
public String retrieveProvisioningEntry(@PathParam("entryId") @Parameter(description = "entryId") final Long entryId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
public ProvisioningEntryData retrieveProvisioningEntry(@PathParam("entryId") @Parameter(description = "entryId") final Long entryId) {
|
||||
platformSecurityContext.authenticatedUser();
|
||||
ProvisioningEntryData data = this.provisioningEntriesReadPlatformService.retrieveProvisioningEntryData(entryId);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, data, PROVISIONING_ENTRY_PARAMETERS);
|
||||
return provisioningEntriesReadPlatformService.retrieveProvisioningEntryData(entryId);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("entries")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = LoanProductProvisioningEntryData.class)))
|
||||
public String retrieveProviioningEntries(@QueryParam("entryId") final Long entryId, @QueryParam("offset") final Integer offset,
|
||||
@QueryParam("limit") final Integer limit, @QueryParam("officeId") final Long officeId,
|
||||
@QueryParam("productId") final Long productId, @QueryParam("categoryId") final Long categoryId,
|
||||
@Context final UriInfo uriInfo) {
|
||||
this.platformSecurityContext.authenticatedUser();
|
||||
SearchParameters params = SearchParameters.builder().limit(limit).offset(offset).provisioningEntryId(entryId).officeId(officeId)
|
||||
.productId(productId).categoryId(categoryId).build();
|
||||
Page<LoanProductProvisioningEntryData> entries = this.provisioningEntriesReadPlatformService.retrieveProvisioningEntries(params);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.entriesApiJsonSerializer.serialize(settings, entries, PROVISIONING_ENTRY_PARAMETERS);
|
||||
public Page<LoanProductProvisioningEntryData> retrieveProviioningEntries(@QueryParam("entryId") final Long entryId,
|
||||
@QueryParam("offset") final Integer offset, @QueryParam("limit") final Integer limit,
|
||||
@QueryParam("officeId") final Long officeId, @QueryParam("productId") final Long productId,
|
||||
@QueryParam("categoryId") final Long categoryId) {
|
||||
platformSecurityContext.authenticatedUser();
|
||||
final SearchParameters params = SearchParameters.builder().limit(limit).offset(offset).provisioningEntryId(entryId)
|
||||
.officeId(officeId).productId(productId).categoryId(categoryId).build();
|
||||
|
||||
return provisioningEntriesReadPlatformService.retrieveProvisioningEntries(params);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List all Provisioning Entries")
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ProvisioningEntryData.class))))
|
||||
public String retrieveAllProvisioningEntries(@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
|
||||
@QueryParam("limit") @Parameter(description = "limit") final Integer limit, @Context final UriInfo uriInfo) {
|
||||
public Page<ProvisioningEntryData> retrieveAllProvisioningEntries(
|
||||
@QueryParam("offset") @Parameter(description = "offset") final Integer offset,
|
||||
@QueryParam("limit") @Parameter(description = "limit") final Integer limit) {
|
||||
platformSecurityContext.authenticatedUser();
|
||||
Page<ProvisioningEntryData> data = this.provisioningEntriesReadPlatformService.retrieveAllProvisioningEntries(offset, limit);
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.entriesApiJsonSerializer.serialize(settings, data, ALL_PROVISIONING_ENTRIES);
|
||||
return provisioningEntriesReadPlatformService.retrieveAllProvisioningEntries(offset, limit);
|
||||
}
|
||||
|
||||
private CommandProcessingResult getResultByCommandParam(String commandParam, Long entryId, String apiRequestBodyAsJson) {
|
||||
final CommandWrapperBuilder commandWrapperBuilder = new CommandWrapperBuilder().withJson(apiRequestBodyAsJson);
|
||||
switch (commandParam) {
|
||||
case CREATE_JOURNAL_ENTRY -> {
|
||||
return commandsSourceWritePlatformService
|
||||
.logCommandSource(commandWrapperBuilder.createProvisioningJournalEntries(entryId).build());
|
||||
}
|
||||
case RECREATE_PROVISION_IN_ENTRY -> {
|
||||
return commandsSourceWritePlatformService
|
||||
.logCommandSource(commandWrapperBuilder.reCreateProvisioningEntries(entryId).build());
|
||||
}
|
||||
default -> throw new UnrecognizedQueryParamException("command", commandParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -32,4 +32,7 @@ public interface ProvisioningEntriesApiConstants {
|
||||
|
||||
String ENTRIES_PARAM = "entries";
|
||||
|
||||
String CREATE_JOURNAL_ENTRY = "createjournalentry";
|
||||
String RECREATE_PROVISION_IN_ENTRY = "recreateprovisioningentry";
|
||||
|
||||
}
|
||||
|
||||
+8
-3
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package org.apache.fineract.accounting.provisioning.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
@@ -29,7 +31,10 @@ import lombok.experimental.Accessors;
|
||||
@NoArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
@SuppressWarnings("unused")
|
||||
public class ProvisioningEntryData {
|
||||
public class ProvisioningEntryData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
@@ -39,9 +44,9 @@ public class ProvisioningEntryData {
|
||||
|
||||
private String createdUser;
|
||||
|
||||
LocalDate createdDate;
|
||||
private LocalDate createdDate;
|
||||
|
||||
Long modifiedById;
|
||||
private Long modifiedById;
|
||||
|
||||
private String modifiedUser;
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/**
|
||||
* 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.accounting.provisioning.data.request;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
public record ProvisionEntryRequest(String date, Boolean createjournalentries, String locale, String dateFormat) implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
+1
-1
@@ -132,7 +132,7 @@ public class ProvisioningEntriesWritePlatformServiceJpaRepositoryImpl implements
|
||||
try {
|
||||
Collection<ProvisioningCriteriaData> criteriaCollection = this.provisioningCriteriaReadPlatformService
|
||||
.retrieveAllProvisioningCriterias();
|
||||
if (criteriaCollection == null || criteriaCollection.size() == 0) {
|
||||
if (criteriaCollection == null || criteriaCollection.isEmpty()) {
|
||||
throw new NoProvisioningCriteriaDefinitionFound();
|
||||
}
|
||||
ProvisioningEntry requestedEntry = createProvisioningEntry(createdDate, addJournalEntries);
|
||||
|
||||
Reference in New Issue
Block a user