diff options
Diffstat (limited to 'catalog-be/src/main')
17 files changed, 545 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"; } |