FINERACT-2119: Address jobs by name

This commit is contained in:
Marta Jankovics
2024-08-28 16:46:20 +02:00
committed by Adam Saghy
parent eef6a8da5e
commit 3aaa2ffe9c
27 changed files with 761 additions and 185 deletions
@@ -34,7 +34,7 @@ public class CacheConfiguration {
public CacheManager cacheManager() {
SimpleCacheManager simpleCacheManager = new SimpleCacheManager();
simpleCacheManager.setCaches(List.of(new ConcurrentMapCache("paymentTypesByName"), //
new ConcurrentMapCache("jobsByName"), //
new ConcurrentMapCache("jobsByShortName"), //
new ConcurrentMapCache("loanProductsByName"), //
new ConcurrentMapCache("accountTypesByName")));//
return simpleCacheManager;
@@ -20,18 +20,28 @@ package org.apache.fineract.test.data.job;
public enum DefaultJob implements Job {
ADD_ACCRUAL_TRANSACTIONS("Add Accrual Transactions"), ADD_PERIODIC_ACCRUAL_TRANSACTIONS(
"Add Periodic Accrual Transactions"), INCREASE_BUSINESS_DAY("Increase Business Date by 1 day"), LOAN_DELINQUENCY_CLASSIFICATION(
"Loan Delinquency Classification"), LOAN_COB("Loan COB");
ADD_ACCRUAL_TRANSACTIONS("Add Accrual Transactions", "LA_AATR"), //
ADD_PERIODIC_ACCRUAL_TRANSACTIONS("Add Periodic Accrual Transactions", "ACC_APTR"), //
INCREASE_BUSINESS_DAY("Increase Business Date by 1 day", "BDT_INC1"), //
LOAN_DELINQUENCY_CLASSIFICATION("Loan Delinquency Classification", "LA_DECL"), //
LOAN_COB("Loan COB", "LA_ECOB"), //
;
private final String customName;
private final String shortName;
DefaultJob(String customName) {
DefaultJob(String customName, String shortName) {
this.customName = customName;
this.shortName = shortName;
}
@Override
public String getName() {
return customName;
}
@Override
public String getShortName() {
return shortName;
}
}
@@ -21,4 +21,6 @@ package org.apache.fineract.test.data.job;
public interface Job {
String getName();
String getShortName();
}
@@ -19,7 +19,6 @@
package org.apache.fineract.test.data.job;
import java.io.IOException;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.fineract.client.models.GetJobsResponse;
@@ -35,20 +34,16 @@ public class JobResolver {
private final SchedulerJobApi schedulerJobApi;
@Cacheable(key = "#job.getName()", value = "jobsByName")
@Cacheable(key = "#job.getShortName()", value = "jobsByShortName")
public long resolve(Job job) {
try {
String jobName = job.getName();
log.debug("Resolving job by name [{}]", jobName);
Response<List<GetJobsResponse>> response = schedulerJobApi.retrieveAll8().execute();
String shortName = job.getShortName();
log.debug("Resolving job by short-name [{}]", shortName);
Response<GetJobsResponse> response = schedulerJobApi.retrieveByShortName(shortName).execute();
if (!response.isSuccessful()) {
throw new IllegalStateException("Unable to get jobs list. Status code was HTTP " + response.code());
throw new IllegalStateException("Unable to get job. Status code was HTTP " + response.code());
}
List<GetJobsResponse> jobsResponses = response.body();
GetJobsResponse foundJob = jobsResponses.stream().filter(j -> jobName.equals(j.getDisplayName())).findAny()
.orElseThrow(() -> new IllegalArgumentException("Job [%s] not found".formatted(jobName)));
return foundJob.getJobId();
return response.body().getJobId();
} catch (IOException e) {
throw new RuntimeException(e);
}