/
ProcessInstanceDto.java
162 lines (130 loc) · 5.16 KB
/
ProcessInstanceDto.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (c) 2010-2013 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.workflow.dto;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.schema.util.WfContextUtil;
import com.evolveum.midpoint.web.component.DateLabelComponent;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
import org.apache.commons.lang.Validate;
import org.apache.wicket.datetime.PatternDateConverter;
import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;
/**
* @author mederly
*/
public class ProcessInstanceDto extends Selectable {
public static final String F_OBJECT_NAME = "objectName";
public static final String F_TARGET_NAME = "targetName";
public static final String F_NAME = "name";
public static final String F_START_FORMATTED = "startFormatted";
public static final String F_END_FORMATTED = "endFormatted";
public static final String F_STATE = "state";
public static final String F_STAGE = "stage";
public static final String F_ANSWER = "answer";
private TaskType task;
private PatternDateConverter converter = new PatternDateConverter
(WebComponentUtil.getLocalizedDatePattern(DateLabelComponent.LONG_MEDIUM_STYLE), true );
public ProcessInstanceDto(TaskType task) {
Validate.notNull(task, "Task is null");
Validate.notNull(task.getWorkflowContext(), "Task has no workflow context");
this.task = task;
}
public XMLGregorianCalendar getStartTimestamp() {
return task.getWorkflowContext().getStartTimestamp();
}
public XMLGregorianCalendar getEndTimestamp() {
return task.getWorkflowContext().getEndTimestamp();
}
public String getStartFormatted() {
return getStartTimestamp() != null ? converter.convertToString(XmlTypeConverter.toDate(getStartTimestamp()),
WebComponentUtil.getCurrentLocale()) : "";
}
public String getEndFormatted() {
return getEndTimestamp() != null ? converter.convertToString(XmlTypeConverter.toDate(getEndTimestamp()),
WebComponentUtil.getCurrentLocale()) : "";
}
public String getName() {
return PolyString.getOrig(task.getName());
}
public String getAnswer() {
return task.getWorkflowContext().getAnswer();
}
public String getObjectName() {
return WebComponentUtil.getName(task.getWorkflowContext().getObjectRef());
}
public ObjectReferenceType getObjectRef() {
return task.getWorkflowContext().getObjectRef();
}
public ObjectReferenceType getTargetRef() {
return task.getWorkflowContext().getTargetRef();
}
public QName getObjectType() {
return getObjectRef() != null ? getObjectRef().getType() : null;
}
public QName getTargetType() {
return getTargetRef() != null ? getTargetRef().getType() : null;
}
public String getTargetName() {
return WebComponentUtil.getName(task.getWorkflowContext().getTargetRef());
}
public String getState() {
return task.getWorkflowContext().getState();
}
public String getStage() {
return WfContextUtil.getStageInfo(task.getWorkflowContext());
}
public String getProcessInstanceId() {
return task.getWorkflowContext().getProcessInstanceId();
}
// public List<WorkItemDto> getWorkItems() {
// List<WorkItemDto> retval = new ArrayList<WorkItemDto>();
// if (processInstance.getWorkItems() != null) {
// for (WorkItemType workItem : processInstance.getWorkItems()) {
// retval.add(new WorkItemDto(workItem));
// }
// }
// return retval;
// }
// public String getAnswer() {
// if (processInstanceState == null) {
// return null;
// }
// return processInstanceState.getAnswer();
// }
// public boolean isAnswered() {
// return getAnswer() != null;
// }
// null if not answered or answer is not true/false
// public Boolean getAnswerAsBoolean() {
// return ApprovalUtils.approvalBooleanValue(getAnswer());
// }
// public boolean isFinished() {
// return processInstance.isFinished();
// }
// public ProcessInstanceState getInstanceState() {
// return (ProcessInstanceState) processInstance.getState();
// }
// public String getShadowTaskOid() {
// return processInstanceState.getShadowTaskOid();
// }
public String getTaskOid() {
return task.getOid();
}
}