aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java61
1 files changed, 36 insertions, 25 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
index 94a7340ff7..cded9ee706 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java
@@ -32,9 +32,7 @@ import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.commons.lang3.text.translate.CharSequenceTranslator;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
-import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.HeatParameterDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
@@ -45,9 +43,11 @@ import org.openecomp.sdc.be.model.operations.impl.PropertyOperation.PropertyCons
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.common.api.ArtifactTypeEnum;
import org.openecomp.sdc.common.util.GsonFactory;
+import org.springframework.beans.factory.config.YamlProcessor;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
+import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.resolver.Resolver;
@@ -61,17 +61,31 @@ public final class ImportUtils {
private ImportUtils() {
}
-
+ public static Yaml STRICT_MAPPING_YAML_LOADER = new YamlLoader().getStrictYamlLoader();
+
private static CustomResolver customResolver = new CustomResolver();
private static class CustomResolver extends Resolver {
+ @Override
protected void addImplicitResolvers() {
- // avoid implicit resolvers
+ // avoid implicit resolvers for strings that can be interpreted as boolean values
+ addImplicitResolver(Tag.STR, EMPTY, "");
+ addImplicitResolver(Tag.STR, NULL, null);
+ addImplicitResolver(Tag.NULL, NULL, "~nN\0");
+ addImplicitResolver(Tag.NULL, EMPTY, null);
+ addImplicitResolver(Tag.YAML, YAML, "!&*");
+ }
+ }
+
+ private static class YamlLoader extends YamlProcessor {
+ public Yaml getStrictYamlLoader() {
+ return createYaml();
}
}
+ @SuppressWarnings("unchecked")
public static Either<List<HeatParameterDefinition>, ResultStatusEnum> getHeatParamsWithoutImplicitTypes(String heatDecodedPayload, String artifactType) {
- Map<String, Object> heatData = (Map<String, Object>) new Yaml(new Constructor(), new Representer(), new DumperOptions(), customResolver).load(heatDecodedPayload);
+ Map<String, Object> heatData = (Map<String, Object>) new Yaml(new Constructor(), new Representer(), new DumperOptions(), customResolver).load(heatDecodedPayload);
return getHeatParameters(heatData, artifactType);
}
@@ -82,6 +96,7 @@ public final class ImportUtils {
public static final String VENDOR_NAME = "ATT (Tosca)";
public static final String VENDOR_RELEASE = "1.0.0.wd03";
public static final LifecycleStateEnum NORMATIVE_TYPE_LIFE_CYCLE = LifecycleStateEnum.CERTIFIED;
+ public static final LifecycleStateEnum NORMATIVE_TYPE_LIFE_CYCLE_NOT_CERTIFIED_CHECKOUT = LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT;
public static final boolean NORMATIVE_TYPE_HIGHEST_VERSION = true;
// public static final String ABSTRACT_CATEGORY = "Generic/Abstract";
public static final String ABSTRACT_CATEGORY_NAME = "Generic";
@@ -92,11 +107,10 @@ public final class ImportUtils {
public static final List<String> TOSCA_DEFINITION_VERSIONS = Arrays.asList(new String[] { "tosca_simple_yaml_1_0_0", "tosca_simple_profile_for_nfv_1_0_0", "tosca_simple_yaml_1_0" });
public static final List<String> TOSCA_YML_CSAR_VALID_SUFFIX = Arrays.asList(new String[] { ".yml", ".yaml", ".csar" });
public static final String UI_JSON_PAYLOAD_NAME = "payloadName";
- public static final String ABSTRACT_NODE = "abstact";
}
public enum ResultStatusEnum {
- ELEMENT_NOT_FOUND, GENERAL_ERROR, OK, INVALID_PROPERTY_DEFAULT_VALUE, INVALID_PROPERTY_TYPE, INVALID_PROPERTY_VALUE, MISSING_ENTRY_SCHEMA_TYPE
+ ELEMENT_NOT_FOUND, GENERAL_ERROR, OK, INVALID_PROPERTY_DEFAULT_VALUE, INVALID_PROPERTY_TYPE, INVALID_PROPERTY_VALUE, MISSING_ENTRY_SCHEMA_TYPE, INVALID_PROPERTY_NAME
}
public enum ToscaElementTypeEnum {
@@ -172,10 +186,7 @@ public final class ImportUtils {
else if (elementType == ToscaElementTypeEnum.ALL) {
if (elementValue != null) {
returnedList.add(String.valueOf(elementValue));
- } else {
- returnedList.add(elementValue);
- }
-
+ }
}
}
@@ -342,9 +353,9 @@ public final class ImportUtils {
return inputDef;
}
- public static AttributeDefinition createModuleAttribute(Map<String, Object> attributeMap) {
+ public static PropertyDefinition createModuleAttribute(Map<String, Object> attributeMap) {
- AttributeDefinition attributeDef = new AttributeDefinition();
+ PropertyDefinition attributeDef = new PropertyDefinition();
ImportUtils.setField(attributeMap, ToscaTagNamesEnum.TYPE, type -> attributeDef.setType(type));
ImportUtils.setField(attributeMap, ToscaTagNamesEnum.DESCRIPTION, desc -> attributeDef.setDescription(desc));
ImportUtils.setField(attributeMap, ToscaTagNamesEnum.STATUS, status -> attributeDef.setStatus(status));
@@ -370,7 +381,7 @@ public final class ImportUtils {
}
- private static void setAttributeFieldStatus(Map<String, Object> propertyValue, AttributeDefinition propertyDef) {
+ private static void setAttributeFieldStatus(Map<String, Object> propertyValue, PropertyDefinition propertyDef) {
Either<String, ResultStatusEnum> propertyFieldIsStatus = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.STATUS);
if (propertyFieldIsStatus.isLeft()) {
propertyDef.setStatus(propertyFieldIsStatus.left().value());
@@ -388,7 +399,7 @@ public final class ImportUtils {
}
- private static void setAttributeScheme(Map<String, Object> propertyValue, AttributeDefinition propertyDefinition) {
+ private static void setAttributeScheme(Map<String, Object> propertyValue, PropertyDefinition propertyDefinition) {
Either<SchemaDefinition, ResultStatusEnum> eitherSchema = getSchema(propertyValue);
if (eitherSchema.isLeft()) {
SchemaDefinition schemaDef = new SchemaDefinition();
@@ -461,7 +472,7 @@ public final class ImportUtils {
return ResultStatusEnum.OK;
}
- private static ResultStatusEnum setAttributeFieldDefaultValue(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ private static ResultStatusEnum setAttributeFieldDefaultValue(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
Either<Object, ResultStatusEnum> propertyFieldDefaultValue = findToscaElement(propertyValue, ToscaTagNamesEnum.DEFAULT_VALUE, ToscaElementTypeEnum.ALL);
Gson gson = GsonFactory.getGson();
if (propertyFieldDefaultValue.isLeft()) {
@@ -515,7 +526,7 @@ public final class ImportUtils {
}
}
- private static void setAttributeFieldType(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ private static void setAttributeFieldType(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
Either<String, ResultStatusEnum> propertyFieldType = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.TYPE);
if (propertyFieldType.isLeft()) {
dataDefinition.setType(propertyFieldType.left().value());
@@ -529,7 +540,7 @@ public final class ImportUtils {
}
}
- private static void setAttributeFieldDescription(Map<String, Object> propertyValue, AttributeDefinition dataDefinition) {
+ private static void setAttributeFieldDescription(Map<String, Object> propertyValue, PropertyDefinition dataDefinition) {
Either<String, ResultStatusEnum> propertyFieldDescription = findFirstToscaStringElement(propertyValue, ToscaTagNamesEnum.DESCRIPTION);
if (propertyFieldDescription.isLeft()) {
dataDefinition.setDescription(propertyFieldDescription.left().value());
@@ -552,9 +563,9 @@ public final class ImportUtils {
}
- public static Either<Map<String, AttributeDefinition>, ResultStatusEnum> getAttributes(Map<String, Object> toscaJson) {
- Function<String, AttributeDefinition> elementGenByName = elementName -> createAttribute(elementName);
- Function<Map<String, Object>, AttributeDefinition> func = map -> createModuleAttribute(map);
+ public static Either<Map<String, PropertyDefinition>, ResultStatusEnum> getAttributes(Map<String, Object> toscaJson) {
+ Function<String, PropertyDefinition> elementGenByName = elementName -> createAttribute(elementName);
+ Function<Map<String, Object>, PropertyDefinition> func = map -> createModuleAttribute(map);
return getElements(toscaJson, ToscaTagNamesEnum.ATTRIBUTES, elementGenByName, func);
}
@@ -591,8 +602,8 @@ public final class ImportUtils {
}
- private static AttributeDefinition createAttribute(String name) {
- AttributeDefinition attribute = new AttributeDefinition();
+ private static PropertyDefinition createAttribute(String name) {
+ PropertyDefinition attribute = new PropertyDefinition();
attribute.setName(name);
return attribute;
@@ -622,7 +633,7 @@ public final class ImportUtils {
Iterator<Entry<String, Object>> propertiesNameValue = jsonProperties.entrySet().iterator();
while (propertiesNameValue.hasNext()) {
Entry<String, Object> propertyNameValue = propertiesNameValue.next();
- if (propertyNameValue.getValue() instanceof Map) {
+ if (propertyNameValue.getValue() instanceof Map || propertyNameValue.getValue() instanceof List) {
if (!artifactType.equals(ArtifactTypeEnum.HEAT_ENV.getType())) {
@SuppressWarnings("unchecked")
Either<HeatParameterDefinition, ResultStatusEnum> propertyStatus = createModuleHeatParameter((Map<String, Object>) propertyNameValue.getValue());
@@ -695,7 +706,7 @@ public final class ImportUtils {
return null;
}
ToscaPropertyType validType = ToscaPropertyType.isValidType(type);
- if (validType == null || validType.equals(ToscaPropertyType.MAP) || validType.equals(ToscaPropertyType.LIST)) {
+ if (validType == null || validType.equals(ToscaPropertyType.JSON) ||validType.equals(ToscaPropertyType.MAP) || validType.equals(ToscaPropertyType.LIST)) {
return gson.toJson(value);
}
return value.toString();