X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaProperty.java;h=0ef8ffbaa05a7eb258916fabd24a532b910b646f;hb=938005505883cf7a636a8840e20e3dc8a0ad9176;hp=e2b6e6f937417d7ca6974e0d91843bc44934eb6d;hpb=009e46781b895c60a012c4ac13baddb145f698e9;p=policy%2Fmodels.git diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java index e2b6e6f93..0ef8ffbaa 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java @@ -2,8 +2,9 @@ * ============LICENSE_START======================================================= * ONAP Policy Model * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation. + * Modifications Copyright (C) 2022 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,33 +24,29 @@ package org.onap.policy.models.tosca.simple.concepts; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.EmbeddedId; +import java.io.Serial; import java.util.ArrayList; +import java.util.LinkedHashMap; import java.util.List; - -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.Table; - +import java.util.Map; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; - import org.apache.commons.lang3.ObjectUtils; -import org.onap.policy.common.utils.validation.Assertions; +import org.onap.policy.common.parameters.annotations.NotBlank; +import org.onap.policy.common.parameters.annotations.NotNull; +import org.onap.policy.common.parameters.annotations.Valid; +import org.onap.policy.common.utils.coder.YamlJsonTranslator; import org.onap.policy.models.base.PfAuthorative; import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfUtils; -import org.onap.policy.models.base.PfValidationMessage; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; -import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint; +import org.onap.policy.models.base.validation.annotations.VerifyKey; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty; import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status; @@ -59,37 +56,45 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty.Status; * @author Chenfei Gao (cgao@research.att.com) * @author Liam Fallon (liam.fallon@est.tech) */ -@Entity -@Table(name = "ToscaProperty") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) @Data @EqualsAndHashCode(callSuper = false) public class JpaToscaProperty extends PfConcept implements PfAuthorative { + @Serial private static final long serialVersionUID = 1675770231921107988L; @EmbeddedId + @VerifyKey + @NotNull private PfReferenceKey key; @Column + @VerifyKey + @NotNull private PfConceptKey type; @Column + @NotBlank private String description; @Column private boolean required = false; - @Column(name = "default") + @Column + @NotBlank private String defaultValue; @Column private Status status = Status.SUPPORTED; @ElementCollection - private List constraints; + private List<@NotNull @Valid JpaToscaConstraint> constraints; @Column - private JpaToscaEntrySchema entrySchema; + @Valid + private JpaToscaSchemaDefinition entrySchema; + + @ElementCollection + private Map metadata; /** * The Default Constructor creates a {@link JpaToscaProperty} object with a null key. @@ -125,6 +130,17 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative(copyConcept.constraints) : null); + this.entrySchema = + (copyConcept.entrySchema != null ? new JpaToscaSchemaDefinition(copyConcept.entrySchema) : null); + this.metadata = (copyConcept.metadata != null ? new LinkedHashMap<>(copyConcept.metadata) : null); } /** @@ -138,7 +154,7 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative toscaConstraints = new ArrayList<>(); - - for (JpaToscaConstraint constraint : constraints) { - toscaConstraints.add(constraint.toAuthorative()); - } - - toscaProperty.setConstraints(toscaConstraints); + if (defaultValue != null) { + toscaProperty.setDefaultValue(new YamlJsonTranslator().fromYaml(defaultValue, Object.class)); } + toscaProperty.setConstraints(PfUtils.mapList(constraints, JpaToscaConstraint::toAuthorative)); + if (entrySchema != null) { toscaProperty.setEntrySchema(entrySchema.toAuthorative()); } + toscaProperty.setMetadata(PfUtils.mapMap(metadata, metadataItem -> metadataItem)); + return toscaProperty; } @@ -180,20 +193,21 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative(); - - for (ToscaConstraint toscaConstraint : toscaProperty.getConstraints()) { - constraints.add(JpaToscaConstraint.newInstance(toscaConstraint)); - } + if (toscaProperty.getDefaultValue() != null) { + defaultValue = new YamlJsonTranslator().toYaml(toscaProperty.getDefaultValue()).trim(); + } else { + defaultValue = null; } + constraints = PfUtils.mapList(toscaProperty.getConstraints(), JpaToscaConstraint::newInstance); + if (toscaProperty.getEntrySchema() != null) { - entrySchema = new JpaToscaEntrySchema(toscaProperty.getEntrySchema()); + entrySchema = new JpaToscaSchemaDefinition(toscaProperty.getEntrySchema()); } + + metadata = PfUtils.mapMap(toscaProperty.getMetadata(), metadataItem -> metadataItem); } @Override @@ -226,67 +240,17 @@ public class JpaToscaProperty extends PfConcept implements PfAuthorative newConstraints = new ArrayList<>(); - for (final JpaToscaConstraint constraint : constraints) { - newConstraints.add(constraint); // Constraints are immutable - } - copy.setConstraints(newConstraints); + result = entrySchema.compareTo(other.entrySchema); + if (result != 0) { + return result; } - copy.setEntrySchema(entrySchema != null ? new JpaToscaEntrySchema(entrySchema) : null); - - return copy; + return PfUtils.compareMaps(metadata, other.metadata); } }