Support for category specific metadata

Signed-off-by: MichaelMorris <michael.morris@est.tech>
Issue-ID: SDC-3412
Change-Id: I87392cc21dc25253b558bdc1d453d99659d049fa
diff --git a/catalog-ui/src/app/models/category.ts b/catalog-ui/src/app/models/category.ts
index 15df985..64588d0 100644
--- a/catalog-ui/src/app/models/category.ts
+++ b/catalog-ui/src/app/models/category.ts
@@ -28,6 +28,7 @@
     normalizedName:string;
     uniqueId:string;
     icons:Array<string>;
+    metadataKeys: IMetadataKey[];
 
     //custom properties
     filterTerms:string;
@@ -46,3 +47,9 @@
 
 export interface IGroup extends ICategoryBase {
 }
+
+export interface IMetadataKey {
+	name:string;
+	mandatory:boolean
+	validValues: string[];
+}
diff --git a/catalog-ui/src/app/models/component-metadata.ts b/catalog-ui/src/app/models/component-metadata.ts
index 8a4b257..186cd8a 100644
--- a/catalog-ui/src/app/models/component-metadata.ts
+++ b/catalog-ui/src/app/models/component-metadata.ts
@@ -21,6 +21,7 @@
 import { CapabilitiesGroup, RequirementsGroup } from 'app/models';
 import { ComponentType } from 'app/utils';
 import { IMainCategory } from './category';
+import { Metadata } from "app/models/metadata";
 /**
  * Created by obarda on 4/18/2017.
  */
@@ -53,6 +54,7 @@
     vspArchived: boolean;
     selectedCategory: string;
     filterTerm: string;
+    categorySpecificMetadata: Metadata;
 
     // Resource only
     resourceType: string;
@@ -115,6 +117,7 @@
     public toscaResourceName: string;
     public selectedCategory: string;
     public filterTerm: string;
+    public categorySpecificMetadata: Metadata = new Metadata();
 
     // Resource only
     public resourceType: string;
@@ -192,6 +195,7 @@
         this.toscaResourceName = response.toscaResourceName;
         this.capabilities = response.capabilities;
         this.requirements = response.requirements;
+        this.categorySpecificMetadata = response.categorySpecificMetadata;
         return this;
     }
 
diff --git a/catalog-ui/src/app/models/components/component.ts b/catalog-ui/src/app/models/components/component.ts
index a0706b4..1d48151 100644
--- a/catalog-ui/src/app/models/components/component.ts
+++ b/catalog-ui/src/app/models/components/component.ts
@@ -35,6 +35,7 @@
 import {Relationship} from "../graph/relationship";
 import { PolicyInstance } from "app/models/graph/zones/policy-instance";
 import { GroupInstance } from "../graph/zones/group-instance";
+import { Metadata } from "app/models/metadata";
 
 
 // import {}
@@ -142,6 +143,7 @@
     public archived:boolean;
     public vspArchived: boolean;
     public componentMetadata: ComponentMetadata;
+    public categorySpecificMetadata: Metadata = new Metadata();
 
     constructor(componentService:IComponentService, protected $q:ng.IQService, component?:Component) {
         if (component) {
@@ -198,12 +200,36 @@
             this.policies = component.policies;
             this.archived = component.archived;
             this.vspArchived = component.vspArchived;
+
+            if (component.categorySpecificMetadata && component.categories && component.categories[0]){
+                this.copyCategoryMetadata(component);
+                this.copySubcategoryMetadata(component);
+            }
         }
 
         //custom properties
         this.componentService = componentService;
     }
 
+    private copyCategoryMetadata = (component:Component):void => {
+        if (component.categories[0].metadataKeys){
+            for (let key of Object.keys(component.categorySpecificMetadata)) {
+                if (component.categories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+                    this.categorySpecificMetadata[key] = component.categorySpecificMetadata[key];
+                }
+            }
+        }
+    }
+    private copySubcategoryMetadata = (component:Component):void => {
+        if (component.categories[0].subcategories && component.categories[0].subcategories[0] && component.categories[0].subcategories[0].metadataKeys){
+            for (let key of Object.keys(component.categorySpecificMetadata)) {
+                if (component.categories[0].subcategories[0].metadataKeys.some(metadataKey => metadataKey.name == key)) {
+                    this.categorySpecificMetadata[key] = component.categorySpecificMetadata[key];
+                }
+            }
+        }
+    }
+
     public setUniqueId = (uniqueId:string):void => {
         this.uniqueId = uniqueId;
     };
@@ -543,6 +569,11 @@
         this.archived = componentMetadata.archived || false;
         this.vspArchived = componentMetadata.vspArchived;
         this.componentMetadata = componentMetadata;
+        if (componentMetadata.categorySpecificMetadata){
+            this.categorySpecificMetadata = componentMetadata.categorySpecificMetadata;
+        } else {
+            this.categorySpecificMetadata = new Metadata();
+        }
     }
 
     public toJSON = ():any => {