FINERACT-2067: NPE business date partition step COB
This commit is contained in:
committed by
Adam Saghy
parent
c511385946
commit
7b058d6772
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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.listener;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
/**
|
||||
* {@link StepExecutionListener} to copy values from Job execution context into Step execution context.
|
||||
*/
|
||||
@Slf4j
|
||||
public class JobExecutionContextCopyListener implements StepExecutionListener {
|
||||
|
||||
private final List<String> stepExecutionKeys;
|
||||
|
||||
public JobExecutionContextCopyListener(List<String> stepExecutionKeys) {
|
||||
this.stepExecutionKeys = stepExecutionKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to copy values from Job execution context into Step execution context before step execution.
|
||||
*
|
||||
* @param stepExecution
|
||||
* the step to be executed.
|
||||
*/
|
||||
@Override
|
||||
public void beforeStep(final StepExecution stepExecution) {
|
||||
log.debug("Before step: copying job execution context to step [{}]", stepExecution.getStepName());
|
||||
|
||||
final ExecutionContext stepExecutionContext = stepExecution.getExecutionContext();
|
||||
final ExecutionContext jobExecutionContext = stepExecution.getJobExecution().getExecutionContext();
|
||||
|
||||
jobExecutionContext.entrySet().forEach(jobExecutionContextEntry -> {
|
||||
if (stepExecutionKeys.contains(jobExecutionContextEntry.getKey())
|
||||
&& BooleanUtils.isFalse(stepExecutionContext.containsKey(jobExecutionContextEntry.getKey()))) {
|
||||
stepExecutionContext.put(jobExecutionContextEntry.getKey(), jobExecutionContextEntry.getValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+6
-2
@@ -20,16 +20,19 @@ package org.apache.fineract.cob.loan;
|
||||
|
||||
import static org.apache.fineract.cob.loan.LoanCOBConstant.JOB_NAME;
|
||||
|
||||
import java.util.List;
|
||||
import org.apache.fineract.cob.COBBusinessStepService;
|
||||
import org.apache.fineract.cob.common.CustomJobParameterResolver;
|
||||
import org.apache.fineract.cob.conditions.BatchManagerCondition;
|
||||
import org.apache.fineract.cob.listener.COBExecutionListenerRunner;
|
||||
import org.apache.fineract.cob.listener.JobExecutionContextCopyListener;
|
||||
import org.apache.fineract.infrastructure.event.business.service.BusinessEventNotifierService;
|
||||
import org.apache.fineract.infrastructure.jobs.service.JobName;
|
||||
import org.apache.fineract.infrastructure.springbatch.PropertyService;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.configuration.annotation.JobScope;
|
||||
import org.springframework.batch.core.configuration.annotation.StepScope;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
@@ -78,7 +81,7 @@ public class LoanCOBManagerConfiguration {
|
||||
private CustomJobParameterResolver customJobParameterResolver;
|
||||
|
||||
@Bean
|
||||
@JobScope
|
||||
@StepScope
|
||||
public LoanCOBPartitioner partitioner() {
|
||||
return new LoanCOBPartitioner(propertyService, cobBusinessStepService, retrieveLoanIdService, jobOperator, jobExplorer,
|
||||
LoanCOBConstant.NUMBER_OF_DAYS_BEHIND);
|
||||
@@ -88,7 +91,8 @@ public class LoanCOBManagerConfiguration {
|
||||
public Step loanCOBStep() {
|
||||
return stepBuilderFactory.get(LoanCOBConstant.LOAN_COB_PARTITIONER_STEP)
|
||||
.partitioner(LoanCOBConstant.LOAN_COB_WORKER_STEP, partitioner()).pollInterval(propertyService.getPollInterval(JOB_NAME))
|
||||
.outputChannel(outboundRequests).build();
|
||||
.listener(new JobExecutionContextCopyListener(List.of("BusinessDate", "IS_CATCH_UP"))).outputChannel(outboundRequests)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
+2
-2
@@ -58,10 +58,10 @@ public class LoanCOBPartitioner implements Partitioner {
|
||||
|
||||
private final Long numberOfDays;
|
||||
|
||||
@Value("#{jobExecutionContext['BusinessDate']}")
|
||||
@Value("#{stepExecutionContext['BusinessDate']}")
|
||||
@Setter
|
||||
private LocalDate businessDate;
|
||||
@Value("#{jobExecutionContext['IS_CATCH_UP']}")
|
||||
@Value("#{stepExecutionContext['IS_CATCH_UP']}")
|
||||
@Setter
|
||||
private Boolean isCatchUp;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user