X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=models-base%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Fbase%2FPfKeyUse.java;h=f9141cc2796389b38407915abecf68d6b9cb0819;hb=refs%2Fchanges%2F05%2F136005%2F1;hp=57141c2fa926a0334048a9b80ff7cf23aea7b1a9;hpb=886df68bad719ab7ab3672e58ee153f4f6af92c2;p=policy%2Fmodels.git diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java index 57141c2fa..f9141cc27 100644 --- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java +++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019, 2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. 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. @@ -20,16 +21,15 @@ package org.onap.policy.models.base; +import java.io.Serial; import java.util.List; - -import javax.ws.rs.core.Response; - import lombok.EqualsAndHashCode; +import lombok.Getter; import lombok.NonNull; import lombok.ToString; - +import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.utils.validation.Assertions; -import org.onap.policy.models.base.PfValidationResult.ValidationResult; +import org.onap.policy.models.base.validation.annotations.VerifyKey; /** * This class records a usage of a key in the system. When the list of keys being used by a concept @@ -42,8 +42,12 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; @EqualsAndHashCode(callSuper = false) @ToString public class PfKeyUse extends PfKey { + @Serial private static final long serialVersionUID = 2007147220109881705L; + @VerifyKey + @NotNull + @Getter private PfKey usedKey; /** @@ -69,6 +73,7 @@ public class PfKeyUse extends PfKey { */ public PfKeyUse(@NonNull final PfKeyUse copyConcept) { super(copyConcept); + this.usedKey = PfUtils.makeCopy(copyConcept.usedKey); } @Override @@ -111,49 +116,43 @@ public class PfKeyUse extends PfKey { } @Override - public void clean() { - usedKey.clean(); + public boolean isNewerThan(@NonNull final PfKey otherKey) { + return usedKey.isCompatible(otherKey); } @Override - public PfValidationResult validate(@NonNull final PfValidationResult result) { - if (usedKey.isNullKey()) { - result.addValidationMessage(new PfValidationMessage(usedKey, this.getClass(), ValidationResult.INVALID, - "usedKey is a null key")); - } - return usedKey.validate(result); + public int getMajorVersion() { + return usedKey.getMajorVersion(); + } + + @Override + public int getMinorVersion() { + return usedKey.getMinorVersion(); } @Override - public int compareTo(final PfConcept otherObj) { + public int getPatchVersion() { + return usedKey.getPatchVersion(); + } + + @Override + public void clean() { + usedKey.clean(); + } + + @Override + public int compareTo(@NonNull final PfConcept otherObj) { Assertions.argumentNotNull(otherObj, "comparison object may not be null"); if (this == otherObj) { return 0; } if (getClass() != otherObj.getClass()) { - return this.hashCode() - otherObj.hashCode(); + return getClass().getName().compareTo(otherObj.getClass().getName()); } final PfKeyUse other = (PfKeyUse) otherObj; return usedKey.compareTo(other.usedKey); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept target) { - final Object copyObject = target; - Assertions.instanceOf(copyObject, PfKeyUse.class); - - final PfKeyUse copy = ((PfKeyUse) copyObject); - try { - copy.usedKey = usedKey.getClass().newInstance(); - } catch (final Exception e) { - throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, - "error copying concept key: " + e.getMessage(), e); - } - usedKey.copyTo(copy.usedKey); - - return copy; - } }