galovics commented on code in PR #2500: URL: https://github.com/apache/fineract/pull/2500#discussion_r949892808
########## fineract-provider/src/main/java/org/apache/fineract/cob/service/ConfigJobParameterServiceImpl.java: ########## @@ -0,0 +1,97 @@ +/** + * 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.service; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.cob.COBBusinessStep; +import org.apache.fineract.cob.data.BusinessStep; +import org.apache.fineract.cob.data.BusinessStepDetail; +import org.apache.fineract.cob.data.JobBusinessStepConfigData; +import org.apache.fineract.cob.data.JobBusinessStepDetail; +import org.apache.fineract.cob.domain.BatchBusinessStep; +import org.apache.fineract.cob.domain.BatchBusinessStepRepository; +import org.apache.fineract.cob.exceptions.BusinessStepNotBelongsToJobException; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class ConfigJobParameterServiceImpl implements ConfigJobParameterService { + + private final BatchBusinessStepRepository batchBusinessStepRepository; + private final BusinessStepConfigDataParser dataParser; + private final BusinessStepCategoryService businessStepCategoryService; + private final ApplicationContext applicationContext; + + @Override + public JobBusinessStepConfigData getBusinessStepConfigByJobName(String jobName) { + List<BatchBusinessStep> batchBusinessSteps = batchBusinessStepRepository.findAllByJobName(jobName); + JobBusinessStepConfigData jobBusinessStepConfigData = new JobBusinessStepConfigData(); + List<BusinessStep> businessSteps = new ArrayList<>(); + batchBusinessSteps.forEach(businessStepconfig -> { + BusinessStep businessStep = new BusinessStep(); + businessStep.setStepName(businessStepconfig.getStepName()); Review Comment: We could do this transformation with MapStruct, please check. ########## fineract-provider/src/main/java/org/apache/fineract/cob/api/ConfigureBusinessStepResource.java: ########## @@ -0,0 +1,122 @@ +/** + * 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.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.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +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.UriInfo; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.cob.data.JobBusinessStepConfigData; +import org.apache.fineract.cob.data.JobBusinessStepDetail; +import org.apache.fineract.cob.service.ConfigJobParameterService; +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.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Path("/jobs") +@Component +@Scope("singleton") +@Tag(name = "Business Step Configuration", description = "") +@RequiredArgsConstructor +public class ConfigureBusinessStepResource { + + private static final Set<String> BUSINESS_STEP_CONFIG_RESPONSE_DATA_PARAMETERS = new HashSet<>( + Arrays.asList("jobName", "businessSteps")); + private static final Set<String> BUSINESS_STEP_DETAIL_RESPONSE_DATA_PARAMETERS = new HashSet<>( + Arrays.asList("jobName", "availableBusinessSteps")); + + private final DefaultToApiJsonSerializer<JobBusinessStepConfigData> businessStepConfigSerializeService; + private final DefaultToApiJsonSerializer<JobBusinessStepDetail> businessStepDetailSerializeService; + private final ApiRequestParameterHelper apiRequestParameterHelper; + private final ConfigJobParameterService configJobParameterService; + private final PortfolioCommandSourceWritePlatformService commandWritePlatformService; + + @GET + @Path("{jobName}/steps") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + @Operation(summary = "List Business Step Configurations for a Job", description = "") + @ApiResponses({ + @ApiResponse(responseCode = "200", description = "OK", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ConfigureBusinessStepResourceSwagger.GetBusinessStepConfigResponse.class)))) }) + public String retrieveAllConfiguredBusinessStep(@Context final UriInfo uriInfo, + @PathParam("jobName") @Parameter(description = "jobName") final String jobName) { + + JobBusinessStepConfigData jobBusinessStepConfigData = configJobParameterService.getBusinessStepConfigByJobName(jobName); + + final ApiRequestJsonSerializationSettings settings = apiRequestParameterHelper.process(uriInfo.getQueryParameters()); + return businessStepConfigSerializeService.serialize(settings, jobBusinessStepConfigData, + BUSINESS_STEP_CONFIG_RESPONSE_DATA_PARAMETERS); + } + + @PUT + @Path("{jobName}/steps") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + @Operation(summary = "List Business Step Configurations for a Job", description = "") + @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, Review Comment: The update Swagger spec is missing from here hence it won't be generated for the fineract-client project. ########## fineract-provider/src/main/java/org/apache/fineract/cob/api/ConfigureBusinessStepResource.java: ########## @@ -0,0 +1,122 @@ +/** + * 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.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.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +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.UriInfo; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.cob.data.JobBusinessStepConfigData; +import org.apache.fineract.cob.data.JobBusinessStepDetail; +import org.apache.fineract.cob.service.ConfigJobParameterService; +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.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Path("/jobs") +@Component +@Scope("singleton") Review Comment: The scope annotation is superfluous. ########## fineract-provider/src/main/java/org/apache/fineract/cob/service/BusinessStepCategoryServiceImpl.java: ########## @@ -0,0 +1,45 @@ +/** + * 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.service; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.PostConstruct; +import org.apache.fineract.cob.COBBusinessStep; +import org.apache.fineract.cob.loan.LoanCOBBusinessStep; +import org.springframework.data.util.Pair; +import org.springframework.stereotype.Service; + +@Service +public class BusinessStepCategoryServiceImpl implements BusinessStepCategoryService { + + private final List<Pair<String, Class<? extends COBBusinessStep>>> businessSteps = new ArrayList<>(); + + @PostConstruct + public void init() { Review Comment: This could be skipped. The whole business step initialization could go into inline initialization and then you can use an immutable data structure as well. Plus, I'm not sure why you're utilizing a List here since you're mimicing a Map structure. ########## fineract-provider/src/main/java/org/apache/fineract/cob/service/BusinessStepCategoryServiceImpl.java: ########## @@ -0,0 +1,45 @@ +/** + * 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.service; + +import java.util.ArrayList; +import java.util.List; +import javax.annotation.PostConstruct; +import org.apache.fineract.cob.COBBusinessStep; +import org.apache.fineract.cob.loan.LoanCOBBusinessStep; +import org.springframework.data.util.Pair; +import org.springframework.stereotype.Service; + +@Service +public class BusinessStepCategoryServiceImpl implements BusinessStepCategoryService { + + private final List<Pair<String, Class<? extends COBBusinessStep>>> businessSteps = new ArrayList<>(); + + @PostConstruct + public void init() { + businessSteps.add(Pair.of("LOAN", LoanCOBBusinessStep.class)); Review Comment: Can we extract the magic string into an enum rather or at least a constant somewhere? I wanna make sure people can reference it somewhere in a more type safe manner. ########## fineract-provider/src/main/resources/db/changelog/tenant/parts/0036_add_loan_cob_job_data.xml: ########## @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> Review Comment: Same as for the previous file. ########## fineract-provider/src/main/resources/db/changelog/tenant/parts/0027_add_loan_cob_job_data.xml: ########## @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> Review Comment: Something has been mixed up I think and this file is not needed. Please double-check. ########## fineract-provider/src/main/java/org/apache/fineract/cob/service/BusinessStepConfigUpdateHandler.java: ########## @@ -0,0 +1,43 @@ +/** + * 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.service; + +import com.google.common.base.Splitter; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.commands.annotation.CommandType; +import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +@CommandType(entity = "BATCH_BUSINESS_STEP", action = "UPDATE") +public class BusinessStepConfigUpdateHandler implements NewCommandSourceHandler { + + private final ConfigJobParameterService configJobParameterService; + + @Override Review Comment: `@Transactional` is missing. ########## fineract-provider/src/main/java/org/apache/fineract/cob/service/BusinessStepConfigUpdateHandler.java: ########## @@ -0,0 +1,43 @@ +/** + * 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.service; + +import com.google.common.base.Splitter; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.apache.fineract.commands.annotation.CommandType; +import org.apache.fineract.commands.handler.NewCommandSourceHandler; +import org.apache.fineract.infrastructure.core.api.JsonCommand; +import org.apache.fineract.infrastructure.core.data.CommandProcessingResult; +import org.springframework.stereotype.Service; + +@RequiredArgsConstructor +@Service +@CommandType(entity = "BATCH_BUSINESS_STEP", action = "UPDATE") +public class BusinessStepConfigUpdateHandler implements NewCommandSourceHandler { + + private final ConfigJobParameterService configJobParameterService; + + @Override + public CommandProcessingResult processCommand(JsonCommand command) { + List<String> split = Splitter.on("/").splitToList(command.getUrl()); Review Comment: I hope we have test coverage for this at least on 80%. String manipulation is always very risky, please add the necessary coverage. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
