--- /dev/null
+/* Copyright (c) 2019 AT&T Intellectual Property. #\r
+# #\r
+# Licensed under the Apache License, Version 2.0 (the "License"); #\r
+# you may not use this file except in compliance with the License. #\r
+# You may obtain a copy of the License at #\r
+# #\r
+# http://www.apache.org/licenses/LICENSE-2.0 #\r
+# #\r
+# Unless required by applicable law or agreed to in writing, software #\r
+# distributed under the License is distributed on an "AS IS" BASIS, #\r
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #\r
+# See the License for the specific language governing permissions and #\r
+# limitations under the License. #\r
+##############################################################################*/\r
+\r
+\r
+import { DefinitionInstance } from "./definition-instance.class";\r
+import { element } from "@angular/core/src/render3/instructions";\r
+\r
+export class TestDefinition {\r
+\r
+ public _id: String;\r
+ public testName: String;\r
+ public testDescription: String;\r
+ public groupId: String;\r
+ public processDefinitionKey: String;\r
+\r
+ public bpmnInstances: DefinitionInstance[];\r
+\r
+ public currentVersion; // int Array index of the bpmnInstances\r
+ public currentVersionName;\r
+ public currentInstance: DefinitionInstance;\r
+\r
+ constructor(testDefinition: TestDefinition = null){\r
+ if(testDefinition){\r
+ this.setAll(testDefinition);\r
+ }\r
+ }\r
+\r
+\r
+ reset(){\r
+ this._id = '';\r
+ this.testName = '';\r
+ this.testDescription = '';\r
+ this.groupId = '';\r
+ this.processDefinitionKey = '';\r
+ this.bpmnInstances = [\r
+ this.newInstance() as DefinitionInstance\r
+ ];\r
+ this.currentInstance = this.bpmnInstances[0];\r
+ this.currentVersion = 0;\r
+ }\r
+\r
+ getAll(){\r
+ return {\r
+ _id: this._id,\r
+ testName: this.testName,\r
+ testDescription: this.testDescription,\r
+ processDefinitionKey: this.processDefinitionKey,\r
+ bpmnInstances: this.bpmnInstances,\r
+ currentVersion: this.currentVersion\r
+ };\r
+ }\r
+\r
+ switchVersion(version: String = null){\r
+ \r
+ if(version){\r
+ //find the version\r
+ this.bpmnInstances.forEach((elem, val) => {\r
+ if(elem['version'] == version){\r
+ this.currentVersion = val;\r
+ this.currentInstance = this.bpmnInstances[val];\r
+ this.currentVersionName = this.currentInstance.version;\r
+ }\r
+ });\r
+ }else{\r
+ //get latest version\r
+ this.currentVersion = this.bpmnInstances.length - 1;\r
+ this.currentInstance = this.bpmnInstances[this.currentVersion];\r
+ this.currentVersionName = this.currentInstance.version;\r
+ }\r
+ }\r
+\r
+ getVersionKey(){\r
+ return this.currentVersion;\r
+ }\r
+\r
+ //Setter Methods\r
+\r
+ setAll(td){\r
+ this._id = td._id;\r
+ this.testName = td.testName;\r
+ this.testDescription = td.testDescription;\r
+ this.groupId = td.groupId;\r
+ this.processDefinitionKey = td.processDefinitionKey;\r
+ this.setBpmnInstances(td.bpmnInstances);\r
+\r
+ this.bpmnInstances.forEach((elem, val) => {\r
+ if(!elem.dataTestHeads)\r
+ this.bpmnInstances[val].dataTestHeads = [];\r
+ })\r
+ }\r
+\r
+ setId(id: String){\r
+ this._id = id;\r
+ }\r
+\r
+ setName(testName: String){\r
+ this.testName = testName;\r
+ }\r
+\r
+ setDescription(testDescription: String){\r
+ this.testDescription = testDescription;\r
+ }\r
+\r
+ setGroupId(groupId: String){\r
+ this.groupId = groupId;\r
+ }\r
+\r
+ setProcessDefinitionKey(processDefinitionKey: String){\r
+ this.processDefinitionKey = processDefinitionKey;\r
+ }\r
+\r
+ setBpmnInstances(instances: DefinitionInstance[] = []){\r
+ // this.bpmnInstances = [];\r
+ // for(let i = instances.length - 1; i >= 0; i--){\r
+ // this.bpmnInstances.push(instances[i]);\r
+ // }\r
+ this.bpmnInstances = instances;\r
+ }\r
+\r
+ setNewVersion(newVersion: number = null){\r
+ if(newVersion == null){\r
+ newVersion = this.bpmnInstances.length;\r
+ }\r
+ if(this.setVersion(newVersion) == -1){\r
+ this.setNewVersion(++newVersion);\r
+ }\r
+ return newVersion;\r
+ }\r
+\r
+ setVersion(version){\r
+ \r
+ this.bpmnInstances.forEach((elem, val) => {\r
+ \r
+ \r
+ if(elem.version == version && this.currentVersion != val ){\r
+ return -1;\r
+ }\r
+ });\r
+ this.currentInstance.version = version;\r
+ return version;\r
+ }\r
+\r
+ addBpmnInstance(instance = null){\r
+ \r
+ if(!instance){\r
+ instance = this.newInstance();\r
+ }\r
+ let alreadyIn = false;\r
+ this.bpmnInstances.forEach((elem, val) => {\r
+ if(elem.version == instance.version && val != 0){\r
+ alreadyIn = true;\r
+ }\r
+ });\r
+ if(!alreadyIn){\r
+ this.bpmnInstances.push(instance);\r
+ this.setNewVersion()\r
+ }\r
+ \r
+ }\r
+\r
+ removeBpmnInstance(version){\r
+ this.bpmnInstances.forEach((elem, val) =>{\r
+ if(elem['version'] == version){\r
+ this.bpmnInstances.splice(val, 1);\r
+ }\r
+ });\r
+ }\r
+\r
+ //Getter Methods\r
+\r
+ getId(){\r
+ return this._id;\r
+ }\r
+\r
+ getName(){\r
+ return this.testName;\r
+ }\r
+\r
+ getDescription(){\r
+ return this.testDescription;\r
+ }\r
+\r
+ getGroupId(){\r
+ return this.groupId;\r
+ }\r
+\r
+ getProcessDefinitionKey(){\r
+ return this.processDefinitionKey;\r
+ }\r
+\r
+ getBpmnInstances(version: String = null){\r
+ if(!version)\r
+ return this.bpmnInstances;\r
+ \r
+ this.bpmnInstances.forEach((elem, val) => {\r
+ if(elem['version'] == version){\r
+ return elem;\r
+ }\r
+ });\r
+ }\r
+\r
+ newInstance() {\r
+ return new DefinitionInstance();\r
+ }\r
+\r
+\r
+\r
+\r
+\r
+}
\ No newline at end of file