FINERACT-2169: Business date api refactor;
This commit is contained in:
committed by
Adam Saghy
parent
99f313e02c
commit
35aa6e1f4f
+15
-27
@@ -20,7 +20,6 @@ package org.apache.fineract.infrastructure.businessdate.api;
|
||||
|
||||
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,19 +32,16 @@ import jakarta.ws.rs.POST;
|
||||
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 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.businessdate.data.BusinessDateData;
|
||||
import org.apache.fineract.infrastructure.businessdate.data.request.BusinessDateRequest;
|
||||
import org.apache.fineract.infrastructure.businessdate.service.BusinessDateReadPlatformService;
|
||||
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.springframework.stereotype.Component;
|
||||
@@ -56,7 +52,8 @@ import org.springframework.stereotype.Component;
|
||||
@Tag(name = "Business Date Management", description = "Business date management enables you to set up, fetch and adjust organisation business dates")
|
||||
public class BusinessDateApiResource {
|
||||
|
||||
private final ApiRequestParameterHelper parameterHelper;
|
||||
private static final String BUSINESS_DATE = "BUSINESS_DATE";
|
||||
|
||||
private final PlatformSecurityContext securityContext;
|
||||
private final DefaultToApiJsonSerializer<BusinessDateData> jsonSerializer;
|
||||
private final BusinessDateReadPlatformService readPlatformService;
|
||||
@@ -66,13 +63,9 @@ public class BusinessDateApiResource {
|
||||
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(summary = "List all business dates", description = "")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = BusinessDateApiResourceSwagger.BusinessDateResponse.class)))) })
|
||||
public String getBusinessDates(@Context final UriInfo uriInfo) {
|
||||
securityContext.authenticatedUser().validateHasReadPermission("BUSINESS_DATE");
|
||||
final List<BusinessDateData> foundBusinessDates = this.readPlatformService.findAll();
|
||||
ApiRequestJsonSerializationSettings settings = parameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.jsonSerializer.serialize(settings, foundBusinessDates);
|
||||
public List<BusinessDateData> getBusinessDates() {
|
||||
securityContext.authenticatedUser().validateHasReadPermission(BUSINESS_DATE);
|
||||
return this.readPlatformService.findAll();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -80,28 +73,23 @@ public class BusinessDateApiResource {
|
||||
@Consumes({ MediaType.TEXT_HTML, MediaType.APPLICATION_JSON })
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Operation(summary = "Retrieve a specific Business date", description = "")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = BusinessDateApiResourceSwagger.BusinessDateResponse.class))) })
|
||||
public String getBusinessDate(@PathParam("type") @Parameter(description = "type") final String type, @Context final UriInfo uriInfo) {
|
||||
securityContext.authenticatedUser().validateHasReadPermission("BUSINESS_DATE");
|
||||
final BusinessDateData businessDate = this.readPlatformService.findByType(type);
|
||||
ApiRequestJsonSerializationSettings settings = parameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.jsonSerializer.serialize(settings, businessDate);
|
||||
public BusinessDateData getBusinessDate(@PathParam("type") @Parameter(description = "type") final String type) {
|
||||
securityContext.authenticatedUser().validateHasReadPermission(BUSINESS_DATE);
|
||||
return this.readPlatformService.findByType(type);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "Update Business Date", description = "")
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = BusinessDateApiResourceSwagger.BusinessDateRequest.class)))
|
||||
@RequestBody(required = true, content = @Content(schema = @Schema(implementation = BusinessDateRequest.class)))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = BusinessDateApiResourceSwagger.BusinessDateResponse.class))) })
|
||||
public String updateBusinessDate(final String jsonRequestBody, @Context UriInfo uriInfo) {
|
||||
securityContext.authenticatedUser().validateHasUpdatePermission("BUSINESS_DATE");
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateBusinessDate().withJson(jsonRequestBody).build();
|
||||
|
||||
CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
|
||||
return jsonSerializer.serialize(result);
|
||||
public CommandProcessingResult updateBusinessDate(BusinessDateRequest businessDateRequest) {
|
||||
securityContext.authenticatedUser().validateHasUpdatePermission(BUSINESS_DATE);
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateBusinessDate()
|
||||
.withJson(jsonSerializer.serialize(businessDateRequest)).build();
|
||||
return commandWritePlatformService.logCommandSource(commandRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-24
@@ -19,7 +19,7 @@
|
||||
package org.apache.fineract.infrastructure.businessdate.api;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Map;
|
||||
|
||||
final class BusinessDateApiResourceSwagger {
|
||||
|
||||
@@ -30,32 +30,12 @@ final class BusinessDateApiResourceSwagger {
|
||||
@Schema(description = "BusinessDateResponse")
|
||||
public static final class BusinessDateResponse {
|
||||
|
||||
@Schema(example = "COB date")
|
||||
public String description;
|
||||
@Schema(example = "COB_DATE")
|
||||
public String type;
|
||||
@Schema(example = "[2015,02,15]")
|
||||
public LocalDate date;
|
||||
@Schema(example = "1")
|
||||
public Long commandId;
|
||||
public Map<String, Object> changes;
|
||||
|
||||
private BusinessDateResponse() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Schema(description = "BusinessDateRequest")
|
||||
public static final class BusinessDateRequest {
|
||||
|
||||
@Schema(example = "yyyy-MM-dd")
|
||||
public String dateFormat;
|
||||
@Schema(example = "COB_DATE")
|
||||
public String type;
|
||||
@Schema(example = "2015-02-15")
|
||||
public String date;
|
||||
@Schema(example = "en")
|
||||
public String locale;
|
||||
|
||||
private BusinessDateRequest() {}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
package org.apache.fineract.infrastructure.businessdate.data;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import lombok.Data;
|
||||
@@ -30,6 +31,7 @@ import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
|
||||
@Accessors(chain = true)
|
||||
public class BusinessDateData implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String description;
|
||||
private String type;
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* 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.infrastructure.businessdate.data.request;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
public record BusinessDateRequest(String dateFormat, String type, String date, String locale) implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static BusinessDateRequest ofNull() {
|
||||
return new BusinessDateRequest(null, null, null, null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user