summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2022-10-13 14:12:47 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-10-24 15:06:02 +0000
commit2edea35f59360fbc8b4f451fc573e02dc5f65010 (patch)
tree1b1ead43f07d813562b55e9dbad80efcd5308ea8 /catalog-be/src
parentaa361f84ec4d137e7a64df8c7feaec6d2304c03e (diff)
Support import of VFCs with property constraints
Signed-off-by: MichaelMorris <michael.morris@est.tech> Issue-ID: SDC-4216 Change-Id: I19dce9f929535aa22cad6a1d95a213f42dd6e99c
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ImportUtils.java5
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java72
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java51
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java49
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java48
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java50
18 files changed, 595 insertions, 11 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 8ad86b3510..a28d587cae 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
@@ -22,7 +22,6 @@ package org.openecomp.sdc.be.components.impl;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.openecomp.sdc.be.components.impl.ResourceImportManager.PROPERTY_NAME_PATTERN_IGNORE_LENGTH;
import static org.openecomp.sdc.be.datatypes.elements.Annotation.setAnnotationsName;
-
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
@@ -286,7 +285,9 @@ public final class ImportUtils {
final Gson gson = new GsonBuilder().registerTypeAdapter(constraintType, new PropertyConstraintDeserialiser()).create();
for (final Object constraintJson : propertyFieldConstraints) {
final PropertyConstraint propertyConstraint = validateAndGetPropertyConstraint(propertyType, constraintType, gson, constraintJson);
- constraintList.add(propertyConstraint);
+ if (propertyConstraint != null) {
+ constraintList.add(propertyConstraint);
+ }
}
return constraintList;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index 2d3ef85488..4b8d88fa79 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -128,8 +128,7 @@ public class PropertyValueConstraintValidationUtil {
private void evaluateConstraintsOnProperty(PropertyDefinition propertyDefinition) {
ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType());
- if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())
- && isValidValueConstraintPresent(propertyDefinition.getConstraints())) {
+ if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) {
for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) {
try {
propertyConstraint.initialize(toscaType);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
index dec13a94c8..dfe065a79e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/impl/ComponentsUtils.java
@@ -21,6 +21,7 @@
*/
package org.openecomp.sdc.be.impl;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -210,6 +211,7 @@ public class ComponentsUtils {
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
module.addDeserializer(ToscaFunction.class, new ToscaFunctionJsonDeserializer());
mapper.registerModule(module);
+ mapper.setSerializationInclusion(Include.NON_NULL);
component = mapper.readValue(data, clazz);
if (component == null) {
BeEcompErrorManager.getInstance().logBeInvalidJsonInput(CONVERT_JSON_TO_OBJECT);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
index 7c9101df82..2cd2ddf978 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/BeGenericServlet.java
@@ -19,6 +19,7 @@
*/
package org.openecomp.sdc.be.servlets;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
@@ -226,6 +227,7 @@ public class BeGenericServlet extends BasicServlet {
SimpleModule module = new SimpleModule("customDeserializationModule");
module.addDeserializer(PropertyConstraint.class, new PropertyConstraintJacksonDeserializer());
mapper.registerModule(module);
+ mapper.setSerializationInclusion(Include.NON_NULL);
object = mapper.readValue(json, clazz);
if (object != null) {
return object;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
index 148e69907c..90a5161f7a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/PropertyConvertor.java
@@ -26,32 +26,57 @@ import com.google.gson.JsonParser;
import com.google.gson.stream.JsonReader;
import fj.data.Either;
import java.io.StringReader;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Supplier;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.PropertyConstraint;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
+import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.model.tosca.converters.DataTypePropertyConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaMapValueConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueBaseConverter;
import org.openecomp.sdc.be.model.tosca.converters.ToscaValueConverter;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterOrEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintGreaterThan;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintInRange;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessOrEqual;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintLessThan;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMaxLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintMinLength;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraintValidValues;
import org.openecomp.sdc.be.tosca.model.ToscaSchemaDefinition;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.tosca.datatypes.ToscaFunctions;
import org.springframework.stereotype.Service;
import org.yaml.snakeyaml.Yaml;
+
@Service
public class PropertyConvertor {
@@ -102,8 +127,55 @@ public class PropertyConvertor {
prop.setStatus(property.getStatus());
}
prop.setMetadata(property.getMetadata());
+
+ List<ToscaPropertyConstraint> constraints = new ArrayList<>();
+ if (CollectionUtils.isNotEmpty(property.getConstraints())) {
+ constraints = convertConstraints(property.getConstraints());
+ prop.setConstraints(constraints);
+ }
return prop;
}
+
+ private List<ToscaPropertyConstraint> convertConstraints(List<PropertyConstraint> constraints) {
+ List<ToscaPropertyConstraint> convertedConstraints = new ArrayList<>();
+ for (PropertyConstraint constraint: constraints){
+ if (constraint instanceof EqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintEqual(((EqualConstraint) constraint).getEqual()));
+ }
+ if (constraint instanceof GreaterThanConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintGreaterThan(((GreaterThanConstraint) constraint).getGreaterThan()));
+ }
+ if (constraint instanceof GreaterOrEqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintGreaterOrEqual(((GreaterOrEqualConstraint) constraint).getGreaterOrEqual()));
+ }
+ if (constraint instanceof LessThanConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLessThan(((LessThanConstraint) constraint).getLessThan()));
+ }
+ if (constraint instanceof LessOrEqualConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLessOrEqual(((LessOrEqualConstraint) constraint).getLessOrEqual()));
+ }
+ if (constraint instanceof InRangeConstraint) {
+ InRangeConstraint inRangeConstraint = (InRangeConstraint) constraint;
+ List<String> range = new ArrayList<>();
+ range.add(inRangeConstraint.getRangeMinValue());
+ range.add(inRangeConstraint.getRangeMaxValue());
+ convertedConstraints.add(new ToscaPropertyConstraintInRange(range));
+ }
+ if (constraint instanceof ValidValuesConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintValidValues(((ValidValuesConstraint) constraint).getValidValues()));
+ }
+ if (constraint instanceof LengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintLength(((LengthConstraint) constraint).getLength().toString()));
+ }
+ if (constraint instanceof MinLengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintMinLength(((MinLengthConstraint) constraint).getMinLength()));
+ }
+ if (constraint instanceof MaxLengthConstraint) {
+ convertedConstraints.add(new ToscaPropertyConstraintMaxLength(((MaxLengthConstraint) constraint).getMaxLength()));
+ }
+ }
+ return convertedConstraints;
+ }
public Object convertToToscaObject(PropertyDataDefinition property, String value, Map<String, DataTypeDefinition> dataTypes,
boolean preserveEmptyValue) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 85f29bf352..5f21f52960 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -127,6 +127,7 @@ import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaPolicyTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
import org.openecomp.sdc.be.tosca.model.ToscaPropertyAssignment;
+import org.openecomp.sdc.be.tosca.model.ToscaPropertyConstraint;
import org.openecomp.sdc.be.tosca.model.ToscaRelationshipTemplate;
import org.openecomp.sdc.be.tosca.model.ToscaRequirement;
import org.openecomp.sdc.be.tosca.model.ToscaTemplate;
@@ -271,6 +272,8 @@ public class ToscaExportHandler {
options.setCanonical(false);
representer.addClassTag(toscaTemplate.getClass(), Tag.MAP);
representer.setPropertyUtils(new UnsortedPropertyUtils());
+
+
Yaml yaml = new Yaml(representer, options);
String yamlAsString = yaml.dumpAsMap(toscaTemplate);
StringBuilder sb = new StringBuilder();
@@ -1817,6 +1820,9 @@ public class ToscaExportHandler {
if (javaBean instanceof ToscaRelationshipTemplate && "name".equals(property.getName())) {
return null;
}
+ if (javaBean instanceof ToscaPropertyConstraint) {
+ return handleToscaPropertyConstraint((ToscaPropertyConstraint)javaBean, property, propertyValue, customTag);
+ }
removeDefaultP(propertyValue);
NodeTuple defaultNode = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
if (javaBean instanceof ToscaTopolgyTemplate && "relationshipTemplates".equals(property.getName())) {
@@ -1824,6 +1830,13 @@ public class ToscaExportHandler {
}
return "_defaultp_".equals(property.getName()) ? new NodeTuple(representData("default"), defaultNode.getValueNode()) : defaultNode;
}
+
+ private NodeTuple handleToscaPropertyConstraint(final ToscaPropertyConstraint javaBean, final Property property, final Object propertyValue,
+ final Tag customTag) {
+ final NodeTuple nodeTuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
+ final String entryToscaName = javaBean.getEntryToscaName(property.getName());
+ return new NodeTuple(representData(entryToscaName), nodeTuple.getValueNode());
+ }
private void removeDefaultP(final Object propertyValue) {
if (propertyValue instanceof Map) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
index 6049be2fd6..8224613ac2 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraint.java
@@ -26,4 +26,12 @@ import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
public interface ToscaPropertyConstraint {
ConstraintType getConstraintType();
+
+ /**
+ * Get the TOSCA entry name of an attribute in this class.
+ *
+ * @param attributeName the class attribute name
+ * @return the TOSCA entry represented by the attribute
+ */
+ String getEntryToscaName(final String attributeName);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java
new file mode 100644
index 0000000000..532cb8c91b
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintEqual.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintEqual implements ToscaPropertyConstraint {
+
+ private String equal;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("equal".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java
new file mode 100644
index 0000000000..fcc9dcc884
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterOrEqual.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA greater_or_equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintGreaterOrEqual implements ToscaPropertyConstraint {
+
+ private String greaterOrEqual;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_OR_EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("greaterOrEqual".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java
new file mode 100644
index 0000000000..6f2268bd9e
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintGreaterThan.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA greater_than constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintGreaterThan implements ToscaPropertyConstraint {
+
+ private String greaterThan;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.GREATER_THAN;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("greaterThan".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java
new file mode 100644
index 0000000000..6c8cfba620
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintInRange.java
@@ -0,0 +1,51 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import java.util.List;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA in_range constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintInRange implements ToscaPropertyConstraint {
+
+ private List<String> inRange;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.IN_RANGE;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("inRange".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java
new file mode 100644
index 0000000000..67aaca0188
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLength.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLength implements ToscaPropertyConstraint {
+
+ private String length;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LENGTH;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("length".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java
new file mode 100644
index 0000000000..3d51ec9419
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessOrEqual.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA less_or_equal constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLessOrEqual implements ToscaPropertyConstraint {
+
+ private String lessOrEqual;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_OR_EQUAL;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("lessOrEqual".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java
new file mode 100644
index 0000000000..ad51f66fde
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintLessThan.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA less_than constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintLessThan implements ToscaPropertyConstraint {
+
+ private String lessThan;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.LESS_THAN;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("lessThan".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java
new file mode 100644
index 0000000000..29d1464714
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMaxLength.java
@@ -0,0 +1,49 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA max_length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintMaxLength implements ToscaPropertyConstraint {
+
+ private Integer maxLength;
+ private static final ConstraintType CONSTRAINT_TYPE = ConstraintType.MAX_LENGTH;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("maxLength".equals(attributeName)) {
+ return CONSTRAINT_TYPE.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return CONSTRAINT_TYPE;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java
new file mode 100644
index 0000000000..3613df9928
--- /dev/null
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintMinLength.java
@@ -0,0 +1,48 @@
+/*
+ * ============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 lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
+
+/**
+ * Represents a TOSCA min_length constraint
+ */
+@Getter
+@Setter
+@AllArgsConstructor
+public class ToscaPropertyConstraintMinLength implements ToscaPropertyConstraint {
+
+ private Integer minLength;
+
+ @Override
+ public String getEntryToscaName(final String attributeName) {
+ if ("minLength".equals(attributeName)) {
+ return ConstraintType.MIN_LENGTH.getType();
+ }
+ return attributeName;
+ }
+
+ @Override
+ public ConstraintType getConstraintType() {
+ return ConstraintType.MIN_LENGTH;
+ }
+}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java
index 8e73f6985b..c23be5725c 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/model/ToscaPropertyConstraintValidValues.java
@@ -34,13 +34,8 @@ public class ToscaPropertyConstraintValidValues implements ToscaPropertyConstrai
private List<String> validValues;
- /**
- * Get the TOSCA entry name of an attribute in this class.
- *
- * @param attributeName the class attribute name
- * @return the TOSCA entry represented by the attribute
- */
- public static String getEntryToscaName(final String attributeName) {
+ @Override
+ public String getEntryToscaName(final String attributeName) {
if ("validValues".equals(attributeName)) {
return "valid_values";
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
index a01831e70c..3260521084 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/impl/ComponentsUtilsTest.java
@@ -41,6 +41,7 @@ import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.CapabilityTypeDefinition;
import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.GroupTypeDefinition;
import org.openecomp.sdc.be.model.PolicyTypeDefinition;
@@ -48,6 +49,15 @@ import org.openecomp.sdc.be.model.RequirementDefinition;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.tosca.constraints.EqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.GreaterOrEqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.LessThanConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
+import org.openecomp.sdc.be.model.tosca.constraints.ValidValuesConstraint;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
@@ -61,6 +71,7 @@ import org.openecomp.sdc.test.utils.TestConfigurationProvider;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -771,6 +782,45 @@ public class ComponentsUtilsTest {
assertThat(response.left().value()).isEqualTo(assertuser);
}
+ @Test
+ public void testconvertJsonToObjectUsingObjectMapper() {
+
+ AuditingManager auditingmanager = Mockito.mock(AuditingManager.class);
+ ComponentsUtils compUtils = new ComponentsUtils(auditingmanager);
+ when(auditingmanager.auditEvent(any())).thenReturn("OK");
+
+ User user = new User();
+ String data =
+ "[{\"constraints\":[{\"equal\":\"value\"}]},"
+ + "{\"constraints\":[{\"greaterOrEqual\":5}]},"
+ + "{\"constraints\":[{\"lessThan\":7}]},"
+ + "{\"constraints\":[{\"lessOrEqual\":9}]},"
+ + "{\"constraints\":[{\"inRange\":[\"5\", \"10\"]}]},"
+ + "{\"constraints\":[{\"validValues\":[\"abc\", \"def\", \"hij\"]}]},"
+ + "{\"constraints\":[{\"length\":11}]},"
+ + "{\"constraints\":[{\"minLength\":13}]},"
+ + "{\"constraints\":[{\"maxLength\":15}]}"
+ +"]";
+
+
+ Either<ComponentInstanceProperty[], ResponseFormat> response = compUtils.convertJsonToObjectUsingObjectMapper(data, user,
+ ComponentInstanceProperty[].class, null, ComponentTypeEnum.RESOURCE_INSTANCE);
+
+ assertThat(response.isLeft()).isTrue();
+ ComponentInstanceProperty[] properties = response.left().value();
+ assertEquals(9, properties.length);
+ assertEquals("value", ((EqualConstraint)properties[0].getConstraints().iterator().next()).getEqual());
+ assertEquals("5", ((GreaterOrEqualConstraint)properties[1].getConstraints().iterator().next()).getGreaterOrEqual());
+ assertEquals("7", ((LessThanConstraint)properties[2].getConstraints().iterator().next()).getLessThan());
+ assertEquals("9", ((LessOrEqualConstraint)properties[3].getConstraints().iterator().next()).getLessOrEqual());
+ assertEquals("5", ((InRangeConstraint)properties[4].getConstraints().iterator().next()).getRangeMinValue());
+ assertEquals("10", ((InRangeConstraint)properties[4].getConstraints().iterator().next()).getRangeMaxValue());
+ assertEquals(3, ((ValidValuesConstraint)properties[5].getConstraints().iterator().next()).getValidValues().size());
+ assertEquals(11, ((LengthConstraint)properties[6].getConstraints().iterator().next()).getLength());
+ assertEquals(13, ((MinLengthConstraint)properties[7].getConstraints().iterator().next()).getMinLength());
+ assertEquals(15, ((MaxLengthConstraint)properties[8].getConstraints().iterator().next()).getMaxLength());
+ }
+
@Test
public void testconvertJsonToObject_NllData() {