diff options
Diffstat (limited to 'catalog-be/src/main/java')
4 files changed, 77 insertions, 120 deletions
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<CategoryDefinition> createServiceCategories(Map<String, Object> categories) { - List<CategoryDefinition> categroiesDef = new ArrayList<>(); + List<CategoryDefinition> categoriesDef = new ArrayList<>(); String catName = null; List<String> icons = null; for (Entry<String, Object> 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<MetadataKeyDataDefinition> getMetadataKeys(Map<String, Object> parentObject) { + Map<String, Object> metadataKeys = (Map<String, Object>) parentObject.getOrDefault(MetadataKeyEnum.METADATA_KEYS.getName(), Collections.EMPTY_MAP); + List<MetadataKeyDataDefinition> metadataKeyDefs = new ArrayList<>(); + for (Entry<String, Object> metadataKey : metadataKeys.entrySet()) { + Map<String, Object> metadataKeyInfo = (Map<String, Object>) 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<String> validValues = (List<String>) metadataKeyInfo.get(MetadataKeyEnum.VALID_VALUES.getName()); + metadataKeyDef.setValidValues(validValues); + metadataKeyDefs.add(metadataKeyDef); + } + return metadataKeyDefs; } private List<CategoryDefinition> createResourceCategories(Map<String, Object> 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<String, String> convertMetadata(Component component) { return convertMetadata(component, false, null); } - private ToscaMetadata convertMetadata(Component component, boolean isInstance, + private Map<String, String> 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<String, String> 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<CategoryDefinition> 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<String> directives; - private ToscaMetadata metadata; + private Map<String, String> metadata; private String description; private Map<String, Object> properties; private List<Map<String, ToscaTemplateRequirement>> 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<String, String> metadata; private List<Map<String, Map<String, String>>> imports; private Map<String, Object> interface_types; private Map<String, ToscaDataType> data_types; private Map<String, ToscaNodeType> node_types; private ToscaTopolgyTemplate topology_template; - private List<Triple<String, String, Component>> dependencies; - public ToscaTemplate(String tosca_definitions_version) { - this.tosca_definitions_version = tosca_definitions_version; - } - - public Map<String, ToscaNodeType> getNode_types() { - return node_types; - } - - public void setNode_types(Map<String, ToscaNodeType> node_types) { - this.node_types = node_types; - } - - - public List<Map<String, Map<String, String>>> getImports() { - return imports; - } - - public void setImports(List<Map<String, Map<String, String>>> 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<Triple<String, String, Component>> getDependencies() { - return dependencies; - } - - public void setDependencies(List<Triple<String, String, Component>> dependencies) { - this.dependencies = dependencies; - } - - public Map<String, Object> getInterface_types() { - return interface_types; - } - - // public void setInterface_types(Map<String, Object> interface_types) { - // this.interface_types = interface_types; - // } - - public void setInterface_types(Map<String, Object> 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<String, ToscaDataType> getData_types() { - return data_types; - } - - /** - * Sets data_types map. - * @param data_types New data_types map. - */ - public void setData_types(Map<String, ToscaDataType> data_types) { - this.data_types = data_types; - } } |