added svcapi ui and camunda code
[it/otf.git] / otf-camunda / src / main / java / org / oran / otf / common / model / historic / TestDefinitionHistoric.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.historic;\r
18 \r
19 import org.oran.otf.common.model.TestDefinition;\r
20 import org.oran.otf.common.model.local.BpmnInstance;\r
21 import org.oran.otf.common.utility.gson.Convert;\r
22 import java.io.Serializable;\r
23 import java.util.ArrayList;\r
24 import java.util.Date;\r
25 import java.util.List;\r
26 import org.bson.types.ObjectId;\r
27 \r
28 public class TestDefinitionHistoric implements Serializable {\r
29 \r
30   private static final long serialVersionUID = 1L;\r
31 \r
32   private ObjectId _id;\r
33   private String testName;\r
34   private String testDescription;\r
35   private String processDefinitionKey;\r
36   private List<BpmnInstance> bpmnInstances;\r
37   private ObjectId groupId;\r
38   private Date createdAt;\r
39   private Date updatedAt;\r
40   private ObjectId createdBy;\r
41   private ObjectId updatedBy;\r
42 \r
43   public TestDefinitionHistoric() {\r
44   }\r
45 \r
46   public TestDefinitionHistoric(TestDefinition testDefinition, String processDefinitionId) {\r
47     this._id = testDefinition.get_id();\r
48     this.testName = testDefinition.getTestName();\r
49     this.testDescription = testDefinition.getTestDescription();\r
50     this.processDefinitionKey = testDefinition.getProcessDefinitionKey();\r
51     this.bpmnInstances =\r
52         getHistoricBpmnInstanceAsList(testDefinition.getBpmnInstances(), processDefinitionId);\r
53     this.groupId = testDefinition.getGroupId();\r
54     this.createdAt = testDefinition.getCreatedAt();\r
55     this.updatedAt = testDefinition.getUpdatedAt();\r
56     this.createdBy = testDefinition.getCreatedBy();\r
57     this.updatedBy = testDefinition.getUpdatedBy();\r
58   }\r
59 \r
60   public TestDefinitionHistoric(\r
61       ObjectId _id,\r
62       String testName,\r
63       String testDescription,\r
64       String processDefinitionKey,\r
65       List<BpmnInstance> bpmnInstances,\r
66       ObjectId groupId,\r
67       Date createdAt,\r
68       Date updatedAt,\r
69       ObjectId createdBy,\r
70       ObjectId updatedBy) {\r
71     this._id = _id;\r
72     this.testName = testName;\r
73     this.testDescription = testDescription;\r
74     this.processDefinitionKey = processDefinitionKey;\r
75     this.bpmnInstances = bpmnInstances;\r
76     this.groupId = groupId;\r
77     this.createdAt = createdAt;\r
78     this.updatedAt = updatedAt;\r
79     this.createdBy = createdBy;\r
80     this.updatedBy = updatedBy;\r
81   }\r
82 \r
83   private List<BpmnInstance> getHistoricBpmnInstanceAsList(\r
84       List<BpmnInstance> bpmnInstances, String processDefinitionId) {\r
85     BpmnInstance bpmnInstance =\r
86         bpmnInstances.stream()\r
87             .filter(\r
88                 _bpmnInstance -> {\r
89                   return _bpmnInstance.isDeployed()\r
90                       && _bpmnInstance.getProcessDefinitionId() != null\r
91                       && _bpmnInstance.getProcessDefinitionId().equals(processDefinitionId);\r
92                 })\r
93             .findFirst()\r
94             .orElse(null);\r
95 \r
96     List<BpmnInstance> historicBpmnInstance = new ArrayList<>();\r
97     if (bpmnInstance != null) {\r
98       historicBpmnInstance.add(bpmnInstance);\r
99     }\r
100 \r
101     return historicBpmnInstance;\r
102   }\r
103 \r
104   public ObjectId get_id() {\r
105     return _id;\r
106   }\r
107 \r
108   public void set_id(ObjectId _id) {\r
109     this._id = _id;\r
110   }\r
111 \r
112   public String getTestName() {\r
113     return testName;\r
114   }\r
115 \r
116   public void setTestName(String testName) {\r
117     this.testName = testName;\r
118   }\r
119 \r
120   public String getTestDescription() {\r
121     return testDescription;\r
122   }\r
123 \r
124   public void setTestDescription(String testDescription) {\r
125     this.testDescription = testDescription;\r
126   }\r
127 \r
128   public String getProcessDefinitionKey() {\r
129     return processDefinitionKey;\r
130   }\r
131 \r
132   public void setProcessDefinitionKey(String processDefinitionKey) {\r
133     this.processDefinitionKey = processDefinitionKey;\r
134   }\r
135 \r
136   public List<BpmnInstance> getBpmnInstances() {\r
137     return bpmnInstances;\r
138   }\r
139 \r
140   public void setBpmnInstances(List<BpmnInstance> bpmnInstances) {\r
141     this.bpmnInstances = bpmnInstances;\r
142   }\r
143 \r
144   public ObjectId getGroupId() {\r
145     return groupId;\r
146   }\r
147 \r
148   public void setGroupId(ObjectId groupId) {\r
149     this.groupId = groupId;\r
150   }\r
151 \r
152   public Date getCreatedAt() {\r
153     return createdAt;\r
154   }\r
155 \r
156   public void setCreatedAt(Date createdAt) {\r
157     this.createdAt = createdAt;\r
158   }\r
159 \r
160   public Date getUpdatedAt() {\r
161     return updatedAt;\r
162   }\r
163 \r
164   public void setUpdatedAt(Date updatedAt) {\r
165     this.updatedAt = updatedAt;\r
166   }\r
167 \r
168   public ObjectId getCreatedBy() {\r
169     return createdBy;\r
170   }\r
171 \r
172   public void setCreatedBy(ObjectId createdBy) {\r
173     this.createdBy = createdBy;\r
174   }\r
175 \r
176   public ObjectId getUpdatedBy() {\r
177     return updatedBy;\r
178   }\r
179 \r
180   public void setUpdatedBy(ObjectId updatedBy) {\r
181     this.updatedBy = updatedBy;\r
182   }\r
183 \r
184   @Override\r
185   public String toString() {\r
186     return Convert.objectToJson(this);\r
187   }\r
188 }\r