aboutsummaryrefslogtreecommitdiffstats
path: root/models-base/src/main
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-03-26 22:31:43 +0000
committerliamfallon <liam.fallon@est.tech>2019-03-26 22:31:43 +0000
commitcee84a9344f35356f86384b0d48127f5a83e3776 (patch)
treec2a796218273fa4553f07d1328adac3882ab4711 /models-base/src/main
parent38e3ea9ff6a0a1534a30655e22082cf4c8d887d0 (diff)
Add Legacy Op Policy Persistence
Legacy operational policies now fully supported for serialization and persistence from provider through to database and back. Unit test coverage completed also Issue-ID: POLICY-1095 Change-Id: I65755859c94b50edee537d2685f51a7838c6541f Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/main')
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java67
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKey.java29
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java20
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java28
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfUtils.java3
5 files changed, 145 insertions, 2 deletions
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
index 9f575851b..84239e5eb 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
@@ -177,6 +177,73 @@ public class PfConceptKey extends PfKey {
}
@Override
+ public boolean isNewerThan(@NonNull final PfKey otherKey) {
+ Assertions.instanceOf(otherKey, PfConceptKey.class);
+
+ final PfConceptKey otherConceptKey = (PfConceptKey) otherKey;
+
+ if (this.equals(otherConceptKey)) {
+ return false;
+ }
+
+ if (!this.getName().equals(otherConceptKey.getName())) {
+ return this.getName().compareTo(otherConceptKey.getName()) > 0;
+ }
+
+ final String[] thisVersionArray = getVersion().split("\\.");
+ final String[] otherVersionArray = otherConceptKey.getVersion().split("\\.");
+
+ // There must always be at least one element in each version
+ if (!thisVersionArray[0].equals(otherVersionArray[0])) {
+ return thisVersionArray[0].compareTo(otherVersionArray[0]) > 0;
+ }
+
+ if (thisVersionArray.length >= 2 && otherVersionArray.length >= 2
+ && !thisVersionArray[1].equals(otherVersionArray[1])) {
+ return thisVersionArray[1].compareTo(otherVersionArray[1]) > 0;
+ }
+
+ if (thisVersionArray.length >= 3 && otherVersionArray.length >= 3
+ && !thisVersionArray[2].equals(otherVersionArray[2])) {
+ return thisVersionArray[2].compareTo(otherVersionArray[2]) > 0;
+ }
+
+ return false;
+ }
+
+ @Override
+ public int getMajorVersion() {
+ final String[] versionArray = getVersion().split("\\.");
+
+ // There must always be at least one element in each version
+ return Integer.parseInt(versionArray[0]);
+ }
+
+ @Override
+ public int getMinorVersion() {
+ final String[] versionArray = getVersion().split("\\.");
+
+ if (versionArray.length >= 2) {
+ return Integer.parseInt(versionArray[1]);
+ }
+ else {
+ return 0;
+ }
+ }
+
+ @Override
+ public int getPatchVersion() {
+ final String[] versionArray = getVersion().split("\\.");
+
+ if (versionArray.length >= 3) {
+ return Integer.parseInt(versionArray[2]);
+ }
+ else {
+ return 0;
+ }
+ }
+
+ @Override
public PfValidationResult validate(final PfValidationResult result) {
final String nameValidationErrorMessage = Assertions.getStringParameterValidationMessage(NAME_TOKEN, name,
NAME_REGEXP);
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
index 6e9035e95..5407030ba 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
@@ -102,9 +102,38 @@ public abstract class PfKey extends PfConcept {
public abstract boolean isCompatible(@NonNull PfKey otherKey);
/**
+ * Check if this key is a newer version than the other key.
+ *
+ * @param otherKey the key to check against
+ * @return true, if this key is newer than the other key
+ */
+ public abstract boolean isNewerThan(@NonNull PfKey otherKey);
+
+ /**
* Check if a key equals its null key.
*
* @return true, if the key is a null key
*/
public abstract boolean isNullKey();
+
+ /**
+ * Get the major version of a key.
+ *
+ * @return the major version of a key
+ */
+ public abstract int getMajorVersion();
+
+ /**
+ * Get the minor version of a key.
+ *
+ * @return the minor version of a key
+ */
+ public abstract int getMinorVersion();
+
+ /**
+ * Get the patch version of a key.
+ *
+ * @return the patch version of a key
+ */
+ public abstract int getPatchVersion();
}
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..836707ef2 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
@@ -111,6 +111,26 @@ public class PfKeyUse extends PfKey {
}
@Override
+ public boolean isNewerThan(@NonNull final PfKey otherKey) {
+ return usedKey.isCompatible(otherKey);
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return usedKey.getMajorVersion();
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return usedKey.getMinorVersion();
+ }
+
+ @Override
+ public int getPatchVersion() {
+ return usedKey.getPatchVersion();
+ }
+
+ @Override
public void clean() {
usedKey.clean();
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
index 19e8beee9..185ccfa69 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
@@ -28,6 +28,7 @@ import javax.persistence.Embeddable;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@@ -305,7 +306,7 @@ public class PfReferenceKey extends PfKey {
}
@Override
- public boolean isCompatible(final PfKey otherKey) {
+ public boolean isCompatible(@NonNull final PfKey otherKey) {
if (!(otherKey instanceof PfReferenceKey)) {
return false;
}
@@ -315,6 +316,31 @@ public class PfReferenceKey extends PfKey {
}
@Override
+ public int getMajorVersion() {
+ return this.getParentConceptKey().getMajorVersion();
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return this.getParentConceptKey().getMinorVersion();
+ }
+
+ @Override
+ public int getPatchVersion() {
+ return this.getParentConceptKey().getPatchVersion();
+ }
+
+
+ @Override
+ public boolean isNewerThan(@NonNull final PfKey otherKey) {
+ Assertions.instanceOf(otherKey, PfReferenceKey.class);
+
+ final PfReferenceKey otherReferenceKey = (PfReferenceKey) otherKey;
+
+ return this.getParentConceptKey().isNewerThan(otherReferenceKey.getParentConceptKey());
+ }
+
+ @Override
public PfValidationResult validate(final PfValidationResult result) {
final String parentNameValidationErrorMessage = Assertions.getStringParameterValidationMessage(PARENT_KEY_NAME,
parentKeyName, NAME_REGEXP);
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
index 8e77d3fcf..7bdd9a5f4 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
@@ -21,6 +21,7 @@
package org.onap.policy.models.base;
+import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -72,7 +73,7 @@ public final class PfUtils {
*/
public static <T> List<T> mapList(List<T> source, Function<T, T> mapFunc) {
if (source == null) {
- return null;
+ return new ArrayList<>();
}
return source.stream().map(mapFunc).collect(Collectors.toList());