1 /* Copyright (c) 2019 AT&T Intellectual Property. #
\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
7 # http://www.apache.org/licenses/LICENSE-2.0 #
\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
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
20 export class TestDefinitionElement implements TestDefinition {
\r
23 testDescription: String;
\r
24 processDefinitionKey: String;
\r
26 bpmnInstances: BpmnInstanceElement[];
\r
34 currentVersion; // int Array index of the bpmnInstances
\r
36 currentInstance: BpmnInstanceElement;
\r
38 constructor(testDefinition?){
\r
40 this.setAll(testDefinition);
\r
50 this.testDescription = '';
\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
59 this.bpmnInstances = [];
\r
60 this.addBpmnInstance();
\r
62 this.switchVersion();
\r
65 switchVersion(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
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
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
99 setName(testName: String){
\r
100 this.testName = testName;
\r
103 setDescription(testDescription: String){
\r
104 this.testDescription = testDescription;
\r
107 setGroupId(groupId: String){
\r
108 this.groupId = groupId;
\r
111 setProcessDefinitionKey(processDefinitionKey: String){
\r
112 this.processDefinitionKey = processDefinitionKey;
\r
115 setBpmnInstances(instances: BpmnInstanceElement[] = []){
\r
118 this.bpmnInstances = instances;
\r
121 setNewVersion(newVersion: number = null){
\r
122 if(newVersion == null){
\r
123 newVersion = this.bpmnInstances.length;
\r
125 if(this.setVersion(newVersion) == -1){
\r
126 this.setNewVersion(++newVersion);
\r
131 setVersion(version){
\r
132 this.bpmnInstances.forEach((elem, val) => {
\r
133 if(elem.version == version && this.currentVersion != val ){
\r
137 this.currentInstance.version = version;
\r
141 addBpmnInstance(instance?){
\r
143 instance = this.newInstance();
\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
149 instance['version'] = "1";
\r
151 this.bpmnInstances.push(instance);
\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
163 getBpmnInstances(version: String = null){
\r
165 return this.bpmnInstances;
\r
167 this.bpmnInstances.forEach((elem, val) => {
\r
168 if(elem['version'] == version){
\r
174 newInstance(): BpmnInstanceElement {
\r
175 return {} as BpmnInstanceElement;
\r
184 export class BpmnInstanceElement implements BpmnInstance {
\r
187 processDefinitionId: String;
\r
188 deploymentId: String;
\r
190 bpmnFileId: String;
\r
191 resourceFileId: String;
\r
192 isDeployed: Boolean;
\r
193 testHeads: TestHeadRef[];
\r
195 testDataTemplate: String;
\r
196 testDataTemplateJSON: any;
\r
201 bpmnHasChanged: Boolean;
\r