added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / layout / modeler / test-definition-element.class.ts
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 import { TestDefinition, BpmnInstance, TestHeadRef, Pflow } from "app/shared/models/test-definition.model";\r
18 import { toInteger } from "@ng-bootstrap/ng-bootstrap/util/util";\r
19 \r
20 export class TestDefinitionElement implements TestDefinition  {\r
21 \r
22     testName: String;\r
23     testDescription: String;\r
24     processDefinitionKey: String;\r
25     groupId: String;\r
26     bpmnInstances: BpmnInstanceElement[];\r
27     disabled: Boolean;\r
28     _id: String;\r
29     createdAt: String;\r
30     createdBy: String;\r
31     updatedAt: String;\r
32     updatedBy: String;\r
33 \r
34     currentVersion; // int Array index of the bpmnInstances\r
35     currentVersionName;\r
36     currentInstance: BpmnInstanceElement;\r
37 \r
38     constructor(testDefinition?){\r
39         if(testDefinition){\r
40             this.setAll(testDefinition);\r
41         }else{\r
42             this.reset();\r
43         }\r
44     }\r
45 \r
46 \r
47     reset(){\r
48         this._id = "";\r
49         this.testName = '';\r
50         this.testDescription = '';\r
51         this.groupId = '';\r
52         this.processDefinitionKey = '';\r
53         this.disabled = false;\r
54         this.createdAt = null;\r
55         this.createdBy = null;\r
56         this.updatedAt = null;\r
57         this.updatedBy = null;\r
58 \r
59         this.bpmnInstances = [];\r
60         this.addBpmnInstance();\r
61 \r
62         this.switchVersion();\r
63     }\r
64 \r
65     switchVersion(version?){\r
66         if(version){\r
67             //find the version\r
68             this.bpmnInstances.forEach((elem, val) => {\r
69                 if(elem['version'] == version){\r
70                     this.currentVersion = val;\r
71                     this.currentInstance = this.bpmnInstances[val];\r
72                     this.currentVersionName = this.currentInstance.version;\r
73                 }\r
74             });\r
75         }else{\r
76             //get latest version\r
77             this.currentVersion = this.bpmnInstances.length - 1;\r
78             this.currentInstance = this.bpmnInstances[this.currentVersion];\r
79             this.currentVersionName = this.currentInstance.version;\r
80         }\r
81     }\r
82 \r
83     //Setter Methods\r
84 \r
85     setAll(td){\r
86         this._id = td._id;\r
87         this.testName = td.testName;\r
88         this.testDescription = td.testDescription;\r
89         this.groupId = td.groupId;\r
90         this.processDefinitionKey = td.processDefinitionKey;\r
91         this.setBpmnInstances(td.bpmnInstances);\r
92         this.switchVersion();\r
93     }\r
94 \r
95     setId(id: String){\r
96         this._id = id;\r
97     }\r
98 \r
99     setName(testName: String){\r
100         this.testName = testName;\r
101     }\r
102 \r
103     setDescription(testDescription: String){\r
104         this.testDescription = testDescription;\r
105     }\r
106 \r
107     setGroupId(groupId: String){\r
108         this.groupId = groupId;\r
109     }\r
110 \r
111     setProcessDefinitionKey(processDefinitionKey: String){\r
112         this.processDefinitionKey = processDefinitionKey;\r
113     }\r
114 \r
115     setBpmnInstances(instances: BpmnInstanceElement[] = []){\r
116         \r
117         \r
118         this.bpmnInstances = instances;\r
119     }\r
120 \r
121     setNewVersion(newVersion: number = null){\r
122         if(newVersion == null){\r
123             newVersion = this.bpmnInstances.length;\r
124         }\r
125         if(this.setVersion(newVersion) == -1){\r
126             this.setNewVersion(++newVersion);\r
127         }\r
128         return newVersion;\r
129     }\r
130 \r
131     setVersion(version){\r
132         this.bpmnInstances.forEach((elem, val) => {\r
133             if(elem.version == version && this.currentVersion != val ){\r
134                 return -1;\r
135             }\r
136         });\r
137         this.currentInstance.version = version;\r
138         return version;\r
139     }\r
140 \r
141     addBpmnInstance(instance?){\r
142         if(!instance){\r
143            instance = this.newInstance();\r
144         }\r
145         //console.log(this.bpmnInstances[this.bpmnInstances.length - 1].version )\r
146         if(this.bpmnInstances[this.bpmnInstances.length - 1]){\r
147             instance['version'] = (toInteger(this.bpmnInstances[this.bpmnInstances.length - 1].version) + 1).toString();\r
148         }else{\r
149             instance['version'] = "1";      \r
150         }\r
151         this.bpmnInstances.push(instance);\r
152                 \r
153     }\r
154 \r
155     removeBpmnInstance(version){\r
156         this.bpmnInstances.forEach((elem, val) =>{\r
157             if(elem['version'] == version){\r
158                 this.bpmnInstances.splice(val, 1);\r
159             }\r
160         });\r
161     }\r
162 \r
163     getBpmnInstances(version: String = null){\r
164         if(!version)\r
165             return this.bpmnInstances;\r
166         \r
167         this.bpmnInstances.forEach((elem, val) => {\r
168             if(elem['version'] == version){\r
169                 return elem;\r
170             }\r
171         });\r
172     }\r
173 \r
174     newInstance(): BpmnInstanceElement {\r
175         return {} as BpmnInstanceElement;\r
176     }\r
177 \r
178 \r
179 \r
180 \r
181 \r
182 }\r
183 \r
184 export class BpmnInstanceElement implements BpmnInstance {\r
185     createdAt: String;\r
186     updatedAt: String;\r
187     processDefinitionId: String;    \r
188     deploymentId: String;\r
189     version: String;\r
190     bpmnFileId: String;\r
191     resourceFileId: String;\r
192     isDeployed: Boolean;\r
193     testHeads: TestHeadRef[];\r
194     pflos: Pflow[];\r
195     testDataTemplate: String;\r
196     testDataTemplateJSON: any;\r
197     updatedBy: String;\r
198     createdBy: String;\r
199 \r
200     bpmnXml: String;\r
201     bpmnHasChanged: Boolean;\r
202 \r
203 }