Project

General

Profile

1
package eu.dnetlib.functionality.modular.ui.workflows.objects;
2

    
3
import java.util.ArrayList;
4
import java.util.List;
5
import java.util.Map;
6

    
7
import org.apache.commons.lang3.math.NumberUtils;
8

    
9
import eu.dnetlib.msro.logging.LogMessage;
10
import eu.dnetlib.msro.workflows.graph.Graph;
11
import eu.dnetlib.msro.workflows.procs.Token;
12
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
13
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
14

    
15
/**
16
 * Created by michele on 09/11/15.
17
 */
18
public class ProcessInfo {
19

    
20
	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
		private final String status;
27
		private final String progress;
28
		private final Map<String, Object> params;
29
		private final Map<String, Object> envParams;
30

    
31
		public ProcessNode(final Token t, final Graph graph) {
32
			this.id = t.getId();
33
			this.name = t.getNodeName();
34
			this.startDate = t.getStartDate();
35
			this.endDate = t.getEndDate();
36
			this.status = t.isActive() ? "active" : t.isFailed() ? "failed" : "done";
37
			this.progress = t.getProgressProvider() != null ? t.getProgressProvider().getProgressDescription() : "-";
38
			this.envParams = t.getEnv().getAttributes();
39
			this.params = graph.getNode(t.getNodeName()).resolveParams(t.getEnv());
40
		}
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
		public String getStatus() {
59
			return this.status;
60
		}
61

    
62
		public String getProgress() {
63
			return this.progress;
64
		}
65

    
66
		public Map<String, Object> getParams() {
67
			return this.params;
68
		}
69

    
70
		public Map<String, Object> getEnvParams() {
71
			return this.envParams;
72
		}
73

    
74
	}
75

    
76
	private String procId;
77
	private String wfId;
78
	private String name;
79
	private String family;
80
	private String status = "CREATED";
81
	private String datasource;
82
	private long date = Long.MAX_VALUE;
83
	private long startDate = 0;
84
	private long endDate = 0;
85
	private List<EnvParam> outputParams = new ArrayList<>();
86
	private List<ProcessNode> processNodes = new ArrayList<>();
87

    
88
	public ProcessInfo() {}
89

    
90
	public ProcessInfo(final String procId) {
91
		this.procId = procId;
92
	}
93

    
94
	public ProcessInfo(final WorkflowProcess process) {
95
		this.procId = process.getId();
96
		this.wfId = process.getProfileId();
97
		this.name = process.getName();
98
		this.family = process.getFamily();
99
		this.status = process.getStatus().toString();
100
		this.datasource = process.getDsName();
101
		this.date = process.getLastActivityDate();
102
		this.startDate = process.getStartDate();
103
		this.endDate = process.getEndDate();
104
		process.getTokens().stream().map(t -> new ProcessNode(t, process.getGraph())).forEach(this.processNodes::add);
105
	}
106

    
107
	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
	public String getProcId() {
125
		return this.procId;
126
	}
127

    
128
	public void setProcId(final String processId) {
129
		this.procId = processId;
130
	}
131

    
132
	public String getWfId() {
133
		return this.wfId;
134
	}
135

    
136
	public void setWfId(final String wfId) {
137
		this.wfId = wfId;
138
	}
139

    
140
	public String getName() {
141
		return this.name;
142
	}
143

    
144
	public void setName(final String name) {
145
		this.name = name;
146
	}
147

    
148
	public String getFamily() {
149
		return this.family;
150
	}
151

    
152
	public void setFamily(final String family) {
153
		this.family = family;
154
	}
155

    
156
	public String getStatus() {
157
		return this.status;
158
	}
159

    
160
	public void setStatus(final String status) {
161
		this.status = status;
162
	}
163

    
164
	public long getStartDate() {
165
		return this.startDate;
166
	}
167

    
168
	public void setStartDate(final long startDate) {
169
		this.startDate = startDate;
170
	}
171

    
172
	public long getEndDate() {
173
		return this.endDate;
174
	}
175

    
176
	public void setEndDate(final long endDate) {
177
		this.endDate = endDate;
178
	}
179

    
180
	public String getDatasource() {
181
		return this.datasource;
182
	}
183

    
184
	public void setDatasource(final String datasource) {
185
		this.datasource = datasource;
186
	}
187

    
188
	public long getDate() {
189
		return this.date;
190
	}
191

    
192
	public void setDate(final long date) {
193
		this.date = date;
194
	}
195

    
196
	public List<EnvParam> getOutputParams() {
197
		return this.outputParams;
198
	}
199

    
200
	public void setOutputParams(final List<EnvParam> outputParams) {
201
		this.outputParams = outputParams;
202
	}
203

    
204
	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
}
(6-6/10)