Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,28 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_WORKING_DAYS")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/workingdays"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_WORKING_DAYS")
// interest rate chart slabs (before charts for specificity)
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*/chartslabs"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CHARTSLAB")
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*/chartslabs/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_CHARTSLAB")
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/interestratecharts/*/chartslabs"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_CHARTSLAB")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/interestratecharts/*/chartslabs/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_CHARTSLAB")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/interestratecharts/*/chartslabs/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_CHARTSLAB")
// interest rate chart
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_INTERESTRATECHART")
.requestMatchers(API_MATCHER.matcher(HttpMethod.GET, "/api/*/interestratecharts/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_READ, "READ_INTERESTRATECHART")
.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/interestratecharts"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "CREATE_INTERESTRATECHART")
.requestMatchers(API_MATCHER.matcher(HttpMethod.PUT, "/api/*/interestratecharts/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "UPDATE_INTERESTRATECHART")
.requestMatchers(API_MATCHER.matcher(HttpMethod.DELETE, "/api/*/interestratecharts/*"))
.hasAnyAuthority(ALL_FUNCTIONS, ALL_FUNCTIONS_WRITE, "DELETE_INTERESTRATECHART")

.requestMatchers(API_MATCHER.matcher(HttpMethod.POST, "/api/*/twofactor/validate")).fullyAuthenticated()
.requestMatchers(API_MATCHER.matcher("/api/*/twofactor")).fullyAuthenticated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
*/
package org.apache.fineract.portfolio.interestratechart.api;

import static org.apache.fineract.portfolio.interestratechart.InterestRateChartSlabApiConstants.INTERESTRATE_CHART_SLAB_RESOURCE_NAME;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.ws.rs.Consumes;
Expand All @@ -35,118 +31,97 @@
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.List;
import java.util.function.Supplier;
import lombok.RequiredArgsConstructor;
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.serialization.ApiRequestJsonSerializationSettings;
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.command.core.CommandPipeline;
import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsCreateCommand;
import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsDeleteCommand;
import org.apache.fineract.portfolio.interestratechart.command.InterestRateChartSlabsUpdateCommand;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabData;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartStabRequest;
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabReadPlatformService;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateRequest;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsCreateResponse;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteRequest;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsDeleteResponse;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateRequest;
import org.apache.fineract.portfolio.interestratechart.data.InterestRateChartSlabsUpdateResponse;
import org.apache.fineract.portfolio.interestratechart.service.InterestRateChartSlabsReadService;
import org.springframework.stereotype.Component;

@Path("/v1/interestratecharts/{chartId}/chartslabs")
@Component
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Tag(name = "Interest Rate Slab (A.K.A interest bands)", description = "The slabs a.k.a interest bands are associated with Interest Rate Chart. These bands allow to define different interest rates for different deposit term periods.")
@RequiredArgsConstructor
public class InterestRateChartSlabsApiResource {

private final InterestRateChartSlabReadPlatformService interestRateChartSlabReadPlatformService;
private final PlatformSecurityContext context;
private final DefaultToApiJsonSerializer<InterestRateChartSlabData> toApiJsonSerializer;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final InterestRateChartSlabsReadService interestRateChartSlabsReadService;
private final CommandPipeline commandPipeline;

@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public InterestRateChartSlabData template(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId) {
return this.interestRateChartSlabReadPlatformService.retrieveTemplate();
public InterestRateChartSlabData template(@PathParam("chartId") final Long chartId) {
return interestRateChartSlabsReadService.retrieveTemplate();
}

@GET
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve all Slabs", description = "Retrieve list of slabs associated with a chart\n" + "\n"
+ "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs")
public List<InterestRateChartSlabData> retrieveAll(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId) {

this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME);
return this.interestRateChartSlabReadPlatformService.retrieveAll(chartId);
public List<InterestRateChartSlabData> retrieveAll(@PathParam("chartId") final Long chartId) {
return interestRateChartSlabsReadService.retrieveAll(chartId);
}

@GET
@Path("{chartSlabId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Retrieve a Slab", description = "Retrieve a slab associated with an Interest rate chart\n" + "\n"
+ "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs/1\n")
public InterestRateChartSlabData retrieveOne(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId,
@PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId, @Context final UriInfo uriInfo) {

this.context.authenticatedUser().validateHasReadPermission(INTERESTRATE_CHART_SLAB_RESOURCE_NAME);

InterestRateChartSlabData chartSlab = this.interestRateChartSlabReadPlatformService.retrieveOne(chartId, chartSlabId);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
if (settings.isTemplate()) {
chartSlab = this.interestRateChartSlabReadPlatformService.retrieveWithTemplate(chartSlab);
}

return chartSlab;
public InterestRateChartSlabData retrieveOne(@PathParam("chartId") final Long chartId,
@PathParam("chartSlabId") final Long chartSlabId) {
return interestRateChartSlabsReadService.retrieveOne(chartId, chartSlabId);
}

@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Create a Slab", description = "Creates a new interest rate slab for an interest rate chart.\n"
+ "Mandatory Fields\n" + "periodType, fromPeriod, annualInterestRate\n" + "Optional Fields\n" + "toPeriod and description\n"
+ "Example Requests:\n" + "\n" + "interestratecharts/1/chartslabs")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = InterestRateChartStabRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.PostInterestRateChartsChartIdChartSlabsResponse.class)))
public CommandProcessingResult create(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId,
@Parameter(hidden = true) InterestRateChartStabRequest interestRateChartStabRequest) {

final CommandWrapper commandRequest = new CommandWrapperBuilder().createInterestRateChartSlab(chartId)
.withJson(toApiJsonSerializer.serialize(interestRateChartStabRequest)).build();

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsCreateResponse.class)))
public InterestRateChartSlabsCreateResponse create(@PathParam("chartId") final Long chartId,
final InterestRateChartSlabsCreateRequest request) {
request.setChartId(chartId);
final var command = new InterestRateChartSlabsCreateCommand();
command.setPayload(request);
final Supplier<InterestRateChartSlabsCreateResponse> responseSupplier = commandPipeline.send(command);
return responseSupplier.get();
}

@PUT
@Path("{chartSlabId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Update a Slab", description = "It updates the Slab from chart")
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = InterestRateChartStabRequest.class)))
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.PutInterestRateChartsChartIdChartSlabsChartSlabIdResponse.class)))
public CommandProcessingResult update(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId,
@PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId,
@Parameter(hidden = true) InterestRateChartStabRequest request) {
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsUpdateResponse.class)))
public InterestRateChartSlabsUpdateResponse update(@PathParam("chartId") final Long chartId,
@PathParam("chartSlabId") final Long chartSlabId, final InterestRateChartSlabsUpdateRequest request) {
request.setChartId(chartId);
request.setChartSlabId(chartSlabId);

final var command = new InterestRateChartSlabsUpdateCommand();
command.setPayload(request);

final CommandWrapper commandRequest = new CommandWrapperBuilder().updateInterestRateChartSlab(chartId, chartSlabId)
.withJson(toApiJsonSerializer.serialize(request)).build();
final Supplier<InterestRateChartSlabsUpdateResponse> responseSupplier = commandPipeline.send(command);

return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return responseSupplier.get();
}

@DELETE
@Path("{chartSlabId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Operation(summary = "Delete a Slab", description = "Delete a Slab from a chart")
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsApiResourceSwagger.DeleteInterestRateChartsChartIdChartSlabsResponse.class)))
public CommandProcessingResult delete(@PathParam("chartId") @Parameter(description = "chartId") final Long chartId,
@PathParam("chartSlabId") @Parameter(description = "chartSlabId") final Long chartSlabId) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().deleteInterestRateChartSlab(chartId, chartSlabId).build();
return this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = InterestRateChartSlabsDeleteResponse.class)))
public InterestRateChartSlabsDeleteResponse delete(@PathParam("chartId") final Long chartId,
@PathParam("chartSlabId") final Long chartSlabId) {
final var command = new InterestRateChartSlabsDeleteCommand();
command.setPayload(InterestRateChartSlabsDeleteRequest.builder().chartId(chartId).chartSlabId(chartSlabId).build());
final Supplier<InterestRateChartSlabsDeleteResponse> responseSupplier = commandPipeline.send(command);
return responseSupplier.get();
}
}

This file was deleted.

Loading
Loading