2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the “License”);
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.workflow.scheduler;
40 import java.util.Calendar;
41 import java.util.Date;
42 import java.util.HashMap;
44 import java.util.UUID;
46 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
47 import org.quartz.impl.triggers.CronTriggerImpl;
48 import org.springframework.context.annotation.DependsOn;
49 import org.springframework.scheduling.quartz.CronTriggerFactoryBean;
50 import org.springframework.scheduling.quartz.JobDetailFactoryBean;
51 import org.springframework.stereotype.Component;
54 @DependsOn({"systemProperties"})
55 public class WorkFlowScheduleRegistry{
57 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(WorkFlowScheduleRegistry.class);
59 public WorkFlowScheduleRegistry() {
63 private static final String groupName = "AppGroup";
64 private static final String jobName = "WorkflowScheduleJob";
65 private static final String triggerName = "WorkflowScheduleTrigger";
68 // private SystemProperties systemProperties;
71 public JobDetailFactoryBean jobDetailFactoryBean(Map<String, ?> contextInfoMap) {
73 JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
74 jobDetailFactory.setJobClass(WorkFlowScheduleJob.class);
75 jobDetailFactory.setJobDataAsMap(contextInfoMap);
76 jobDetailFactory.setGroup(groupName);
77 jobDetailFactory.setName(jobName + "_" + UUID.randomUUID());
78 jobDetailFactory.afterPropertiesSet();
79 return jobDetailFactory;
83 public CronTriggerFactoryBean cronTriggerFactoryBean(JobDetailFactoryBean jobDetailFactory, Long id,
84 String cronExpression, Date startDateTime, Date enddatetime) throws Exception {
85 CronTriggerFactoryBean cronTriggerFactory = new CronTriggerFactoryBean();
86 cronTriggerFactory.setJobDetail(jobDetailFactory.getObject());
87 cronTriggerFactory.setStartDelay(3000);
88 cronTriggerFactory.setName(triggerName + "_" + id);
89 cronTriggerFactory.setGroup(groupName);
90 logger.debug(EELFLoggerDelegate.debugLogger, (triggerName + " Scheduled: " + cronExpression));
91 cronTriggerFactory.setCronExpression( cronExpression); //"0 * * * * ? *"
92 cronTriggerFactory.afterPropertiesSet();
94 final CronTriggerImpl cronTrigger = (CronTriggerImpl) cronTriggerFactory.getObject();
95 cronTrigger.setStartTime(startDateTime == null ? Calendar.getInstance().getTime() : startDateTime);
96 cronTrigger.setEndTime(enddatetime);
97 Date fireAgainTime = cronTrigger.getFireTimeAfter(cronTrigger.getStartTime());
98 if (fireAgainTime == null)
99 throw new Exception("Cron not added as it may not fire again " + " Expr: " + cronExpression + " End Time: "
100 + cronTrigger.getEndTime());
101 return cronTriggerFactory;
105 public CronTriggerFactoryBean setUpTrigger(Long wfId, String serverUrl, String workflowKey, String arguments,
106 String startdatetimecron, Date startDateTime, Date enddatetime) throws Exception {
108 Map<String, String> contextInfo = new HashMap<String, String>();
109 contextInfo.put("serverUrl", serverUrl);
110 contextInfo.put("workflowKey", workflowKey);
111 contextInfo.put("arguments", arguments);
112 JobDetailFactoryBean jobDetailFactory = jobDetailFactoryBean(contextInfo);
114 CronTriggerFactoryBean cronTriggerFactory = cronTriggerFactoryBean(jobDetailFactory, wfId, startdatetimecron, startDateTime, enddatetime);
116 logger.debug(EELFLoggerDelegate.debugLogger, (" Job to be Scheduled: " + contextInfo.get("workflowKey")));
118 //cronTriggerFactory.
120 return cronTriggerFactory;