added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / common / model / local / OTFProcessInstanceCompletionResponse.java
1 /*  Copyright (c) 2019 AT&T Intellectual Property.                             #\r
2 #                                                                              #\r
3 #   Licensed under the Apache License, Version 2.0 (the "License");            #\r
4 #   you may not use this file except in compliance with the License.           #\r
5 #   You may obtain a copy of the License at                                    #\r
6 #                                                                              #\r
7 #       http://www.apache.org/licenses/LICENSE-2.0                             #\r
8 #                                                                              #\r
9 #   Unless required by applicable law or agreed to in writing, software        #\r
10 #   distributed under the License is distributed on an "AS IS" BASIS,          #\r
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #\r
12 #   See the License for the specific language governing permissions and        #\r
13 #   limitations under the License.                                             #\r
14 ##############################################################################*/\r
15 \r
16 \r
17 package org.oran.otf.common.model.local;\r
18 \r
19 import org.oran.otf.camunda.model.ExecutionConstants;\r
20 import org.camunda.bpm.engine.history.*;\r
21 import org.camunda.bpm.engine.impl.history.event.HistoricExternalTaskLogEntity;\r
22 import org.camunda.bpm.engine.impl.persistence.entity.HistoricJobLogEventEntity;\r
23 import org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity;\r
24 \r
25 import java.io.Serializable;\r
26 import java.util.ArrayList;\r
27 import java.util.HashMap;\r
28 import java.util.List;\r
29 import java.util.Map;\r
30 \r
31 public class OTFProcessInstanceCompletionResponse implements Serializable {\r
32     private HistoricProcessInstance historicProcessInstance;\r
33     private List<HistoricActivityInstance> historicActivityInstance;\r
34     private List<HistoricIncident> historicIncident;\r
35     private List<Map<String, Object>> historicJobLog;\r
36     private List<Map<String, Object>> historicExternalTaskLog;\r
37     private List<Map<String, Object>> historicVariableInstance;\r
38 \r
39     public OTFProcessInstanceCompletionResponse() {\r
40     }\r
41 \r
42 \r
43     public HistoricProcessInstance getHistoricProcessInstance() {\r
44         return historicProcessInstance;\r
45     }\r
46 \r
47     public void setHistoricProcessInstance(HistoricProcessInstance historicProcessInstance) {\r
48         this.historicProcessInstance = historicProcessInstance;\r
49     }\r
50 \r
51     public List<HistoricActivityInstance> getHistoricActivityInstance() {\r
52         return historicActivityInstance;\r
53     }\r
54 \r
55     public void setHistoricActivityInstance(List<HistoricActivityInstance> historicActivityInstance) {\r
56         this.historicActivityInstance = historicActivityInstance;\r
57     }\r
58 \r
59     public List<HistoricIncident> getHistoricIncident() {\r
60         return historicIncident;\r
61     }\r
62 \r
63     public void setHistoricIncident(List<HistoricIncident> historicIncident) {\r
64         this.historicIncident = historicIncident;\r
65     }\r
66 \r
67     public List<Map<String, Object>> getHistoricJobLog() {\r
68         return historicJobLog;\r
69     }\r
70 \r
71     public void setHistoricJobLog(List<HistoricJobLog> historicJobLog) {\r
72         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();\r
73         for(HistoricJobLog jobLog: historicJobLog){\r
74             HistoricJobLogEventEntity log = (HistoricJobLogEventEntity) jobLog;\r
75             HashMap map = new HashMap();\r
76 \r
77             map.put("id", log.getId());\r
78             map.put("executionId", log.getExecutionId());\r
79             map.put("activityId", log.getActivityId());\r
80             map.put("eventType", log.getEventType());\r
81             map.put("sequenceCounter", log.getSequenceCounter());\r
82             map.put("retries", log.getJobRetries());\r
83             map.put("jobExceptionMessage", log.getJobExceptionMessage());\r
84             map.put("jobDefinitionType", log.getJobDefinitionType());\r
85             map.put("jobDefinitionConfiguration", log.getJobDefinitionConfiguration());\r
86             map.put("processDefinitionKey", log.getProcessDefinitionKey());\r
87             map.put("state", convertState(log.getState()));\r
88 \r
89             list.add(map);\r
90         }\r
91         this.historicJobLog = list;\r
92     }\r
93 \r
94     public List<Map<String, Object>> getHistoricExternalTaskLog() {\r
95         return this.historicExternalTaskLog;\r
96     }\r
97 \r
98     public void setHistoricExternalTaskLog(List<HistoricExternalTaskLog> historicExternalTaskLog) {\r
99         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();\r
100         for(HistoricExternalTaskLog externalTaskLog: historicExternalTaskLog){\r
101             HistoricExternalTaskLogEntity log = (HistoricExternalTaskLogEntity) externalTaskLog;\r
102             HashMap map = new HashMap();\r
103 \r
104             map.put("id", log.getId());\r
105             map.put("executionId", log.getExecutionId());\r
106             map.put("activityId", log.getActivityId());\r
107             map.put("state", convertState(log.getState()));\r
108             map.put("retries", log.getRetries());\r
109             map.put("processDefinitionKey", log.getProcessDefinitionKey());\r
110             map.put("errorMessage", log.getErrorMessage());\r
111             try {\r
112                 map.put("errorDetails", log.getErrorDetails());\r
113             }\r
114             catch (Exception e){}\r
115             map.put("workerId", log.getWorkerId());\r
116             map.put("topic", log.getTopicName());\r
117             list.add(map);\r
118         }\r
119         this.historicExternalTaskLog = list;\r
120     }\r
121 \r
122     public List<Map<String, Object>> getHistoricVariableInstance() {\r
123         return historicVariableInstance;\r
124     }\r
125 \r
126     public void setHistoricVariableInstance(List<HistoricVariableInstance> historicVariableInstance) {\r
127         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();\r
128         for(HistoricVariableInstance variableInstanceEntity: historicVariableInstance){\r
129             HistoricVariableInstanceEntity variable = (HistoricVariableInstanceEntity) variableInstanceEntity;\r
130             HashMap map = new HashMap();\r
131             if (variable.getVariableName().equalsIgnoreCase(ExecutionConstants.ExecutionVariable.TEST_EXECUTION)){\r
132                 continue;\r
133             }\r
134             map.put("id", variable.getId());\r
135             map.put("executionId", variable.getExecutionId());\r
136             map.put("processDefinitionKey", variable.getProcessDefinitionKey());\r
137             map.put("taskId", variable.getTaskId());\r
138             map.put("eventType", variable.getVariableName());\r
139             map.put("errorMessage", variable.getErrorMessage());\r
140             map.put("state", variable.getState());\r
141             map.put("variableName", variable.getVariableName());\r
142             map.put("type",  variable.getTypedValue().getType());\r
143             map.put("value",  variable.getTypedValue().getValue());\r
144             map.put("persistentState", variable.getPersistentState());\r
145 \r
146             list.add(map);\r
147         }\r
148         this.historicVariableInstance = list;\r
149     }\r
150 \r
151     private String convertState(int state){\r
152         switch (state){\r
153             case 0 :\r
154                 return "CREATED";\r
155             case 1 :\r
156                 return "FAILED";\r
157             case 2 :\r
158                 return "SUCCESSFUL";\r
159             case 3 :\r
160                 return "DELETED";\r
161             default:\r
162                 return "UNKNOWN";\r
163         }\r
164     }\r
165 \r
166 }\r