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 { Component, OnInit, Input, ViewChild, HostListener, AfterContentInit, AfterViewInit, ElementRef, OnDestroy } from '@angular/core';
\r
18 import { TestDefinitionService } from 'app/shared/services/test-definition.service';
\r
19 import { TestInstanceService } from 'app/shared/services/test-instance.service';
\r
20 import { MatTableDataSource, MatPaginator, MatDialog, MatSnackBar } from '@angular/material';
\r
21 import Modeler from 'bpmn-js';
\r
22 import { timeInterval } from 'rxjs/operators';
\r
23 import { Observable } from 'rxjs';
\r
24 import { TestExecutionService } from 'app/shared/services/test-execution.service';
\r
25 import { AlertModalComponent } from 'app/shared/modules/alert-modal/alert-modal.component';
\r
26 import { AlertSnackbarComponent } from 'app/shared/modules/alert-snackbar/alert-snackbar.component';
\r
27 import { SchedulingService } from 'app/shared/services/scheduling.service';
\r
28 import { FileTransferService } from 'app/shared/services/file-transfer.service';
\r
29 import { Buffer } from 'buffer';
\r
30 import { ViewWorkflowModalComponent } from 'app/shared/modules/view-workflow-modal/view-workflow-modal.component';
\r
31 import { ExecuteService } from 'app/shared/services/execute.service';
\r
32 import { BpmnFactoryService } from 'app/shared/factories/bpmn-factory.service';
\r
35 selector: 'app-test-definition-expanded-details',
\r
36 templateUrl: './test-definition-expanded-details.component.pug',
\r
37 styleUrls: ['./test-definition-expanded-details.component.scss']
\r
39 export class TestDefinitionExpandedDetailsComponent implements OnInit, OnDestroy {
\r
41 @Input() public testDefinitionId;
\r
43 @Input() public events: Observable<void>;
\r
45 @ViewChild(MatPaginator) instancePaginator: MatPaginator;
\r
46 @ViewChild('canvas') canvas: ElementRef;
\r
49 public dataLength = 0;
\r
50 public displayedColumns;
\r
51 public foundStatuses = ['name'];
\r
52 public statusList = ['COMPLETED', 'SUCCESS', 'UNKNOWN', 'FAILURE', 'STOPPED', 'UNAUTHORIZED', 'FAILED'];
\r
53 public testInstanceList = null;
\r
54 public testExecutionList = [];
\r
60 private bpmnFactory: BpmnFactoryService,
\r
61 private fileTransfer: FileTransferService,
\r
62 private dialog: MatDialog,
\r
63 private testDefinition: TestDefinitionService,
\r
64 private testInstance: TestInstanceService,
\r
65 private testExecution: TestExecutionService,
\r
66 private execute: ExecuteService,
\r
67 private modal: MatDialog,
\r
68 private snack: MatSnackBar
\r
73 await this.testDefinition.get(this.testDefinitionId).subscribe(
\r
75 result['createdAt'] = new Date(result['createdAt']).toLocaleString();
\r
76 result['updatedAt'] = new Date(result['updatedAt']).toLocaleString();
\r
78 if(this.data.bpmnInstances){
\r
79 this.bpmnFactory.setup({
\r
82 container: this.canvas.nativeElement
\r
84 fileId: this.data.bpmnInstances[0].bpmnFileId
\r
88 // this.loadDiagram();
\r
93 this.testInstanceList = new MatTableDataSource();
\r
94 this.testInstance.find({
\r
99 testDefinitionId: this.testDefinitionId
\r
102 this.testInstanceList.data = result;
\r
103 this.testInstanceList.paginator = this.instancePaginator;
\r
105 this.testInstanceList.data.forEach(elem => {
\r
106 this.setExecutions(elem._id);
\r
109 this.displayedColumns = ['name', 'COMPLETED', 'SUCCESS', 'UNKNOWN', 'FAILURE', 'STOPPED', 'UNAUTHORIZED', 'FAILED', 'options'];
\r
114 //If parent emeits, diagram will reload
\r
115 if(this.events != undefined && this.events){
\r
116 this.events.subscribe(() => {
\r
118 this.loadDiagram();
\r
125 this.dialog.open(ViewWorkflowModalComponent, {
\r
127 xml: this.viewer.getBpmnXml()
\r
135 delete this.events;
\r
138 async setExecutions(instanceId) {
\r
139 // ['$limit=-1', '$sort[startTime]=-1', 'testInstanceId=' + instanceId]
\r
140 this.testExecution.find({
\r
145 'historicTestInstance._id': instanceId
\r
148 for(let i = 0; i < result['length']; i++){
\r
149 result[i].startTime = new Date(result[i].startTime).toLocaleString();
\r
150 this.testExecutionList.push(result[i]);
\r
151 for(let j = 0; j < this.testInstanceList.data.length; j++){
\r
152 if(this.testInstanceList.data[j]._id == instanceId){
\r
153 if(!this.testInstanceList.data[j][result[i]['testResult']]){
\r
154 this.testInstanceList.data[j][result[i]['testResult']] = 1;
\r
156 this.testInstanceList.data[j][result[i]['testResult']] += 1;
\r
162 //this.setDisplayColumns();
\r
163 // for(let i = 0; i < result[i]; i++){
\r
164 // this.testInstanceList[instanceId] = result;
\r
172 if(this.viewer && this.data && this.data.bpmnInstances){
\r
173 this.viewer.renderDiagram();
\r
177 executeTestInstance(element){
\r
179 if(element.testDefinitionId){
\r
180 const executer = this.modal.open(AlertModalComponent, {
\r
183 type: 'confirmation',
\r
184 message: 'Are you sure you want to run ' + element.testInstanceName + '?'
\r
188 executer.afterClosed().subscribe(result => {
\r
190 this.execute.create({
\r
193 }).subscribe((result) => {
\r
194 this.snack.openFromComponent(AlertSnackbarComponent, {
\r
197 message: 'Test Instance Executed'
\r
202 this.modal.open(AlertModalComponent, {
\r
206 message: 'Failed to execute Test Instance!\n' + JSON.stringify(error)
\r