* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.sdc.be.tosca;
import com.google.gson.JsonElement;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.onap.sdc.tosca.datatypes.model.EntrySchema;
+import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.model.AttributeDefinition;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
final ToscaAttribute toscaAttribute = new ToscaAttribute();
LOGGER.trace("Converting attribute '{}' from type '{}' with default value '{}'", attributeDefinition.getName(), attributeDefinition.getType(),
attributeDefinition.getDefaultValue());
- toscaAttribute.setEntrySchema(convert(attributeDefinition.getEntry_schema()));
+ SchemaDefinition schema = attributeDefinition.getSchema();
+ if (schema != null && schema.getProperty() != null && schema.getProperty().getType() != null
+ && StringUtils.isNotEmpty(schema.getProperty().getType())) {
+ final ToscaSchemaDefinition toscaSchemaDefinition = new ToscaSchemaDefinition();
+ toscaSchemaDefinition.setType(schema.getProperty().getType());
+ toscaSchemaDefinition.setDescription(schema.getProperty().getDescription());
+ toscaAttribute.setEntrySchema(toscaSchemaDefinition);
+ }
toscaAttribute.setType(attributeDefinition.getType());
toscaAttribute.setDescription(attributeDefinition.getDescription());
toscaAttribute.setStatus(attributeDefinition.getStatus());
return toscaAttribute;
}
- private ToscaSchemaDefinition convert(final EntrySchema entrySchema) {
- if (entrySchema == null) {
- return null;
- }
- final ToscaSchemaDefinition toscaSchemaDefinition = new ToscaSchemaDefinition();
- toscaSchemaDefinition.setType(entrySchema.getType());
- toscaSchemaDefinition.setDescription(entrySchema.getDescription());
- return toscaSchemaDefinition;
- }
-
private Object convertToToscaObject(final AttributeDefinition attributeDefinition,
String value,
final boolean preserveEmptyValue) {
return toscaMapValueConverter.handleComplexJsonValue(valueAsJson);
}
//if it is a data type
- return toscaMapValueConverter.convertDataTypeToToscaObject(innerType, dataTypes, null, false, valueAsJson, preserveEmptyValue);
+ return toscaMapValueConverter.convertDataTypeToToscaObject(innerType, dataTypes, null, false, valueAsJson,
+ preserveEmptyValue, false);
} catch (final JsonParseException e) {
final String errorMsg = "Failed to parse json value";
LOGGER.error(EcompLoggerErrorCode.SCHEMA_ERROR, "Attribute Converter", errorMsg, e);
public void convertAndAddValue(final Map<String, Object> attribs,
final AttributeDefinition attribute) {
- final Object convertedValue = convertToToscaObject(attribute, attribute.getDefaultValue(), false);
- if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue)) {
+ final Object convertedValue = convertToToscaObject(attribute, attribute.getValue(), false);
+ if (!ToscaValueBaseConverter.isEmptyObjectValue(convertedValue) && !attribute.isGetOutputAttribute()) {
attribs.put(attribute.getName(), convertedValue);
}
}