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 {ArtifactModel, IFileDownload, InstancesInputsPropertiesMap, InputModel, IValidate, RelationshipModel, PropertyModel, Component, ComponentInstance,
22 AttributeModel, IAppConfigurtaion, Resource, Module, DisplayModule, ArtifactGroupModel, InputsAndProperties} from "app/models";
23 import {ComponentInstanceFactory, CommonUtils} from "app/utils";
24 import {SharingService} from "../sharing-service";
25 import {ComponentMetadata} from "../../models/component-metadata";
26 import {EventBusService} from "../../ng2/services/event-bus.service";
28 export interface IComponentService {
30 getComponent(id:string);
31 updateComponent(component:Component):ng.IPromise<Component>;
32 changeLifecycleState(component:Component, state:string, userRemarks:any):ng.IPromise<ComponentMetadata> ;
33 validateName(newName:string, subtype?:string):ng.IPromise<IValidate>;
34 createComponent(component:Component):ng.IPromise<Component>;
35 addOrUpdateArtifact(componentId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
36 deleteArtifact(componentId:string, artifact:string, artifactLabel):ng.IPromise<ArtifactModel>;
37 addProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>;
38 updateProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>;
39 addAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
40 updateAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
41 deleteProperty(componentId:string, propertyId:string):ng.IPromise<PropertyModel>;
42 deleteAttribute(componentId:string, attributeId:string):ng.IPromise<AttributeModel>;
43 changeResourceInstanceVersion(componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<ComponentInstance>;
44 updateInstanceArtifact(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
45 addInstanceArtifact(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
46 deleteInstanceArtifact(componentId:string, instanceId:string, artifact:string, artifactLabel):ng.IPromise<ArtifactModel>;
47 createComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>;
48 updateComponentInstance(componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance>;
49 updateMultipleComponentInstances(componentId:string, instances:Array<ComponentInstance>):ng.IPromise< Array<ComponentInstance>>;
50 downloadArtifact(componentId:string, artifactId:string):ng.IPromise<IFileDownload>;
51 uploadInstanceEnvFile(componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel>;
52 downloadInstanceArtifact(componentId:string, instanceId:string, artifactId:string):ng.IPromise<IFileDownload>;
53 deleteComponentInstance(componentId:string, componentInstanceId:string):ng.IPromise<ComponentInstance>;
54 createRelation(componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel>;
55 deleteRelation(componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel>;
56 fetchRelation(componentId:string, linkId:string):ng.IPromise<RelationshipModel>;
57 getRequirementsCapabilities(componentId:string):ng.IPromise<any>;
58 updateInstanceProperty(componentId:string, property:PropertyModel):ng.IPromise<PropertyModel>;
59 updateInstanceAttribute(componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel>;
60 getComponentInstancesFilteredByInputsAndProperties(componentId:string, searchText:string):ng.IPromise<Array<ComponentInstance>>
61 getComponentInstanceInputs(componentId:string, instanceId:string, originComponentUid):ng.IPromise<Array<InputModel>>;
62 getComponentInputs(componentId:string):ng.IPromise<Array<InputModel>>;
63 getComponentInstanceInputProperties(componentId:string, instanceId:string, inputId:string):ng.IPromise<Array<PropertyModel>>;
64 getComponentInstanceProperties(componentId:string, instanceId:string):ng.IPromise<Array<PropertyModel>>;
65 getModuleForDisplay(componentId:string, moduleId:string):ng.IPromise<DisplayModule>;
66 getComponentInstanceModule(componentId:string, componentInstanceId:string, moduleId:string):ng.IPromise<DisplayModule>;
67 updateGroupMetadata(componentId:string, group:Module):ng.IPromise<Module>;
68 getComponentInputInputsAndProperties(serviceId:string, input:string):ng.IPromise<InputsAndProperties>;
69 createInputsFromInstancesInputs(serviceId:string, instancesInputsMap:InstancesInputsPropertiesMap):ng.IPromise<Array<InputModel>>;
70 createInputsFromInstancesInputsProperties(resourceId:string, instanceInputsPropertiesMap:InstancesInputsPropertiesMap):ng.IPromise<Array<PropertyModel>>;
71 deleteComponentInput(serviceId:string, inputId:string):ng.IPromise<InputModel>;
72 getArtifactByGroupType(componentId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel>;
73 getComponentInstanceArtifactsByGroupType(componentId:string, componentInstanceId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel>;
76 export class ComponentService implements IComponentService {
81 'Sdc.Services.SharingService',
87 constructor(protected restangular:restangular.IElement,
88 protected sdcConfig:IAppConfigurtaion,
89 protected sharingService:SharingService,
90 protected $q:ng.IQService,
91 protected $base64:any,
92 protected eventBusService:EventBusService
95 this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
96 this.restangular.setRequestInterceptor(function (elem, operation) {
97 if (operation === "remove") {
102 // this.restangular.setDefaultHeaders({'Content-Type': 'application/json; charset=UTF-8'});
105 //this function is override by each service, we need to change this method to abstract when updtaing typescript version
106 protected createComponentObject = (component:Component):Component => {
110 public getComponent = (id:string):ng.IPromise<Component> => {
111 let deferred = this.$q.defer();
112 this.restangular.one(id).get().then((response:Component) => {
113 let component:Component = this.createComponentObject(response);
114 //console.log("Component Loaded successfully : ", component);
115 deferred.resolve(component);
117 console.log("Failed to load component with ID: " + id);
118 deferred.reject(err);
120 return deferred.promise;
123 public updateComponent = (component:Component):ng.IPromise<Component> => {
124 // If this is resource
125 if (component instanceof Resource) {
126 let resource:Resource = <Resource>component;
127 if (resource.importedFile) {
128 // Update resource with payload data.
129 return this.updateResourceWithPayload(resource);
131 if (component.csarUUID) {
132 // Update resource without payload data.
133 return this.updateResource(component);
135 // Update resource without payload data (metadata).
136 return this.updateResourceMetadata(component);
140 return this.updateService(component);
144 private updateService = (component:Component):ng.IPromise<Component> => {
145 let deferred = this.$q.defer();
146 this.restangular.one(component.uniqueId).one("metadata").customPUT(JSON.stringify(component)).then((response:Component) => {
147 let component:Component = this.createComponentObject(response);
148 deferred.resolve(component);
150 deferred.reject(err);
152 return deferred.promise;
155 private updateResource = (component:Component):ng.IPromise<Component> => {
156 let deferred = this.$q.defer();
157 this.restangular.one(component.uniqueId).customPUT(JSON.stringify(component)).then((response:Component) => {
158 let component:Component = this.createComponentObject(response);
159 deferred.resolve(component);
161 deferred.reject(err);
163 return deferred.promise;
166 private updateResourceMetadata = (component:Component):ng.IPromise<Component> => {
167 let deferred = this.$q.defer();
168 this.restangular.one(component.uniqueId).one('metadata').customPUT(JSON.stringify(component)).then((response:Component) => {
169 let component:Component = this.createComponentObject(response);
170 deferred.resolve(component);
172 deferred.reject(err);
174 return deferred.promise;
178 * Only resource can be updated with payload data
180 * @returns {IPromise<T>}
182 private updateResourceWithPayload = (resource:Resource):ng.IPromise<Component> => {
183 let deferred = this.$q.defer();
185 resource.payloadData = resource.importedFile.base64;
186 resource.payloadName = resource.importedFile.filename;
187 let headerObj = this.getHeaderMd5(resource);
189 this.restangular.one(resource.uniqueId).customPUT(JSON.stringify(resource), '', {}, headerObj).then((response:Component) => {
190 let componentResult:Component = this.createComponentObject(response);
191 deferred.resolve(componentResult);
193 deferred.reject(err);
196 return deferred.promise;
199 public createComponent = (component:Component):ng.IPromise<Component> => {
200 let deferred = this.$q.defer();
201 let headerObj = this.getHeaderMd5(component);
202 this.restangular.customPOST(JSON.stringify(component), '', {}, headerObj).then((response:Component) => {
203 let component:Component = this.createComponentObject(response);
204 deferred.resolve(component);
206 deferred.reject(err);
208 return deferred.promise;
211 public validateName = (newName:string, subtype?:string):ng.IPromise<IValidate> => {
212 let deferred = this.$q.defer();
213 this.restangular.one("validate-name").one(newName).get({'subtype': subtype}).then((response:any) => {
214 deferred.resolve(response.plain());
216 deferred.reject(err);
218 return deferred.promise;
221 public changeLifecycleState = (component:Component, state:string, userRemarks:any):ng.IPromise<ComponentMetadata> => {
222 let deferred = this.$q.defer();
223 this.restangular.one(component.uniqueId).one(state).customPOST(userRemarks).then((response:ComponentMetadata) => {
224 this.sharingService.addUuidValue(response.uniqueId, response.uuid);
225 let component:ComponentMetadata = new ComponentMetadata().deserialize(response);
226 deferred.resolve(component);
228 deferred.reject(err);
231 // Notifying about events before executing the actual actions
234 this.eventBusService.notify("CHECK_IN");
236 case "submitForTesting":
237 this.eventBusService.notify("SUBMIT_FOR_TESTING");
241 return deferred.promise;
244 // ------------------------------------------------ Artifacts API --------------------------------------------------//
245 public addOrUpdateArtifact = (componentId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
246 let deferred = this.$q.defer();
248 if (artifact.payloadData) {
249 headerObj = this.getHeaderMd5(artifact);
251 this.restangular.one(componentId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
252 deferred.resolve(response.plain());
254 deferred.reject(err);
256 return deferred.promise;
259 public downloadArtifact = (componentId:string, artifactId:string):ng.IPromise<IFileDownload> => {
260 let deferred = this.$q.defer();
261 this.restangular.one(componentId).one("artifacts").one(artifactId).get().then((response:any) => {
262 deferred.resolve(response.plain());
264 deferred.reject(err);
266 return deferred.promise;
269 public deleteArtifact = (componentId:string, artifactId:string, artifactLabel:string):ng.IPromise<ArtifactModel> => {
270 let deferred = this.$q.defer();
271 this.restangular.one(componentId).one("artifacts").one(artifactId).remove({'operation': artifactLabel}).then((response:ArtifactModel) => {
272 deferred.resolve(response);
274 deferred.reject(err);
276 return deferred.promise;
279 public getArtifactByGroupType = (componentId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel> => {
280 let deferred = this.$q.defer();
281 this.restangular.one(componentId).one("artifactsByType").one(artifactGroupType).get().then((response:any) => {
282 var artifacts:ArtifactGroupModel = new ArtifactGroupModel(response.plain());
283 deferred.resolve(artifacts);
285 deferred.reject(err);
287 return deferred.promise;
290 public getComponentInstanceArtifactsByGroupType = (componentId:string, componentInstanceId:string, artifactGroupType:string):ng.IPromise<ArtifactGroupModel> => {
291 let deferred = this.$q.defer();
292 this.restangular.one(componentId).one("resourceInstances").one(componentInstanceId).one("artifactsByType").one(artifactGroupType).get().then((response:any) => {
293 var artifacts:ArtifactGroupModel = new ArtifactGroupModel(response.plain());
294 deferred.resolve(artifacts);
296 deferred.reject(err);
298 return deferred.promise;
302 // ------------------------------------------------ Properties API --------------------------------------------------//
303 public addProperty = (componentId:string, property:PropertyModel):ng.IPromise<PropertyModel> => {
304 let deferred = this.$q.defer();
305 this.restangular.one(componentId).one("properties").customPOST(property.convertToServerObject()).then((response:any) => {
306 let property:PropertyModel = new PropertyModel(response[Object.keys(response)[0]]);
307 deferred.resolve(property);
309 deferred.reject(err);
311 return deferred.promise;
314 public updateProperty = (componentId:string, property:PropertyModel):ng.IPromise<PropertyModel> => {
315 let deferred = this.$q.defer();
316 this.restangular.one(componentId).one("properties").one(property.uniqueId).customPUT(property.convertToServerObject()).then((response:any) => {
317 let property:PropertyModel = new PropertyModel(response[Object.keys(response)[0]]);
318 deferred.resolve(property);
320 deferred.reject(err);
322 return deferred.promise;
325 public deleteProperty = (componentId:string, propertyId:string):ng.IPromise<PropertyModel> => {
326 let deferred = this.$q.defer();
327 this.restangular.one(componentId).one("properties").one(propertyId).remove().then((response:any) => {
328 deferred.resolve(response);
330 deferred.reject(err);
332 return deferred.promise;
335 // ------------------------------------------------ Attributes API --------------------------------------------------//
336 public addAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
337 let deferred = this.$q.defer();
338 this.restangular.one(componentId).one("attributes").customPOST(attribute.convertToServerObject()).then((response:any) => {
339 let attribute:AttributeModel = new AttributeModel(response);
340 deferred.resolve(attribute);
342 deferred.reject(err);
344 return deferred.promise;
347 public updateAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
348 let deferred = this.$q.defer();
349 this.restangular.one(componentId).one("attributes").one(attribute.uniqueId).customPUT(attribute.convertToServerObject()).then((response:any) => {
350 let attribute:AttributeModel = new AttributeModel(response);
351 deferred.resolve(attribute);
353 deferred.reject(err);
355 return deferred.promise;
358 public deleteAttribute = (componentId:string, attributeId:string):ng.IPromise<AttributeModel> => {
359 let deferred = this.$q.defer();
360 this.restangular.one(componentId).one("attributes").one(attributeId).remove().then((response:any) => {
361 deferred.resolve(response);
363 deferred.reject(err);
365 return deferred.promise;
368 // ------------------------------------------------ Component Instances API --------------------------------------------------//
370 public createComponentInstance = (componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance> => {
371 let deferred = this.$q.defer();
372 this.restangular.one(componentId).one("resourceInstance").customPOST(JSON.stringify(componentInstance)).then((response:any) => {
373 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
374 console.log("Component Instance created", componentInstance);
375 deferred.resolve(componentInstance);
377 console.log("Failed to create componentInstance. With Name: " + componentInstance.name);
378 deferred.reject(err);
380 return deferred.promise;
383 public updateComponentInstance = (componentId:string, componentInstance:ComponentInstance):ng.IPromise<ComponentInstance> => {
384 let deferred = this.$q.defer();
385 this.restangular.one(componentId).one("resourceInstance").one(componentInstance.uniqueId).customPOST(JSON.stringify(componentInstance)).then((response:any) => {
386 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
387 console.log("Component Instance was updated", componentInstance);
388 deferred.resolve(componentInstance);
390 console.log("Failed to update componentInstance. With ID: " + componentInstance.uniqueId + "Name: " + componentInstance.name);
391 deferred.reject(err);
393 return deferred.promise;
396 public updateMultipleComponentInstances = (componentId:string, instances:Array<ComponentInstance>):ng.IPromise<Array<ComponentInstance>> => {
397 let deferred = this.$q.defer();
398 this.restangular.one(componentId).one("resourceInstance/multipleComponentInstance").customPOST(JSON.stringify(instances)).then((response:any) => {
399 console.log("Multiple Component Instances was updated", response);
400 let updateInstances:Array<ComponentInstance> = new Array<ComponentInstance>();
401 _.forEach(response, (componentInstance:ComponentInstance) => {
402 let updatedComponentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(componentInstance);
403 updateInstances.push(updatedComponentInstance);
405 deferred.resolve(updateInstances);
407 console.log("Failed to update Multiple componentInstance.");
408 deferred.reject(err);
410 return deferred.promise;
413 public deleteComponentInstance = (componentId:string, componentInstanceId:string):ng.IPromise<ComponentInstance> => {
414 let deferred = this.$q.defer();
415 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).remove().then(() => {
416 console.log("Component Instance was deleted");
419 console.log("Failed to delete componentInstance. With ID: " + componentInstanceId);
420 deferred.reject(err);
422 return deferred.promise;
425 public changeResourceInstanceVersion = (componentId:string, componentInstanceId:string, componentUid:string):ng.IPromise<ComponentInstance> => {
426 let deferred = this.$q.defer();
427 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one("changeVersion").customPOST({'componentUid': componentUid}).then((response:any) => {
428 let componentInstance:ComponentInstance = ComponentInstanceFactory.createComponentInstance(response);
429 deferred.resolve(componentInstance);
431 deferred.reject(err);
433 return deferred.promise;
436 public downloadInstanceArtifact = (componentId:string, instanceId:string, artifactId:string):ng.IPromise<IFileDownload> => {
437 let deferred = this.$q.defer();
438 this.restangular.one(componentId).one("resourceInstances").one(instanceId).one("artifacts").one(artifactId).get().then((response:any) => {
439 deferred.resolve(response.plain());
441 deferred.reject(err);
443 return deferred.promise;
446 public updateInstanceArtifact = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
447 let deferred = this.$q.defer();
449 if (artifact.payloadData) {
450 headerObj = this.getHeaderMd5(artifact);
452 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
453 let newArtifact = new ArtifactModel(response);
454 deferred.resolve(newArtifact);
456 deferred.reject(err);
458 return deferred.promise;
461 public addInstanceArtifact = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
462 let deferred = this.$q.defer();
464 if (artifact.payloadData) {
465 headerObj = this.getHeaderMd5(artifact);
467 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
468 let artifact:ArtifactModel = new ArtifactModel(response.plain());
469 deferred.resolve(artifact);
471 deferred.reject(err);
473 return deferred.promise;
476 public deleteInstanceArtifact = (componentId:string, instanceId:string, artifactId:string, artifactLabel:string):ng.IPromise<ArtifactModel> => {
477 let deferred = this.$q.defer();
478 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").one(artifactId).remove({'operation': artifactLabel}).then((response:ArtifactModel) => {
479 deferred.resolve(response);
481 deferred.reject(err);
483 return deferred.promise;
486 public uploadInstanceEnvFile = (componentId:string, instanceId:string, artifact:ArtifactModel):ng.IPromise<ArtifactModel> => {
487 let deferred = this.$q.defer();
489 if (artifact.payloadData) {
490 headerObj = this.getHeaderMd5(artifact);
492 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("artifacts").customPOST(JSON.stringify(artifact), artifact.uniqueId, {}, headerObj).then((response:any) => {
493 let newArtifact = new ArtifactModel(response);
494 deferred.resolve(newArtifact);
496 deferred.reject(err);
498 return deferred.promise;
501 public updateInstanceProperty = (componentId:string, property:PropertyModel):ng.IPromise<PropertyModel> => {
502 let deferred = this.$q.defer();
503 let instanceId = property.resourceInstanceUniqueId;
504 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("property").customPOST(JSON.stringify(property)).then((response:any) => {
505 let newProperty = new PropertyModel(response);
506 newProperty.readonly = true;
507 newProperty.resourceInstanceUniqueId = instanceId;
508 deferred.resolve(newProperty);
510 deferred.reject(err);
512 return deferred.promise;
515 public updateInstanceAttribute = (componentId:string, attribute:AttributeModel):ng.IPromise<AttributeModel> => {
516 let deferred = this.$q.defer();
517 let instanceId = attribute.resourceInstanceUniqueId;
518 this.restangular.one(componentId).one("resourceInstance").one(instanceId).one("attribute").customPOST(JSON.stringify(attribute)).then((response:any) => {
519 let newAttribute = new AttributeModel(response);
520 newAttribute.readonly = true;
521 newAttribute.resourceInstanceUniqueId = instanceId;
522 deferred.resolve(newAttribute);
524 deferred.reject(err);
526 return deferred.promise;
529 public createRelation = (componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel> => {
530 let deferred = this.$q.defer();
531 const linkPayload:RelationshipModel = new RelationshipModel(link);
532 linkPayload.relationships.forEach((rel) => {
533 delete rel.capability;
534 delete rel.requirement;
536 this.restangular.one(componentId).one("resourceInstance").one("associate").customPOST(JSON.stringify(linkPayload)).then((response:any) => {
537 let relation:RelationshipModel = new RelationshipModel(response.plain());
538 console.log("Link created successfully ", relation);
539 deferred.resolve(relation);
541 console.log("Failed to create Link From: " + link.fromNode + "To: " + link.toNode);
542 deferred.reject(err);
544 return deferred.promise;
547 public deleteRelation = (componentId:string, link:RelationshipModel):ng.IPromise<RelationshipModel> => {
548 let deferred = this.$q.defer();
549 const linkPayload:RelationshipModel = new RelationshipModel(link);
550 linkPayload.relationships.forEach((rel) => {
551 delete rel.capability;
552 delete rel.requirement;
554 this.restangular.one(componentId).one("resourceInstance").one("dissociate").customPUT(JSON.stringify(linkPayload)).then((response:any) => {
555 let relation:RelationshipModel = new RelationshipModel(response);
556 console.log("Link deleted successfully ", relation);
557 deferred.resolve(relation);
559 console.log("Failed to delete Link From: " + link.fromNode + "To: " + link.toNode);
560 deferred.reject(err);
562 return deferred.promise;
565 public fetchRelation = (componentId:string, linkId:string):ng.IPromise<RelationshipModel> => {
566 let deferred = this.$q.defer<RelationshipModel>();
567 this.restangular.one(componentId).one("relationId").one(linkId).get().then((response:any) => {
568 let relation:RelationshipModel = new RelationshipModel(response);
569 console.log("Link fetched successfully ", relation);
570 deferred.resolve(relation);
572 console.log("Failed to fetch Link Id: " + linkId);
573 deferred.reject(err);
575 return deferred.promise;
578 public getRequirementsCapabilities = (componentId:string):ng.IPromise<any> => {
579 let deferred = this.$q.defer();
580 this.restangular.one(componentId).one("requirmentsCapabilities").get().then((response:any) => {
581 console.log("Component requirement capabilities recived: ", response);
582 deferred.resolve(response);
584 console.log("Failed to get requirements & capabilities");
585 deferred.reject(err);
587 return deferred.promise;
590 public getModuleForDisplay = (componentId:string, moduleId:string):ng.IPromise<DisplayModule> => {
591 let deferred = this.$q.defer();
592 this.restangular.one(componentId).one("groups").one(moduleId).get().then((response:any) => {
593 console.log("module loaded successfully: ", response);
594 let module:DisplayModule = new DisplayModule(response);
595 deferred.resolve(module);
597 console.log("Failed to get module with id: ", moduleId);
598 deferred.reject(err);
600 return deferred.promise;
603 public getComponentInstanceModule = (componentId:string, componentInstanceId:string, moduleId:string):ng.IPromise<Module> => {
604 let deferred = this.$q.defer();
605 this.restangular.one(componentId).one("resourceInstance").one(componentInstanceId).one("groupInstance").one(moduleId).get().then((response:any) => {
606 console.log("module loaded successfully: ", response);
607 let module:DisplayModule = new DisplayModule(response);
608 deferred.resolve(module);
610 console.log("Failed to get module with id: ", moduleId);
611 deferred.reject(err);
613 return deferred.promise;
616 public getComponentInstancesFilteredByInputsAndProperties = (componentId:string, searchText?:string):ng.IPromise<Array<ComponentInstance>> => {
617 let deferred = this.$q.defer();
618 this.restangular.one(componentId).one("componentInstances").get({'searchText': searchText}).then((response:any) => {
619 console.log("component instances return successfully: ", response);
620 let componentInstances:Array<ComponentInstance> = CommonUtils.initComponentInstances(response);
621 deferred.resolve(componentInstances);
623 console.log("Failed to get component instances of component with id: " + componentId);
624 deferred.reject(err);
627 return deferred.promise;
630 public getComponentInstanceInputs = (componentId:string, instanceId:string, originComponentUid):ng.IPromise<Array<InputModel>> => {
632 let deferred = this.$q.defer();
633 this.restangular.one(componentId).one("componentInstances").one(instanceId).one(originComponentUid).one("inputs").get().then((response:any) => {
634 console.log("component instance input return successfully: ", response);
635 let inputsArray:Array<InputModel> = new Array<InputModel>();
636 _.forEach(response, (inputObj:InputModel) => {
637 inputsArray.push(new InputModel(inputObj));
639 deferred.resolve(inputsArray);
641 console.log("Failed to get component instance input with id: " + instanceId);
642 deferred.reject(err);
645 return deferred.promise;
648 public getComponentInputs = (componentId:string):ng.IPromise<Array<InputModel>> => {
650 let deferred = this.$q.defer();
651 this.restangular.one(componentId).one("inputs").get().then((response:any) => {
652 console.log("component inputs return successfully: ", response);
653 let inputsArray:Array<InputModel> = new Array<InputModel>();
654 _.forEach(response, (inputObj:InputModel) => {
655 inputsArray.push(new InputModel(inputObj));
657 deferred.resolve(inputsArray);
659 console.log("Failed to get component inputs for component with id: " + componentId);
660 deferred.reject(err);
663 return deferred.promise;
666 public getComponentInstanceInputProperties = (componentId:string, instanceId:string, inputId:string):ng.IPromise<Array<PropertyModel>> => {
668 let deferred = this.$q.defer();
669 this.restangular.one(componentId).one("componentInstances").one(instanceId).one(inputId).one("properties").get().then((response:any) => {
670 console.log("component instance input properties return successfully: ", response);
671 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
672 _.forEach(response, (propertyObj:PropertyModel) => {
673 propertiesArray.push(new PropertyModel(propertyObj));
675 deferred.resolve(propertiesArray);
677 console.log("Failed to get component instance input properties with instanceId: " + instanceId + "and input id: " + inputId);
678 deferred.reject(err);
681 return deferred.promise;
685 public getComponentInstanceProperties = (componentId:string, instanceId:string):ng.IPromise<Array<PropertyModel>> => {
687 let deferred = this.$q.defer();
688 this.restangular.one(componentId).one("componentInstances").one(instanceId).one("properties").get().then((response:any) => {
689 console.log("component instance properties return successfully: ", response);
690 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
691 _.forEach(response, (propertyObj:PropertyModel) => {
692 propertiesArray.push(new PropertyModel(propertyObj));
694 deferred.resolve(propertiesArray);
696 console.log("Failed to get component instance properties with instanceId: " + instanceId);
697 deferred.reject(err);
700 return deferred.promise;
703 public updateGroupMetadata = (componentId:string, group:Module):ng.IPromise<Module> => {
705 let deferred = this.$q.defer();
706 this.restangular.one(componentId).one("groups").one(group.uniqueId).one("metadata").customPUT(JSON.stringify(group)).then((response:Module) => {
707 console.log("group metadata updated successfully: ", response);
708 let updatedGroup:Module = new Module(response);
710 deferred.resolve(updatedGroup);
712 console.log("Failed to update group metadata for component: " + componentId + " for group with id: " + group.uniqueId);
713 deferred.reject(err);
716 return deferred.promise;
719 public getComponentInputInputsAndProperties = (serviceId:string, inputId:string):ng.IPromise<InputsAndProperties> => {
720 let defer = this.$q.defer<any>();
721 this.restangular.one(serviceId).one("inputs").one(inputId).get().then((response:InputsAndProperties) => {
723 let inputsArray:Array<InputModel> = new Array<InputModel>();
724 _.forEach(response.inputs, (inputObj:InputModel) => {
725 inputsArray.push(new InputModel(inputObj));
728 let propertiesArray:Array<PropertyModel> = new Array<PropertyModel>();
729 _.forEach(response.properties, (property:PropertyModel) => {
730 propertiesArray.push(new PropertyModel(property));
733 defer.resolve(new InputsAndProperties(inputsArray, propertiesArray));
735 console.log("failed to get inputs of input : ", err);
738 return defer.promise;
741 createInputsFromInstancesInputsProperties = (resourceId:string, instancePropertyMap:InstancesInputsPropertiesMap):ng.IPromise<Array<PropertyModel>> => {
742 let defer = this.$q.defer<any>();
743 this.restangular.one(resourceId).one("create/properties").customPOST(instancePropertyMap).then((response:any) => {
744 let inputsArray:Array<PropertyModel> = new Array<PropertyModel>();
745 _.forEach(response, (inputObj:PropertyModel) => {
746 inputsArray.push(new PropertyModel(inputObj));
748 defer.resolve(inputsArray);
750 console.log("failed to create service inputs from VF instances inputs : ", err);
753 return defer.promise;
756 createInputsFromInstancesInputs = (serviceId:string, instancesMap:InstancesInputsPropertiesMap):ng.IPromise<Array<InputModel>> => {
757 let defer = this.$q.defer<any>();
758 this.restangular.one(serviceId).one("create/inputs").customPOST(instancesMap).then((response:any) => {
759 let inputsArray:Array<InputModel> = new Array<InputModel>();
760 _.forEach(response, (inputObj:InputModel) => {
761 inputsArray.push(new InputModel(inputObj));
763 defer.resolve(inputsArray);
765 console.log("failed to create service inputs from VF instances inputs : ", err);
768 return defer.promise;
771 deleteComponentInput = (serviceId:string, inputId:string):ng.IPromise<InputModel> => {
772 let defer = this.$q.defer();
773 this.restangular.one(serviceId).one("delete").one(inputId).one("input").remove().then((response:any) => {
774 let inputToDelete = new InputModel(response);
775 defer.resolve(inputToDelete);
777 console.log("failed to delete input from service: ", err);
780 return defer.promise;
783 private getHeaderMd5 = (object:any):any => {
785 // This is ugly workaround!!!
786 // The md5 result is not correct if we do not add the line JSON.stringify(resource); twice.
787 JSON.stringify(object);
788 let componentString:string = JSON.stringify(object);
789 let md5Result = md5(componentString).toLowerCase();
790 headerObj = {'Content-MD5': this.$base64.encode(md5Result)};