X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-pdp%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fpdp%2Fpersistence%2Fconcepts%2FJpaPdpGroup.java;h=52f145659cca95287c18e22d0571c4e36ce93e9d;hb=refs%2Fchanges%2F05%2F136005%2F1;hp=d0fc216c26ac64710399870a797df0a96e43ef7c;hpb=9ce39af891ccf063d46e18ecf5a2a47eb1408930;p=policy%2Fmodels.git diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java index d0fc216c2..52f145659 100644 --- a/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.java +++ b/models-pdp/src/main/java/org/onap/policy/models/pdp/persistence/concepts/JpaPdpGroup.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,42 +24,38 @@ package org.onap.policy.models.pdp.persistence.concepts; +import jakarta.persistence.CascadeType; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.Column; +import jakarta.persistence.ElementCollection; +import jakarta.persistence.EmbeddedId; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.Inheritance; +import jakarta.persistence.InheritanceType; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.OneToMany; +import jakarta.persistence.Table; +import java.io.Serial; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; - -import javax.persistence.CascadeType; -import javax.persistence.CollectionTable; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.Table; - import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; - import org.apache.commons.lang3.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.policy.common.utils.validation.Assertions; -import org.onap.policy.common.utils.validation.ParameterValidationUtils; +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.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.base.validation.annotations.VerifyKey; import org.onap.policy.models.pdp.concepts.PdpGroup; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.pdp.enums.PdpState; @@ -74,30 +71,34 @@ import org.onap.policy.models.pdp.enums.PdpState; @Data @EqualsAndHashCode(callSuper = false) public class JpaPdpGroup extends PfConcept implements PfAuthorative { + @Serial private static final long serialVersionUID = -357224425637789775L; @EmbeddedId + @VerifyKey + @NotNull private PfConceptKey key; @Column + @NotBlank private String description; @Column + @NotNull private PdpState pdpGroupState; @ElementCollection - private Map properties; + private Map<@NotNull @NotBlank String, @NotNull @NotBlank String> properties; // @formatter:off @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) @CollectionTable(joinColumns = { - @JoinColumn(name = "pdpGroupParentKeyName", referencedColumnName = "parentKeyName"), - @JoinColumn(name = "pdpGroupParentKeyVersion", referencedColumnName = "parentKeyVersion"), - @JoinColumn(name = "pdpGroupParentLocalName", referencedColumnName = "parentLocalName"), - @JoinColumn(name = "pdpGroupLocalName", referencedColumnName = "localName") - }) + @JoinColumn(name = "name", referencedColumnName = "name"), + @JoinColumn(name = "version", referencedColumnName = "version") + }) // @formatter:on - private List pdpSubGroups; + @NotNull + private List<@NotNull @Valid JpaPdpSubGroup> pdpSubGroups; /** * The Default Constructor creates a {@link JpaPdpGroup} object with a null key. @@ -135,6 +136,11 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { */ public JpaPdpGroup(@NonNull final JpaPdpGroup copyConcept) { super(copyConcept); + this.key = new PfConceptKey(copyConcept.key); + this.description = copyConcept.description; + this.pdpGroupState = copyConcept.pdpGroupState; + this.properties = (copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties)); + this.pdpSubGroups = PfUtils.mapList(copyConcept.pdpSubGroups, JpaPdpSubGroup::new, new ArrayList<>(0)); } /** @@ -148,7 +154,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { @Override public PdpGroup toAuthorative() { - PdpGroup pdpGroup = new PdpGroup(); + var pdpGroup = new PdpGroup(); pdpGroup.setName(getKey().getName()); pdpGroup.setVersion(getKey().getVersion()); @@ -179,7 +185,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { this.pdpSubGroups = new ArrayList<>(); for (PdpSubGroup pdpSubgroup : pdpGroup.getPdpSubgroups()) { - JpaPdpSubGroup jpaPdpSubGroup = new JpaPdpSubGroup(); + var jpaPdpSubGroup = new JpaPdpSubGroup(); jpaPdpSubGroup.setKey(new PfReferenceKey(getKey(), pdpSubgroup.getPdpType())); jpaPdpSubGroup.fromAuthorative(pdpSubgroup); this.pdpSubGroups.add(jpaPdpSubGroup); @@ -216,52 +222,6 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { } } - @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = resultIn; - - if (key.isNullKey()) { - result.addValidationMessage( - new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key")); - } - - result = key.validate(result); - - if (description != null && StringUtils.isBlank(description)) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "description may not be blank")); - } - - if (pdpGroupState == null) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "pdpGroupState may not be null")); - } - - if (properties != null) { - for (Entry propertyEntry : properties.entrySet()) { - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property key may not be null or blank")); - } - if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getValue())) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a property value may not be null or blank")); - } - } - } - - if (pdpSubGroups == null) { - result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "a PDP group must have a list of PDP subgroups")); - } else { - for (JpaPdpSubGroup jpaPdpSubgroup : pdpSubGroups) { - result = jpaPdpSubgroup.validate(result); - } - } - - return result; - } - @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { @@ -271,7 +231,7 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { return 0; } if (getClass() != otherConcept.getClass()) { - return this.getClass().getCanonicalName().compareTo(otherConcept.getClass().getCanonicalName()); + return this.getClass().getName().compareTo(otherConcept.getClass().getName()); } final JpaPdpGroup other = (JpaPdpGroup) otherConcept; @@ -296,19 +256,4 @@ public class JpaPdpGroup extends PfConcept implements PfAuthorative { return PfUtils.compareObjects(pdpSubGroups, other.pdpSubGroups); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - Assertions.instanceOf(target, JpaPdpGroup.class); - - final JpaPdpGroup copy = ((JpaPdpGroup) target); - copy.setKey(new PfConceptKey(key)); - - copy.setDescription(description); - copy.setPdpGroupState(pdpGroupState); - copy.setProperties(properties == null ? null : new LinkedHashMap<>(properties)); - copy.setPdpSubGroups(PfUtils.mapList(pdpSubGroups, JpaPdpSubGroup::new)); - - return copy; - } }