Merge "regression unit test for getServicesByOwningEntityId"
[vid.git] / vid-webpack-master / src / app / drawingBoard / service-planning / objectsToTree / shared.tree.service.ts
index d60bbd3..964e120 100644 (file)
@@ -19,7 +19,6 @@ import {NodeInstance} from "../../../shared/models/nodeInstance";
 
 @Injectable()
 export class SharedTreeService {
-  private _sharedTreeService: SharedTreeService;
   constructor(private _store: NgRedux<AppState>) {
   }
 
@@ -63,12 +62,12 @@ export class SharedTreeService {
    * @param modelTypeName "vnfs" | "networks" | "vfModules" | "collectionResources" | ...
    * @param modelUniqueNameOrId Either an entry name (i.e. "originalName"), modelCustomizationId or modelInvariantId.
    *                      Note that modelInvariantId will work only where model lacks a modelCustomizationId.
-   * @param modeName An optional entry name (i.e. "originalName"); will not try to use as id
+   * @param modelName An optional entry name (i.e. "originalName"); will not try to use as id
    */
-  modelByIdentifiers = (serviceModelFromHierarchy, modelTypeName: string, modelUniqueNameOrId: string, modeName?: string): any => {
+  modelByIdentifiers = (serviceModelFromHierarchy, modelTypeName: string, modelUniqueNameOrId: string, modelName?: string): any => {
     const logErrorAndReturnUndefined = () =>
       console.info(`modelByIdentifiers: could not find a model matching query`, {
-        modelTypeName, modelUniqueNameOrId, modeName, serviceModelFromHierarchy
+        modelTypeName, modelUniqueNameOrId, modelName, serviceModelFromHierarchy
       });
 
     if (_.isNil(serviceModelFromHierarchy)) return logErrorAndReturnUndefined();
@@ -77,7 +76,7 @@ export class SharedTreeService {
     if (_.isNil(modelsOfType)) return logErrorAndReturnUndefined();
 
     const modelIfModelIdentifierIsEntryName = modelsOfType[modelUniqueNameOrId];
-    const modelIfModeNameExists = _.isNil(modeName) ? null : modelsOfType[modeName];
+    const modelIfModeNameExists = _.isNil(modelName) ? null : modelsOfType[modelName];
 
     if (!_.isNil(modelIfModelIdentifierIsEntryName)) {
       return modelIfModelIdentifierIsEntryName;
@@ -208,7 +207,7 @@ export class SharedTreeService {
    ****************************************************/
   shouldShowUpgrade(node, serviceModelId): boolean {
     if (FeatureFlagsService.getFlagState(Features.FLAG_FLASH_REPLACE_VF_MODULE, this._store) &&
-      this.isThereAnUpdatedLatestVersion(serviceModelId)) {
+      (this.isThereAnUpdatedLatestVersion(serviceModelId)) || this.isDiffCustomizationUuid(node, serviceModelId)) {
       return this.shouldShowButtonGeneric(node, VNFMethods.UPGRADE, serviceModelId);
     }
     else {
@@ -216,7 +215,25 @@ export class SharedTreeService {
     }
   }
 
-  private isThereAnUpdatedLatestVersion(serviceModelId) : boolean{
+
+  isDiffCustomizationUuid(node, serviceModelId) : boolean {
+    const vfModuleServiceHierarchy =  this.getVfModuleHierarchyThroughParentModelName(node, serviceModelId);
+    if(_.isNil(vfModuleServiceHierarchy)){
+      return true;
+    }
+    return node.data && !_.isNil(vfModuleServiceHierarchy) && vfModuleServiceHierarchy.customizationUuid  && (vfModuleServiceHierarchy.customizationUuid !== node.data.modelCustomizationId);
+  }
+
+  getVfModuleHierarchyThroughParentModelName(node, serviceModelId) {
+    if(node.parent && node.parent.data && node.data){
+      const vnfHierarchy =  this._store.getState().service.serviceHierarchy[serviceModelId].vnfs[node.parent.data.modelName];
+      return vnfHierarchy ? vnfHierarchy.vfModules[node.data.modelName] : null;
+    }
+    return null;
+  }
+
+
+  isThereAnUpdatedLatestVersion(serviceModelId) : boolean{
     let serviceInstance = this.getServiceInstance(serviceModelId);
     return !_.isNil(serviceInstance.latestAvailableVersion) && (Number(serviceInstance.modelInfo.modelVersion) < serviceInstance.latestAvailableVersion);
   }
@@ -403,7 +420,13 @@ export class SharedTreeService {
     AuditInfoModalComponent.openInstanceAuditInfoModal.next({
       instanceId: serviceModelId,
       type: instanceType,
-      model: modelInfoService.getModel(node.data.modelName, instance, this._store.getState().service.serviceHierarchy[serviceModelId]),
+      model: modelInfoService.getModel(
+        this.modelByIdentifiers(
+          this._store.getState().service.serviceHierarchy[serviceModelId],
+          modelInfoService.name,
+          this.modelUniqueNameOrId(instance), node.data.modelName
+        )
+      ),
       instance
     });
   }