From fbfa96e29315ede4e41d43f6009367282ee46115 Mon Sep 17 00:00:00 2001 From: MichaelMorris Date: Mon, 15 Aug 2022 17:14:13 +0100 Subject: Fix ClassCastException in import Signed-off-by: MichaelMorris Issue-ID: SDC-4133 Change-Id: Ic7ac38dac39ed9b962691390818e18b753f9378e --- .../csar/YamlTemplateParsingHandler.java | 54 ++++++++++++---------- 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'catalog-be') 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 ee31112253..01b62595b8 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 @@ -1255,31 +1255,37 @@ public class YamlTemplateParsingHandler { final ArtifactDataDefinition artifactDataDefinition = new ArtifactDataDefinition(); if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof Map && ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).containsKey("primary")) { - Map implDetails = (Map) ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary"); - - if (implDetails.get("file") != null) { - final String file = implDetails.get("file").toString(); - artifactDataDefinition.setArtifactName(generateArtifactName(file)); - } - if (implDetails.get("type") != null) { - artifactDataDefinition.setArtifactType(implDetails.get("type").toString()); - } - if (implDetails.get("artifact_version") != null) { - artifactDataDefinition.setArtifactVersion(implDetails.get("artifact_version").toString()); - } + + final Object primary = ((Map)operationDefinitionMap.get(IMPLEMENTATION.getElementName())).get("primary"); + if(primary instanceof Map) { + Map implDetails = (Map) primary; + + if (implDetails.get("file") != null) { + final String file = implDetails.get("file").toString(); + artifactDataDefinition.setArtifactName(generateArtifactName(file)); + } + if (implDetails.get("type") != null) { + artifactDataDefinition.setArtifactType(implDetails.get("type").toString()); + } + if (implDetails.get("artifact_version") != null) { + artifactDataDefinition.setArtifactVersion(implDetails.get("artifact_version").toString()); + } - if(implDetails.get("properties") instanceof Map) { - List operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties(); - Map properties = (Map) implDetails.get("properties"); - properties.forEach((k,v) -> { - ToscaPropertyType type = getTypeFromObject(v); - if (type != null) { - PropertyDataDefinition propertyDef = new PropertyDataDefinition(); - propertyDef.setName(k); - propertyDef.setValue(v.toString()); - artifactDataDefinition.addProperty(propertyDef); - } - }); + if(implDetails.get("properties") instanceof Map) { + List operationProperties = artifactDataDefinition.getProperties() == null ? new ArrayList<>() : artifactDataDefinition.getProperties(); + Map properties = (Map) implDetails.get("properties"); + properties.forEach((k,v) -> { + ToscaPropertyType type = getTypeFromObject(v); + if (type != null) { + PropertyDataDefinition propertyDef = new PropertyDataDefinition(); + propertyDef.setName(k); + propertyDef.setValue(v.toString()); + artifactDataDefinition.addProperty(propertyDef); + } + }); + } + } else { + artifactDataDefinition.setArtifactName(generateArtifactName(primary.toString())); } } if (operationDefinitionMap.get(IMPLEMENTATION.getElementName()) instanceof String) { -- cgit 1.2.3-korg