Project

General

Profile

1 39798 michele.ar
package eu.dnetlib.functionality.modular.ui.workflows.objects;
2
3 42128 michele.ar
import java.util.ArrayList;
4 39798 michele.ar
import java.util.List;
5 42130 michele.ar
import java.util.Map;
6 39798 michele.ar
7 42130 michele.ar
import org.apache.commons.lang3.math.NumberUtils;
8
9
import eu.dnetlib.msro.logging.LogMessage;
10 42300 michele.ar
import eu.dnetlib.msro.workflows.graph.Graph;
11 42132 michele.ar
import eu.dnetlib.msro.workflows.procs.Token;
12 40096 michele.ar
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
13 42130 michele.ar
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
14 39798 michele.ar
15
/**
16
 * Created by michele on 09/11/15.
17
 */
18
public class ProcessInfo {
19
20 42132 michele.ar
	public class ProcessNode {
21
22
		private final String id;
23
		private final String name;
24
		private final long startDate;
25
		private final long endDate;
26 42134 michele.ar
		private final String status;
27 42155 michele.ar
		private final String progress;
28 42300 michele.ar
		private final Map<String, Object> params;
29
		private final Map<String, Object> envParams;
30 42132 michele.ar
31 42300 michele.ar
		public ProcessNode(final Token t, final Graph graph) {
32 42132 michele.ar
			this.id = t.getId();
33
			this.name = t.getNodeName();
34
			this.startDate = t.getStartDate();
35
			this.endDate = t.getEndDate();
36 42134 michele.ar
			this.status = t.isActive() ? "active" : t.isFailed() ? "failed" : "done";
37 42203 michele.ar
			this.progress = t.getProgressProvider() != null ? t.getProgressProvider().getProgressDescription() : "-";
38 42300 michele.ar
			this.envParams = t.getEnv().getAttributes();
39 43063 michele.ar
			this.params = graph.getNode(t.getNodeName()).resolveParams(t.getEnv());
40 42132 michele.ar
		}
41
42
		public String getId() {
43
			return this.id;
44
		}
45
46
		public String getName() {
47
			return this.name;
48
		}
49
50
		public long getStartDate() {
51
			return this.startDate;
52
		}
53
54
		public long getEndDate() {
55
			return this.endDate;
56
		}
57
58 42134 michele.ar
		public String getStatus() {
59
			return this.status;
60
		}
61
62 42155 michele.ar
		public String getProgress() {
63
			return this.progress;
64
		}
65
66 42300 michele.ar
		public Map<String, Object> getParams() {
67
			return this.params;
68
		}
69
70
		public Map<String, Object> getEnvParams() {
71
			return this.envParams;
72
		}
73
74 42132 michele.ar
	}
75
76 39831 michele.ar
	private String procId;
77 39798 michele.ar
	private String wfId;
78
	private String name;
79 39831 michele.ar
	private String family;
80
	private String status = "CREATED";
81
	private String datasource;
82
	private long date = Long.MAX_VALUE;
83 39798 michele.ar
	private long startDate = 0;
84
	private long endDate = 0;
85 42128 michele.ar
	private List<EnvParam> outputParams = new ArrayList<>();
86 42132 michele.ar
	private List<ProcessNode> processNodes = new ArrayList<>();
87 39798 michele.ar
88 41550 michele.ar
	public ProcessInfo() {}
89 39798 michele.ar
90 39831 michele.ar
	public ProcessInfo(final String procId) {
91
		this.procId = procId;
92 39798 michele.ar
	}
93
94 40096 michele.ar
	public ProcessInfo(final WorkflowProcess process) {
95 40094 michele.ar
		this.procId = process.getId();
96 41550 michele.ar
		this.wfId = process.getProfileId();
97 40094 michele.ar
		this.name = process.getName();
98 41550 michele.ar
		this.family = process.getFamily();
99
		this.status = process.getStatus().toString();
100
		this.datasource = process.getDsName();
101
		this.date = process.getLastActivityDate();
102 41620 michele.ar
		this.startDate = process.getStartDate();
103
		this.endDate = process.getEndDate();
104 42300 michele.ar
		process.getTokens().stream().map(t -> new ProcessNode(t, process.getGraph())).forEach(this.processNodes::add);
105 39798 michele.ar
	}
106
107 42130 michele.ar
	public ProcessInfo(final Map<String, String> logs) {
108
		if (logs == null || logs.isEmpty()) { return; }
109
110
		this.procId = logs.get(WorkflowsConstants.LOG_WF_PROCESS_ID);
111
		this.wfId = logs.containsKey(WorkflowsConstants.LOG_WF_PROFILE_ID)
112
				? logs.get(WorkflowsConstants.LOG_WF_PROFILE_ID)
113
				: logs.get(WorkflowsConstants.LOG_WF_PROFILE_TEMPLATE_ID);
114
		this.name = logs.get(WorkflowsConstants.LOG_WF_NAME);
115
		this.family = logs.get(WorkflowsConstants.LOG_WF_FAMILY);
116
		this.status = logs.get(WorkflowsConstants.LOG_WF_PROCESS_STATUS);
117
		this.datasource = logs.get(WorkflowsConstants.LOG_DATASOURCE_NAME);
118
		this.date = NumberUtils.toLong(logs.get(LogMessage.LOG_DATE_FIELD), Long.MAX_VALUE);
119
		this.startDate = NumberUtils.toLong(logs.get(WorkflowsConstants.LOG_WF_PROCESS_START_DATE), Long.MAX_VALUE);
120
		this.endDate = NumberUtils.toLong(logs.get(WorkflowsConstants.LOG_WF_PROCESS_END_DATE), Long.MAX_VALUE);
121
122
	}
123
124 39831 michele.ar
	public String getProcId() {
125 41550 michele.ar
		return this.procId;
126 39798 michele.ar
	}
127
128 39831 michele.ar
	public void setProcId(final String processId) {
129
		this.procId = processId;
130
	}
131
132 39798 michele.ar
	public String getWfId() {
133 41550 michele.ar
		return this.wfId;
134 39798 michele.ar
	}
135
136
	public void setWfId(final String wfId) {
137
		this.wfId = wfId;
138
	}
139
140
	public String getName() {
141 41550 michele.ar
		return this.name;
142 39798 michele.ar
	}
143
144
	public void setName(final String name) {
145
		this.name = name;
146
	}
147
148 39831 michele.ar
	public String getFamily() {
149 41550 michele.ar
		return this.family;
150 39831 michele.ar
	}
151
152
	public void setFamily(final String family) {
153
		this.family = family;
154
	}
155
156 39798 michele.ar
	public String getStatus() {
157 41550 michele.ar
		return this.status;
158 39798 michele.ar
	}
159
160
	public void setStatus(final String status) {
161
		this.status = status;
162
	}
163
164
	public long getStartDate() {
165 41550 michele.ar
		return this.startDate;
166 39798 michele.ar
	}
167
168
	public void setStartDate(final long startDate) {
169
		this.startDate = startDate;
170
	}
171
172
	public long getEndDate() {
173 41550 michele.ar
		return this.endDate;
174 39798 michele.ar
	}
175
176
	public void setEndDate(final long endDate) {
177
		this.endDate = endDate;
178
	}
179
180 39831 michele.ar
	public String getDatasource() {
181 41550 michele.ar
		return this.datasource;
182 39831 michele.ar
	}
183
184
	public void setDatasource(final String datasource) {
185
		this.datasource = datasource;
186
	}
187
188
	public long getDate() {
189 41550 michele.ar
		return this.date;
190 39831 michele.ar
	}
191
192
	public void setDate(final long date) {
193
		this.date = date;
194
	}
195
196 42128 michele.ar
	public List<EnvParam> getOutputParams() {
197
		return this.outputParams;
198 39798 michele.ar
	}
199
200 42128 michele.ar
	public void setOutputParams(final List<EnvParam> outputParams) {
201
		this.outputParams = outputParams;
202 39798 michele.ar
	}
203 42128 michele.ar
204 42132 michele.ar
	public List<ProcessNode> getProcessNodes() {
205
		return this.processNodes;
206
	}
207
208
	public void setProcessNodes(final List<ProcessNode> processNodes) {
209
		this.processNodes = processNodes;
210
	}
211
212 39798 michele.ar
}