Fix resource population to DB

Fix resource population to DB.

Change-Id: Iae25ce2f15fa121a45a55559458fcbbd217f2c7d
Issue-ID: SO-624
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
diff --git a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
index fc4e522..a8c67fd 100644
--- a/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
+++ b/asdc-controller/src/main/java/org/openecomp/mso/asdc/installer/heat/ToscaResourceInstaller.java
@@ -596,23 +596,34 @@
             

             List<NodeTemplate> allottedResourceList = toscaResourceStruct.getSdcCsarHelper().getAllottedResources();

         	

-        		if(allottedResourceList != null){

-        		

-        			for(NodeTemplate allottedNode : allottedResourceList){

-					

-        				createAllottedResource(allottedNode, toscaResourceStruct);

-					

-        				catalogDB.saveAllottedResource(toscaResourceStruct.getAllottedResource());

-					

-        				catalogDB.saveAllottedResourceCustomization(toscaResourceStruct.getCatalogAllottedResourceCustomization());

-        				

-        				catalogDB.saveServiceToResourceCustomization(toscaResourceStruct.getCatalogAllottedServiceToResourceCustomization());

-					

-        			}

-        		}

-        		

+			if(allottedResourceList != null){

 

-        	List<NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper().getServiceVlList();

+				for(NodeTemplate allottedNode : allottedResourceList){

+

+					createAllottedResource(allottedNode, toscaResourceStruct);

+

+					catalogDB.saveAllottedResource(toscaResourceStruct.getAllottedResource());

+

+					catalogDB.saveAllottedResourceCustomization(toscaResourceStruct.getCatalogAllottedResourceCustomization());

+

+					catalogDB.saveServiceToResourceCustomization(toscaResourceStruct.getCatalogAllottedServiceToResourceCustomization());

+

+				}

+			}

+

+			// handle VF resource

+			List<NodeTemplate> serviceVfList = toscaResourceStruct.getSdcCsarHelper().getServiceVfList();

+			if (serviceVfList != null) {

+				for (NodeTemplate vfNode : serviceVfList) {

+					createVnfResource(vfNode, toscaResourceStruct);

+					catalogDB.saveVnfResource(toscaResourceStruct.getCatalogVnfResource());

+					catalogDB.saveVnfResourceCustomization(toscaResourceStruct.getCatalogVnfResourceCustomization());

+					catalogDB.saveServiceToResourceCustomization(toscaResourceStruct.getCatalogVfServiceToResourceCustomization());

+				}

+			}

+

+

+			List<NodeTemplate> nodeTemplatesVLList = toscaResourceStruct.getSdcCsarHelper().getServiceVlList();

 				

         		if(nodeTemplatesVLList != null){

 				

diff --git a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
index 4fb5ebc..91c19dd 100644
--- a/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
+++ b/mso-catalog-db/src/main/java/org/openecomp/mso/db/catalog/CatalogDatabase.java
@@ -3826,6 +3826,22 @@
             LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateAllottedResourceCustomization", null);
         }
     }
+
+    public void saveVnfResource (VnfResource vnfResource) {
+        long startTime = System.currentTimeMillis ();
+        LOGGER.debug ("Catalog database - save vnf Resource with Name " + vnfResource.getModelName());
+        try {
+            VnfResource existing = this.getVnfResourceByModelUuid(vnfResource.getModelUuid());
+            if (existing == null) {
+                this.getSession().save(vnfResource);
+            } else {
+                LOGGER.debug("Found existing vnfResource with this modelUuid - no need to save");
+            }
+
+        } finally {
+            LOGGER.recordMetricEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully", "CatalogDB", "saveOrUpdateVnfResourceCustomization", null);
+        }
+    }
     
     public void saveNetworkResource (NetworkResource networkResource) throws RecordNotFoundException {
         long startTime = System.currentTimeMillis ();