From 69779180f8f4e020606634f9bd8cac728daed2a2 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Tue, 15 Dec 2020 16:12:59 +0000 Subject: Support for category specific metadata Signed-off-by: MichaelMorris Issue-ID: SDC-3412 Change-Id: I87392cc21dc25253b558bdc1d453d99659d049fa --- .../components/impl/CategoriesImportManager.java | 29 ++++++- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 73 +++++++++-------- .../sdc/be/tosca/model/ToscaNodeTemplate.java | 2 +- .../sdc/be/tosca/model/ToscaTemplate.java | 93 +++------------------- 4 files changed, 77 insertions(+), 120 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java index 4330c0de43..d49284eab0 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CategoriesImportManager.java @@ -25,7 +25,9 @@ import org.openecomp.sdc.be.dao.api.ActionStatus; import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary; import org.openecomp.sdc.be.datamodel.api.CategoryTypeEnum; import org.openecomp.sdc.be.datamodel.utils.NodeTypeConvertUtils; +import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.MetadataKeyEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.category.CategoryDefinition; @@ -40,6 +42,7 @@ import org.springframework.stereotype.Component; import org.yaml.snakeyaml.Yaml; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -226,7 +229,7 @@ public class CategoriesImportManager { } private List createServiceCategories(Map categories) { - List categroiesDef = new ArrayList<>(); + List categoriesDef = new ArrayList<>(); String catName = null; List icons = null; for (Entry entry : categories.entrySet()) { @@ -242,10 +245,29 @@ public class CategoriesImportManager { final boolean useServiceSubstitutionForNestedServices = useServiceSubstitutionForNestedServicesProperty == null ? false : (Boolean) useServiceSubstitutionForNestedServicesProperty; catDef.setUseServiceSubstitutionForNestedServices(useServiceSubstitutionForNestedServices); - categroiesDef.add(catDef); + catDef.setMetadataKeys(getMetadataKeys(category)); + categoriesDef.add(catDef); } - return categroiesDef; + return categoriesDef; + } + + private List getMetadataKeys(Map parentObject) { + Map metadataKeys = (Map) parentObject.getOrDefault(MetadataKeyEnum.METADATA_KEYS.getName(), Collections.EMPTY_MAP); + List metadataKeyDefs = new ArrayList<>(); + for (Entry metadataKey : metadataKeys.entrySet()) { + Map metadataKeyInfo = (Map) metadataKey.getValue(); + MetadataKeyDataDefinition metadataKeyDef = new MetadataKeyDataDefinition(); + String metadataKeyName = (String) metadataKeyInfo.get(MetadataKeyEnum.NAME.getName()); + metadataKeyDef.setName(metadataKeyName); + final Object mandatoryProperty = metadataKeyInfo.get(MetadataKeyEnum.MANDATORY.getName()); + final boolean mandatory = mandatoryProperty == null ? false : (Boolean) mandatoryProperty; + metadataKeyDef.setMandatory(mandatory); + List validValues = (List) metadataKeyInfo.get(MetadataKeyEnum.VALID_VALUES.getName()); + metadataKeyDef.setValidValues(validValues); + metadataKeyDefs.add(metadataKeyDef); + } + return metadataKeyDefs; } private List createResourceCategories(Map categoryPerType) { @@ -268,6 +290,7 @@ public class CategoriesImportManager { subDef.setIcons(subcategoryIcons); normalizedName = ValidationUtils.normalizeCategoryName4Uniqueness(subcategoryName); subDef.setNormalizedName(normalizedName); + subDef.setMetadataKeys(getMetadataKeys(subcategoryInfo)); subcateDef.add(subDef); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java index 5c8d9c6c6d..6131eb5850 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java @@ -35,6 +35,7 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -67,6 +68,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementSubstitutionFilterProp import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.model.ArtifactDefinition; @@ -410,37 +412,40 @@ public class ToscaExportHandler { } } - private ToscaMetadata convertMetadata(Component component) { + private Map convertMetadata(Component component) { return convertMetadata(component, false, null); } - private ToscaMetadata convertMetadata(Component component, boolean isInstance, + private Map convertMetadata(Component component, boolean isInstance, ComponentInstance componentInstance) { - ToscaMetadata toscaMetadata = new ToscaMetadata(); - toscaMetadata.setInvariantUUID(component.getInvariantUUID()); - toscaMetadata.setUUID(component.getUUID()); - toscaMetadata.setDescription(component.getDescription()); - toscaMetadata.setName(component.getComponentMetadataDefinition().getMetadataDataDefinition().getName()); + Map toscaMetadata = new LinkedHashMap<>(); + toscaMetadata.put(JsonPresentationFields.INVARIANT_UUID.getPresentation(), component.getInvariantUUID()); + toscaMetadata.put(JsonPresentationFields.UUID.getPresentation(), component.getUUID()); + toscaMetadata.put(JsonPresentationFields.NAME.getPresentation(), component.getComponentMetadataDefinition().getMetadataDataDefinition().getName()); + toscaMetadata.put(JsonPresentationFields.DESCRIPTION.getPresentation(), component.getDescription()); List categories = component.getCategories(); CategoryDefinition categoryDefinition = categories.get(0); - toscaMetadata.setCategory(categoryDefinition.getName()); + toscaMetadata.put(JsonPresentationFields.CATEGORY.getPresentation(), categoryDefinition.getName()); if (isInstance) { - toscaMetadata.setVersion(component.getVersion()); - toscaMetadata.setCustomizationUUID(componentInstance.getCustomizationUUID()); + toscaMetadata.put(JsonPresentationFields.VERSION.getPresentation(),component.getVersion()); + toscaMetadata.put(JsonPresentationFields.CUSTOMIZATION_UUID.getPresentation(), componentInstance.getCustomizationUUID()); if (componentInstance.getSourceModelInvariant() != null && !componentInstance.getSourceModelInvariant().isEmpty()) { - toscaMetadata.setVersion(componentInstance.getComponentVersion()); - toscaMetadata.setSourceModelInvariant(componentInstance.getSourceModelInvariant()); - toscaMetadata.setSourceModelUuid(componentInstance.getSourceModelUuid()); - toscaMetadata.setSourceModelName(componentInstance.getSourceModelName()); + toscaMetadata.put(JsonPresentationFields.VERSION.getPresentation(),componentInstance.getComponentVersion()); + toscaMetadata.put(JsonPresentationFields.CI_SOURCE_MODEL_INVARIANT.getPresentation(),componentInstance.getSourceModelInvariant()); + toscaMetadata.put(JsonPresentationFields.CI_SOURCE_MODEL_UUID.getPresentation(),componentInstance.getSourceModelUuid()); + toscaMetadata.put(JsonPresentationFields.CI_SOURCE_MODEL_NAME.getPresentation(),componentInstance.getSourceModelName()); if (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy) { - toscaMetadata.setName(componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceProxy.getDisplayValue()); + toscaMetadata.put(JsonPresentationFields.NAME.getPresentation(), + componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceProxy.getDisplayValue()); } else if (componentInstance.getOriginType() == OriginTypeEnum.ServiceSubstitution) { - toscaMetadata.setName(componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceSubstitution.getDisplayValue()); + toscaMetadata.put(JsonPresentationFields.NAME.getPresentation(), + componentInstance.getSourceModelName() + " " + OriginTypeEnum.ServiceSubstitution + .getDisplayValue()); } - toscaMetadata.setDescription(componentInstance.getDescription()); + toscaMetadata.put(JsonPresentationFields.DESCRIPTION.getPresentation(),componentInstance.getDescription()); } } @@ -449,33 +454,37 @@ public class ToscaExportHandler { Resource resource = (Resource) component; if (isInstance && (componentInstance.getOriginType() == OriginTypeEnum.ServiceProxy || componentInstance.getOriginType() == OriginTypeEnum.ServiceSubstitution)) { - toscaMetadata.setType(componentInstance.getOriginType().getDisplayValue()); + toscaMetadata.put(JsonPresentationFields.TYPE.getPresentation(), componentInstance.getOriginType().getDisplayValue()); } else { - toscaMetadata.setType(resource.getResourceType().name()); + toscaMetadata.put(JsonPresentationFields.TYPE.getPresentation(), resource.getResourceType().name()); } - toscaMetadata.setSubcategory(categoryDefinition.getSubcategories().get(0).getName()); - toscaMetadata.setResourceVendor(resource.getVendorName()); - toscaMetadata.setResourceVendorRelease(resource.getVendorRelease()); - toscaMetadata.setResourceVendorModelNumber(resource.getResourceVendorModelNumber()); + toscaMetadata.put(JsonPresentationFields.SUB_CATEGORY.getPresentation(), categoryDefinition.getSubcategories().get(0).getName()); + toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR.getPresentation(), resource.getVendorName()); + toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_RELEASE.getPresentation(),resource.getVendorRelease()); + toscaMetadata.put(JsonPresentationFields.RESOURCE_VENDOR_MODEL_NUMBER.getPresentation(),resource.getResourceVendorModelNumber()); break; case SERVICE: Service service = (Service) component; - toscaMetadata.setType(component.getComponentType().getValue()); - toscaMetadata.setServiceType(service.getServiceType()); - toscaMetadata.setServiceRole(service.getServiceRole()); - toscaMetadata.setServiceFunction(service.getServiceFunction()); - toscaMetadata.setEnvironmentContext(service.getEnvironmentContext()); - resolveInstantiationTypeAndSetItToToscaMetaData(toscaMetadata, service); + toscaMetadata.put(JsonPresentationFields.TYPE.getPresentation(),component.getComponentType().getValue()); + toscaMetadata.put(JsonPresentationFields.SERVICE_TYPE.getPresentation(),service.getServiceType()); + 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.INSTANTIATION_TYPE.getPresentation(),service.getEnvironmentContext() == null ? StringUtils.EMPTY : service.getInstantiationType()); if (!isInstance) { // DE268546 - toscaMetadata.setServiceEcompNaming(((Service) component).isEcompGeneratedNaming()); - toscaMetadata.setEcompGeneratedNaming(((Service) component).isEcompGeneratedNaming()); - toscaMetadata.setNamingPolicy(((Service) component).getNamingPolicy()); + toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(),service.isEcompGeneratedNaming().toString()); + toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(),service.isEcompGeneratedNaming().toString()); + toscaMetadata.put(JsonPresentationFields.NAMING_POLICY.getPresentation(),service.getNamingPolicy()); } break; default: log.debug(NOT_SUPPORTED_COMPONENT_TYPE, component.getComponentType()); } + + for (final String key: component.getCategorySpecificMetadata().keySet()) { + toscaMetadata.put(key, component.getCategorySpecificMetadata().get(key)); + } return toscaMetadata; } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java index 04515b297c..50a8f3da3b 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaNodeTemplate.java @@ -37,7 +37,7 @@ public class ToscaNodeTemplate { private String type; private List directives; - private ToscaMetadata metadata; + private Map metadata; private String description; private Map properties; private List> requirements; diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java index 742e8bb233..7fc60d1b5d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaTemplate.java @@ -20,104 +20,29 @@ package org.openecomp.sdc.be.tosca.model; -import org.apache.commons.lang3.tuple.Triple; -import org.openecomp.sdc.be.model.Component; - import java.util.List; import java.util.Map; +import lombok.Getter; +import lombok.Setter; +import org.apache.commons.lang3.tuple.Triple; +import org.openecomp.sdc.be.model.Component; +@Getter +@Setter public class ToscaTemplate { private String tosca_definitions_version; - private ToscaMetadata metadata; + private Map metadata; private List>> imports; private Map interface_types; private Map data_types; private Map node_types; private ToscaTopolgyTemplate topology_template; - private List> dependencies; - public ToscaTemplate(String tosca_definitions_version) { - this.tosca_definitions_version = tosca_definitions_version; - } - - public Map getNode_types() { - return node_types; - } - - public void setNode_types(Map node_types) { - this.node_types = node_types; - } - - - public List>> getImports() { - return imports; - } - - public void setImports(List>> imports) { - this.imports = imports; - } - - public String getTosca_definitions_version() { - return tosca_definitions_version; - } - - public void setTosca_definitions_version(String tosca_definitions_version) { - this.tosca_definitions_version = tosca_definitions_version; - } - - public ToscaMetadata getMetadata() { - return metadata; - } - - public void setMetadata(ToscaMetadata metadata) { - this.metadata = metadata; - } - - public ToscaTopolgyTemplate getTopology_template() { - return topology_template; - } - - public void setTopology_template(ToscaTopolgyTemplate topology_template) { - this.topology_template = topology_template; - } - - public List> getDependencies() { - return dependencies; - } - - public void setDependencies(List> dependencies) { - this.dependencies = dependencies; - } - - public Map getInterface_types() { - return interface_types; - } - - // public void setInterface_types(Map interface_types) { - // this.interface_types = interface_types; - // } - - public void setInterface_types(Map interface_types) { - this.interface_types = interface_types; - + public ToscaTemplate(final String toscaDefinitionsVersion) { + this.tosca_definitions_version = toscaDefinitionsVersion; } - /** - * Gets data_types map. - * @return Current data_types map. - */ - public Map getData_types() { - return data_types; - } - - /** - * Sets data_types map. - * @param data_types New data_types map. - */ - public void setData_types(Map data_types) { - this.data_types = data_types; - } } -- cgit 1.2.3-korg