From 3935993a90fe768585ab5e908d6334567c1823de Mon Sep 17 00:00:00 2001 From: vasraz Date: Thu, 15 Sep 2022 14:27:20 +0100 Subject: Import unknown group types during Service import Signed-off-by: Vasyl Razinkov Change-Id: Ic435ee0c440dd8ed64339bab08e921687d23b9c0 Issue-ID: SDC-4176 --- .../openecomp/sdc/be/components/csar/CsarInfo.java | 34 +++--- .../sdc/be/components/csar/OnboardedCsarInfo.java | 58 ++++++---- .../sdc/be/components/csar/ServiceCsarInfo.java | 50 +++++---- .../csar/YamlTemplateParsingHandler.java | 71 ++++++------ .../be/components/impl/CommonImportManager.java | 12 +- .../impl/ComponentInstanceBusinessLogic.java | 2 +- .../be/components/impl/GroupTypeImportManager.java | 6 +- .../impl/ServiceImportBusinessLogic.java | 123 ++++++++++++++++----- .../components/impl/model/ToscaTypeImportData.java | 13 +-- 9 files changed, 221 insertions(+), 148 deletions(-) (limited to 'catalog-be/src/main/java/org') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java index b845b104fe..5f49bd7bf2 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/CsarInfo.java @@ -89,13 +89,11 @@ public abstract class CsarInfo { private boolean isUpdate; @Getter private Map createdNodes; - protected Map datatypeDefinitions; protected Map artifacttypeDefinitions; private Map policytypeDefinitions; - - public CsarInfo(User modifier, String csarUUID, Map csar, String vfResourceName, String mainTemplateName, - String mainTemplateContent, boolean isUpdate) { + protected CsarInfo(User modifier, String csarUUID, Map csar, String vfResourceName, String mainTemplateName, + String mainTemplateContent, boolean isUpdate) { this.vfResourceName = vfResourceName; this.modifier = modifier; this.csarUUID = csarUUID; @@ -109,13 +107,13 @@ public abstract class CsarInfo { this.createdNodes = new HashMap<>(); this.nonManoConfiguration = NonManoConfigurationManager.getInstance().getNonManoConfiguration(); } - + public String getVfResourceName() { return vfResourceName; } - public CsarInfo(final User modifier, final String csarUUID, final String csarVersionId, final Map csarContent, - final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { + protected CsarInfo(final User modifier, final String csarUUID, final String csarVersionId, final Map csarContent, + final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { this(modifier, csarUUID, csarContent, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate); this.csarVersionId = csarVersionId; } @@ -169,16 +167,18 @@ public abstract class CsarInfo { public void setUpdate(boolean isUpdate) { this.isUpdate = isUpdate; } - + public abstract Map extractTypesInfo(); - + /** * Get the data types defined in the CSAR - * + * * @return map with the data type name as key and representaion of the data type defintion as value */ public abstract Map getDataTypes(); + public abstract Map getGroupTypes(); + public abstract Map getArtifactTypes(); public Map getPolicyTypes() { @@ -188,11 +188,10 @@ public abstract class CsarInfo { } return policytypeDefinitions; } - + @SuppressWarnings("unchecked") protected Map getTypesFromTemplate(final Map mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type) { - final Either dataTypesEither = findToscaElement(mappedToscaTemplate, type, - ToscaElementTypeEnum.MAP); + final Either dataTypesEither = findToscaElement(mappedToscaTemplate, type, ToscaElementTypeEnum.MAP); if (dataTypesEither != null && dataTypesEither.isLeft()) { return (Map) dataTypesEither.left().value(); } @@ -200,15 +199,14 @@ public abstract class CsarInfo { } @SuppressWarnings("unchecked") - protected Map getTypesFromTemplate(final Map mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type, Collection names) { + protected Map getTypesFromTemplate(final Map mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type, + Collection names) { Map allTypes = getTypesFromTemplate(mappedToscaTemplate, type); final Map typesToReturn = new HashMap<>(); final Stream> requestedTypes = allTypes.entrySet().stream().filter(entry -> names.contains(entry.getKey())); - requestedTypes.forEach(requestedType -> { - typesToReturn.put(requestedType.getKey(), requestedType.getValue()); - }); + requestedTypes.forEach(requestedType -> typesToReturn.put(requestedType.getKey(), requestedType.getValue())); return typesToReturn; } @@ -223,7 +221,7 @@ public abstract class CsarInfo { @SuppressWarnings("unchecked") protected NodeTypeInfo buildNodeTypeInfo(final Map.Entry nodeType, final String templateFileName, - final Map mappedToscaTemplate) { + final Map mappedToscaTemplate) { final NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); nodeTypeInfo.setSubstitutionMapping(false); nodeTypeInfo.setNested(true); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java index 8ab05b9bc8..68a51e3ed3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/OnboardedCsarInfo.java @@ -22,6 +22,10 @@ package org.openecomp.sdc.be.components.csar; import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.DATA_TYPES; +import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.GROUP_TYPES; + +import fj.data.Either; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -38,13 +42,12 @@ import org.openecomp.sdc.be.model.NodeTypeInfo; import org.openecomp.sdc.be.model.User; import org.openecomp.sdc.be.tosca.CsarUtils; import org.openecomp.sdc.be.utils.TypeUtils; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.api.Constants; import org.yaml.snakeyaml.Yaml; -import fj.data.Either; /** - * Provides access to the contents of a CSAR which has been created through the SDC onboarding - * process + * Provides access to the contents of a CSAR which has been created through the SDC onboarding process */ public class OnboardedCsarInfo extends CsarInfo { @@ -55,13 +58,13 @@ public class OnboardedCsarInfo extends CsarInfo { } public OnboardedCsarInfo(final User modifier, final String csarUUID, final Map csar, final String vfResourceName, - final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { + final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { super(modifier, csarUUID, csar, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate); this.globalSubstitutes = getGlobalSubstitutes(csar); } public OnboardedCsarInfo(final User modifier, final String csarUUID, final String csarVersionId, final Map csarContent, - final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { + final String vfResourceName, final String mainTemplateName, final String mainTemplateContent, final boolean isUpdate) { super(modifier, csarUUID, csarVersionId, csarContent, vfResourceName, mainTemplateName, mainTemplateContent, isUpdate); this.globalSubstitutes = getGlobalSubstitutes(csar); } @@ -93,13 +96,13 @@ public class OnboardedCsarInfo extends CsarInfo { @SuppressWarnings("unchecked") private void extractNodeTypeInfo(final Map nodeTypesInfo, final Set nodeTypesUsedInNodeTemplates, - final Map.Entry entry) { + final Map.Entry entry) { if (isAServiceTemplate(entry.getKey()) && !isGlobalSubstitute(entry.getKey())) { final Map mappedToscaTemplate = (Map) new Yaml().load(new String(entry.getValue())); findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP).right() - .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map) sub)); + .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map) sub)); final Either nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map> nodeTemplates = (Map>) nodeTypesEither.left().value(); nodeTypesUsedInNodeTemplates.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates)); @@ -113,15 +116,16 @@ public class OnboardedCsarInfo extends CsarInfo { private boolean isGlobalSubstitute(final String fileName) { return fileName.equalsIgnoreCase(Constants.GLOBAL_SUBSTITUTION_TYPES_SERVICE_TEMPLATE) - || fileName.equalsIgnoreCase(Constants.ABSTRACT_SUBSTITUTE_GLOBAL_TYPES_SERVICE_TEMPLATE); + || fileName.equalsIgnoreCase(Constants.ABSTRACT_SUBSTITUTE_GLOBAL_TYPES_SERVICE_TEMPLATE); } private ResultStatusEnum handleSubstitutionMappings(final Map nodeTypesInfo, final Map.Entry entry, - final Map mappedToscaTemplate, final Map substitutionMappings) { + final Map mappedToscaTemplate, + final Map substitutionMappings) { final Set nodeTypesDefinedInTemplate = findNodeTypesDefinedInTemplate(mappedToscaTemplate); if (substitutionMappings.containsKey(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName()) - && !nodeTypesDefinedInTemplate.contains(substitutionMappings.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName()))) { + && !nodeTypesDefinedInTemplate.contains(substitutionMappings.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName()))) { NodeTypeInfo nodeTypeInfo = new NodeTypeInfo(); nodeTypeInfo.setSubstitutionMapping(true); nodeTypeInfo.setType((String) substitutionMappings.get(TypeUtils.ToscaTagNamesEnum.NODE_TYPE.getElementName())); @@ -135,7 +139,7 @@ public class OnboardedCsarInfo extends CsarInfo { @SuppressWarnings("unchecked") private Set findNodeTypesDefinedInTemplate(final Map mappedToscaTemplate) { final Either nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map nodeTypes = (Map) nodeTypesEither.left().value(); return nodeTypes.keySet(); @@ -149,7 +153,7 @@ public class OnboardedCsarInfo extends CsarInfo { final String yamlFileContents = new String(entry.getValue()); final Map mappedToscaTemplate = (Map) new Yaml().load(yamlFileContents); Either nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { Map nodeTypes = (Map) nodeTypesEither.left().value(); for (Map.Entry nodeType : nodeTypes.entrySet()) { @@ -174,9 +178,9 @@ public class OnboardedCsarInfo extends CsarInfo { private void addGlobalSubstitutionsToNodeTypes(final Set nodeTypesUsedInNodeTemplates, final Map nodeTypesInfo) { for (Map.Entry entry : globalSubstitutes) { final String yamlFileContents = new String(entry.getValue()); - final Map mappedToscaTemplate = (Map) new Yaml().load(yamlFileContents); + final Map mappedToscaTemplate = new Yaml().load(yamlFileContents); final Either nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map nodeTypes = (Map) nodeTypesEither.left().value(); for (final Map.Entry nodeType : nodeTypes.entrySet()) { @@ -204,16 +208,22 @@ public class OnboardedCsarInfo extends CsarInfo { @Override public Map getDataTypes() { - if (datatypeDefinitions == null) { - datatypeDefinitions = new HashMap<>(); - for (Map.Entry entry : globalSubstitutes) { - final String yamlFileContents = new String(entry.getValue()); - final Map mappedToscaTemplate = new Yaml().load(yamlFileContents); - datatypeDefinitions.putAll(getTypesFromTemplate(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES)); - } - datatypeDefinitions.putAll(getTypesFromTemplate(mappedToscaMainTemplate, TypeUtils.ToscaTagNamesEnum.DATA_TYPES)); + return getTypes(DATA_TYPES); + } + + @Override + public Map getGroupTypes() { + return getTypes(GROUP_TYPES); + } + + private Map getTypes(ToscaTagNamesEnum toscaTag) { + final Map types = new HashMap<>(); + for (Map.Entry entry : globalSubstitutes) { + final Map mappedToscaTemplate = new Yaml().load(new String(entry.getValue())); + types.putAll(getTypesFromTemplate(mappedToscaTemplate, toscaTag)); } - return datatypeDefinitions; + types.putAll(getTypesFromTemplate(mappedToscaMainTemplate, toscaTag)); + return types; } } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java index 4a9fa5eb18..aeef3acd64 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java @@ -79,17 +79,17 @@ public class ServiceCsarInfo extends CsarInfo { final List importFilePaths = getTemplateImportFilePaths(mappedToscaMainTemplate, fileParentDir); importFilePaths.stream().filter(path -> !filesHandled.contains(path)).forEach( - importFilePath -> { - byte[] importFile = csar.get(importFilePath.toString()); - if (importFile != null) { - filesHandled.add(importFilePath); - Map mappedImportFile = new Yaml().load(new String(csar.get(importFilePath.toString()))); - templateImports.put(importFilePath.toString(), mappedImportFile); - templateImports.putAll(getTemplateImports(csar, mappedImportFile, importFilePath.getParent(), filesHandled)); - } else { - log.info("Import {} cannot be found in CSAR", importFilePath.toString()); - } - }); + importFilePath -> { + byte[] importFile = csar.get(importFilePath.toString()); + if (importFile != null) { + filesHandled.add(importFilePath); + Map mappedImportFile = new Yaml().load(new String(csar.get(importFilePath.toString()))); + templateImports.put(importFilePath.toString(), mappedImportFile); + templateImports.putAll(getTemplateImports(csar, mappedImportFile, importFilePath.getParent(), filesHandled)); + } else { + log.info("Import {} cannot be found in CSAR", importFilePath.toString()); + } + }); return templateImports; } @@ -105,7 +105,8 @@ public class ServiceCsarInfo extends CsarInfo { if (importsList.get(0) instanceof String) { List importPaths = new ArrayList<>(); importsList.stream() - .forEach(importPath -> importPaths.add(fileParentDir == null ? Paths.get((String) importPath) : fileParentDir.resolve(Paths.get((String) importPath)).normalize())); + .forEach(importPath -> importPaths.add(fileParentDir == null ? Paths.get((String) importPath) + : fileParentDir.resolve(Paths.get((String) importPath)).normalize())); return importPaths; } else if (importsList.get(0) instanceof Map) { return getTemplateImportFilePathsMultiLineGrammar(importsList, fileParentDir); @@ -145,11 +146,19 @@ public class ServiceCsarInfo extends CsarInfo { @Override public Map getDataTypes() { - final Map definitions = new HashMap<>(); - mainTemplateImports.entrySet().stream() - .forEach(entry -> definitions.putAll(getTypesFromTemplate(entry.getValue(), TypeUtils.ToscaTagNamesEnum.DATA_TYPES))); - definitions.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), TypeUtils.ToscaTagNamesEnum.DATA_TYPES)); - return definitions; + return getTypes(ToscaTagNamesEnum.DATA_TYPES); + } + + @Override + public Map getGroupTypes() { + return getTypes(ToscaTagNamesEnum.GROUP_TYPES); + } + + private Map getTypes(ToscaTagNamesEnum toscaTag) { + final Map types = new HashMap<>(); + mainTemplateImports.entrySet().stream().forEach(entry -> types.putAll(getTypesFromTemplate(entry.getValue(), toscaTag))); + types.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), toscaTag)); + return types; } public Map getArtifactTypes() { @@ -210,7 +219,7 @@ public class ServiceCsarInfo extends CsarInfo { findToscaElement((Map) nodeTypeDef.getMappedNodeType().getValue(), TypeUtils.ToscaTagNamesEnum.DERIVED_FROM, ToscaElementTypeEnum.STRING); if (derivedFromTypeEither.isLeft()) { - recursiveNodeTypesToGet.add((String)derivedFromTypeEither.left().value()); + recursiveNodeTypesToGet.add((String) derivedFromTypeEither.left().value()); } }); recursiveNodeTypesToGet.removeAll(nodeTypesToGet); @@ -251,7 +260,8 @@ public class ServiceCsarInfo extends CsarInfo { private NodeTypeMetadata getMetaDataFromTemplate(Map mappedResourceTemplate, String nodeTemplateType) { NodeTypeMetadata nodeTypeMetadata = new NodeTypeMetadata(); - Either, ImportUtils.ResultStatusEnum> metadataEither = ImportUtils.findFirstToscaMapElement(mappedResourceTemplate, TypeUtils.ToscaTagNamesEnum.METADATA); + Either, ImportUtils.ResultStatusEnum> metadataEither = ImportUtils.findFirstToscaMapElement(mappedResourceTemplate, + TypeUtils.ToscaTagNamesEnum.METADATA); if (metadataEither.isLeft() && metadataEither.left().value().get("type").equals(ResourceTypeEnum.VFC.getValue())) { Map metadata = metadataEither.left().value(); createMetadataFromTemplate(nodeTypeMetadata, metadata, nodeTemplateType); @@ -261,7 +271,7 @@ public class ServiceCsarInfo extends CsarInfo { return nodeTypeMetadata; } - private void createMetadataFromTemplate(NodeTypeMetadata nodeTypeMetadata, Map metadata, String nodeTemplateType) { + private void createMetadataFromTemplate(NodeTypeMetadata nodeTypeMetadata, Map metadata, String nodeTemplateType) { nodeTypeMetadata.setToscaName(nodeTemplateType); nodeTypeMetadata.setContactId(getModifier().getUserId()); nodeTypeMetadata.setDescription((String) metadata.get("description")); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java index 09a84887aa..b57e2cb2cb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java @@ -148,7 +148,6 @@ public class YamlTemplateParsingHandler { private static final int SUB_MAPPING_CAPABILITY_OWNER_NAME_IDX = 0; private static final int SUB_MAPPING_CAPABILITY_NAME_IDX = 1; private static final Logger log = Logger.getLogger(YamlTemplateParsingHandler.class); - private static final String WITH_ATTRIBUTE = "with attribute '{}': '{}'"; private final Gson gson = new Gson(); private final JanusGraphDao janusGraphDao; private final GroupTypeBusinessLogic groupTypeBusinessLogic; @@ -184,8 +183,8 @@ public class YamlTemplateParsingHandler { parsedToscaYamlInfo.setInputs(getInputs(mappedTopologyTemplateInputs)); parsedToscaYamlInfo.setOutputs(getOutputs(mappedTopologyTemplateOutputs)); parsedToscaYamlInfo.setInstances(getInstances( - mappedToscaTemplate, - createdNodesToscaResourceNames + mappedToscaTemplate, + createdNodesToscaResourceNames )); associateRelationshipTemplatesToInstances(parsedToscaYamlInfo.getInstances(), mappedTopologyTemplate); parsedToscaYamlInfo.setGroups(getGroups(mappedToscaTemplate, component.getModel())); @@ -389,32 +388,32 @@ public class YamlTemplateParsingHandler { } private Map getInstances( - Map toscaJson, - Map createdNodesToscaResourceNames + Map toscaJson, + Map createdNodesToscaResourceNames ) { Map nodeTemplates = findFirstToscaMapElement(toscaJson, NODE_TEMPLATES) - .left().on(err -> new HashMap<>()); + .left().on(err -> new HashMap<>()); if (nodeTemplates.isEmpty()) { return Collections.emptyMap(); } return getInstances( - toscaJson, - createdNodesToscaResourceNames, - nodeTemplates + toscaJson, + createdNodesToscaResourceNames, + nodeTemplates ); } private Map getInstances( - Map toscaJson, - Map createdNodesToscaResourceNames, - Map nodeTemplates + Map toscaJson, + Map createdNodesToscaResourceNames, + Map nodeTemplates ) { Map substitutionMappings = getSubstitutionMappings(toscaJson); return nodeTemplates.entrySet().stream() .map(node -> buildModuleComponentInstanceInfo( - node, - substitutionMappings, - createdNodesToscaResourceNames + node, + substitutionMappings, + createdNodesToscaResourceNames )) .collect(Collectors.toMap(UploadComponentInstanceInfo::getName, i -> i)); } @@ -504,7 +503,7 @@ public class YamlTemplateParsingHandler { interfaceDefinition.getOperations() .forEach((operationType, operationValue) -> operationUiList.add(buildOperation(interfaceDefinition.getType(), operationType, (Map) operationValue)) - )); + )); return operationUiList; } @@ -793,9 +792,9 @@ public class YamlTemplateParsingHandler { @SuppressWarnings("unchecked") private UploadComponentInstanceInfo buildModuleComponentInstanceInfo( - Map.Entry nodeTemplateJsonEntry, - Map substitutionMappings, - Map createdNodesToscaResourceNames + Map.Entry nodeTemplateJsonEntry, + Map substitutionMappings, + Map createdNodesToscaResourceNames ) { UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo(); nodeTemplateInfo.setName(nodeTemplateJsonEntry.getKey()); @@ -860,12 +859,12 @@ public class YamlTemplateParsingHandler { } private void updateInterfaces( - UploadComponentInstanceInfo nodeTemplateInfo, - Map nodeTemplateJsonMap - ){ + UploadComponentInstanceInfo nodeTemplateInfo, + Map nodeTemplateJsonMap + ) { if (nodeTemplateJsonMap.containsKey(INTERFACES.getElementName())) { Map interfaces = buildInterfacesModuleFromYaml( - nodeTemplateJsonMap + nodeTemplateJsonMap ); if (!interfaces.isEmpty()) { nodeTemplateInfo.setInterfaces(interfaces); @@ -946,7 +945,8 @@ public class YamlTemplateParsingHandler { return moduleRequirements; } - private void addModuleNodeTemplateReq(Map> moduleRequirements, Object requirementJson, String requirementName, String nodeName) { + private void addModuleNodeTemplateReq(Map> moduleRequirements, Object requirementJson, String requirementName, + String nodeName) { UploadReqInfo requirement = buildModuleNodeTemplateReg(requirementJson, nodeName); requirement.setName(requirementName); if (moduleRequirements.containsKey(requirementName)) { @@ -1107,7 +1107,7 @@ public class YamlTemplateParsingHandler { if (nodeTemplateJsonMap.containsKey(RELATIONSHIP.getElementName())) { final String template = (String) nodeTemplateJsonMap.get(RELATIONSHIP.getElementName()); if (StringUtils.isNotEmpty(nodeName) && template.contains(nodeName)) { - regTemplateInfo.setRelationshipTemplate(template); + regTemplateInfo.setRelationshipTemplate(template); } } } @@ -1115,7 +1115,7 @@ public class YamlTemplateParsingHandler { } private Map buildAttributeModuleFromYaml( - Map nodeTemplateJsonMap) { + Map nodeTemplateJsonMap) { Map moduleAttribute = new HashMap<>(); Either, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(nodeTemplateJsonMap, ATTRIBUTES); if (toscaAttributes.isLeft()) { @@ -1142,7 +1142,7 @@ public class YamlTemplateParsingHandler { } private Map buildInterfacesModuleFromYaml( - Map nodeTemplateJsonMap + Map nodeTemplateJsonMap ) { Map moduleInterfaces = new HashMap<>(); Either, ResultStatusEnum> toscaInterfaces = findFirstToscaMapElement(nodeTemplateJsonMap, INTERFACES); @@ -1286,8 +1286,8 @@ public class YamlTemplateParsingHandler { ) { if (value instanceof Map) { log.debug("Creating interface operation input '{}'", inputName); - Gson gson = new Gson(); - Type type = new TypeToken>(){}.getType(); + Type type = new TypeToken>() { + }.getType(); String stringValue = gson.toJson(value, type); operationInput.setValue(stringValue); } @@ -1307,10 +1307,10 @@ public class YamlTemplateParsingHandler { } final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map && - ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) { - - final Object primary = ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary"); - if(primary instanceof Map) { + ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) { + + final Object primary = ((Map) operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary"); + if (primary instanceof Map) { Map implDetails = (Map) primary; if (implDetails.get("file") != null) { @@ -1324,10 +1324,9 @@ public class YamlTemplateParsingHandler { artifactDataDefinition.setArtifactVersion(implDetails.get("artifact_version").toString()); } - if(implDetails.get("properties") instanceof Map) { - List operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties(); + if (implDetails.get("properties") instanceof Map) { Map properties = (Map) implDetails.get("properties"); - properties.forEach((k,v) -> { + properties.forEach((k, v) -> { ToscaPropertyType type = getTypeFromObject(v); if (type != null) { PropertyDataDefinition propertyDef = new PropertyDataDefinition(); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java index 6bbeed0dd0..474df3f9e5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java @@ -69,8 +69,7 @@ public class CommonImportManager { private final ModelOperation modelOperation; @Autowired - public CommonImportManager(final ComponentsUtils componentsUtils, - final PropertyOperation propertyOperation, + public CommonImportManager(final ComponentsUtils componentsUtils, final PropertyOperation propertyOperation, final ModelOperation modelOperation) { this.componentsUtils = componentsUtils; this.propertyOperation = propertyOperation; @@ -509,8 +508,8 @@ public class CommonImportManager { } private T setNonToscaMetaDataOnType(Map toscaTypeMetadata, T toscaTypeDefinition) { - String toscaType = toscaTypeDefinition.getType(); - ToscaTypeMetadata typeMetaData = toscaTypeMetadata.get(toscaType); + final String toscaType = toscaTypeDefinition.getType(); + final ToscaTypeMetadata typeMetaData = toscaTypeMetadata.get(toscaType); if (typeMetaData == null) { log.debug("failing while trying to associate metadata for type {}. type not exist", toscaType); throw new ByActionStatusComponentException(ActionStatus.GENERAL_ERROR); @@ -538,7 +537,7 @@ public class CommonImportManager { public void addTypesToDefaultImports(final ElementTypeEnum elementTypeEnum, final String typesYaml, final String modelName) { modelOperation.addTypesToDefaultImports(elementTypeEnum, typesYaml, modelName); } - + public void updateTypesInAdditionalTypesImport(final ElementTypeEnum elementTypeEnum, final String dataTypeYml, final String modelName) { modelOperation.updateTypesInAdditionalTypesImport(elementTypeEnum, dataTypeYml, modelName); } @@ -548,7 +547,4 @@ public class CommonImportManager { T3 createElement(T1 firstArg, T2 secondArg); } - - - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java index 9e04572075..ac01be010d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java @@ -3727,7 +3727,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { if (sourceAttributeName.equals(destAttribute.getName())) { log.debug("Start to copy the attribute exists {}", sourceAttributeName); sourceAttribute.setUniqueId( - UniqueIdBuilder.buildResourceInstanceUniuqeId("attribute", destComponentInstanceId.split("\\.")[1], sourceAttributeName)); + UniqueIdBuilder.buildResourceInstanceUniqueId("attribute", destComponentInstanceId.split("\\.")[1], sourceAttributeName)); Either updateAttributeValueEither = createOrUpdateAttributeValueForCopyPaste( ComponentTypeEnum.SERVICE, destComponent.getUniqueId(), destComponentInstanceId, sourceAttribute, userId); if (updateAttributeValueEither.isRight()) { diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java index 135003e7f8..7ed833ac1d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/GroupTypeImportManager.java @@ -33,7 +33,6 @@ import org.apache.commons.lang3.tuple.ImmutablePair; import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.dao.api.ActionStatus; -import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.impl.ComponentsUtils; import org.openecomp.sdc.be.model.CapabilityDefinition; import org.openecomp.sdc.be.model.ComponentInstanceProperty; @@ -73,7 +72,8 @@ public class GroupTypeImportManager { } public Either>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, - String modelName, final boolean includeToModelDefaultImports) { + String modelName, + final boolean includeToModelDefaultImports) { final Either>, ResponseFormat> elementTypes = commonImportManager.createElementTypes( toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName); if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) { @@ -100,7 +100,7 @@ public class GroupTypeImportManager { List groupTypesToCreate, String modelName) { return commonImportManager.createElementTypesWithVersionByDao(groupTypesToCreate, this::validateGroupType, groupType -> new ImmutablePair<>(ElementTypeEnum.GROUP_TYPE, UniqueIdBuilder.buildGroupTypeUid(groupType.getModel(), - groupType.getType(), groupType.getVersion(), NodeTypeEnum.GroupType.getName()).toLowerCase()), + groupType.getType(), groupType.getVersion())), groupTypeOperation::getLatestGroupTypeByType, groupTypeOperation::addGroupType, this::updateGroupType, modelName); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index 1e867e66da..a5e20f30eb 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -36,6 +36,7 @@ import java.util.EnumMap; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -60,6 +61,7 @@ import org.openecomp.sdc.be.components.impl.artifact.ArtifactOperationInfo; import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException; import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException; import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.components.impl.model.ToscaTypeImportData; import org.openecomp.sdc.be.components.impl.utils.CINodeFilterUtils; import org.openecomp.sdc.be.components.impl.utils.CreateServiceFromYamlParameter; import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic; @@ -81,8 +83,8 @@ import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition; import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition; import org.openecomp.sdc.be.datatypes.elements.PolicyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; -import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction; +import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; @@ -102,6 +104,7 @@ import org.openecomp.sdc.be.model.ComponentParametersView; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.DistributionStatusEnum; import org.openecomp.sdc.be.model.GroupDefinition; +import org.openecomp.sdc.be.model.GroupTypeDefinition; import org.openecomp.sdc.be.model.InputDefinition; import org.openecomp.sdc.be.model.InterfaceDefinition; import org.openecomp.sdc.be.model.LifeCycleTransitionEnum; @@ -133,10 +136,12 @@ import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache; import org.openecomp.sdc.be.model.jsonjanusgraph.datamodel.ToscaElement; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; import org.openecomp.sdc.be.model.jsonjanusgraph.utils.ModelConverter; +import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata; import org.openecomp.sdc.be.model.operations.StorageException; import org.openecomp.sdc.be.model.operations.api.IGraphLockOperation; import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus; import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation; +import org.openecomp.sdc.be.model.operations.impl.GroupTypeOperation; import org.openecomp.sdc.be.model.operations.impl.UniqueIdBuilder; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum; @@ -144,6 +149,7 @@ import org.openecomp.sdc.be.tosca.CsarUtils; import org.openecomp.sdc.be.tosca.ToscaExportHandler; import org.openecomp.sdc.be.ui.model.OperationUi; import org.openecomp.sdc.be.utils.TypeUtils; +import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum; import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum; import org.openecomp.sdc.common.api.ArtifactTypeEnum; import org.openecomp.sdc.common.api.Constants; @@ -193,6 +199,9 @@ public class ServiceImportBusinessLogic { private ApplicationDataTypeCache applicationDataTypeCache; private final ArtifactTypeOperation artifactTypeOperation; + private final GroupTypeImportManager groupTypeImportManager; + private final GroupTypeOperation groupTypeOperation; + public ServiceImportBusinessLogic(final GroupBusinessLogic groupBusinessLogic, final ArtifactsBusinessLogic artifactsBusinessLogic, final ComponentsUtils componentsUtils, final ToscaOperationFacade toscaOperationFacade, final ServiceBusinessLogic serviceBusinessLogic, final CsarBusinessLogic csarBusinessLogic, @@ -203,7 +212,8 @@ public class ServiceImportBusinessLogic { final ResourceImportManager resourceImportManager, final JanusGraphDao janusGraphDao, final IGraphLockOperation graphLockOperation, final ToscaFunctionService toscaFunctionService, final DataTypeBusinessLogic dataTypeBusinessLogic, final ArtifactTypeOperation artifactTypeOperation, - ArtifactTypeImportManager artifactTypeImportManager) { + final ArtifactTypeImportManager artifactTypeImportManager, final GroupTypeImportManager groupTypeImportManager, + final GroupTypeOperation groupTypeOperation) { this.componentsUtils = componentsUtils; this.toscaOperationFacade = toscaOperationFacade; this.serviceBusinessLogic = serviceBusinessLogic; @@ -223,6 +233,8 @@ public class ServiceImportBusinessLogic { this.dataTypeBusinessLogic = dataTypeBusinessLogic; this.artifactTypeOperation = artifactTypeOperation; this.artifactTypeImportManager = artifactTypeImportManager; + this.groupTypeImportManager = groupTypeImportManager; + this.groupTypeOperation = groupTypeOperation; } @Autowired @@ -267,19 +279,28 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(dataTypesToCreate)) { dataTypeBusinessLogic.createDataTypeFromYaml(new Yaml().dump(dataTypesToCreate), service.getModel(), true); dataTypesToCreate.entrySet().stream().forEach(createdOrUpdatedDataType -> { - applicationDataTypeCache.reload(service.getModel(), UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey())); + applicationDataTypeCache.reload(service.getModel(), + UniqueIdBuilder.buildDataTypeUid(service.getModel(), createdOrUpdatedDataType.getKey())); }); } final Map artifactTypesToCreate = getArtifactTypesToCreate(service.getModel(), csarInfo); if (MapUtils.isNotEmpty(artifactTypesToCreate)) { - artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), service.getModel(),true); + artifactTypeImportManager.createArtifactTypes(new Yaml().dump(artifactTypesToCreate), service.getModel(), true); } final List nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo); if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) { createNodeTypes(nodeTypesToCreate, service.getModel(), csarInfo.getModifier()); } + + final Map groupTypesToCreate = getGroupTypesToCreate(service.getModel(), csarInfo); + if (MapUtils.isNotEmpty(groupTypesToCreate)) { + final Map toscaTypeMetadata = fillToscaTypeMetadata(groupTypesToCreate); + final ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(new Yaml().dump(groupTypesToCreate), toscaTypeMetadata); + groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true); + } + Map nodeTypesInfo = csarInfo.extractTypesInfo(); Either>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic .findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service); @@ -298,6 +319,47 @@ public class ServiceImportBusinessLogic { } } + private Map fillToscaTypeMetadata(final Map groupTypesToCreate) { + final Map toscaTypeMetadata = new HashMap<>(); + groupTypesToCreate.entrySet().forEach(entry -> { + final ToscaTypeMetadata metadata = new ToscaTypeMetadata(); + metadata.setIcon(getIconFromGroupType(entry.getValue())); + metadata.setDisplayName(extractDisplayName(entry.getKey())); + toscaTypeMetadata.put(entry.getKey(), metadata); + }); + return toscaTypeMetadata; + } + + private String extractDisplayName(final String key) { + final String[] split = key.split("\\."); + return split[split.length - 1]; + } + + private String getIconFromGroupType(final Object value) { + final Either groupType = groupTypeOperation.getLatestGroupTypeByType( + (String) ((LinkedHashMap) value).get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()), null); + if (groupType.isLeft()) { + return groupType.left().value().getIcon(); + } + return null; + } + + private Map getGroupTypesToCreate(final String model, final CsarInfo csarInfo) { + final Map groupTypesToCreate = new HashMap<>(); + final Map groupTypes = csarInfo.getGroupTypes(); + if (MapUtils.isNotEmpty(groupTypes)) { + for (final Entry entry : groupTypes.entrySet()) { + final Either result + = groupTypeOperation.getGroupTypeByUid(UniqueIdBuilder.buildGroupTypeUid(model, entry.getKey(), "1.0")); + if (result.isRight() && result.right().value().equals(StorageOperationStatus.NOT_FOUND)) { + groupTypesToCreate.put(entry.getKey(), entry.getValue()); + log.info("Deploying new group type {} to model {} from package {}", entry.getKey(), model, csarInfo.getCsarUUID()); + } + } + } + return groupTypesToCreate; + } + private Map getDatatypesToCreate(final String model, final CsarInfo csarInfo) { final Map dataTypesToCreate = new HashMap<>(); @@ -306,11 +368,11 @@ public class ServiceImportBusinessLogic { UniqueIdBuilder.buildDataTypeUid(model, dataTypeEntry.getKey())); if (result.isRight() && result.right().value().equals(JanusGraphOperationStatus.NOT_FOUND)) { dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue()); - log.info("Deploying unknown type " + dataTypeEntry.getKey() + " to model " + model + " from package " + csarInfo.getCsarUUID()); + log.info("Deploying unknown type {} to model {} from package {}", dataTypeEntry.getKey(), model, csarInfo.getCsarUUID()); } if (hasNewProperties(result, (Map>) dataTypeEntry.getValue())) { dataTypesToCreate.put(dataTypeEntry.getKey(), dataTypeEntry.getValue()); - log.info("Deploying new version of type " + dataTypeEntry.getKey() + " to model " + model + " from package " + csarInfo.getCsarUUID()); + log.info("Deploying new version of type {} to model {} from package {}", dataTypeEntry.getKey(), model, csarInfo.getCsarUUID()); } } return dataTypesToCreate; @@ -322,7 +384,7 @@ public class ServiceImportBusinessLogic { if (MapUtils.isNotEmpty(artifactTypesMap)) { for (final Entry artifactTypeEntry : artifactTypesMap.entrySet()) { final Either result = - artifactTypeOperation.getArtifactTypeByUid(UniqueIdBuilder.buildArtifactTypeUid(model,artifactTypeEntry.getKey())); + artifactTypeOperation.getArtifactTypeByUid(UniqueIdBuilder.buildArtifactTypeUid(model, artifactTypeEntry.getKey())); if (result.isRight() && StorageOperationStatus.NOT_FOUND.equals(result.right().value())) { artifactTypesToCreate.put(artifactTypeEntry.getKey(), artifactTypeEntry.getValue()); log.info("Deploying new artifact type={}, to model={}, from package={}", @@ -332,10 +394,11 @@ public class ServiceImportBusinessLogic { } return artifactTypesToCreate; } - - private boolean hasNewProperties(final Either result, final Map> dataType) { + + private boolean hasNewProperties(final Either result, + final Map> dataType) { return result.isLeft() && dataType.containsKey("properties") && result.left().value().getProperties() != null - && result.left().value().getProperties().size() != dataType.get("properties").size(); + && result.left().value().getProperties().size() != dataType.get("properties").size(); } private void createNodeTypes(List nodeTypesToCreate, String model, User user) { @@ -347,7 +410,7 @@ public class ServiceImportBusinessLogic { nodeTypeMetadataList.add(nodeType.getNodeTypeMetadata()); }); nodeTypesMetadataList.setNodeMetadataList(nodeTypeMetadataList); - resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, user, model,true, false); + resourceImportManager.importAllNormativeResource(allTypesToCreate, nodeTypesMetadataList, user, model, true, false); } private List getNodeTypesToCreate(final String model, final ServiceCsarInfo csarInfo) { @@ -361,10 +424,10 @@ public class ServiceImportBusinessLogic { } else if (result.isLeft()) { Resource latestResource = (Resource) result.left().value(); Entry latestMappedToscaTemplate = getResourceToscaTemplate(latestResource.getUniqueId(), - latestResource.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE), csarInfo.getModifier().getUserId()); + latestResource.getToscaArtifacts().get(ToscaExportHandler.ASSET_TOSCA_TEMPLATE), csarInfo.getModifier().getUserId()); Map mappedToscaTemplate = (Map) nodeTypeDefinition.getMappedNodeType().getValue(); Map newMappedToscaTemplate = - getNewChangesToToscaTemplate(mappedToscaTemplate, (Map) latestMappedToscaTemplate.getValue()); + getNewChangesToToscaTemplate(mappedToscaTemplate, (Map) latestMappedToscaTemplate.getValue()); if (!newMappedToscaTemplate.equals(latestMappedToscaTemplate.getValue())) { latestMappedToscaTemplate.setValue(newMappedToscaTemplate); nodeTypeDefinition.setMappedNodeType(latestMappedToscaTemplate); @@ -378,15 +441,14 @@ public class ServiceImportBusinessLogic { private Entry getResourceToscaTemplate(String uniqueId, ArtifactDefinition assetToscaTemplate, String userId) { String assetToToscaTemplate = assetToscaTemplate.getUniqueId(); ImmutablePair toscaTemplate = artifactsBusinessLogic. - handleDownloadRequestById(uniqueId, assetToToscaTemplate, userId, ComponentTypeEnum.RESOURCE, null, null); + handleDownloadRequestById(uniqueId, assetToToscaTemplate, userId, ComponentTypeEnum.RESOURCE, null, null); Map mappedToscaTemplate = new Yaml().load(new String(toscaTemplate.right)); Either, ImportUtils.ResultStatusEnum> eitherNodeTypes = - findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES); + findFirstToscaMapElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES); if (eitherNodeTypes.isRight()) { throw new ComponentException(ActionStatus.INVALID_TOSCA_TEMPLATE); } - Entry entry = eitherNodeTypes.left().value().entrySet().iterator().next(); - return entry; + return eitherNodeTypes.left().value().entrySet().iterator().next(); } private Map getNewChangesToToscaTemplate(Map mappedToscaTemplate, Map latestMappedToscaTemplate) { @@ -1929,9 +1991,9 @@ public class ServiceImportBusinessLogic { } final var property = new ComponentInstanceProperty(curPropertyDef, value, null); String validatedPropValue = serviceBusinessLogic.validatePropValueBeforeCreate(property, value, true, allDataTypes); - + addSubPropertyYamlToscaFunctions(validatedPropValue, value, property.getType(), propertyInfo, allDataTypes); - + if (CollectionUtils.isNotEmpty(propertyInfo.getSubPropertyToscaFunctions())) { validatedPropValue = value; } @@ -1984,12 +2046,14 @@ public class ServiceImportBusinessLogic { instProperties.put(currentCompInstance.getUniqueId(), instPropList); return componentsUtils.getResponseFormat(ActionStatus.OK); } - + private boolean tryHandlingAsYamlToscaFunction(String validatedPropValue, String value, UploadPropInfo propertyInfo) { - return StringUtils.isEmpty(validatedPropValue) && StringUtils.isNotEmpty(value) && propertyInfo.getToscaFunction() == null && CollectionUtils.isEmpty(propertyInfo.getSubPropertyToscaFunctions()); + return StringUtils.isEmpty(validatedPropValue) && StringUtils.isNotEmpty(value) && propertyInfo.getToscaFunction() == null + && CollectionUtils.isEmpty(propertyInfo.getSubPropertyToscaFunctions()); } - - private void addSubPropertyYamlToscaFunctions(final String validatedPropValue, final String value, final String propertyType, final UploadPropInfo propertyInfo, final Map allDataTypes) { + + private void addSubPropertyYamlToscaFunctions(final String validatedPropValue, final String value, final String propertyType, + final UploadPropInfo propertyInfo, final Map allDataTypes) { if (StringUtils.isNotEmpty(validatedPropValue) || StringUtils.isEmpty(value) || ToscaPropertyType.isValidType(propertyType) != null) { return; } @@ -1998,14 +2062,14 @@ public class ServiceImportBusinessLogic { final DataTypeDefinition dataTypeDefinition = allDataTypes.get(propertyType); final List propertyNames = - dataTypeDefinition.getProperties().stream().map(PropertyDataDefinition::getName).collect(Collectors.toList()); + dataTypeDefinition.getProperties().stream().map(PropertyDataDefinition::getName).collect(Collectors.toList()); boolean hasSubPropertyValues = jsonObject.entrySet().stream().allMatch(entry -> propertyNames.contains(entry.getKey())); if (hasSubPropertyValues) { for (final PropertyDefinition prop : dataTypeDefinition.getProperties()) { if (propertyInfo.getSubPropertyToscaFunctions().stream() - .anyMatch(subPropertyToscaFunction -> subPropertyToscaFunction.getSubPropertyPath().get(0).equals(prop.getName()))) { + .anyMatch(subPropertyToscaFunction -> subPropertyToscaFunction.getSubPropertyPath().get(0).equals(prop.getName()))) { continue; } Optional subPropertyToscaFunction = createSubPropertyYamlToscaFunction(jsonObject, prop, allDataTypes); @@ -2018,14 +2082,15 @@ public class ServiceImportBusinessLogic { log.info("Cannot create YAML value for {}", value); } } - - private Optional createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop, final Map allDataTypes) { + + private Optional createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop, + final Map allDataTypes) { JsonElement propJsonElement = jsonObject.get(prop.getName()); if (propJsonElement != null) { final String subPropValue = propJsonElement.toString(); final ComponentInstanceProperty subProperty = new ComponentInstanceProperty(prop, subPropValue, null); final String validateSubPropValue = - serviceBusinessLogic.validatePropValueBeforeCreate(subProperty, subPropValue, true, allDataTypes); + serviceBusinessLogic.validatePropValueBeforeCreate(subProperty, subPropValue, true, allDataTypes); if (StringUtils.isEmpty(validateSubPropValue) && StringUtils.isNotEmpty(subPropValue)) { try { @@ -2114,7 +2179,7 @@ public class ServiceImportBusinessLogic { private void mergeOperationInputDefinitions(ListDataDefinition inputsFromNodeType, ListDataDefinition instanceInputs) { if (inputsFromNodeType == null || CollectionUtils.isEmpty(inputsFromNodeType.getListToscaDataDefinition()) || instanceInputs == null - || CollectionUtils.isEmpty(instanceInputs.getListToscaDataDefinition())) { + || CollectionUtils.isEmpty(instanceInputs.getListToscaDataDefinition())) { return; } instanceInputs.getListToscaDataDefinition().forEach( diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/model/ToscaTypeImportData.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/model/ToscaTypeImportData.java index a5416dd73d..61757956ff 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/model/ToscaTypeImportData.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/model/ToscaTypeImportData.java @@ -20,23 +20,18 @@ package org.openecomp.sdc.be.components.impl.model; import java.util.Map; +import lombok.Getter; import org.openecomp.sdc.be.model.normatives.ToscaTypeMetadata; +@Getter public class ToscaTypeImportData { - private String toscaTypesYml; - private Map toscaTypeMetadata; + private final String toscaTypesYml; + private final Map toscaTypeMetadata; public ToscaTypeImportData(String toscaTypesYml, Map toscaTypeMetadata) { this.toscaTypesYml = toscaTypesYml; this.toscaTypeMetadata = toscaTypeMetadata; } - public String getToscaTypesYml() { - return toscaTypesYml; - } - - public Map getToscaTypeMetadata() { - return toscaTypeMetadata; - } } -- cgit 1.2.3-korg