aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java
diff options
context:
space:
mode:
Diffstat (limited to 'a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java')
-rw-r--r--a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/PolicyTypes.java23
1 files changed, 8 insertions, 15 deletions
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;
}