added svcapi ui and camunda code
[it/otf.git] / otf-service-api / 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                     _bpmnInstance.getProcessDefinitionId().equalsIgnoreCase(processDefinitionId))\r
90             .findFirst()\r
91             .orElse(null);\r
92 \r
93     List<BpmnInstance> historicBpmnInstance = new ArrayList<>();\r
94     if (bpmnInstance != null) {\r
95       historicBpmnInstance.add(bpmnInstance);\r
96     }\r
97 \r
98     return historicBpmnInstance;\r
99   }\r
100 \r
101   public ObjectId get_id() {\r
102     return _id;\r
103   }\r
104 \r
105   public void set_id(ObjectId _id) {\r
106     this._id = _id;\r
107   }\r
108 \r
109   public String getTestName() {\r
110     return testName;\r
111   }\r
112 \r
113   public void setTestName(String testName) {\r
114     this.testName = testName;\r
115   }\r
116 \r
117   public String getTestDescription() {\r
118     return testDescription;\r
119   }\r
120 \r
121   public void setTestDescription(String testDescription) {\r
122     this.testDescription = testDescription;\r
123   }\r
124 \r
125   public String getProcessDefinitionKey() {\r
126     return processDefinitionKey;\r
127   }\r
128 \r
129   public void setProcessDefinitionKey(String processDefinitionKey) {\r
130     this.processDefinitionKey = processDefinitionKey;\r
131   }\r
132 \r
133   public List<BpmnInstance> getBpmnInstances() {\r
134     return bpmnInstances;\r
135   }\r
136 \r
137   public void setBpmnInstances(List<BpmnInstance> bpmnInstances) {\r
138     this.bpmnInstances = bpmnInstances;\r
139   }\r
140 \r
141   public ObjectId getGroupId() {\r
142     return groupId;\r
143   }\r
144 \r
145   public void setGroupId(ObjectId groupId) {\r
146     this.groupId = groupId;\r
147   }\r
148 \r
149   public Date getCreatedAt() {\r
150     return createdAt;\r
151   }\r
152 \r
153   public void setCreatedAt(Date createdAt) {\r
154     this.createdAt = createdAt;\r
155   }\r
156 \r
157   public Date getUpdatedAt() {\r
158     return updatedAt;\r
159   }\r
160 \r
161   public void setUpdatedAt(Date updatedAt) {\r
162     this.updatedAt = updatedAt;\r
163   }\r
164 \r
165   public ObjectId getCreatedBy() {\r
166     return createdBy;\r
167   }\r
168 \r
169   public void setCreatedBy(ObjectId createdBy) {\r
170     this.createdBy = createdBy;\r
171   }\r
172 \r
173   public ObjectId getUpdatedBy() {\r
174     return updatedBy;\r
175   }\r
176 \r
177   public void setUpdatedBy(ObjectId updatedBy) {\r
178     this.updatedBy = updatedBy;\r
179   }\r
180 \r
181   @Override\r
182   public String toString() {\r
183     return Convert.objectToJson(this);\r
184   }\r
185 }\r