FINERACT-2169: Taxes api refactor;

This commit is contained in:
viktorpavlenko
2025-03-04 20:24:39 +00:00
committed by Adam Saghy
parent d826913753
commit d61bbeb71a
7 changed files with 178 additions and 100 deletions
@@ -0,0 +1,47 @@
/**
* 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.portfolio.tax.request;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class TaxComponentRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String name;
private BigDecimal percentage;
private Integer debitAccountType;
private Long debitAccountId;
private Integer creditAccountType;
private Long creditAcountId;
private String startDate;
private String dateFormat;
private String locale;
}
@@ -0,0 +1,37 @@
/**
* 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.portfolio.tax.request;
import java.io.Serial;
import java.io.Serializable;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
@NoArgsConstructor
public class TaxGroupComponent implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long taxComponentId;
private String startDate;
}
@@ -0,0 +1,40 @@
/**
* 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.portfolio.tax.request;
import java.io.Serial;
import java.io.Serializable;
import java.util.Set;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Setter
@Getter
@NoArgsConstructor
public class TaxGroupRequest implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private String name;
private String locale;
private Set<TaxGroupComponent> taxComponents;
private String dateFormat;
}
@@ -34,20 +34,17 @@ import jakarta.ws.rs.PUT;
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.Collection;
import java.util.List;
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.portfolio.tax.data.TaxComponentData;
import org.apache.fineract.portfolio.tax.request.TaxComponentRequest;
import org.apache.fineract.portfolio.tax.service.TaxReadPlatformService;
import org.springframework.stereotype.Component;
@@ -61,9 +58,8 @@ public class TaxComponentApiResource {
private final PlatformSecurityContext context;
private final TaxReadPlatformService readPlatformService;
private final DefaultToApiJsonSerializer<TaxComponentData> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
private final DefaultToApiJsonSerializer<String> toApiJsonSerializer;
@GET
@Consumes({ MediaType.APPLICATION_JSON })
@@ -71,14 +67,9 @@ public class TaxComponentApiResource {
@Operation(summary = "List Tax Components", description = "List Tax Components")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TaxComponentApiResourceSwagger.GetTaxesComponentsResponse.class)))) })
public String retrieveAllTaxComponents(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final Collection<TaxComponentData> taxComponents = this.readPlatformService.retrieveAllTaxComponents();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, taxComponents);
public List<TaxComponentData> retrieveAllTaxComponents() {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
return readPlatformService.retrieveAllTaxComponents();
}
@GET
@@ -88,29 +79,19 @@ public class TaxComponentApiResource {
@Operation(summary = "Retrieve Tax Component", description = "Retrieve Tax Component")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxComponentApiResourceSwagger.GetTaxesComponentsResponse.class))) })
public String retrieveTaxComponent(@PathParam("taxComponentId") @Parameter(description = "taxComponentId") final Long taxComponentId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
TaxComponentData taxComponentData = this.readPlatformService.retrieveTaxComponentData(taxComponentId);
return this.toApiJsonSerializer.serialize(settings, taxComponentData);
public TaxComponentData retrieveTaxComponent(
@PathParam("taxComponentId") @Parameter(description = "taxComponentId") final Long taxComponentId) {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
return readPlatformService.retrieveTaxComponentData(taxComponentId);
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final TaxComponentData taxComponentData = this.readPlatformService.retrieveTaxComponentTemplate();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, taxComponentData);
public TaxComponentData retrieveTemplate() {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
return readPlatformService.retrieveTaxComponentTemplate();
}
@POST
@@ -122,13 +103,10 @@ public class TaxComponentApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = TaxComponentApiResourceSwagger.PostTaxesComponentsRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxComponentApiResourceSwagger.PostTaxesComponentsResponse.class))) })
public String createTaxCompoent(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createTaxComponent().withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult createTaxComponent(@Parameter(hidden = true) TaxComponentRequest taxComponentRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createTaxComponent()
.withJson(toApiJsonSerializer.serialize(taxComponentRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
@PUT
@@ -139,15 +117,12 @@ public class TaxComponentApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = TaxComponentApiResourceSwagger.PutTaxesComponentsTaxComponentIdRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxComponentApiResourceSwagger.PutTaxesComponentsTaxComponentIdResponse.class))) })
public String updateTaxCompoent(@PathParam("taxComponentId") @Parameter(description = "taxComponentId") final Long taxComponentId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateTaxComponent(taxComponentId).withJson(apiRequestBodyAsJson)
.build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult updateTaxCompoent(
@PathParam("taxComponentId") @Parameter(description = "taxComponentId") final Long taxComponentId,
@Parameter(hidden = true) TaxComponentRequest taxComponentRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateTaxComponent(taxComponentId)
.withJson(toApiJsonSerializer.serialize(taxComponentRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
@@ -37,7 +37,7 @@ 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.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.domain.CommandWrapper;
import org.apache.fineract.commands.service.CommandWrapperBuilder;
@@ -48,6 +48,7 @@ import org.apache.fineract.infrastructure.core.serialization.ApiRequestJsonSeria
import org.apache.fineract.infrastructure.core.serialization.DefaultToApiJsonSerializer;
import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
import org.apache.fineract.portfolio.tax.data.TaxGroupData;
import org.apache.fineract.portfolio.tax.request.TaxGroupRequest;
import org.apache.fineract.portfolio.tax.service.TaxReadPlatformService;
import org.springframework.stereotype.Component;
@@ -61,7 +62,7 @@ public class TaxGroupApiResource {
private final PlatformSecurityContext context;
private final TaxReadPlatformService readPlatformService;
private final DefaultToApiJsonSerializer<TaxGroupData> toApiJsonSerializer;
private final DefaultToApiJsonSerializer<String> toApiJsonSerializer;
private final ApiRequestParameterHelper apiRequestParameterHelper;
private final PortfolioCommandSourceWritePlatformService commandsSourceWritePlatformService;
@@ -71,14 +72,9 @@ public class TaxGroupApiResource {
@Operation(summary = "List Tax Group", description = "List Tax Group")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = TaxGroupApiResourceSwagger.GetTaxesGroupResponse.class)))) })
public String retrieveAllTaxGroups(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final Collection<TaxGroupData> taxGroupDatas = this.readPlatformService.retrieveAllTaxGroups();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, taxGroupDatas);
public List<TaxGroupData> retrieveAllTaxGroups() {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
return readPlatformService.retrieveAllTaxGroups();
}
@GET
@@ -88,33 +84,21 @@ public class TaxGroupApiResource {
@Operation(summary = "Retrieve Tax Group", description = "Retrieve Tax Group")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxGroupApiResourceSwagger.GetTaxesGroupResponse.class))) })
public String retrieveTaxGroup(@PathParam("taxGroupId") @Parameter(description = "taxGroupId") final Long taxGroupId,
public TaxGroupData retrieveTaxGroup(@PathParam("taxGroupId") @Parameter(description = "taxGroupId") final Long taxGroupId,
@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
TaxGroupData taxGroupData = null;
if (settings.isTemplate()) {
taxGroupData = this.readPlatformService.retrieveTaxGroupWithTemplate(taxGroupId);
} else {
taxGroupData = this.readPlatformService.retrieveTaxGroupData(taxGroupId);
}
return this.toApiJsonSerializer.serialize(settings, taxGroupData);
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return settings.isTemplate() ? readPlatformService.retrieveTaxGroupWithTemplate(taxGroupId)
: readPlatformService.retrieveTaxGroupData(taxGroupId);
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveTemplate(@Context final UriInfo uriInfo) {
this.context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
final TaxGroupData taxGroupData = this.readPlatformService.retrieveTaxGroupTemplate();
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
return this.toApiJsonSerializer.serialize(settings, taxGroupData);
public TaxGroupData retrieveTemplate() {
context.authenticatedUser().validateHasReadPermission(RESOURCE_NAME_FOR_PERMISSIONS);
return readPlatformService.retrieveTaxGroupTemplate();
}
@POST
@@ -125,13 +109,10 @@ public class TaxGroupApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = TaxGroupApiResourceSwagger.PostTaxesGroupRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxGroupApiResourceSwagger.PostTaxesGroupResponse.class))) })
public String createTaxGroup(@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createTaxGroup().withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult createTaxGroup(@Parameter(hidden = true) TaxGroupRequest taxGroupRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().createTaxGroup()
.withJson(toApiJsonSerializer.serialize(taxGroupRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
@PUT
@@ -142,14 +123,11 @@ public class TaxGroupApiResource {
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = TaxGroupApiResourceSwagger.PutTaxesGroupTaxGroupIdRequest.class)))
@ApiResponses({
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = TaxGroupApiResourceSwagger.PutTaxesGroupTaxGroupIdResponse.class))) })
public String updateTaxGroup(@PathParam("taxGroupId") @Parameter(description = "taxGroupId") final Long taxGroupId,
@Parameter(hidden = true) final String apiRequestBodyAsJson) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateTaxGroup(taxGroupId).withJson(apiRequestBodyAsJson).build();
final CommandProcessingResult result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
return this.toApiJsonSerializer.serialize(result);
public CommandProcessingResult updateTaxGroup(@PathParam("taxGroupId") @Parameter(description = "taxGroupId") final Long taxGroupId,
@Parameter(hidden = true) TaxGroupRequest taxGroupRequest) {
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateTaxGroup(taxGroupId)
.withJson(toApiJsonSerializer.serialize(taxGroupRequest)).build();
return commandsSourceWritePlatformService.logCommandSource(commandRequest);
}
}
@@ -18,7 +18,7 @@
*/
package org.apache.fineract.portfolio.tax.service;
import java.util.Collection;
import java.util.List;
import org.apache.fineract.portfolio.tax.data.TaxComponentData;
import org.apache.fineract.portfolio.tax.data.TaxGroupData;
@@ -34,10 +34,10 @@ public interface TaxReadPlatformService {
TaxGroupData retrieveTaxGroupTemplate();
Collection<TaxComponentData> retrieveAllTaxComponents();
List<TaxComponentData> retrieveAllTaxComponents();
Collection<TaxGroupData> retrieveAllTaxGroups();
List<TaxGroupData> retrieveAllTaxGroups();
Collection<TaxGroupData> retrieveTaxGroupsForLookUp();
List<TaxGroupData> retrieveTaxGroupsForLookUp();
}
@@ -24,6 +24,7 @@ import java.sql.SQLException;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.fineract.accounting.common.AccountingDropdownReadPlatformService;
import org.apache.fineract.accounting.common.AccountingEnumerations;
@@ -49,7 +50,7 @@ public class TaxReadPlatformServiceImpl implements TaxReadPlatformService {
private final AccountingDropdownReadPlatformService accountingDropdownReadPlatformService;
@Override
public Collection<TaxComponentData> retrieveAllTaxComponents() {
public List<TaxComponentData> retrieveAllTaxComponents() {
String sql = "select " + TAX_COMPONENT_MAPPER.getSchema();
return this.jdbcTemplate.query(sql, TAX_COMPONENT_MAPPER); // NOSONAR
}
@@ -67,7 +68,7 @@ public class TaxReadPlatformServiceImpl implements TaxReadPlatformService {
}
@Override
public Collection<TaxGroupData> retrieveAllTaxGroups() {
public List<TaxGroupData> retrieveAllTaxGroups() {
String sql = "select " + TAX_GROUP_MAPPER.getSchema();
return this.jdbcTemplate.query(sql, TAX_GROUP_MAPPER); // NOSONAR
}
@@ -96,7 +97,7 @@ public class TaxReadPlatformServiceImpl implements TaxReadPlatformService {
}
@Override
public Collection<TaxGroupData> retrieveTaxGroupsForLookUp() {
public List<TaxGroupData> retrieveTaxGroupsForLookUp() {
String sql = "select " + TAX_GROUP_LOOK_UP_MAPPER.getSchema();
return this.jdbcTemplate.query(sql, TAX_GROUP_LOOK_UP_MAPPER); // NOSONAR
}