aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-model/src/main
diff options
context:
space:
mode:
authorJvD_Ericsson <jeff.van.dam@est.tech>2023-01-26 15:53:57 +0000
committerJvD_Ericsson <jeff.van.dam@est.tech>2023-01-27 12:20:26 +0000
commitaa14db6b062be61ae8cba2bda1bb1aae6737d790 (patch)
tree89f7aa728b549b7b1605c188230c446546aa4bad /catalog-model/src/main
parentea6f082cd544f72400ac3e9eedb28880ebd9ccf0 (diff)
Fix added datatype property not include in model definitions
Issue-ID: SDC-4349 Signed-off-by: JvD_Ericsson <jeff.van.dam@est.tech> Change-Id: Ie94d697a64816f83be4783f1e52657b7fdd77b8c
Diffstat (limited to 'catalog-model/src/main')
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java5
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java64
2 files changed, 67 insertions, 2 deletions
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
index 7d01f3f273..103221cb76 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/DataTypeOperation.java
@@ -50,6 +50,7 @@ import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.mapper.PropertyDefinitionDtoMapper;
+import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.DataTypeData;
import org.openecomp.sdc.be.resources.data.PropertyData;
@@ -279,4 +280,8 @@ public class DataTypeOperation extends AbstractOperation {
return PropertyDefinitionDtoMapper.mapFrom(propertyDataDefinition);
}
+ public void addPropertyToAdditionalTypeDataType(DataTypeDataDefinition dataTypeDataDefinition, PropertyDefinitionDto property) {
+ modelOperation.addPropertyToAdditionalType(ElementTypeEnum.DATA_TYPE, property, dataTypeDataDefinition.getModel(), dataTypeDataDefinition.getName());
+ }
+
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
index 8baa9a73c0..2e35c30e06 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/operations/impl/ModelOperation.java
@@ -54,14 +54,15 @@ import org.openecomp.sdc.be.data.model.ToscaImportByModel;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.ModelTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
-import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.Model;
+import org.openecomp.sdc.be.model.dto.PropertyDefinitionDto;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.ModelOperationExceptionSupplier;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.exception.OperationException;
import org.openecomp.sdc.be.model.normatives.ElementTypeEnum;
import org.openecomp.sdc.be.model.operations.api.DerivedFromOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.resources.data.ModelData;
+import org.openecomp.sdc.be.utils.TypeUtils;
import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -424,10 +425,69 @@ public class ModelOperation {
final List<ToscaImportByModel> modelImportList = toscaModelImportCassandraDao.findAllByModel(modelName);
return modelImportList.stream().filter(t -> ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(t.getFullPath()))).findAny();
}
-
+
private Map<String, Object> getExistingTypes(final ElementTypeEnum elementTypeEnum, final ToscaImportByModel additionalTypeDefinitionsImport) {
final Map<String, Object> existingContent = new Yaml().load(additionalTypeDefinitionsImport.getContent());
return (Map<String, Object>) existingContent.get(elementTypeEnum.getToscaEntryName());
}
+ public void addPropertyToAdditionalType(final ElementTypeEnum elementTypeEnum, final PropertyDefinitionDto property,
+ final String modelName, final String name) {
+ final List<ToscaImportByModel> modelImportList = toscaModelImportCassandraDao.findAllByModel(modelName);
+ final Optional<ToscaImportByModel> additionalTypeDefinitionsImportOptional = modelImportList.stream()
+ .filter(t -> ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(t.getFullPath()))).findAny();
+ final ToscaImportByModel additionalTypeDefinitionsImport;
+ final List<ToscaImportByModel> rebuiltModelImportList;
+ if (additionalTypeDefinitionsImportOptional.isEmpty()) {
+ return;
+ }
+ additionalTypeDefinitionsImport = additionalTypeDefinitionsImportOptional.get();
+ rebuiltModelImportList = modelImportList.stream()
+ .filter(toscaImportByModel -> !ADDITIONAL_TYPE_DEFINITIONS_PATH.equals(Path.of(toscaImportByModel.getFullPath())))
+ .collect(Collectors.toList());
+ final Map<String, Object> originalContent = new Yaml().load(additionalTypeDefinitionsImport.getContent());
+ additionalTypeDefinitionsImport.setContent(buildPropertyAdditionalTypeDefinitionContent(elementTypeEnum, name, property, originalContent));
+ rebuiltModelImportList.add(additionalTypeDefinitionsImport);
+ toscaModelImportCassandraDao.saveAll(modelName, rebuiltModelImportList);
+ }
+
+ private String buildPropertyAdditionalTypeDefinitionContent(final ElementTypeEnum elementTypeEnum, final String name,
+ final PropertyDefinitionDto property, final Map<String, Object> originalContent) {
+ final Map<String, Object> originalTypeContent = (Map<String, Object>) originalContent.get(elementTypeEnum.getToscaEntryName());
+ Map<String, Object> typeContent = (Map<String, Object>) originalTypeContent.get(name);
+ Map<String, Object> typeProperties = (Map<String, Object>) typeContent.get("properties");
+ if (typeProperties == null) {
+ typeProperties = new HashMap<>();
+ }
+ Map<String, Object> typeProp = constructProperty(property);
+ typeProperties.put(property.getName(), typeProp);
+ typeContent.put("properties", typeProperties);
+ return new YamlUtil().objectToYaml(originalContent);
+ }
+
+ private Map<String, Object> constructProperty(final PropertyDefinitionDto property) {
+ Map<String, Object> typeProp = new HashMap<>();
+ if (property.getType() != null) {
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName(), property.getType());
+ }
+ if (property.getDescription() != null) {
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.DESCRIPTION.getElementName(), property.getDescription());
+ }
+ Map<String, Object> schema = new HashMap<>();
+ if (property.getSchemaType() != null) {
+ schema.put(TypeUtils.ToscaTagNamesEnum.TYPE.getElementName(), property.getSchemaType());
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.ENTRY_SCHEMA.getElementName(), schema);
+ }
+ if (property.getDefaultValue() != null) {
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.DEFAULT.getElementName(), property.getDefaultValue());
+ }
+ if (property.getRequired() != null) {
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.REQUIRED.getElementName(), property.getRequired());
+ }
+ if (property.getConstraints() != null) {
+ typeProp.put(TypeUtils.ToscaTagNamesEnum.CONSTRAINTS.getElementName(), property.getConstraints());
+ }
+ return typeProp;
+ }
+
}