Skip to content

Commit 240a51e

Browse files
committed
FINERACT-2373: Fix backward compatibility issue of Loan COB
1 parent a81f4f8 commit 240a51e

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.cob.converter;
20+
21+
import org.apache.fineract.cob.data.COBParameter;
22+
import org.apache.fineract.cob.data.LoanCOBParameter;
23+
24+
public final class COBParameterConverter {
25+
26+
private COBParameterConverter() {}
27+
28+
public static COBParameter convert(Object obj) {
29+
if (obj instanceof COBParameter) {
30+
return (COBParameter) obj;
31+
} else if (obj instanceof LoanCOBParameter loanCOBParameter) {
32+
return loanCOBParameter.toCOBParameter();
33+
}
34+
return null;
35+
}
36+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.cob.data;
20+
21+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
22+
import lombok.AllArgsConstructor;
23+
import lombok.EqualsAndHashCode;
24+
import lombok.Getter;
25+
import lombok.NoArgsConstructor;
26+
27+
@AllArgsConstructor
28+
@Getter
29+
@NoArgsConstructor
30+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS)
31+
@EqualsAndHashCode
32+
public class LoanCOBParameter {
33+
34+
private Long minLoanId;
35+
private Long maxLoanId;
36+
37+
public COBParameter toCOBParameter() {
38+
return new COBParameter(this.minLoanId, this.maxLoanId);
39+
}
40+
}

fineract-provider/src/main/java/org/apache/fineract/cob/loan/ApplyLoanLockTasklet.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import lombok.RequiredArgsConstructor;
3030
import lombok.extern.slf4j.Slf4j;
3131
import org.apache.fineract.cob.common.CustomJobParameterResolver;
32+
import org.apache.fineract.cob.converter.COBParameterConverter;
3233
import org.apache.fineract.cob.data.COBParameter;
3334
import org.apache.fineract.cob.domain.LoanAccountLock;
3435
import org.apache.fineract.cob.domain.LockOwner;
@@ -61,7 +62,7 @@ public RepeatStatus execute(@NonNull StepContribution contribution, @NonNull Chu
6162
throws LoanLockCannotBeAppliedException {
6263
ExecutionContext executionContext = contribution.getStepExecution().getExecutionContext();
6364
long numberOfExecutions = contribution.getStepExecution().getCommitCount();
64-
COBParameter loanCOBParameter = (COBParameter) executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER);
65+
COBParameter loanCOBParameter = COBParameterConverter.convert(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER));
6566
List<Long> loanIds;
6667
if (Objects.isNull(loanCOBParameter)
6768
|| (Objects.isNull(loanCOBParameter.getMinAccountId()) && Objects.isNull(loanCOBParameter.getMaxAccountId()))

fineract-provider/src/main/java/org/apache/fineract/cob/loan/LoanItemReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.concurrent.LinkedBlockingQueue;
2626
import lombok.extern.slf4j.Slf4j;
2727
import org.apache.fineract.cob.common.CustomJobParameterResolver;
28+
import org.apache.fineract.cob.converter.COBParameterConverter;
2829
import org.apache.fineract.cob.data.COBParameter;
2930
import org.apache.fineract.cob.domain.LoanAccountLock;
3031
import org.apache.fineract.cob.domain.LockOwner;
@@ -53,7 +54,7 @@ public LoanItemReader(LoanRepository loanRepository, RetrieveLoanIdService retri
5354
@SuppressWarnings({ "unchecked" })
5455
public void beforeStep(@NonNull StepExecution stepExecution) {
5556
ExecutionContext executionContext = stepExecution.getExecutionContext();
56-
COBParameter loanCOBParameter = (COBParameter) executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER);
57+
COBParameter loanCOBParameter = COBParameterConverter.convert(executionContext.get(LoanCOBConstant.LOAN_COB_PARAMETER));
5758
List<Long> loanIds;
5859
if (Objects.isNull(loanCOBParameter)
5960
|| (Objects.isNull(loanCOBParameter.getMinAccountId()) && Objects.isNull(loanCOBParameter.getMaxAccountId()))

0 commit comments

Comments
 (0)