galovics commented on code in PR #2759:
URL: https://github.com/apache/fineract/pull/2759#discussion_r1031629950
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/JobStarter.java:
##########
@@ -45,14 +50,19 @@ public class JobStarter {
private final JobExplorer jobExplorer;
private final JobLauncher jobLauncher;
private final JobParameterRepository jobParameterRepository;
+ private final List<JobParameterProvider> jobParameterProviders;
+ private final JobNameService jobNameService;
- public void run(Job job, ScheduledJobDetail scheduledJobDetail,
FineractContext fineractContext)
- throws JobInstanceAlreadyCompleteException,
JobExecutionAlreadyRunningException, JobParametersInvalidException,
- JobRestartException {
+ public void run(Job job, ScheduledJobDetail scheduledJobDetail,
FineractContext fineractContext,
+ List<JobParameterDTO> jobParameterDTOList) throws
JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException,
Review Comment:
I think we can make this a Set instead of a List and make the
JobParameterDTO to implement an equals and hashcode. What do you think?
##########
fineract-provider/src/main/java/org/apache/fineract/cob/loan/ResolveLoanCOBCustomJobParametersTasklet.java:
##########
@@ -0,0 +1,76 @@
+/**
+ * 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.loan;
+
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.cob.exceptions.CustomJobParameterNotFoundException;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import
org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
+import org.apache.fineract.infrastructure.jobs.domain.CustomJobParameter;
+import
org.apache.fineract.infrastructure.jobs.domain.CustomJobParameterRepository;
+import org.apache.fineract.infrastructure.springbatch.SpringBatchJobConstants;
+import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.core.step.tasklet.Tasklet;
+import org.springframework.batch.repeat.RepeatStatus;
+import org.springframework.beans.factory.InitializingBean;
+
+@Slf4j
+@RequiredArgsConstructor
+public class ResolveLoanCOBCustomJobParametersTasklet implements Tasklet,
InitializingBean {
Review Comment:
I feel like we should do some abstraction here.
Obviously the majority of this code is generic:
- Creating the GSON serializer
- Reading the custom job parameter from the DB
- deserializing it
The rest is specific to the Loan COB, i.e. that the business date parameter
is used. I think other jobs could benefit from making an abstract class from
this an have specializations for jobs.
Thoughts?
##########
fineract-provider/src/main/java/org/apache/fineract/portfolio/loanaccount/domain/Loan.java:
##########
@@ -430,6 +430,9 @@ public class Loan extends
AbstractAuditableWithUTCDateTimeCustom {
@Column(name = "fixed_principal_percentage_per_installment", scale = 2,
precision = 5, nullable = true)
private BigDecimal fixedPrincipalPercentagePerInstallment;
+ @Column(name = "last_cob_business_date")
Review Comment:
I think this could be called more generically like
`last_closed_business_date`
##########
fineract-provider/src/main/java/org/apache/fineract/cob/loan/AbstractLoanItemWriter.java:
##########
@@ -18,25 +18,41 @@
*/
package org.apache.fineract.cob.loan;
+import java.time.LocalDate;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.cob.domain.LoanAccountLockRepository;
import org.apache.fineract.cob.domain.LockOwner;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
import
org.apache.fineract.infrastructure.core.domain.AbstractPersistableCustom;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.portfolio.loanaccount.domain.Loan;
import org.jetbrains.annotations.NotNull;
+import org.springframework.batch.core.StepExecution;
+import org.springframework.batch.core.annotation.BeforeStep;
+import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.data.RepositoryItemWriter;
@Slf4j
@RequiredArgsConstructor
public abstract class AbstractLoanItemWriter extends
RepositoryItemWriter<Loan> {
private final LoanAccountLockRepository accountLockRepository;
+ private LocalDate businessDate;
+
+ @BeforeStep
+ public void beforeStep(@NotNull StepExecution stepExecution) {
+ ExecutionContext jobExecutionContext =
stepExecution.getJobExecution().getExecutionContext();
+ String businessDate = (String)
jobExecutionContext.get(LoanCOBConstant.BUSINESS_DATE_PARAMETER_NAME);
+ this.businessDate = businessDate != null ?
LocalDate.parse(businessDate)
+ :
ThreadLocalContextUtil.getBusinessDateByType(BusinessDateType.COB_DATE);
+ }
@Override
public void write(@NotNull List<? extends Loan> items) throws Exception {
super.write(items);
+ items.forEach(loan -> loan.setLastCOBBusinessDate(businessDate));
Review Comment:
Not sure about this. Wouldn't it be better within the processor?
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/jobparameterprovider/LoanCOBJobParameterProviderImpl.java:
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.jobs.service.jobparameterprovider;
+
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.cob.loan.LoanCOBConstant;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import
org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
+import org.apache.fineract.infrastructure.jobs.domain.CustomJobParameter;
+import
org.apache.fineract.infrastructure.jobs.domain.CustomJobParameterRepository;
+import org.apache.fineract.infrastructure.jobs.service.JobName;
+import org.apache.fineract.infrastructure.springbatch.SpringBatchJobConstants;
+import org.springframework.batch.core.JobParameter;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+public class LoanCOBJobParameterProviderImpl implements JobParameterProvider,
InitializingBean {
+
+ private final CustomJobParameterRepository customJobParameterRepository;
+ private final GoogleGsonSerializerHelper gsonFactory;
+
+ private Gson gson;
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ this.gson = gsonFactory.createSimpleGson();
+ }
+
+ @Override
+ public Map<String, JobParameter> provide(List<JobParameterDTO>
jobParameterDTOList) {
+ Map<String, JobParameter> jobParameterMap = new HashMap<>();
+ CustomJobParameter customJobParameter = new CustomJobParameter();
+
customJobParameter.setParameterJson(gson.toJson(getJobParameterDTOListWithCorrectBusinessDate(jobParameterDTOList)));
+ CustomJobParameter savedCustomJobParameter =
customJobParameterRepository.saveAndFlush(customJobParameter);
Review Comment:
No need for saveAndFlush. A regular save should be enough I think and put
the @Transactional annotation onto the method so the boundaries are properly
defined.
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/jobparameterprovider/JobParameterProvider.java:
##########
@@ -0,0 +1,35 @@
+/**
+ * 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.jobs.service.jobparameterprovider;
+
+import java.util.List;
+import java.util.Map;
+import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
+import org.springframework.batch.core.JobParameter;
+
+public interface JobParameterProvider {
+
+ Map<String, JobParameter> provide(List<JobParameterDTO>
jobParameterDTOList);
+
+ String getJobName();
+
+ default boolean canProvideParametersForJob(String jobName) {
Review Comment:
Well. :))))
Would be nicer to put this logic into an abstract class and use the template
method pattern but works this way too. It's just abusing the default methods a
little bit :)))
##########
fineract-provider/src/main/java/org/apache/fineract/infrastructure/jobs/service/jobparameterprovider/LoanCOBJobParameterProviderImpl.java:
##########
@@ -0,0 +1,82 @@
+/**
+ * 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.jobs.service.jobparameterprovider;
+
+import com.google.gson.Gson;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import lombok.RequiredArgsConstructor;
+import org.apache.fineract.cob.loan.LoanCOBConstant;
+import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType;
+import
org.apache.fineract.infrastructure.core.serialization.GoogleGsonSerializerHelper;
+import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
+import org.apache.fineract.infrastructure.jobs.data.JobParameterDTO;
+import org.apache.fineract.infrastructure.jobs.domain.CustomJobParameter;
+import
org.apache.fineract.infrastructure.jobs.domain.CustomJobParameterRepository;
+import org.apache.fineract.infrastructure.jobs.service.JobName;
+import org.apache.fineract.infrastructure.springbatch.SpringBatchJobConstants;
+import org.springframework.batch.core.JobParameter;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.stereotype.Component;
+
+@Component
+@RequiredArgsConstructor
+public class LoanCOBJobParameterProviderImpl implements JobParameterProvider,
InitializingBean {
Review Comment:
Let's drop the Impl postfix. Never liked it and doesn't add value at all.
--
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]