1
|
package eu.dnetlib.msro.workflows.util;
|
2
|
|
3
|
import java.text.SimpleDateFormat;
|
4
|
import java.util.Date;
|
5
|
|
6
|
import org.apache.commons.logging.Log;
|
7
|
import org.apache.commons.logging.LogFactory;
|
8
|
|
9
|
import com.googlecode.sarasvati.GraphProcess;
|
10
|
import com.googlecode.sarasvati.NodeToken;
|
11
|
|
12
|
public class ProcessUtils {
|
13
|
|
14
|
private static String oldGeneratedId = "";
|
15
|
|
16
|
private static final Log log = LogFactory.getLog(ProcessUtils.class);
|
17
|
|
18
|
public static String calculateName(final GraphProcess process) {
|
19
|
return process.getGraph().getName();
|
20
|
}
|
21
|
|
22
|
public static String calculateFamily(final GraphProcess process) {
|
23
|
return process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_FAMILY);
|
24
|
}
|
25
|
|
26
|
public static String calculateWfId(final GraphProcess process) {
|
27
|
return process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_WF_PROFILE_ID);
|
28
|
}
|
29
|
|
30
|
public static String calculateStatus(final GraphProcess process) {
|
31
|
if (!process.isComplete()) {
|
32
|
return process.getState().toString().toUpperCase();
|
33
|
} else if ("true".equals(process.getEnv().getAttribute(WorkflowsConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) {
|
34
|
return "SUCCESS";
|
35
|
} else {
|
36
|
return "FAILURE";
|
37
|
}
|
38
|
}
|
39
|
|
40
|
public static Date calculateLastActivityDate(final GraphProcess process) {
|
41
|
Date date = null;
|
42
|
for (final NodeToken token : process.getNodeTokens()) {
|
43
|
Date activity = token.getCompleteDate();
|
44
|
if (activity == null) {
|
45
|
activity = token.getCreateDate();
|
46
|
}
|
47
|
|
48
|
if (date == null) {
|
49
|
date = activity;
|
50
|
}
|
51
|
|
52
|
if (activity != null && date != null && activity.compareTo(date) > 0) {
|
53
|
date = activity;
|
54
|
}
|
55
|
}
|
56
|
return date;
|
57
|
}
|
58
|
|
59
|
public static String calculateRepo(final GraphProcess process) {
|
60
|
if (process.getEnv().hasAttribute(WorkflowsConstants.DATAPROVIDER_NAME)) { return process.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_NAME); }
|
61
|
return "";
|
62
|
}
|
63
|
|
64
|
public static String calculateRepoId(final GraphProcess process) {
|
65
|
if (process.getEnv().hasAttribute(WorkflowsConstants.DATAPROVIDER_ORIGINALID)) {
|
66
|
return process.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_ORIGINALID);
|
67
|
}
|
68
|
return "";
|
69
|
}
|
70
|
|
71
|
public static String calculateApiId(final GraphProcess process) {
|
72
|
if (process.getEnv().hasAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE)) {
|
73
|
return process.getEnv().getAttribute(WorkflowsConstants.DATAPROVIDER_INTERFACE);
|
74
|
}
|
75
|
return "";
|
76
|
}
|
77
|
|
78
|
public static synchronized String generateProcessId() {
|
79
|
String id = "";
|
80
|
do {
|
81
|
id = "wf_" + new SimpleDateFormat("yyyyMMdd_HHmmss_S").format(new Date());
|
82
|
log.info("Generated processID " + id);
|
83
|
} while (id.equals(oldGeneratedId));
|
84
|
|
85
|
oldGeneratedId = id;
|
86
|
|
87
|
return id;
|
88
|
}
|
89
|
|
90
|
}
|