1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.provisioning.api.job;
20
21 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23 import org.apache.syncope.common.lib.SyncopeConstants;
24 import org.apache.syncope.core.persistence.api.entity.Report;
25 import org.apache.syncope.core.persistence.api.entity.task.Task;
26 import org.quartz.JobKey;
27 import org.quartz.Scheduler;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 public final class JobNamer {
32
33 private static final Logger LOG = LoggerFactory.getLogger(JobNamer.class);
34
35 private static String getKeyFromJobName(final String name, final String pattern, final int prefixLength) {
36 String result = null;
37
38 Matcher jobMatcher = Pattern.compile(pattern).matcher(name);
39 if (jobMatcher.matches()) {
40 try {
41 result = name.substring(prefixLength);
42 } catch (IllegalArgumentException e) {
43 LOG.error("Unparsable id: {}", name.substring(prefixLength), e);
44 }
45 }
46
47 return result;
48 }
49
50 public static String getTaskKeyFromJobName(final String name) {
51 return getKeyFromJobName(name, "taskJob" + SyncopeConstants.UUID_REGEX, 7);
52 }
53
54 public static String getReportKeyFromJobName(final String name) {
55 return getKeyFromJobName(name, "reportJob" + SyncopeConstants.UUID_REGEX, 9);
56 }
57
58 public static JobKey getJobKey(final Task<?> task) {
59 return new JobKey("taskJob" + task.getKey(), Scheduler.DEFAULT_GROUP);
60 }
61
62 public static JobKey getJobKey(final Report report) {
63 return new JobKey("reportJob" + report.getKey(), Scheduler.DEFAULT_GROUP);
64 }
65
66 public static String getTriggerName(final String jobName) {
67 return "Trigger_" + jobName;
68 }
69
70 private JobNamer() {
71
72 }
73 }