1
|
package eu.dnetlib.msro.dispatcher;
|
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
|
import eu.dnetlib.msro.worker.WorkflowConstants;
|
13
|
|
14
|
public class ProcessUtils {
|
15
|
|
16
|
private static String oldGeneratedId = "";
|
17
|
|
18
|
private static final Log log = LogFactory.getLog(ProcessUtils.class);
|
19
|
|
20
|
public static String calculateMetaWfId(final GraphProcess process) {
|
21
|
if (process.getEnv().hasAttribute(WorkflowConstants.SYSTEM_METAWF_ID)) {
|
22
|
return process.getEnv().getAttribute(WorkflowConstants.SYSTEM_METAWF_ID);
|
23
|
} else {
|
24
|
return "";
|
25
|
}
|
26
|
}
|
27
|
|
28
|
public static String calculateName(final GraphProcess process) {
|
29
|
return process.getGraph().getName();
|
30
|
}
|
31
|
|
32
|
public static String calculateFamily(final GraphProcess process) {
|
33
|
return process.getEnv().getAttribute(WorkflowConstants.SYSTEM_WF_PROFILE_FAMILY);
|
34
|
}
|
35
|
|
36
|
public static String calculateStatus(final GraphProcess process) {
|
37
|
if (!process.isComplete()) {
|
38
|
return process.getState().toString().toUpperCase();
|
39
|
} else if ("true".equals(process.getEnv().getAttribute(WorkflowConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) {
|
40
|
return "SUCCESS";
|
41
|
} else {
|
42
|
return "FAILURE";
|
43
|
}
|
44
|
}
|
45
|
|
46
|
public static Date calculateLastActivityDate(final GraphProcess process) {
|
47
|
Date date = null;
|
48
|
for (final NodeToken token : process.getNodeTokens()) {
|
49
|
Date activity = token.getCompleteDate();
|
50
|
if (activity == null) {
|
51
|
activity = token.getCreateDate();
|
52
|
}
|
53
|
|
54
|
if (date == null) {
|
55
|
date = activity;
|
56
|
}
|
57
|
|
58
|
if (activity != null && date != null && activity.compareTo(date) > 0) {
|
59
|
date = activity;
|
60
|
}
|
61
|
}
|
62
|
return date;
|
63
|
}
|
64
|
|
65
|
public static String calculateRepo(final GraphProcess process) {
|
66
|
if (process.getEnv().hasAttribute(WorkflowConstants.DATAPROVIDER_NAME)) {
|
67
|
return process.getEnv().getAttribute(WorkflowConstants.DATAPROVIDER_NAME);
|
68
|
} else {
|
69
|
return "";
|
70
|
}
|
71
|
}
|
72
|
|
73
|
public static synchronized String generateProcessId() {
|
74
|
String id = "";
|
75
|
do {
|
76
|
id = "wf_" + new SimpleDateFormat("yyyyMMdd_HHmmss_S").format(new Date());
|
77
|
log.info("Generated processID " + id);
|
78
|
} while (id.equals(oldGeneratedId));
|
79
|
|
80
|
oldGeneratedId = id;
|
81
|
|
82
|
return id;
|
83
|
}
|
84
|
|
85
|
}
|