Improve handling 'empty'/null string in Service fields
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / tosca / ToscaExportHandler.java
index 44da4f2..4d99b4d 100644 (file)
@@ -358,7 +358,7 @@ public class ToscaExportHandler {
     }
 
     private List<Map<String, Map<String, String>>> getDefaultToscaImports(final String modelId) {
-        if (modelId == null) {
+        if (StringUtils.isEmpty(modelId)) {
             return getDefaultToscaImportConfig();
         }
 
@@ -557,12 +557,12 @@ public class ToscaExportHandler {
         }
     }
 
-    private Map<String, String> convertMetadata(Component component) {
+    private Map<String, Object> convertMetadata(Component component) {
         return convertMetadata(component, false, null);
     }
 
-    private Map<String, String> convertMetadata(Component component, boolean isInstance, ComponentInstance componentInstance) {
-        Map<String, String> toscaMetadata = new LinkedHashMap<>();
+    private Map<String, Object> convertMetadata(Component component, boolean isInstance, ComponentInstance componentInstance) {
+        Map<String, Object> toscaMetadata = new LinkedHashMap<>();
         toscaMetadata.put(convertMetadataKey(JsonPresentationFields.INVARIANT_UUID), component.getInvariantUUID());
         toscaMetadata.put(JsonPresentationFields.UUID.getPresentation(), component.getUUID());
         toscaMetadata
@@ -606,6 +606,7 @@ public class ToscaExportHandler {
                 }
                 toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_RELEASE.getPresentation(), resource.getVendorRelease());
                 toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER.getPresentation(), resource.getResourceVendorModelNumber());
+                toscaMetadata.put(resource.isTopologyTemplate() ? JsonPresentationFields.TEMPLATE_VERSION.getPresentation() : JsonPresentationFields.VERSION.getPresentation(), resource.getVersion());
                 break;
             case SERVICE:
                 Service service = (Service) component;
@@ -614,12 +615,11 @@ public class ToscaExportHandler {
                 toscaMetadata.put(JsonPresentationFields.SERVICE_ROLE.getPresentation(), service.getServiceRole());
                 toscaMetadata.put(JsonPresentationFields.SERVICE_FUNCTION.getPresentation(), service.getServiceFunction());
                 toscaMetadata.put(JsonPresentationFields.ENVIRONMENT_CONTEXT.getPresentation(), service.getEnvironmentContext());
+                toscaMetadata.put(JsonPresentationFields.TEMPLATE_VERSION.getPresentation(), service.getVersion());
                 toscaMetadata.put(JsonPresentationFields.INSTANTIATION_TYPE.getPresentation(),
                         service.getEnvironmentContext() == null ? StringUtils.EMPTY : service.getInstantiationType());
                 if (!isInstance) {
-                    // DE268546
-                    toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(), service.isEcompGeneratedNaming().toString());
-                    toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(), service.isEcompGeneratedNaming().toString());
+                    toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(), service.isEcompGeneratedNaming());
                     toscaMetadata.put(JsonPresentationFields.NAMING_POLICY.getPresentation(), service.getNamingPolicy());
                 }
                 break;