diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/converter/COBParameterConverter.java b/fineract-provider/src/main/java/org/apache/fineract/cob/converter/COBParameterConverter.java new file mode 100644 index 000000000..70639d9fb --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/converter/COBParameterConverter.java @@ -0,0 +1,36 @@ +/** + * 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.converter; + +import org.apache.fineract.cob.data.COBParameter; +import org.apache.fineract.cob.data.LoanCOBParameter; + +public final class COBParameterConverter { + + private COBParameterConverter() {} + + public static COBParameter convert(Object obj) { + if (obj instanceof COBParameter) { + return (COBParameter) obj; + } else if (obj instanceof LoanCOBParameter loanCOBParameter) { + return loanCOBParameter.toCOBParameter(); + } + return null; + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/data/LoanCOBParameter.java b/fineract-provider/src/main/java/org/apache/fineract/cob/data/LoanCOBParameter.java new file mode 100644 index 000000000..a17c5a9bf --- /dev/null +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/data/LoanCOBParameter.java @@ -0,0 +1,40 @@ +/** + * 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 com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@Getter +@NoArgsConstructor +@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) +@EqualsAndHashCode +public class LoanCOBParameter { + + private Long minLoanId; + private Long maxLoanId; + + public COBParameter toCOBParameter() { + return new COBParameter(this.minLoanId, this.maxLoanId); + } +} diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java index dab46770d..3d6a90793 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java @@ -29,6 +29,7 @@ import java.util.Objects; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.cob.common.CustomJobParameterResolver; +import org.apache.fineract.cob.converter.COBParameterConverter; import org.apache.fineract.cob.data.COBParameter; import org.apache.fineract.cob.domain.LoanAccountLock; import org.apache.fineract.cob.domain.LockOwner; @@ -61,7 +62,7 @@ public class ApplyLoanLockTasklet implements Tasklet { throws LoanLockCannotBeAppliedException { ExecutionContext executionContext = contribution.getStepExecution().getExecutionContext(); long numberOfExecutions = contribution.getStepExecution().getCommitCount(); - COBParameter loanCOBParameter = (COBParameter) executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER); + COBParameter loanCOBParameter = COBParameterConverter.convert(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER)); List loanIds; if (Objects.isNull(loanCOBParameter) || (Objects.isNull(loanCOBParameter.getMinAccountId()) && Objects.isNull(loanCOBParameter.getMaxAccountId())) diff --git a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java index 933c65667..9ee7d325d 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java +++ b/fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java @@ -25,6 +25,7 @@ import java.util.Objects; import java.util.concurrent.LinkedBlockingQueue; import lombok.extern.slf4j.Slf4j; import org.apache.fineract.cob.common.CustomJobParameterResolver; +import org.apache.fineract.cob.converter.COBParameterConverter; import org.apache.fineract.cob.data.COBParameter; import org.apache.fineract.cob.domain.LoanAccountLock; import org.apache.fineract.cob.domain.LockOwner; @@ -53,7 +54,7 @@ public class LoanItemReader extends AbstractLoanItemReader { @SuppressWarnings({ "unchecked" }) public void beforeStep(@NonNull StepExecution stepExecution) { ExecutionContext executionContext = stepExecution.getExecutionContext(); - COBParameter loanCOBParameter = (COBParameter) executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER); + COBParameter loanCOBParameter = COBParameterConverter.convert(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER)); List loanIds; if (Objects.isNull(loanCOBParameter) || (Objects.isNull(loanCOBParameter.getMinAccountId()) && Objects.isNull(loanCOBParameter.getMaxAccountId()))