summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2022-03-07 18:48:09 +0000
committerMichael Morris <michael.morris@est.tech>2022-03-11 16:48:13 +0000
commite5488e5e3623646125802b8ab7e12b7159a2c0d3 (patch)
tree58c896b9d2f434041cff1cafad7835dd9cd691f3 /catalog-be/src/main/java
parentf13f58eb867c763e6ed1c3b674fd99b1081a0664 (diff)
Support complex types in artifact properties
Adds support to complex types in artifact properties of an interface operation implementation. Change-Id: I7a82a3652541b35230fe4ce87bf703a1dbe72d50 Issue-ID: SDC-3899 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'catalog-be/src/main/java')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java95
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaArtifactDefinition.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyAssignmentJsonSerializer.java42
3 files changed, 106 insertions, 34 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
index 64e61699ed..b689959572 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/InterfacesOperationsConverter.java
@@ -22,6 +22,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.OPERATIONS;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.gson.Gson;
import java.util.Collections;
import java.util.HashMap;
@@ -38,6 +39,7 @@ import org.apache.commons.lang3.math.NumberUtils;
import org.openecomp.sdc.be.datatypes.elements.InputDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.DataTypeDefinition;
@@ -53,6 +55,8 @@ import org.openecomp.sdc.be.tosca.model.ToscaInterfaceOperationImplementation;
import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignmentJsonSerializer;
import org.openecomp.sdc.be.tosca.utils.OperationArtifactUtil;
import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
@@ -147,12 +151,8 @@ public class InterfacesOperationsConverter {
return toscaResourceName.substring(toscaResourceName.lastIndexOf(DOT) + 1);
}
- private static boolean isArtifactPresent(Map.Entry<String, OperationDataDefinition> operationEntry) {
- final boolean isImplementationPresent = !Objects.isNull(operationEntry.getValue().getImplementation());
- if (isImplementationPresent) {
- return !Objects.isNull(operationEntry.getValue().getImplementation().getArtifactName());
- }
- return false;
+ private static boolean isArtifactPresent(final OperationDataDefinition operationDataDefinition) {
+ return operationDataDefinition.getImplementation() != null && operationDataDefinition.getImplementation().getArtifactName() != null;
}
private static String getInputValue(final OperationInputDefinition input) {
@@ -178,13 +178,22 @@ public class InterfacesOperationsConverter {
return interfaceType;
}
- private static Map<String, Object> getObjectAsMap(Object obj) {
- ObjectMapper objectMapper = new ObjectMapper();
- if (obj instanceof ToscaInterfaceDefinition) {
- //Prevent empty field serialization in interface definition
- objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ private static Map<String, Object> getObjectAsMap(final Object obj) {
+ final Map<String, Object> objectAsMap;
+ if (obj instanceof Map) {
+ objectAsMap = (Map<String, Object>) obj;
+ } else {
+ final ObjectMapper objectMapper = new ObjectMapper();
+ final SimpleModule module = new SimpleModule("ToscaPropertyAssignmentSerializer");
+ module.addSerializer(ToscaPropertyAssignment.class, new ToscaPropertyAssignmentJsonSerializer());
+ objectMapper.registerModule(module);
+ if (obj instanceof ToscaInterfaceDefinition) {
+ //Prevent empty field serialization in interface definition
+ objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+ }
+ objectAsMap = objectMapper.convertValue(obj, Map.class);
}
- Map<String, Object> objectAsMap = obj instanceof Map ? (Map<String, Object>) obj : objectMapper.convertValue(obj, Map.class);
+
final String defaultEntry = DEFAULT.getElementName();
if (objectAsMap.containsKey(defaultEntry)) {
objectAsMap.put(DEFAULT_HAS_UNDERSCORE, objectAsMap.remove(defaultEntry));
@@ -263,10 +272,10 @@ public class InterfacesOperationsConverter {
final Map<String, Object> toscaOperationMap = new HashMap<>();
for (final Entry<String, OperationDataDefinition> operationEntry : operations.entrySet()) {
final ToscaLifecycleOperationDefinition toscaLifecycleOperationDefinition = new ToscaLifecycleOperationDefinition();
- handleInterfaceOperationImplementation(component, componentInstance, isAssociatedComponent, operationEntry,
- toscaLifecycleOperationDefinition);
+ handleInterfaceOperationImplementation(component, componentInstance, isAssociatedComponent, operationEntry.getValue(),
+ toscaLifecycleOperationDefinition, dataTypes);
toscaLifecycleOperationDefinition.setDescription(operationEntry.getValue().getDescription());
- fillToscaOperationInputs(operationEntry.getValue(), dataTypes, toscaLifecycleOperationDefinition, isServiceProxyInterface);
+ fillToscaOperationInputs(operationEntry.getValue(), dataTypes, toscaLifecycleOperationDefinition);
toscaOperationMap.put(operationEntry.getValue().getName(), toscaLifecycleOperationDefinition);
}
toscaInterfaceDefinition.setOperations(toscaOperationMap);
@@ -286,37 +295,56 @@ public class InterfacesOperationsConverter {
private void handleInterfaceOperationImplementation(final Component component, final ComponentInstance componentInstance,
final boolean isAssociatedComponent,
- final Entry<String, OperationDataDefinition> operationEntry,
- final ToscaLifecycleOperationDefinition toscaOperation) {
+ final OperationDataDefinition operationDataDefinition,
+ final ToscaLifecycleOperationDefinition toscaOperation,
+ final Map<String, DataTypeDefinition> dataTypes) {
final String operationArtifactPath;
final ToscaInterfaceOperationImplementation toscaInterfaceOperationImplementation = new ToscaInterfaceOperationImplementation();
toscaInterfaceOperationImplementation.setPrimary(new ToscaArtifactDefinition());
final ToscaArtifactDefinition toscaArtifactDefinition = toscaInterfaceOperationImplementation.getPrimary();
- if (isArtifactPresent(operationEntry) && StringUtils.isNotEmpty(operationEntry.getValue().getImplementation().getArtifactName())) {
+ if (isArtifactPresent(operationDataDefinition) && StringUtils.isNotEmpty(operationDataDefinition.getImplementation().getArtifactName())) {
operationArtifactPath = OperationArtifactUtil
- .createOperationArtifactPath(component, componentInstance, operationEntry.getValue(), isAssociatedComponent);
+ .createOperationArtifactPath(component, componentInstance, operationDataDefinition, isAssociatedComponent);
toscaArtifactDefinition.setFile(operationArtifactPath);
- toscaArtifactDefinition.setArtifact_version(!operationEntry.getValue().getImplementation().getArtifactVersion()
- .equals(NumberUtils.INTEGER_ZERO.toString()) ? operationEntry.getValue().getImplementation().getArtifactVersion() : null);
- toscaArtifactDefinition.setType(operationEntry.getValue().getImplementation().getArtifactType());
- handleInterfaceOperationImplementationProperties(operationEntry, toscaArtifactDefinition);
+ toscaArtifactDefinition.setArtifact_version(!operationDataDefinition.getImplementation().getArtifactVersion()
+ .equals(NumberUtils.INTEGER_ZERO.toString()) ? operationDataDefinition.getImplementation().getArtifactVersion() : null);
+ toscaArtifactDefinition.setType(operationDataDefinition.getImplementation().getArtifactType());
+ final Map<String, ToscaPropertyAssignment> propertiesMap = handleImplementationProperties(operationDataDefinition, dataTypes);
+ if (!propertiesMap.isEmpty()) {
+ toscaArtifactDefinition.setProperties(propertiesMap);
+ }
toscaOperation.setImplementation(
toscaArtifactDefinition.getType() != null ? toscaInterfaceOperationImplementation : operationArtifactPath);
} else {
- toscaArtifactDefinition.setFile(operationEntry.getValue().getImplementation().getArtifactName());
+ toscaArtifactDefinition.setFile(operationDataDefinition.getImplementation().getArtifactName());
toscaOperation.setImplementation(toscaInterfaceOperationImplementation);
}
}
- private void handleInterfaceOperationImplementationProperties(final Entry<String, OperationDataDefinition> operationEntry,
- final ToscaArtifactDefinition toscaArtifactDefinition) {
- final var properties = operationEntry.getValue().getImplementation().getProperties();
- if (CollectionUtils.isNotEmpty(properties)) {
- final Map<String, String> propertiesMap = new HashMap<>();
- properties.stream().filter(propertyDataDefinition -> StringUtils.isNotEmpty(propertyDataDefinition.getValue()))
- .forEach(propertyDataDefinition -> propertiesMap.put(propertyDataDefinition.getName(), propertyDataDefinition.getValue()));
- toscaArtifactDefinition.setProperties(propertiesMap);
+ private Map<String, ToscaPropertyAssignment> handleImplementationProperties(final OperationDataDefinition operationDataDefinition,
+ final Map<String, DataTypeDefinition> dataTypes) {
+ if (operationDataDefinition.getImplementation() == null) {
+ return new HashMap<>();
}
+
+ final List<PropertyDataDefinition> properties = operationDataDefinition.getImplementation().getProperties();
+ if (CollectionUtils.isEmpty(properties)) {
+ return new HashMap<>();
+ }
+
+ final Map<String, ToscaPropertyAssignment> propertiesMap = new HashMap<>();
+ properties.stream()
+ .filter(propertyDataDefinition -> StringUtils.isNotEmpty(propertyDataDefinition.getValue()))
+ .forEach(propertyDataDefinition -> {
+ final String propertyValue =
+ propertyDataDefinition.getValue() != null ? propertyDataDefinition.getValue() : propertyDataDefinition.getDefaultValue();
+ final ToscaPropertyAssignment toscaPropertyAssignment = new ToscaPropertyAssignment();
+ toscaPropertyAssignment.setValue(propertyConvertor.convertToToscaObject(propertyDataDefinition, propertyValue, dataTypes, false));
+ propertiesMap.put(propertyDataDefinition.getName(), toscaPropertyAssignment);
+ }
+ );
+
+ return propertiesMap;
}
public void removeInterfacesWithoutOperations(final Map<String, Object> interfaceMap) {
@@ -373,7 +401,7 @@ public class InterfacesOperationsConverter {
}
private void fillToscaOperationInputs(OperationDataDefinition operation, Map<String, DataTypeDefinition> dataTypes,
- ToscaLifecycleOperationDefinition toscaOperation, boolean isServiceProxyInterface) {
+ ToscaLifecycleOperationDefinition toscaOperation) {
if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) {
toscaOperation.setInputs(null);
return;
@@ -389,4 +417,5 @@ public class InterfacesOperationsConverter {
}
toscaOperation.setInputs(toscaInputs);
}
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaArtifactDefinition.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaArtifactDefinition.java
index 689dc91d23..ac306073c1 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaArtifactDefinition.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaArtifactDefinition.java
@@ -36,5 +36,6 @@ public class ToscaArtifactDefinition {
private String artifact_version;
private String checksum;
private String checksum_algorithm;
- private Map<String, String> properties;
+ private Map<String, ToscaPropertyAssignment> properties;
+
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyAssignmentJsonSerializer.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyAssignmentJsonSerializer.java
new file mode 100644
index 0000000000..9c695f6924
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyAssignmentJsonSerializer.java
@@ -0,0 +1,42 @@
+/*
+ * -
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.be.tosca.model;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.ser.std.StdSerializer;
+import java.io.IOException;
+
+/**
+ * Jackson JSON serializer for the ToscaPropertyAssignment class
+ */
+public class ToscaPropertyAssignmentJsonSerializer extends StdSerializer<ToscaPropertyAssignment> {
+
+ public ToscaPropertyAssignmentJsonSerializer() {
+ super(ToscaPropertyAssignment.class);
+ }
+
+ @Override
+ public void serialize(ToscaPropertyAssignment toscaPropertyAssignment, JsonGenerator gen, SerializerProvider provider) throws IOException {
+ gen.writeObject(toscaPropertyAssignment.getValue());
+ }
+} \ No newline at end of file