2 * Created by obarda on 2/4/2016.
5 import {IComponentService, ComponentService} from "./component-service";
6 import {Distribution, DistributionComponent, Service, PropertyModel, Component, IAppConfigurtaion} from "app/models";
7 import {SharingService} from "../sharing-service";
9 export interface IServiceService extends IComponentService {
10 getDistributionsList(uuid:string):ng.IPromise<Array<Distribution>>;
11 getDistributionComponents(distributionId:string):ng.IPromise<Array<DistributionComponent>>;
12 markAsDeployed(serviceId:string, distributionId:string):ng.IPromise<any>;
13 updateGroupInstanceProperties(serviceId:string, resourceInstanceId:string, groupInstanceId:string, groupInstanceProperties:Array<PropertyModel>):ng.IPromise<Array<PropertyModel>>;
16 export class ServiceService extends ComponentService implements IServiceService {
21 'Sdc.Services.SharingService',
26 public distribution:string = "distribution";
28 constructor(protected restangular:restangular.IElement,
29 protected sdcConfig:IAppConfigurtaion,
30 protected sharingService:SharingService,
31 protected $q:ng.IQService,
32 protected $base64:any) {
33 super(restangular, sdcConfig, sharingService, $q, $base64);
35 this.restangular = restangular.one("services");
38 getDistributionsList = (uuid:string):ng.IPromise<Array<Distribution>> => {
39 let defer = this.$q.defer<Array<Distribution>>();
40 this.restangular.one(uuid).one("distribution").get().then((distributions:any) => {
41 defer.resolve(<Array<Distribution>> distributions.distributionStatusOfServiceList);
48 getDistributionComponents = (distributionId:string):ng.IPromise<Array<DistributionComponent>> => {
49 let defer = this.$q.defer<Array<DistributionComponent>>();
50 this.restangular.one("distribution").one(distributionId).get().then((distributions:any) => {
51 defer.resolve(<Array<DistributionComponent>> distributions.distributionStatusList);
58 markAsDeployed = (serviceId:string, distributionId:string):ng.IPromise<any> => {
59 let defer = this.$q.defer<any>();
60 this.restangular.one(serviceId).one("distribution").one(distributionId).one("markDeployed").customPOST().then((result:any) => {
61 defer.resolve(result);
69 createComponentObject = (component:Component):Component => {
70 return new Service(this, this.$q, <Service>component);
73 updateGroupInstanceProperties = (serviceId:string, resourceInstanceId:string, groupInstanceId:string, groupInstanceProperties:Array<PropertyModel>):ng.IPromise<Array<PropertyModel>> => {
74 let defer = this.$q.defer<Array<PropertyModel>>();
75 this.restangular.one(serviceId).one("resourceInstance").one(resourceInstanceId).one('groupInstance').one(groupInstanceId).customPUT(JSON.stringify(groupInstanceProperties)).then((updatedProperties:any) => {
76 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
77 _.forEach(updatedProperties, (propertyObj:PropertyModel) => {
78 propertiesArray.push(new PropertyModel(propertyObj));
80 defer.resolve(propertiesArray);