FINERACT-1678-Extending-jobs-with-module-system

This commit is contained in:
Ruchi Dhamankar
2022-11-23 15:51:00 +01:00
committed by Arnold Gálovics
parent 4b290663d3
commit c1df5e73a2
17 changed files with 488 additions and 11 deletions
@@ -0,0 +1,38 @@
/**
* 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.config;
import java.util.Arrays;
import java.util.List;
import org.apache.fineract.infrastructure.jobs.service.JobName;
import org.apache.fineract.infrastructure.jobs.service.jobname.JobNameData;
import org.apache.fineract.infrastructure.jobs.service.jobname.JobNameProvider;
import org.apache.fineract.infrastructure.jobs.service.jobname.SimpleJobNameProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class JobNameProviderConfig {
@Bean
public JobNameProvider fineractJobNameProvider() {
List<JobNameData> jobNames = Arrays.stream(JobName.values()).map(jn -> new JobNameData(jn.name(), jn.toString())).toList();
return new SimpleJobNameProvider(jobNames);
}
}
@@ -18,9 +18,6 @@
*/
package org.apache.fineract.infrastructure.jobs.service;
import java.util.Arrays;
import java.util.Optional;
public enum JobName {
UPDATE_LOAN_ARREARS_AGEING("Update Loan Arrears Ageing"), //
@@ -66,13 +63,9 @@ public enum JobName {
this.name = name;
}
public static JobName getJobByName(String jobName) {
Optional<JobName> optionalJob = Arrays.stream(JobName.values()).filter(jn -> jobName.equals(jn.name)).findAny();
return optionalJob.orElseThrow(() -> new IllegalArgumentException("Job not found by name: " + jobName));
}
@Override
public String toString() {
return this.name;
}
}
@@ -33,6 +33,8 @@ import org.apache.fineract.infrastructure.jobs.domain.ScheduledJobDetail;
import org.apache.fineract.infrastructure.jobs.domain.SchedulerDetail;
import org.apache.fineract.infrastructure.jobs.exception.JobNodeIdMismatchingException;
import org.apache.fineract.infrastructure.jobs.exception.JobNotFoundException;
import org.apache.fineract.infrastructure.jobs.service.jobname.JobNameData;
import org.apache.fineract.infrastructure.jobs.service.jobname.JobNameService;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobKey;
@@ -79,6 +81,9 @@ public class JobRegisterServiceImpl implements JobRegisterService, ApplicationLi
@Autowired
private JobStarter jobStarter;
@Autowired
private JobNameService jobNameService;
private static final String JOB_STARTER_METHOD_NAME = "run";
public void executeJob(final ScheduledJobDetail scheduledJobDetail, String triggerType) {
@@ -313,8 +318,8 @@ public class JobRegisterServiceImpl implements JobRegisterService, ApplicationLi
private JobDetail createJobDetail(final ScheduledJobDetail scheduledJobDetail) throws Exception {
final FineractPlatformTenant tenant = ThreadLocalContextUtil.getTenant();
JobName jobName = JobName.getJobByName(scheduledJobDetail.getJobName());
Job job = jobLocator.getJob(jobName.name());
JobNameData jobName = jobNameService.getJobByHumanReadableName(scheduledJobDetail.getJobName());
Job job = jobLocator.getJob(jobName.getEnumStyleName());
final MethodInvokingJobDetailFactoryBean jobDetailFactoryBean = new MethodInvokingJobDetailFactoryBean();
jobDetailFactoryBean.setName(scheduledJobDetail.getJobName() + "JobDetail" + tenant.getId());
@@ -0,0 +1,30 @@
/**
* 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.jobname;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public class JobNameData {
private final String enumStyleName;
private final String humanReadableName;
}
@@ -0,0 +1,26 @@
/**
* 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.jobname;
import java.util.Set;
public interface JobNameProvider {
Set<JobNameData> provide();
}
@@ -0,0 +1,43 @@
/**
* 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.jobname;
import static java.util.stream.Collectors.toSet;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class JobNameService {
private final Collection<JobNameProvider> providers;
public JobNameData getJobByHumanReadableName(String jobName) {
Optional<JobNameData> optionalJob = getJobNames().stream().filter(jn -> jobName.equals(jn.getHumanReadableName())).findAny();
return optionalJob.orElseThrow(() -> new IllegalArgumentException("Job not found by name: " + jobName));
}
private Set<JobNameData> getJobNames() {
return providers.stream().map(JobNameProvider::provide).flatMap(Collection::stream).collect(toSet());
}
}
@@ -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.infrastructure.jobs.service.jobname;
import java.util.Collection;
import java.util.Set;
public class SimpleJobNameProvider implements JobNameProvider {
private final Set<JobNameData> jobNames;
public SimpleJobNameProvider(Collection<JobNameData> jobNames) {
this.jobNames = Set.copyOf(jobNames);
}
@Override
public Set<JobNameData> provide() {
return jobNames;
}
}