diff options
Diffstat (limited to 'catalog-be/src/main')
9 files changed, 221 insertions, 148 deletions
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<String, Resource> createdNodes; - protected Map<String, Object> datatypeDefinitions; protected Map<String, Object> artifacttypeDefinitions; private Map<String, Object> policytypeDefinitions; - - public CsarInfo(User modifier, String csarUUID, Map<String, byte[]> csar, String vfResourceName, String mainTemplateName, - String mainTemplateContent, boolean isUpdate) { + protected CsarInfo(User modifier, String csarUUID, Map<String, byte[]> 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<String, byte[]> 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<String, byte[]> 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<String, NodeTypeInfo> 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<String, Object> getDataTypes(); + public abstract Map<String, Object> getGroupTypes(); + public abstract Map<String, Object> getArtifactTypes(); public Map<String, Object> getPolicyTypes() { @@ -188,11 +188,10 @@ public abstract class CsarInfo { } return policytypeDefinitions; } - + @SuppressWarnings("unchecked") protected Map<String, Object> getTypesFromTemplate(final Map<String, Object> mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type) { - final Either<Object, ResultStatusEnum> dataTypesEither = findToscaElement(mappedToscaTemplate, type, - ToscaElementTypeEnum.MAP); + final Either<Object, ResultStatusEnum> dataTypesEither = findToscaElement(mappedToscaTemplate, type, ToscaElementTypeEnum.MAP); if (dataTypesEither != null && dataTypesEither.isLeft()) { return (Map<String, Object>) dataTypesEither.left().value(); } @@ -200,15 +199,14 @@ public abstract class CsarInfo { } @SuppressWarnings("unchecked") - protected Map<String, Object> getTypesFromTemplate(final Map<String, Object> mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type, Collection<String> names) { + protected Map<String, Object> getTypesFromTemplate(final Map<String, Object> mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum type, + Collection<String> names) { Map<String, Object> allTypes = getTypesFromTemplate(mappedToscaTemplate, type); final Map<String, Object> typesToReturn = new HashMap<>(); final Stream<Map.Entry<String, Object>> 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<String, Object> nodeType, final String templateFileName, - final Map<String, Object> mappedToscaTemplate) { + final Map<String, Object> 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<String, byte[]> 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<String, byte[]> 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<String, NodeTypeInfo> nodeTypesInfo, final Set<String> nodeTypesUsedInNodeTemplates, - final Map.Entry<String, byte[]> entry) { + final Map.Entry<String, byte[]> entry) { if (isAServiceTemplate(entry.getKey()) && !isGlobalSubstitute(entry.getKey())) { final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(new String(entry.getValue())); findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.SUBSTITUTION_MAPPINGS, ToscaElementTypeEnum.MAP).right() - .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map<String, Object>) sub)); + .on(sub -> handleSubstitutionMappings(nodeTypesInfo, entry, mappedToscaTemplate, (Map<String, Object>) sub)); final Either<Object, ResultStatusEnum> nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map<String, Map<String, Object>> nodeTemplates = (Map<String, Map<String, Object>>) 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<String, NodeTypeInfo> nodeTypesInfo, final Map.Entry<String, byte[]> entry, - final Map<String, Object> mappedToscaTemplate, final Map<String, Object> substitutionMappings) { + final Map<String, Object> mappedToscaTemplate, + final Map<String, Object> substitutionMappings) { final Set<String> 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<String> findNodeTypesDefinedInTemplate(final Map<String, Object> mappedToscaTemplate) { final Either<Object, ResultStatusEnum> nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map<String, Object> nodeTypes = (Map<String, Object>) nodeTypesEither.left().value(); return nodeTypes.keySet(); @@ -149,7 +153,7 @@ public class OnboardedCsarInfo extends CsarInfo { final String yamlFileContents = new String(entry.getValue()); final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents); Either<Object, ResultStatusEnum> nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { Map<String, Object> nodeTypes = (Map<String, Object>) nodeTypesEither.left().value(); for (Map.Entry<String, Object> nodeType : nodeTypes.entrySet()) { @@ -174,9 +178,9 @@ public class OnboardedCsarInfo extends CsarInfo { private void addGlobalSubstitutionsToNodeTypes(final Set<String> nodeTypesUsedInNodeTemplates, final Map<String, NodeTypeInfo> nodeTypesInfo) { for (Map.Entry<String, byte[]> entry : globalSubstitutes) { final String yamlFileContents = new String(entry.getValue()); - final Map<String, Object> mappedToscaTemplate = (Map<String, Object>) new Yaml().load(yamlFileContents); + final Map<String, Object> mappedToscaTemplate = new Yaml().load(yamlFileContents); final Either<Object, ResultStatusEnum> nodeTypesEither = - findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); + findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TYPES, ToscaElementTypeEnum.MAP); if (nodeTypesEither.isLeft()) { final Map<String, Object> nodeTypes = (Map<String, Object>) nodeTypesEither.left().value(); for (final Map.Entry<String, Object> nodeType : nodeTypes.entrySet()) { @@ -204,16 +208,22 @@ public class OnboardedCsarInfo extends CsarInfo { @Override public Map<String, Object> getDataTypes() { - if (datatypeDefinitions == null) { - datatypeDefinitions = new HashMap<>(); - for (Map.Entry<String, byte[]> entry : globalSubstitutes) { - final String yamlFileContents = new String(entry.getValue()); - final Map<String, Object> 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<String, Object> getGroupTypes() { + return getTypes(GROUP_TYPES); + } + + private Map<String, Object> getTypes(ToscaTagNamesEnum toscaTag) { + final Map<String, Object> types = new HashMap<>(); + for (Map.Entry<String, byte[]> entry : globalSubstitutes) { + final Map<String, Object> 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<Path> 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<String, Object> 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<String, Object> 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<Path> 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<String, Object> getDataTypes() { - final Map<String, Object> 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<String, Object> getGroupTypes() { + return getTypes(ToscaTagNamesEnum.GROUP_TYPES); + } + + private Map<String, Object> getTypes(ToscaTagNamesEnum toscaTag) { + final Map<String, Object> types = new HashMap<>(); + mainTemplateImports.entrySet().stream().forEach(entry -> types.putAll(getTypesFromTemplate(entry.getValue(), toscaTag))); + types.putAll(getTypesFromTemplate(getMappedToscaMainTemplate(), toscaTag)); + return types; } public Map<String, Object> getArtifactTypes() { @@ -210,7 +219,7 @@ public class ServiceCsarInfo extends CsarInfo { findToscaElement((Map<String, Object>) 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<String, Object> mappedResourceTemplate, String nodeTemplateType) { NodeTypeMetadata nodeTypeMetadata = new NodeTypeMetadata(); - Either<Map<String, Object>, ImportUtils.ResultStatusEnum> metadataEither = ImportUtils.findFirstToscaMapElement(mappedResourceTemplate, TypeUtils.ToscaTagNamesEnum.METADATA); + Either<Map<String, Object>, ImportUtils.ResultStatusEnum> metadataEither = ImportUtils.findFirstToscaMapElement(mappedResourceTemplate, + TypeUtils.ToscaTagNamesEnum.METADATA); if (metadataEither.isLeft() && metadataEither.left().value().get("type").equals(ResourceTypeEnum.VFC.getValue())) { Map<String, Object> 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<String, Object> metadata, String nodeTemplateType) { + private void createMetadataFromTemplate(NodeTypeMetadata nodeTypeMetadata, Map<String, Object> 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<String, UploadComponentInstanceInfo> getInstances( - Map<String, Object> toscaJson, - Map<String, String> createdNodesToscaResourceNames + Map<String, Object> toscaJson, + Map<String, String> createdNodesToscaResourceNames ) { Map<String, Object> 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<String, UploadComponentInstanceInfo> getInstances( - Map<String, Object> toscaJson, - Map<String, String> createdNodesToscaResourceNames, - Map<String, Object> nodeTemplates + Map<String, Object> toscaJson, + Map<String, String> createdNodesToscaResourceNames, + Map<String, Object> nodeTemplates ) { Map<String, Object> 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<String, Object>) operationValue)) - )); + )); return operationUiList; } @@ -793,9 +792,9 @@ public class YamlTemplateParsingHandler { @SuppressWarnings("unchecked") private UploadComponentInstanceInfo buildModuleComponentInstanceInfo( - Map.Entry<String, Object> nodeTemplateJsonEntry, - Map<String, Object> substitutionMappings, - Map<String, String> createdNodesToscaResourceNames + Map.Entry<String, Object> nodeTemplateJsonEntry, + Map<String, Object> substitutionMappings, + Map<String, String> createdNodesToscaResourceNames ) { UploadComponentInstanceInfo nodeTemplateInfo = new UploadComponentInstanceInfo(); nodeTemplateInfo.setName(nodeTemplateJsonEntry.getKey()); @@ -860,12 +859,12 @@ public class YamlTemplateParsingHandler { } private void updateInterfaces( - UploadComponentInstanceInfo nodeTemplateInfo, - Map<String, Object> nodeTemplateJsonMap - ){ + UploadComponentInstanceInfo nodeTemplateInfo, + Map<String, Object> nodeTemplateJsonMap + ) { if (nodeTemplateJsonMap.containsKey(INTERFACES.getElementName())) { Map<String, UploadInterfaceInfo> interfaces = buildInterfacesModuleFromYaml( - nodeTemplateJsonMap + nodeTemplateJsonMap ); if (!interfaces.isEmpty()) { nodeTemplateInfo.setInterfaces(interfaces); @@ -946,7 +945,8 @@ public class YamlTemplateParsingHandler { return moduleRequirements; } - private void addModuleNodeTemplateReq(Map<String, List<UploadReqInfo>> moduleRequirements, Object requirementJson, String requirementName, String nodeName) { + private void addModuleNodeTemplateReq(Map<String, List<UploadReqInfo>> 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<String, UploadAttributeInfo> buildAttributeModuleFromYaml( - Map<String, Object> nodeTemplateJsonMap) { + Map<String, Object> nodeTemplateJsonMap) { Map<String, UploadAttributeInfo> moduleAttribute = new HashMap<>(); Either<Map<String, Object>, ResultStatusEnum> toscaAttributes = findFirstToscaMapElement(nodeTemplateJsonMap, ATTRIBUTES); if (toscaAttributes.isLeft()) { @@ -1142,7 +1142,7 @@ public class YamlTemplateParsingHandler { } private Map<String, UploadInterfaceInfo> buildInterfacesModuleFromYaml( - Map<String, Object> nodeTemplateJsonMap + Map<String, Object> nodeTemplateJsonMap ) { Map<String, UploadInterfaceInfo> moduleInterfaces = new HashMap<>(); Either<Map<String, Object>, 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<LinkedHashMap<String, Object>>(){}.getType(); + Type type = new TypeToken<LinkedHashMap<String, Object>>() { + }.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<String, Object> 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<PropertyDataDefinition> operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties(); + if (implDetails.get("properties") instanceof Map) { Map<String, Object> properties = (Map<String, Object>) 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 extends ToscaTypeDataDefinition> T setNonToscaMetaDataOnType(Map<String, ToscaTypeMetadata> 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<ComponentInstanceAttribute, ResponseFormat> 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<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> createGroupTypes(ToscaTypeImportData toscaTypeImportData, - String modelName, final boolean includeToModelDefaultImports) { + String modelName, + final boolean includeToModelDefaultImports) { final Either<List<ImmutablePair<GroupTypeDefinition, Boolean>>, ResponseFormat> elementTypes = commonImportManager.createElementTypes( toscaTypeImportData, this::createGroupTypesFromYml, this::upsertGroupTypesByDao, modelName); if (includeToModelDefaultImports && StringUtils.isNotEmpty(modelName)) { @@ -100,7 +100,7 @@ public class GroupTypeImportManager { List<GroupTypeDefinition> 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<String, Object> 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<NodeTypeDefinition> nodeTypesToCreate = getNodeTypesToCreate(service.getModel(), csarInfo); if (CollectionUtils.isNotEmpty(nodeTypesToCreate)) { createNodeTypes(nodeTypesToCreate, service.getModel(), csarInfo.getModifier()); } + + final Map<String, Object> groupTypesToCreate = getGroupTypesToCreate(service.getModel(), csarInfo); + if (MapUtils.isNotEmpty(groupTypesToCreate)) { + final Map<String, ToscaTypeMetadata> toscaTypeMetadata = fillToscaTypeMetadata(groupTypesToCreate); + final ToscaTypeImportData toscaTypeImportData = new ToscaTypeImportData(new Yaml().dump(groupTypesToCreate), toscaTypeMetadata); + groupTypeImportManager.createGroupTypes(toscaTypeImportData, service.getModel(), true); + } + Map<String, NodeTypeInfo> nodeTypesInfo = csarInfo.extractTypesInfo(); Either<Map<String, EnumMap<ArtifactOperationEnum, List<ArtifactDefinition>>>, ResponseFormat> findNodeTypesArtifactsToHandleRes = serviceImportParseLogic .findNodeTypesArtifactsToHandle(nodeTypesInfo, csarInfo, service); @@ -298,6 +319,47 @@ public class ServiceImportBusinessLogic { } } + private Map<String, ToscaTypeMetadata> fillToscaTypeMetadata(final Map<String, Object> groupTypesToCreate) { + final Map<String, ToscaTypeMetadata> 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<GroupTypeDefinition, StorageOperationStatus> groupType = groupTypeOperation.getLatestGroupTypeByType( + (String) ((LinkedHashMap) value).get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()), null); + if (groupType.isLeft()) { + return groupType.left().value().getIcon(); + } + return null; + } + + private Map<String, Object> getGroupTypesToCreate(final String model, final CsarInfo csarInfo) { + final Map<String, Object> groupTypesToCreate = new HashMap<>(); + final Map<String, Object> groupTypes = csarInfo.getGroupTypes(); + if (MapUtils.isNotEmpty(groupTypes)) { + for (final Entry<String, Object> entry : groupTypes.entrySet()) { + final Either<GroupTypeDefinition, StorageOperationStatus> 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<String, Object> getDatatypesToCreate(final String model, final CsarInfo csarInfo) { final Map<String, Object> 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<String, Map<String, Object>>) 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<String, Object> artifactTypeEntry : artifactTypesMap.entrySet()) { final Either<ArtifactTypeDefinition, StorageOperationStatus> 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<DataTypeDefinition, JanusGraphOperationStatus> result, final Map<String, Map<String, Object>> dataType) { + + private boolean hasNewProperties(final Either<DataTypeDefinition, JanusGraphOperationStatus> result, + final Map<String, Map<String, Object>> 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<NodeTypeDefinition> 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<NodeTypeDefinition> 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<String, Object> 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<String, Object> mappedToscaTemplate = (Map<String, Object>) nodeTypeDefinition.getMappedNodeType().getValue(); Map<String, Object> newMappedToscaTemplate = - getNewChangesToToscaTemplate(mappedToscaTemplate, (Map<String, Object>) latestMappedToscaTemplate.getValue()); + getNewChangesToToscaTemplate(mappedToscaTemplate, (Map<String, Object>) latestMappedToscaTemplate.getValue()); if (!newMappedToscaTemplate.equals(latestMappedToscaTemplate.getValue())) { latestMappedToscaTemplate.setValue(newMappedToscaTemplate); nodeTypeDefinition.setMappedNodeType(latestMappedToscaTemplate); @@ -378,15 +441,14 @@ public class ServiceImportBusinessLogic { private Entry<String, Object> getResourceToscaTemplate(String uniqueId, ArtifactDefinition assetToscaTemplate, String userId) { String assetToToscaTemplate = assetToscaTemplate.getUniqueId(); ImmutablePair<String, byte[]> toscaTemplate = artifactsBusinessLogic. - handleDownloadRequestById(uniqueId, assetToToscaTemplate, userId, ComponentTypeEnum.RESOURCE, null, null); + handleDownloadRequestById(uniqueId, assetToToscaTemplate, userId, ComponentTypeEnum.RESOURCE, null, null); Map<String, Object> mappedToscaTemplate = new Yaml().load(new String(toscaTemplate.right)); Either<Map<String, Object>, 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<String, Object> entry = eitherNodeTypes.left().value().entrySet().iterator().next(); - return entry; + return eitherNodeTypes.left().value().entrySet().iterator().next(); } private Map<String, Object> getNewChangesToToscaTemplate(Map<String, Object> mappedToscaTemplate, Map<String, Object> 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<String, DataTypeDefinition> allDataTypes) { + + private void addSubPropertyYamlToscaFunctions(final String validatedPropValue, final String value, final String propertyType, + final UploadPropInfo propertyInfo, final Map<String, DataTypeDefinition> 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<String> 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> subPropertyToscaFunction = createSubPropertyYamlToscaFunction(jsonObject, prop, allDataTypes); @@ -2018,14 +2082,15 @@ public class ServiceImportBusinessLogic { log.info("Cannot create YAML value for {}", value); } } - - private Optional<SubPropertyToscaFunction> createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop, final Map<String, DataTypeDefinition> allDataTypes) { + + private Optional<SubPropertyToscaFunction> createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop, + final Map<String, DataTypeDefinition> 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<OperationInputDefinition> inputsFromNodeType, ListDataDefinition<OperationInputDefinition> 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<String, ToscaTypeMetadata> toscaTypeMetadata; + private final String toscaTypesYml; + private final Map<String, ToscaTypeMetadata> toscaTypeMetadata; public ToscaTypeImportData(String toscaTypesYml, Map<String, ToscaTypeMetadata> toscaTypeMetadata) { this.toscaTypesYml = toscaTypesYml; this.toscaTypeMetadata = toscaTypeMetadata; } - public String getToscaTypesYml() { - return toscaTypesYml; - } - - public Map<String, ToscaTypeMetadata> getToscaTypeMetadata() { - return toscaTypeMetadata; - } } |