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.procs.Token;
11
import eu.dnetlib.msro.workflows.procs.WorkflowProcess;
12
import eu.dnetlib.msro.workflows.util.WorkflowsConstants;
13

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

    
19
	public class ProcessNode {
20

    
21
		private final String id;
22
		private final String name;
23
		private final long startDate;
24
		private final long endDate;
25
		private final String status;
26

    
27
		public ProcessNode(final Token t) {
28
			this.id = t.getId();
29
			this.name = t.getNodeName();
30
			this.startDate = t.getStartDate();
31
			this.endDate = t.getEndDate();
32
			this.status = t.isActive() ? "active" : t.isFailed() ? "failed" : "done";
33
		}
34

    
35
		public String getId() {
36
			return this.id;
37
		}
38

    
39
		public String getName() {
40
			return this.name;
41
		}
42

    
43
		public long getStartDate() {
44
			return this.startDate;
45
		}
46

    
47
		public long getEndDate() {
48
			return this.endDate;
49
		}
50

    
51
		public String getStatus() {
52
			return this.status;
53
		}
54

    
55
	}
56

    
57
	private String procId;
58
	private String wfId;
59
	private String name;
60
	private String family;
61
	private String status = "CREATED";
62
	private String datasource;
63
	private long date = Long.MAX_VALUE;
64
	private long startDate = 0;
65
	private long endDate = 0;
66
	private List<EnvParam> outputParams = new ArrayList<>();
67
	private List<ProcessNode> processNodes = new ArrayList<>();
68

    
69
	public ProcessInfo() {}
70

    
71
	public ProcessInfo(final String procId) {
72
		this.procId = procId;
73
	}
74

    
75
	public ProcessInfo(final WorkflowProcess process) {
76
		this.procId = process.getId();
77
		this.wfId = process.getProfileId();
78
		this.name = process.getName();
79
		this.family = process.getFamily();
80
		this.status = process.getStatus().toString();
81
		this.datasource = process.getDsName();
82
		this.date = process.getLastActivityDate();
83
		this.startDate = process.getStartDate();
84
		this.endDate = process.getEndDate();
85

    
86
		process.getTokens().stream().map(t -> new ProcessNode(t)).forEach(this.processNodes::add);
87
	}
88

    
89
	public ProcessInfo(final Map<String, String> logs) {
90
		if (logs == null || logs.isEmpty()) { return; }
91

    
92
		this.procId = logs.get(WorkflowsConstants.LOG_WF_PROCESS_ID);
93
		this.wfId = logs.containsKey(WorkflowsConstants.LOG_WF_PROFILE_ID)
94
				? logs.get(WorkflowsConstants.LOG_WF_PROFILE_ID)
95
				: logs.get(WorkflowsConstants.LOG_WF_PROFILE_TEMPLATE_ID);
96
		this.name = logs.get(WorkflowsConstants.LOG_WF_NAME);
97
		this.family = logs.get(WorkflowsConstants.LOG_WF_FAMILY);
98
		this.status = logs.get(WorkflowsConstants.LOG_WF_PROCESS_STATUS);
99
		this.datasource = logs.get(WorkflowsConstants.LOG_DATASOURCE_NAME);
100
		this.date = NumberUtils.toLong(logs.get(LogMessage.LOG_DATE_FIELD), Long.MAX_VALUE);
101
		this.startDate = NumberUtils.toLong(logs.get(WorkflowsConstants.LOG_WF_PROCESS_START_DATE), Long.MAX_VALUE);
102
		this.endDate = NumberUtils.toLong(logs.get(WorkflowsConstants.LOG_WF_PROCESS_END_DATE), Long.MAX_VALUE);
103

    
104
	}
105

    
106
	public String getProcId() {
107
		return this.procId;
108
	}
109

    
110
	public void setProcId(final String processId) {
111
		this.procId = processId;
112
	}
113

    
114
	public String getWfId() {
115
		return this.wfId;
116
	}
117

    
118
	public void setWfId(final String wfId) {
119
		this.wfId = wfId;
120
	}
121

    
122
	public String getName() {
123
		return this.name;
124
	}
125

    
126
	public void setName(final String name) {
127
		this.name = name;
128
	}
129

    
130
	public String getFamily() {
131
		return this.family;
132
	}
133

    
134
	public void setFamily(final String family) {
135
		this.family = family;
136
	}
137

    
138
	public String getStatus() {
139
		return this.status;
140
	}
141

    
142
	public void setStatus(final String status) {
143
		this.status = status;
144
	}
145

    
146
	public long getStartDate() {
147
		return this.startDate;
148
	}
149

    
150
	public void setStartDate(final long startDate) {
151
		this.startDate = startDate;
152
	}
153

    
154
	public long getEndDate() {
155
		return this.endDate;
156
	}
157

    
158
	public void setEndDate(final long endDate) {
159
		this.endDate = endDate;
160
	}
161

    
162
	public String getDatasource() {
163
		return this.datasource;
164
	}
165

    
166
	public void setDatasource(final String datasource) {
167
		this.datasource = datasource;
168
	}
169

    
170
	public long getDate() {
171
		return this.date;
172
	}
173

    
174
	public void setDate(final long date) {
175
		this.date = date;
176
	}
177

    
178
	public List<EnvParam> getOutputParams() {
179
		return this.outputParams;
180
	}
181

    
182
	public void setOutputParams(final List<EnvParam> outputParams) {
183
		this.outputParams = outputParams;
184
	}
185

    
186
	public List<ProcessNode> getProcessNodes() {
187
		return this.processNodes;
188
	}
189

    
190
	public void setProcessNodes(final List<ProcessNode> processNodes) {
191
		this.processNodes = processNodes;
192
	}
193

    
194
}
(5-5/9)