--- /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 { TestDefinition, BpmnInstance, TestHeadRef, Pflow } from "app/shared/models/test-definition.model";\r
+import { toInteger } from "@ng-bootstrap/ng-bootstrap/util/util";\r
+\r
+export class TestDefinitionElement implements TestDefinition {\r
+\r
+ testName: String;\r
+ testDescription: String;\r
+ processDefinitionKey: String;\r
+ groupId: String;\r
+ bpmnInstances: BpmnInstanceElement[];\r
+ disabled: Boolean;\r
+ _id: String;\r
+ createdAt: String;\r
+ createdBy: String;\r
+ updatedAt: String;\r
+ updatedBy: String;\r
+\r
+ currentVersion; // int Array index of the bpmnInstances\r
+ currentVersionName;\r
+ currentInstance: BpmnInstanceElement;\r
+\r
+ constructor(testDefinition?){\r
+ if(testDefinition){\r
+ this.setAll(testDefinition);\r
+ }else{\r
+ this.reset();\r
+ }\r
+ }\r
+\r
+\r
+ reset(){\r
+ this._id = "";\r
+ this.testName = '';\r
+ this.testDescription = '';\r
+ this.groupId = '';\r
+ this.processDefinitionKey = '';\r
+ this.disabled = false;\r
+ this.createdAt = null;\r
+ this.createdBy = null;\r
+ this.updatedAt = null;\r
+ this.updatedBy = null;\r
+\r
+ this.bpmnInstances = [];\r
+ this.addBpmnInstance();\r
+\r
+ this.switchVersion();\r
+ }\r
+\r
+ switchVersion(version?){\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
+ //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
+ this.switchVersion();\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: BpmnInstanceElement[] = []){\r
+ \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
+ this.bpmnInstances.forEach((elem, val) => {\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?){\r
+ if(!instance){\r
+ instance = this.newInstance();\r
+ }\r
+ //console.log(this.bpmnInstances[this.bpmnInstances.length - 1].version )\r
+ if(this.bpmnInstances[this.bpmnInstances.length - 1]){\r
+ instance['version'] = (toInteger(this.bpmnInstances[this.bpmnInstances.length - 1].version) + 1).toString();\r
+ }else{\r
+ instance['version'] = "1"; \r
+ }\r
+ this.bpmnInstances.push(instance);\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
+ 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(): BpmnInstanceElement {\r
+ return {} as BpmnInstanceElement;\r
+ }\r
+\r
+\r
+\r
+\r
+\r
+}\r
+\r
+export class BpmnInstanceElement implements BpmnInstance {\r
+ createdAt: String;\r
+ updatedAt: String;\r
+ processDefinitionId: String; \r
+ deploymentId: String;\r
+ version: String;\r
+ bpmnFileId: String;\r
+ resourceFileId: String;\r
+ isDeployed: Boolean;\r
+ testHeads: TestHeadRef[];\r
+ pflos: Pflow[];\r
+ testDataTemplate: String;\r
+ testDataTemplateJSON: any;\r
+ updatedBy: String;\r
+ createdBy: String;\r
+\r
+ bpmnXml: String;\r
+ bpmnHasChanged: Boolean;\r
+\r
+}
\ No newline at end of file