[FINERACT-1852] Swagger schema inconsistency for Business Step Config APIs
This commit is contained in:
committed by
Arnold Gálovics
parent
4a250b7a56
commit
20d96d9542
+12
-13
@@ -18,10 +18,8 @@
|
||||
*/
|
||||
package org.apache.fineract.cob.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
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;
|
||||
@@ -40,8 +38,10 @@ import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.fineract.cob.data.ConfiguredJobNamesDTO;
|
||||
import org.apache.fineract.cob.data.JobBusinessStepConfigData;
|
||||
import org.apache.fineract.cob.data.JobBusinessStepDetail;
|
||||
import org.apache.fineract.cob.service.ConfigJobParameterService;
|
||||
@@ -49,7 +49,6 @@ 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.springframework.stereotype.Component;
|
||||
@@ -67,6 +66,7 @@ public class ConfigureBusinessStepResource {
|
||||
|
||||
private final DefaultToApiJsonSerializer<JobBusinessStepConfigData> businessStepConfigSerializeService;
|
||||
private final DefaultToApiJsonSerializer<JobBusinessStepDetail> businessStepDetailSerializeService;
|
||||
private final DefaultToApiJsonSerializer<ConfiguredJobNamesDTO> configuredJobNamesSerializer;
|
||||
private final ApiRequestParameterHelper apiRequestParameterHelper;
|
||||
private final ConfigJobParameterService configJobParameterService;
|
||||
private final PortfolioCommandSourceWritePlatformService commandWritePlatformService;
|
||||
@@ -76,13 +76,13 @@ public class ConfigureBusinessStepResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List Business Jobs", description = "Returns the configured Business Jobs")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessJobConfigResponse.class)))) })
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessJobConfigResponse.class))) })
|
||||
public String retrieveAllConfiguredBusinessJobs(@Context final UriInfo uriInfo) {
|
||||
|
||||
List<String> businessJobNames = configJobParameterService.getAllConfiguredJobNames();
|
||||
final Gson gson = new Gson();
|
||||
ConfiguredJobNamesDTO result = new ConfiguredJobNamesDTO(businessJobNames);
|
||||
|
||||
return gson.toJson(businessJobNames);
|
||||
return configuredJobNamesSerializer.serialize(result);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -91,7 +91,7 @@ public class ConfigureBusinessStepResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List Business Step Configurations for a Job", description = "Returns the configured Business Steps for a job")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class)))) })
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class))) })
|
||||
public String retrieveAllConfiguredBusinessStep(@Context final UriInfo uriInfo,
|
||||
@PathParam("jobName") @Parameter(description = "jobName") final String jobName) {
|
||||
|
||||
@@ -108,15 +108,14 @@ public class ConfigureBusinessStepResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List Business Step Configurations for a Job", description = "Updates the Business steps execution order for a job")
|
||||
@RequestBody(content = @Content(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.UpdateBusinessStepConfigRequest.class)))
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "204", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class)))) })
|
||||
public String updateJobBusinessStepConfig(@PathParam("jobName") @Parameter(description = "jobName") final String jobName,
|
||||
@ApiResponses({ @ApiResponse(responseCode = "204", description = "NO_CONTENT") })
|
||||
public Response updateJobBusinessStepConfig(@PathParam("jobName") @Parameter(description = "jobName") final String jobName,
|
||||
@Parameter(hidden = true) final String jsonRequestBody) {
|
||||
|
||||
final CommandWrapper commandRequest = new CommandWrapperBuilder().updateBusinessStepConfig(jobName).withJson(jsonRequestBody)
|
||||
.build();
|
||||
CommandProcessingResult result = commandWritePlatformService.logCommandSource(commandRequest);
|
||||
return businessStepConfigSerializeService.serialize(result);
|
||||
commandWritePlatformService.logCommandSource(commandRequest);
|
||||
return Response.status(Response.Status.NO_CONTENT).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -125,7 +124,7 @@ public class ConfigureBusinessStepResource {
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Operation(summary = "List Business Step Configurations for a Job", description = "Returns the available Business Steps for a job")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class)))) })
|
||||
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class))) })
|
||||
public String retrieveAllAvailableBusinessStep(@Context final UriInfo uriInfo,
|
||||
@PathParam("jobName") @Parameter(description = "jobName") final String jobName) {
|
||||
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.cob.data;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ConfiguredJobNamesDTO {
|
||||
|
||||
private List<String> businessJobs;
|
||||
}
|
||||
+1
-1
@@ -165,7 +165,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
command -> new IdempotentCommandProcessUnderProcessingException(wrapper));
|
||||
idempotentExceptionByStatus(ERROR, existingCommand, command -> new IdempotentCommandProcessFailedException(wrapper, command));
|
||||
idempotentExceptionByStatus(PROCESSED, existingCommand,
|
||||
command -> new IdempotentCommandProcessSucceedException(wrapper, command.getResult()));
|
||||
command -> new IdempotentCommandProcessSucceedException(wrapper, command.getResult(), command.getResultStatusCode()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -25,7 +25,14 @@ import org.apache.fineract.commands.domain.CommandWrapper;
|
||||
*/
|
||||
public class IdempotentCommandProcessSucceedException extends AbstractIdempotentCommandException {
|
||||
|
||||
public IdempotentCommandProcessSucceedException(CommandWrapper wrapper, String response) {
|
||||
private final Integer statusCode;
|
||||
|
||||
public IdempotentCommandProcessSucceedException(CommandWrapper wrapper, String response, Integer statusCode) {
|
||||
super(wrapper.actionName(), wrapper.entityName(), wrapper.getIdempotencyKey(), response);
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public Integer getStatusCode() {
|
||||
return statusCode;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-3
@@ -20,7 +20,6 @@ package org.apache.fineract.infrastructure.core.exceptionmapper;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
import javax.ws.rs.ext.ExceptionMapper;
|
||||
import javax.ws.rs.ext.Provider;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -36,7 +35,11 @@ public class IdempotentCommandProcessSucceedExceptionMapper implements Exception
|
||||
@Override
|
||||
public Response toResponse(final IdempotentCommandProcessSucceedException exception) {
|
||||
log.debug("Idempotent processing success request: {}", exception.getMessage());
|
||||
return Response.status(Status.OK).entity(exception.getResponse())
|
||||
.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER, "true").type(MediaType.APPLICATION_JSON).build();
|
||||
Response.ResponseBuilder responseBuilder = Response.status(exception.getStatusCode());
|
||||
if (exception.getResponse() != null) {
|
||||
responseBuilder.entity(exception.getResponse());
|
||||
}
|
||||
return responseBuilder.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER, "true").type(MediaType.APPLICATION_JSON)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -70,7 +70,8 @@ public class IdempotencyStoreFilter extends OncePerRequestFilter implements Batc
|
||||
boolean isSuccessWithoutStored = isStoreIdempotencyKey(request) && commandId.isPresent() && isAllowedContentTypeResponse(response)
|
||||
&& wrapper.getValue() != null;
|
||||
if (isSuccessWithoutStored) {
|
||||
storeCommandResult(response.getStatus(), new String(wrapper.getValue().getContentAsByteArray(), StandardCharsets.UTF_8),
|
||||
storeCommandResult(response.getStatus(), Optional.ofNullable(wrapper.getValue())
|
||||
.map(ContentCachingResponseWrapper::getContentAsByteArray).map(s -> new String(s, StandardCharsets.UTF_8)).orElse(null),
|
||||
commandId);
|
||||
}
|
||||
if (wrapper.getValue() != null) {
|
||||
@@ -92,7 +93,7 @@ public class IdempotencyStoreFilter extends OncePerRequestFilter implements Batc
|
||||
|
||||
private boolean isAllowedContentTypeResponse(HttpServletResponse response) {
|
||||
return Optional.ofNullable(response.getContentType()).map(String::toLowerCase).map(ct -> ct.contains("application/json"))
|
||||
.orElse(false);
|
||||
.orElse(false) || (response.getStatus() > 200 && response.getStatus() < 300);
|
||||
}
|
||||
|
||||
private boolean isAllowedContentTypeRequest(HttpServletRequest request) {
|
||||
|
||||
+5
-4
@@ -83,12 +83,13 @@ public class BusinessConfigurationApiTest {
|
||||
|
||||
@Test
|
||||
public void shouldUpdateStepOrder() {
|
||||
ResponseSpecification updateResponseSpec = new ResponseSpecBuilder().expectStatusCode(204).build();
|
||||
JobBusinessStepConfigData originalStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec,
|
||||
responseSpec, LOAN_JOB_NAME);
|
||||
|
||||
List<BusinessStep> requestBody = new ArrayList<>();
|
||||
requestBody.add(getBusinessSteps(1L, APPLY_CHARGE_TO_OVERDUE_LOANS));
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.toJsonString(requestBody));
|
||||
|
||||
JobBusinessStepConfigData newStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec,
|
||||
@@ -100,7 +101,7 @@ public class BusinessConfigurationApiTest {
|
||||
|
||||
requestBody.add(getBusinessSteps(2L, LOAN_DELINQUENCY_CLASSIFICATION));
|
||||
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.toJsonString(requestBody));
|
||||
newStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec, responseSpec, LOAN_JOB_NAME);
|
||||
applyChargeStep = newStepConfig.getBusinessSteps().stream()
|
||||
@@ -112,7 +113,7 @@ public class BusinessConfigurationApiTest {
|
||||
assertEquals(2L, loanDelinquencyStep.getOrder());
|
||||
|
||||
requestBody.remove(1);
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.toJsonString(requestBody));
|
||||
|
||||
newStepConfig = BusinessStepConfigurationHelper.getConfiguredBusinessStepsByJobName(requestSpec, responseSpec, LOAN_JOB_NAME);
|
||||
@@ -121,7 +122,7 @@ public class BusinessConfigurationApiTest {
|
||||
assertEquals(1, newStepConfig.getBusinessSteps().size());
|
||||
assertEquals(1L, applyChargeStep.getOrder());
|
||||
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
BusinessStepConfigurationHelper.toJsonString(originalStepConfig.getBusinessSteps()));
|
||||
}
|
||||
|
||||
|
||||
+9
-8
@@ -58,6 +58,7 @@ public class IdempotencyTest {
|
||||
|
||||
@Test
|
||||
public void shouldUpdateStepOrder() {
|
||||
ResponseSpecification updateResponseSpec = new ResponseSpecBuilder().expectStatusCode(204).build();
|
||||
JobBusinessStepConfigData originalStepConfig = IdempotencyHelper.getConfiguredBusinessStepsByJobName(requestSpec, responseSpec,
|
||||
LOAN_JOB_NAME);
|
||||
|
||||
@@ -65,9 +66,9 @@ public class IdempotencyTest {
|
||||
|
||||
List<BusinessStep> requestBody = new ArrayList<>();
|
||||
requestBody.add(getBusinessSteps(1L, APPLY_CHARGE_TO_OVERDUE_LOANS));
|
||||
Response response = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
Response response = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
Response responseSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
Response responseSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
Assertions.assertEquals(response.getBody().asString(), responseSecond.getBody().asString());
|
||||
Assertions.assertNull(response.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER));
|
||||
@@ -84,9 +85,9 @@ public class IdempotencyTest {
|
||||
|
||||
requestBody.add(getBusinessSteps(2L, LOAN_DELINQUENCY_CLASSIFICATION));
|
||||
|
||||
Response update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
Response update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
Response updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
Response updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
Assertions.assertNull(update.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER));
|
||||
Assertions.assertNotNull(updateSecond.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER));
|
||||
@@ -103,9 +104,9 @@ public class IdempotencyTest {
|
||||
|
||||
requestBody.remove(1);
|
||||
idempotencyKeyHeader = UUID.randomUUID().toString();
|
||||
update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(requestBody), idempotencyKeyHeader);
|
||||
|
||||
Assertions.assertNull(update.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER));
|
||||
@@ -120,9 +121,9 @@ public class IdempotencyTest {
|
||||
|
||||
idempotencyKeyHeader = UUID.randomUUID().toString();
|
||||
|
||||
update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
update = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(originalStepConfig.getBusinessSteps()), idempotencyKeyHeader);
|
||||
updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, responseSpec, LOAN_JOB_NAME,
|
||||
updateSecond = IdempotencyHelper.updateBusinessStepOrder(requestSpec, updateResponseSpec, LOAN_JOB_NAME,
|
||||
IdempotencyHelper.toJsonString(originalStepConfig.getBusinessSteps()), idempotencyKeyHeader);
|
||||
|
||||
Assertions.assertNull(update.header(AbstractIdempotentCommandException.IDEMPOTENT_CACHE_HEADER));
|
||||
|
||||
Reference in New Issue
Block a user