Fix new data types not found in UI
[sdc.git] / catalog-ui / src / app / services / components / service-service.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /**
22  * Created by obarda on 2/4/2016.
23  */
24 'use strict';
25 import * as _ from "lodash";
26 import {IComponentService, ComponentService} from "./component-service";
27 import {Distribution, DistributionComponent, Service, PropertyModel, Component, IAppConfigurtaion} from "app/models";
28 import {SharingService} from "app/services-ng2";
29 import { DataTypesService } from "app/services";
30
31 export interface IServiceService extends IComponentService {
32     getDistributionsList(uuid:string):ng.IPromise<Array<Distribution>>;
33     getDistributionComponents(distributionId:string):ng.IPromise<Array<DistributionComponent>>;
34     markAsDeployed(serviceId:string, distributionId:string):ng.IPromise<any>;
35     updateGroupInstanceProperties(serviceId:string, resourceInstanceId:string, groupInstanceId:string, groupInstanceProperties:Array<PropertyModel>):ng.IPromise<Array<PropertyModel>>;
36 }
37
38 export class ServiceService extends ComponentService implements IServiceService {
39
40     static '$inject' = [
41         'Restangular',
42         'sdcConfig',
43         'Sdc.Services.SharingService',
44         'Sdc.Services.DataTypesService',
45         '$q',
46         '$base64'
47     ];
48
49     public distribution:string = "distribution";
50
51     constructor(protected restangular:restangular.IElement,
52                 protected sdcConfig:IAppConfigurtaion,
53                 protected sharingService:SharingService,
54                 protected dataTypeService:DataTypesService,
55                 protected $q:ng.IQService,
56                 protected $base64:any) {
57         super(restangular, sdcConfig, sharingService, dataTypeService, $q, $base64);
58
59         this.restangular = restangular.one("services");
60     }
61
62     getDistributionsList = (uuid:string):ng.IPromise<Array<Distribution>> => {
63         let defer = this.$q.defer<Array<Distribution>>();
64         this.restangular.one(uuid).one("distribution").get().then((distributions:any) => {
65             defer.resolve(<Array<Distribution>> distributions.distributionStatusOfServiceList);
66         }, (err)=> {
67             defer.reject(err);
68         });
69         return defer.promise;
70     };
71
72     getDistributionComponents = (distributionId:string):ng.IPromise<Array<DistributionComponent>> => {
73         let defer = this.$q.defer<Array<DistributionComponent>>();
74         this.restangular.one("distribution").one(distributionId).get().then((distributions:any) => {
75             defer.resolve(<Array<DistributionComponent>> distributions.distributionStatusList);
76         }, (err)=> {
77             defer.reject(err);
78         });
79         return defer.promise;
80     };
81
82     markAsDeployed = (serviceId:string, distributionId:string):ng.IPromise<any> => {
83         let defer = this.$q.defer<any>();
84         this.restangular.one(serviceId).one("distribution").one(distributionId).one("markDeployed").customPOST().then((result:any) => {
85             defer.resolve(result);
86         }, (err)=> {
87
88             defer.reject(err);
89         });
90         return defer.promise;
91     };
92
93     createComponentObject = (component:Component):Component => {
94         return new Service(this, this.$q, <Service>component);
95     };
96
97     updateGroupInstanceProperties = (serviceId:string, resourceInstanceId:string, groupInstanceId:string, groupInstanceProperties:Array<PropertyModel>):ng.IPromise<Array<PropertyModel>> => {
98         let defer = this.$q.defer<Array<PropertyModel>>();
99         this.restangular.one(serviceId).one("resourceInstance").one(resourceInstanceId).one('groupInstance').one(groupInstanceId).customPUT(JSON.stringify(groupInstanceProperties)).then((updatedProperties:any) => {
100             let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
101             _.forEach(updatedProperties, (propertyObj:PropertyModel) => {
102                 propertiesArray.push(new PropertyModel(propertyObj));
103             });
104             defer.resolve(propertiesArray);
105         }, (err)=> {
106             defer.reject(err);
107         });
108         return defer.promise;
109     };
110 }