2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 import * as _ from "lodash";
22 import {ArtifactModel, IFileDownload, InstancesInputsPropertiesMap, InputModel, IValidate, RelationshipModel, PropertyModel, Component, ComponentInstance,
23 AttributeModel, IAppConfigurtaion, Resource, Module, DisplayModule, ArtifactGroupModel, InputsAndProperties} from "app/models";
24 import {ComponentInstanceFactory, CommonUtils} from "app/utils";
25 import {SharingService} from "../sharing-service";
26 import {ComponentMetadata} from "../../models/component-metadata";
27 import {EventBusService} from "../../ng2/services/event-bus.service";
29 export interface IComponentService {
31 getComponent(id:string);
32 updateComponent(component:Component):ng.IPromise<Component>;
33 changeLifecycleState(component:Component, state:string, userRemarks:any):ng.IPromise<ComponentMetadata> ;
34 validateName(newName:string, subtype?:string):ng.IPromise<IValidate>;
35 createComponent(component:Component):ng.IPromise<Component>;
36 addOrUpdateArtifact(componentId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
37 deleteArtifact(componentId:string, artifact:string, artifactLabel):ng.IPromise<ArtifactModel>;
38 addProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>;
39 updateProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>;
40 addAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
41 updateAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
42 deleteProperty(componentId:string, propertyId:string):ng.IPromise<PropertyModel>;
43 deleteAttribute(componentId:string, attributeId:string):ng.IPromise<AttributeModel>;
44 checkResourceInstanceVersionChange(componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<any>;
45 changeResourceInstanceVersion(componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<ComponentInstance>;
46 updateInstanceArtifact(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
47 addInstanceArtifact(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
48 deleteInstanceArtifact(componentId:string, instanceId:string, artifact:string, artifactLabel):ng.IPromise<ArtifactModel>;
49 createComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>;
50 updateComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>;
51 updateMultipleComponentInstances(componentId:string, instances:Array<ComponentInstance>):ng.IPromise< Array<ComponentInstance>>;
52 downloadArtifact(componentId:string, artifactId:string):ng.IPromise<IFileDownload>;
53 uploadInstanceEnvFile(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
54 downloadInstanceArtifact(componentId:string, instanceId:string, artifactId:string):ng.IPromise<IFileDownload>;
55 deleteComponentInstance(componentId:string, componentInstanceId:string):ng.IPromise<ComponentInstance>;
56 createRelation(componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel>;
57 deleteRelation(componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel>;
58 fetchRelation(componentId:string, linkId:string):ng.IPromise<RelationshipModel>;
59 getRequirementsCapabilities(componentId:string):ng.IPromise<any>;
60 updateInstanceProperties(componentId:string, componentInstanceId:string, properties:PropertyModel[]):ng.IPromise<PropertyModel[]>;
61 updateInstanceAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
62 getComponentInstancesFilteredByInputsAndProperties(componentId:string, searchText:string):ng.IPromise<Array<ComponentInstance>>
63 getComponentInstanceInputs(componentId:string, instanceId:string, originComponentUid):ng.IPromise<Array<InputModel>>;
64 getComponentInputs(componentId:string):ng.IPromise<Array<InputModel>>;
65 getComponentInstanceInputProperties(componentId:string, instanceId:string, inputId:string):ng.IPromise<Array<PropertyModel>>;
66 getComponentInstanceProperties(componentId:string, instanceId:string):ng.IPromise<Array<PropertyModel>>;
67 getModuleForDisplay(componentId:string, moduleId:string):ng.IPromise<DisplayModule>;
68 getComponentInstanceModule(componentId:string, componentInstanceId:string, moduleId:string):ng.IPromise<DisplayModule>;
69 updateGroupMetadata(componentId:string, group:Module):ng.IPromise<Module>;
70 getComponentInputInputsAndProperties(serviceId:string, input:string):ng.IPromise<InputsAndProperties>;
71 createInputsFromInstancesInputs(serviceId:string, instancesInputsMap:InstancesInputsPropertiesMap):ng.IPromise<Array<InputModel>>;
72 createInputsFromInstancesInputsProperties(resourceId:string, instanceInputsPropertiesMap:InstancesInputsPropertiesMap):ng.IPromise<Array<PropertyModel>>;
73 deleteComponentInput(serviceId:string, inputId:string):ng.IPromise<InputModel>;
74 getArtifactByGroupType(componentId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel>;
75 getComponentInstanceArtifactsByGroupType(componentId:string, componentInstanceId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel>;
78 export class ComponentService implements IComponentService {
83 'Sdc.Services.SharingService',
89 constructor(protected restangular:restangular.IElement,
90 protected sdcConfig:IAppConfigurtaion,
91 protected sharingService:SharingService,
92 protected $q:ng.IQService,
93 protected $base64:any,
94 protected eventBusService:EventBusService
97 this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
98 this.restangular.setRequestInterceptor(function (elem, operation) {
99 if (operation === "remove") {
104 // this.restangular.setDefaultHeaders({'Content-Type': 'application/json; charset=UTF-8'});
107 //this function is override by each service, we need to change this method to abstract when updtaing typescript version
108 protected createComponentObject = (component:Component):Component => {
112 public getComponent = (id:string):ng.IPromise<Component> => {
113 let deferred = this.$q.defer();
114 this.restangular.one(id).get().then((response:Component) => {
115 let component:Component = this.createComponentObject(response);
116 //console.log("Component Loaded successfully : ", component);
117 deferred.resolve(component);
119 console.log("Failed to load component with ID: " + id);
120 deferred.reject(err);
122 return deferred.promise;
125 public updateComponent = (component:Component):ng.IPromise<Component> => {
126 // If this is resource
127 if (component instanceof Resource) {
128 let resource:Resource = <Resource>component;
129 if (resource.importedFile) {
130 // Update resource with payload data.
131 return this.updateResourceWithPayload(resource);
133 if (component.csarUUID) {
134 // Update resource without payload data.
135 return this.updateResource(component);
137 // Update resource without payload data (metadata).
138 return this.updateResourceMetadata(component);
142 return this.updateService(component);
146 private updateService = (component:Component):ng.IPromise<Component> => {
147 let deferred = this.$q.defer();
148 this.restangular.one(component.uniqueId).one("metadata").customPUT(JSON.stringify(component)).then((response:Component) => {
149 let component:Component = this.createComponentObject(response);
150 deferred.resolve(component);
152 deferred.reject(err);
154 return deferred.promise;
157 private updateResource = (component:Component):ng.IPromise<Component> => {
158 let deferred = this.$q.defer();
159 this.restangular.one(component.uniqueId).customPUT(JSON.stringify(component)).then((response:Component) => {
160 let component:Component = this.createComponentObject(response);
161 deferred.resolve(component);
163 deferred.reject(err);
165 return deferred.promise;
168 private updateResourceMetadata = (component:Component):ng.IPromise<Component> => {
169 let deferred = this.$q.defer();
170 this.restangular.one(component.uniqueId).one('metadata').customPUT(JSON.stringify(component)).then((response:Component) => {
171 let component:Component = this.createComponentObject(response);
172 deferred.resolve(component);
174 deferred.reject(err);
176 return deferred.promise;
180 * Only resource can be updated with payload data
182 * @returns {IPromise<T>}
184 private updateResourceWithPayload = (resource:Resource):ng.IPromise<Component> => {
185 let deferred = this.$q.defer();
187 resource.payloadData = resource.importedFile.base64;
188 resource.payloadName = resource.importedFile.filename;
189 let headerObj = this.getHeaderMd5(resource);
191 this.restangular.one(resource.uniqueId).customPUT(JSON.stringify(resource), '', {}, headerObj).then((response:Component) => {
192 let componentResult:Component = this.createComponentObject(response);
193 deferred.resolve(componentResult);
195 deferred.reject(err);
198 return deferred.promise;
201 public createComponent = (component:Component):ng.IPromise<Component> => {
202 let deferred = this.$q.defer();
203 let headerObj = this.getHeaderMd5(component);
204 this.restangular.customPOST(JSON.stringify(component), '', {}, headerObj).then((response:Component) => {
205 let component:Component = this.createComponentObject(response);
206 deferred.resolve(component);
208 deferred.reject(err);
210 return deferred.promise;
213 public validateName = (newName:string, subtype?:string):ng.IPromise<IValidate> => {
214 let deferred = this.$q.defer();
215 this.restangular.one("validate-name").one(newName).get({'subtype': subtype}).then((response:any) => {
216 deferred.resolve(response.plain());
218 deferred.reject(err);
220 return deferred.promise;
223 public changeLifecycleState = (component:Component, state:string, userRemarks:any):ng.IPromise<ComponentMetadata> => {
224 let deferred = this.$q.defer();
225 this.restangular.one(component.uniqueId).one(state).customPOST(userRemarks).then((response:ComponentMetadata) => {
226 this.sharingService.addUuidValue(response.uniqueId, response.uuid);
227 let component:ComponentMetadata = new ComponentMetadata().deserialize(response);
228 deferred.resolve(component);
230 deferred.reject(err);
233 // Notifying about events before executing the actual actions
236 this.eventBusService.notify("CHECK_IN");
238 case "submitForTesting":
239 this.eventBusService.notify("SUBMIT_FOR_TESTING");
243 return deferred.promise;
246 // ------------------------------------------------ Artifacts API --------------------------------------------------//
247 public addOrUpdateArtifact = (componentId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
248 let deferred = this.$q.defer();
250 if (artifact.payloadData) {
251 headerObj = this.getHeaderMd5(artifact);
253 this.restangular.one(componentId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
254 deferred.resolve(response.plain());
256 deferred.reject(err);
258 return deferred.promise;
261 public downloadArtifact = (componentId:string, artifactId:string):ng.IPromise<IFileDownload> => {
262 let deferred = this.$q.defer();
263 this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response:any) => {
264 deferred.resolve(response.plain());
266 deferred.reject(err);
268 return deferred.promise;
271 public deleteArtifact = (componentId:string, artifactId:string, artifactLabel:string):ng.IPromise<ArtifactModel> => {
272 let deferred = this.$q.defer();
273 this.restangular.one(componentId).one("artifacts").one(artifactId).remove({'operation': artifactLabel}).then((response:ArtifactModel) => {
274 deferred.resolve(response);
276 deferred.reject(err);
278 return deferred.promise;
281 public getArtifactByGroupType = (componentId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel> => {
282 let deferred = this.$q.defer();
283 this.restangular.one(componentId).one("artifactsByType").one(artifactGroupType).get().then((response:any) => {
284 var artifacts:ArtifactGroupModel = new ArtifactGroupModel(response.plain());
285 deferred.resolve(artifacts);
287 deferred.reject(err);
289 return deferred.promise;
292 public getComponentInstanceArtifactsByGroupType = (componentId:string, componentInstanceId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel> => {
293 let deferred = this.$q.defer();
294 this.restangular.one(componentId).one("resourceInstances").one(componentInstanceId).one("artifactsByType").one(artifactGroupType).get().then((response:any) => {
295 var artifacts:ArtifactGroupModel = new ArtifactGroupModel(response.plain());
296 deferred.resolve(artifacts);
298 deferred.reject(err);
300 return deferred.promise;
304 // ------------------------------------------------ Properties API --------------------------------------------------//
305 public addProperty = (componentId:string, property:PropertyModel):ng.IPromise<PropertyModel> => {
306 let deferred = this.$q.defer();
307 this.restangular.one(componentId).one("properties").customPOST(property.convertToServerObject()).then((response:any) => {
308 let property:PropertyModel = new PropertyModel(response[Object.keys(response)[0]]);
309 deferred.resolve(property);
311 deferred.reject(err);
313 return deferred.promise;
316 public updateProperty = (componentId:string, property:PropertyModel):ng.IPromise<PropertyModel> => {
317 let deferred = this.$q.defer();
318 this.restangular.one(componentId).one("properties").one(property.uniqueId).customPUT(property.convertToServerObject()).then((response:any) => {
319 let property:PropertyModel = new PropertyModel(response[Object.keys(response)[0]]);
320 deferred.resolve(property);
322 deferred.reject(err);
324 return deferred.promise;
327 public deleteProperty = (componentId:string, propertyId:string):ng.IPromise<PropertyModel> => {
328 let deferred = this.$q.defer();
329 this.restangular.one(componentId).one("properties").one(propertyId).remove().then((response:any) => {
330 deferred.resolve(response);
332 deferred.reject(err);
334 return deferred.promise;
337 // ------------------------------------------------ Attributes API --------------------------------------------------//
338 public addAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
339 let deferred = this.$q.defer();
340 this.restangular.one(componentId).one("attributes").customPOST(attribute.convertToServerObject()).then((response:any) => {
341 let attribute:AttributeModel = new AttributeModel(response);
342 deferred.resolve(attribute);
344 deferred.reject(err);
346 return deferred.promise;
349 public updateAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
350 let deferred = this.$q.defer();
351 this.restangular.one(componentId).one("attributes").one(attribute.uniqueId).customPUT(attribute.convertToServerObject()).then((response:any) => {
352 let attribute:AttributeModel = new AttributeModel(response);
353 deferred.resolve(attribute);
355 deferred.reject(err);
357 return deferred.promise;
360 public deleteAttribute = (componentId:string, attributeId:string):ng.IPromise<AttributeModel> => {
361 let deferred = this.$q.defer();
362 this.restangular.one(componentId).one("attributes").one(attributeId).remove().then((response:any) => {
363 deferred.resolve(response);
365 deferred.reject(err);
367 return deferred.promise;
370 // ------------------------------------------------ Component Instances API --------------------------------------------------//
372 public createComponentInstance = (componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance> => {
373 let deferred = this.$q.defer();
374 this.restangular.one(componentId).one("resourceInstance").customPOST(JSON.stringify(componentInstance)).then((response:any) => {
375 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
376 console.log("Component Instance created", componentInstance);
377 deferred.resolve(componentInstance);
379 console.log("Failed to create componentInstance. With Name: " + componentInstance.name);
380 deferred.reject(err);
382 return deferred.promise;
385 public updateComponentInstance = (componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance> => {
386 let deferred = this.$q.defer();
387 this.restangular.one(componentId).one("resourceInstance").one(componentInstance.uniqueId).customPOST(JSON.stringify(componentInstance)).then((response:any) => {
388 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
389 console.log("Component Instance was updated", componentInstance);
390 deferred.resolve(componentInstance);
392 console.log("Failed to update componentInstance. With ID: " + componentInstance.uniqueId + "Name: " + componentInstance.name);
393 deferred.reject(err);
395 return deferred.promise;
398 public updateMultipleComponentInstances = (componentId:string, instances:Array<ComponentInstance>):ng.IPromise<Array<ComponentInstance>> => {
399 let deferred = this.$q.defer();
400 this.restangular.one(componentId).one("resourceInstance/multipleComponentInstance").customPOST(JSON.stringify(instances)).then((response:any) => {
401 console.log("Multiple Component Instances was updated", response);
402 let updateInstances:Array<ComponentInstance> = new Array<ComponentInstance>();
403 _.forEach(response, (componentInstance:ComponentInstance) => {
404 let updatedComponentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(componentInstance);
405 updateInstances.push(updatedComponentInstance);
407 deferred.resolve(updateInstances);
409 console.log("Failed to update Multiple componentInstance.");
410 deferred.reject(err);
412 return deferred.promise;
415 public deleteComponentInstance = (componentId:string, componentInstanceId:string):ng.IPromise<ComponentInstance> => {
416 let deferred = this.$q.defer();
417 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).remove().then(() => {
418 console.log("Component Instance was deleted");
421 console.log("Failed to delete componentInstance. With ID: " + componentInstanceId);
422 deferred.reject(err);
424 return deferred.promise;
427 public checkResourceInstanceVersionChange = (componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<ComponentInstance> => {
428 let deferred = this.$q.defer();
429 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one(componentUid).one("checkForwardingPathOnVersionChange").get().then((response:any) => {
430 deferred.resolve(response);
432 deferred.reject(err);
434 return deferred.promise;
437 public changeResourceInstanceVersion = (componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<ComponentInstance> => {
438 let deferred = this.$q.defer();
439 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one("changeVersion").customPOST({'componentUid': componentUid}).then((response:any) => {
440 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
441 deferred.resolve(componentInstance);
443 deferred.reject(err);
445 return deferred.promise;
448 public downloadInstanceArtifact = (componentId:string, instanceId:string, artifactId:string):ng.IPromise<IFileDownload> => {
449 let deferred = this.$q.defer();
450 this.restangular.one(componentId).one("resourceInstances").one(instanceId).one("artifacts").one(artifactId).get().then((response:any) => {
451 deferred.resolve(response.plain());
453 deferred.reject(err);
455 return deferred.promise;
458 public updateInstanceArtifact = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
459 let deferred = this.$q.defer();
461 if (artifact.payloadData) {
462 headerObj = this.getHeaderMd5(artifact);
464 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
465 let newArtifact = new ArtifactModel(response);
466 deferred.resolve(newArtifact);
468 deferred.reject(err);
470 return deferred.promise;
473 public addInstanceArtifact = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
474 let deferred = this.$q.defer();
476 if (artifact.payloadData) {
477 headerObj = this.getHeaderMd5(artifact);
479 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
480 let artifact:ArtifactModel = new ArtifactModel(response.plain());
481 deferred.resolve(artifact);
483 deferred.reject(err);
485 return deferred.promise;
488 public deleteInstanceArtifact = (componentId:string, instanceId:string, artifactId:string, artifactLabel:string):ng.IPromise<ArtifactModel> => {
489 let deferred = this.$q.defer();
490 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").one(artifactId).remove({'operation': artifactLabel}).then((response:ArtifactModel) => {
491 deferred.resolve(response);
493 deferred.reject(err);
495 return deferred.promise;
498 public uploadInstanceEnvFile = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
499 let deferred = this.$q.defer();
501 if (artifact.payloadData) {
502 headerObj = this.getHeaderMd5(artifact);
504 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
505 let newArtifact = new ArtifactModel(response);
506 deferred.resolve(newArtifact);
508 deferred.reject(err);
510 return deferred.promise;
513 public updateInstanceProperties = (componentId:string, componentInstanceId:string, properties:PropertyModel[]):ng.IPromise<PropertyModel[]> => {
514 let deferred = this.$q.defer<PropertyModel[]>();
515 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one("properties").customPOST(JSON.stringify(properties)).then((response:any) => {
516 const newProperties = response.map((res) => {
517 const newProperty = new PropertyModel(res);
518 newProperty.readonly = true;
519 newProperty.resourceInstanceUniqueId = componentInstanceId;
522 deferred.resolve(newProperties);
524 deferred.reject(err);
526 return deferred.promise;
529 public updateInstanceAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
530 let deferred = this.$q.defer();
531 let instanceId = attribute.resourceInstanceUniqueId;
532 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("attribute").customPOST(JSON.stringify(attribute)).then((response:any) => {
533 let newAttribute = new AttributeModel(response);
534 newAttribute.readonly = true;
535 newAttribute.resourceInstanceUniqueId = instanceId;
536 deferred.resolve(newAttribute);
538 deferred.reject(err);
540 return deferred.promise;
543 public createRelation = (componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel> => {
544 let deferred = this.$q.defer();
545 const linkPayload:RelationshipModel = new RelationshipModel(link);
546 linkPayload.relationships.forEach((rel) => {
547 delete rel.capability;
548 delete rel.requirement;
550 this.restangular.one(componentId).one("resourceInstance").one("associate").customPOST(JSON.stringify(linkPayload)).then((response:any) => {
551 let relation:RelationshipModel = new RelationshipModel(response.plain());
552 console.log("Link created successfully ", relation);
553 deferred.resolve(relation);
555 console.log("Failed to create Link From: " + link.fromNode + "To: " + link.toNode);
556 deferred.reject(err);
558 return deferred.promise;
561 public deleteRelation = (componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel> => {
562 let deferred = this.$q.defer();
563 const linkPayload:RelationshipModel = new RelationshipModel(link);
564 linkPayload.relationships.forEach((rel) => {
565 delete rel.capability;
566 delete rel.requirement;
568 this.restangular.one(componentId).one("resourceInstance").one("dissociate").customPUT(JSON.stringify(linkPayload)).then((response:any) => {
569 let relation:RelationshipModel = new RelationshipModel(response);
570 console.log("Link deleted successfully ", relation);
571 deferred.resolve(relation);
573 console.log("Failed to delete Link From: " + link.fromNode + "To: " + link.toNode);
574 deferred.reject(err);
576 return deferred.promise;
579 public fetchRelation = (componentId:string, linkId:string):ng.IPromise<RelationshipModel> => {
580 let deferred = this.$q.defer<RelationshipModel>();
581 this.restangular.one(componentId).one("relationId").one(linkId).get().then((response:any) => {
582 let relation:RelationshipModel = new RelationshipModel(response);
583 console.log("Link fetched successfully ", relation);
584 deferred.resolve(relation);
586 console.log("Failed to fetch Link Id: " + linkId);
587 deferred.reject(err);
589 return deferred.promise;
592 public getRequirementsCapabilities = (componentId:string):ng.IPromise<any> => {
593 let deferred = this.$q.defer();
594 this.restangular.one(componentId).one("requirmentsCapabilities").get().then((response:any) => {
595 console.log("Component requirement capabilities recived: ", response);
596 deferred.resolve(response);
598 console.log("Failed to get requirements & capabilities");
599 deferred.reject(err);
601 return deferred.promise;
604 public getModuleForDisplay = (componentId:string, moduleId:string):ng.IPromise<DisplayModule> => {
605 let deferred = this.$q.defer();
606 this.restangular.one(componentId).one("groups").one(moduleId).get().then((response:any) => {
607 console.log("module loaded successfully: ", response);
608 let module:DisplayModule = new DisplayModule(response);
609 deferred.resolve(module);
611 console.log("Failed to get module with id: ", moduleId);
612 deferred.reject(err);
614 return deferred.promise;
617 public getComponentInstanceModule = (componentId:string, componentInstanceId:string, moduleId:string):ng.IPromise<Module> => {
618 let deferred = this.$q.defer();
619 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one("groupInstance").one(moduleId).get().then((response:any) => {
620 console.log("module loaded successfully: ", response);
621 let module:DisplayModule = new DisplayModule(response);
622 deferred.resolve(module);
624 console.log("Failed to get module with id: ", moduleId);
625 deferred.reject(err);
627 return deferred.promise;
630 public getComponentInstancesFilteredByInputsAndProperties = (componentId:string, searchText?:string):ng.IPromise<Array<ComponentInstance>> => {
631 let deferred = this.$q.defer();
632 this.restangular.one(componentId).one("componentInstances").get({'searchText': searchText}).then((response:any) => {
633 console.log("component instances return successfully: ", response);
634 let componentInstances:Array<ComponentInstance> = CommonUtils.initComponentInstances(response);
635 deferred.resolve(componentInstances);
637 console.log("Failed to get component instances of component with id: " + componentId);
638 deferred.reject(err);
641 return deferred.promise;
644 public getComponentInstanceInputs = (componentId:string, instanceId:string, originComponentUid):ng.IPromise<Array<InputModel>> => {
646 let deferred = this.$q.defer();
647 this.restangular.one(componentId).one("componentInstances").one(instanceId).one(originComponentUid).one("inputs").get().then((response:any) => {
648 console.log("component instance input return successfully: ", response);
649 let inputsArray:Array<InputModel> = new Array<InputModel>();
650 _.forEach(response, (inputObj:InputModel) => {
651 inputsArray.push(new InputModel(inputObj));
653 deferred.resolve(inputsArray);
655 console.log("Failed to get component instance input with id: " + instanceId);
656 deferred.reject(err);
659 return deferred.promise;
662 public getComponentInputs = (componentId:string):ng.IPromise<Array<InputModel>> => {
664 let deferred = this.$q.defer();
665 this.restangular.one(componentId).one("inputs").get().then((response:any) => {
666 console.log("component inputs return successfully: ", response);
667 let inputsArray:Array<InputModel> = new Array<InputModel>();
668 _.forEach(response, (inputObj:InputModel) => {
669 inputsArray.push(new InputModel(inputObj));
671 deferred.resolve(inputsArray);
673 console.log("Failed to get component inputs for component with id: " + componentId);
674 deferred.reject(err);
677 return deferred.promise;
680 public getComponentInstanceInputProperties = (componentId:string, instanceId:string, inputId:string):ng.IPromise<Array<PropertyModel>> => {
682 let deferred = this.$q.defer();
683 this.restangular.one(componentId).one("componentInstances").one(instanceId).one(inputId).one("properties").get().then((response:any) => {
684 console.log("component instance input properties return successfully: ", response);
685 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
686 _.forEach(response, (propertyObj:PropertyModel) => {
687 propertiesArray.push(new PropertyModel(propertyObj));
689 deferred.resolve(propertiesArray);
691 console.log("Failed to get component instance input properties with instanceId: " + instanceId + "and input id: " + inputId);
692 deferred.reject(err);
695 return deferred.promise;
699 public getComponentInstanceProperties = (componentId:string, instanceId:string):ng.IPromise<Array<PropertyModel>> => {
701 let deferred = this.$q.defer();
702 this.restangular.one(componentId).one("componentInstances").one(instanceId).one("properties").get().then((response:any) => {
703 console.log("component instance properties return successfully: ", response);
704 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
705 _.forEach(response, (propertyObj:PropertyModel) => {
706 propertiesArray.push(new PropertyModel(propertyObj));
708 deferred.resolve(propertiesArray);
710 console.log("Failed to get component instance properties with instanceId: " + instanceId);
711 deferred.reject(err);
714 return deferred.promise;
717 public updateGroupMetadata = (componentId:string, group:Module):ng.IPromise<Module> => {
719 let deferred = this.$q.defer();
720 this.restangular.one(componentId).one("groups").one(group.uniqueId).one("metadata").customPUT(JSON.stringify(group)).then((response:Module) => {
721 console.log("group metadata updated successfully: ", response);
722 let updatedGroup:Module = new Module(response);
724 deferred.resolve(updatedGroup);
726 console.log("Failed to update group metadata for component: " + componentId + " for group with id: " + group.uniqueId);
727 deferred.reject(err);
730 return deferred.promise;
733 public getComponentInputInputsAndProperties = (serviceId:string, inputId:string):ng.IPromise<InputsAndProperties> => {
734 let defer = this.$q.defer<any>();
735 this.restangular.one(serviceId).one("inputs").one(inputId).get().then((response:InputsAndProperties) => {
737 let inputsArray:Array<InputModel> = new Array<InputModel>();
738 _.forEach(response.inputs, (inputObj:InputModel) => {
739 inputsArray.push(new InputModel(inputObj));
742 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
743 _.forEach(response.properties, (property:PropertyModel) => {
744 propertiesArray.push(new PropertyModel(property));
747 defer.resolve(new InputsAndProperties(inputsArray, propertiesArray));
749 console.log("failed to get inputs of input : ", err);
752 return defer.promise;
755 createInputsFromInstancesInputsProperties = (resourceId:string, instancePropertyMap:InstancesInputsPropertiesMap):ng.IPromise<Array<PropertyModel>> => {
756 let defer = this.$q.defer<any>();
757 this.restangular.one(resourceId).one("create/properties").customPOST(instancePropertyMap).then((response:any) => {
758 let inputsArray:Array<PropertyModel> = new Array<PropertyModel>();
759 _.forEach(response, (inputObj:PropertyModel) => {
760 inputsArray.push(new PropertyModel(inputObj));
762 defer.resolve(inputsArray);
764 console.log("failed to create service inputs from VF instances inputs : ", err);
767 return defer.promise;
770 createInputsFromInstancesInputs = (serviceId:string, instancesMap:InstancesInputsPropertiesMap):ng.IPromise<Array<InputModel>> => {
771 let defer = this.$q.defer<any>();
772 this.restangular.one(serviceId).one("create/inputs").customPOST(instancesMap).then((response:any) => {
773 let inputsArray:Array<InputModel> = new Array<InputModel>();
774 _.forEach(response, (inputObj:InputModel) => {
775 inputsArray.push(new InputModel(inputObj));
777 defer.resolve(inputsArray);
779 console.log("failed to create service inputs from VF instances inputs : ", err);
782 return defer.promise;
785 deleteComponentInput = (serviceId:string, inputId:string):ng.IPromise<InputModel> => {
786 let defer = this.$q.defer();
787 this.restangular.one(serviceId).one("delete").one(inputId).one("input").remove().then((response:any) => {
788 let inputToDelete = new InputModel(response);
789 defer.resolve(inputToDelete);
791 console.log("failed to delete input from service: ", err);
794 return defer.promise;
797 private getHeaderMd5 = (object:any):any => {
799 // This is ugly workaround!!!
800 // The md5 result is not correct if we do not add the line JSON.stringify(resource); twice.
801 JSON.stringify(object);
802 let componentString:string = JSON.stringify(object);
803 let md5Result = md5(componentString).toLowerCase();
804 headerObj = {'Content-MD5': this.$base64.encode(md5Result)};