added svcapi ui and camunda code
[it/otf.git] / otf-frontend / client / src / app / shared / services / test-definition.service.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 { Injectable } from '@angular/core';\r
18 import { HttpClient } from '@angular/common/http';\r
19 import { AppGlobals } from '../../app.global';\r
20 import { Observable } from 'rxjs';\r
21 import { ParamsService } from './params.service';\r
22 import { CookieService } from 'ngx-cookie-service';\r
23 import { ModelService } from './model.service';\r
24 import { FeathersService } from './feathers.service';\r
25 import { GroupService } from './group.service';\r
26 \r
27 \r
28 \r
29 @Injectable({\r
30   providedIn: 'root'\r
31 })\r
32 \r
33 export class TestDefinitionService extends ModelService {\r
34 \r
35   constructor(http: HttpClient, Params: ParamsService, cookie: CookieService, feathers: FeathersService, private _groups: GroupService) {\r
36     super('test-definitions', http, Params, cookie, feathers);\r
37     this.deployAll();\r
38   }\r
39 \r
40   create(data, params?): Observable<Object>{\r
41     this.setGroup(data);\r
42     return super.create(data, params);\r
43   }\r
44 \r
45   validate(testDefinition): Observable<Object> {\r
46     return this.call('create', {data: { testDefinition: testDefinition } }, AppGlobals.baseAPIUrl + 'bpmn-validate')\r
47     //return this.http.post(AppGlobals.baseAPIUrl + 'bpmn-validate', {testDefinition: testDefinition}, this.getHttpOptions());\r
48   }\r
49 \r
50   validateSave(testDefinition): Observable<Object> {\r
51     return this.call('update', { data: {_id: null, testDefinition: testDefinition } }, AppGlobals.baseAPIUrl + 'bpmn-validate')\r
52     //return this.http.put(AppGlobals.baseAPIUrl + 'bpmn-validate', {testDefinition: testDefinition}, this.getHttpOptions());\r
53   }\r
54 \r
55   check(processDefinitionKey): Observable<Object>{\r
56     return this.call('get', {data: processDefinitionKey} , AppGlobals.baseAPIUrl + 'bpmn-validate')\r
57     //return this.http.get(AppGlobals.baseAPIUrl + 'bpmn-validate/' + processDefinitionKey, this.getHttpOptions());\r
58   }\r
59 \r
60   deploy(testDefinition, versionName?): Observable<Object> {\r
61     let data = {testDefinition: testDefinition};\r
62 \r
63     if(versionName != null && versionName != undefined){\r
64       data['version'] = versionName;\r
65     }\r
66     return this.call('create', {data: data }, AppGlobals.baseAPIUrl + 'bpmn-upload')\r
67     //return this.http.post(AppGlobals.baseAPIUrl + 'bpmn-upload', {testDefinition: testDefinition}, this.getHttpOptions());\r
68   }\r
69 \r
70   deployAll(){\r
71     // this.find({$limit: -1}).subscribe(definitions => {\r
72     //   //definitions = definitions['data'];\r
73     //   (definitions as Array<Object>).forEach((elem, val) => {\r
74     //     elem['bpmnInstances'].forEach((e , v) => {\r
75     //       let el = e;\r
76     //       this.deploy(elem, el.version).subscribe(res => {\r
77     //         console.log(res);\r
78     //       });\r
79     //     })\r
80     //   })\r
81     // })\r
82   }\r
83 \r
84   private setGroup(data){\r
85     if(!data['groupId']){\r
86       data['groupId'] = this._groups.getGroup()['_id'];\r
87     }\r
88   }\r
89 }\r