summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java/org
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2021-12-28 13:07:14 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2021-12-29 11:55:32 +0100
commitc1b6222fd1a32bf1cf10afa72bf8c3dabd6be112 (patch)
treecb256392d1cd8048a489df4a9b04d8f8bdc54366 /a1-policy-management/src/main/java/org
parent2b27764f3ba4de24cdf58f3e0df83537b180bb56 (diff)
A1 Policy Management
Sorting of compatible policy type IDs Issue-ID: CCSDK-3495 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: I9b092b82a24e951f0ac1f446b37cc0db2d644e3a
Diffstat (limited to 'a1-policy-management/src/main/java/org')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java3
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyType.java20
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java23
3 files changed, 30 insertions, 16 deletions
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
index 9945e0ab..5f2f6193 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/PolicyController.java
@@ -141,7 +141,8 @@ public class PolicyController {
@Parameter(name = Consts.COMPATIBLE_WITH_VERSION_PARAM, required = false, //
description = "Select types that are compatible with the given version. This parameter is only applicable in conjunction with "
+ Consts.TYPE_NAME_PARAM
- + ". As an example version 1.9.1 is compatible with 1.0.0 but not the other way around.") //
+ + ". As an example version 1.9.1 is compatible with 1.0.0 but not the other way around."
+ + " Matching types will be returned sorted in ascending order.") //
@RequestParam(name = Consts.COMPATIBLE_WITH_VERSION_PARAM, required = false) String compatibleWithVersion
) throws ServiceException {
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyType.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyType.java
index 3a5bdd95..14c9f580 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyType.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyType.java
@@ -62,6 +62,18 @@ public class PolicyType {
throw new ServiceException("Syntax error in " + version, HttpStatus.BAD_REQUEST);
}
}
+
+ public int compareTo(Version other) {
+ if (major != other.major)
+ return major - other.major;
+ if (minor != other.minor)
+ return minor - other.minor;
+ return patch - other.patch;
+ }
+
+ public boolean isCompatibleWith(Version other) {
+ return (major == other.major && minor >= other.minor);
+ }
}
@Getter
@@ -98,4 +110,12 @@ public class PolicyType {
return TypeId.ofString(getId());
}
+ public Version getVersion() {
+ try {
+ return Version.ofString(getTypeId().getVersion());
+ } catch (ServiceException e) {
+ return new Version(0, 0, 0);
+ }
+ }
+
}
diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
index 53dc55db..14acca95 100644
--- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
+++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
@@ -33,6 +33,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Vector;
@@ -89,7 +90,9 @@ public class PolicyTypes {
* @param types the types to select from
* @param typeName select types with given type name
* @param compatibleWithVersion select types that are compatible with given
- * version string (major.minor.patch)
+ * version string (major.minor.patch).
+ * Matching types will be sorted in ascending
+ * order.
* @return the types that matches given criterias
* @throws ServiceException if there are errors in the given input
*/
@@ -172,26 +175,16 @@ public class PolicyTypes {
return result;
}
- private static boolean isTypeCompatibleWithVersion(PolicyType type, PolicyType.Version version) {
- try {
- PolicyType.TypeId typeId = type.getTypeId();
- PolicyType.Version typeVersion = PolicyType.Version.ofString(typeId.getVersion());
- return (typeVersion.major == version.major && typeVersion.minor >= version.minor);
- } catch (Exception e) {
- logger.warn("Ignoring type with syntactically incorrect type ID: {}", type.getId());
- return false;
- }
- }
-
private static Collection<PolicyType> filterCompatibleWithVersion(Collection<PolicyType> types, String versionStr)
throws ServiceException {
- Collection<PolicyType> result = new ArrayList<>();
- PolicyType.Version otherVersion = PolicyType.Version.ofString(versionStr);
+ List<PolicyType> result = new ArrayList<>();
+ PolicyType.Version requestedVersion = PolicyType.Version.ofString(versionStr);
for (PolicyType type : types) {
- if (isTypeCompatibleWithVersion(type, otherVersion)) {
+ if (type.getVersion().isCompatibleWith(requestedVersion)) {
result.add(type);
}
}
+ result.sort((left, right) -> left.getVersion().compareTo(right.getVersion()));
return result;
}