Changed identifiers to concept identifiers
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaPolicyFilter.java
index b4d1b3e..86c2e6f 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 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.
@@ -22,16 +23,13 @@ package org.onap.policy.models.tosca.authorative.concepts;
 
 import java.util.List;
 import java.util.stream.Collectors;
-
 import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
-
 import org.onap.policy.models.base.PfObjectFilter;
 
 /**
- * Filter class for searches for {@link ToscaPolicy} instances.
- * If any fields are null, they are ignored.
+ * Filter class for searches for {@link ToscaPolicy} instances. If any fields are null, they are ignored.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
@@ -40,16 +38,19 @@ import org.onap.policy.models.base.PfObjectFilter;
 public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> {
     public static final String LATEST_VERSION = "LATEST";
 
-    // Regular expression
+    // Exact expression
     private String name;
 
-    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    // Exact match, set to LATEST_VERSION to get the latest version
     private String version;
 
-    // Regular expression
+    // version prefix
+    private String versionPrefix;
+
+    // Exact expression
     private String type;
 
-    // Regular Expression, set to LATEST_VERRSION to get the latest version
+    // Exact Expression, set to LATEST_VERSION to get the latest version
     private String typeVersion;
 
     @Override
@@ -57,17 +58,17 @@ public class ToscaPolicyFilter implements PfObjectFilter<ToscaPolicy> {
 
         // @formatter:off
         List<ToscaPolicy> returnList = originalList.stream()
-                .filter(p -> filterOnRegexp(p.getName(),        name))
-                .filter(p -> version.equals(LATEST_VERSION) || filterOnRegexp(p.getVersion(), version))
-                .filter(p -> filterOnRegexp(p.getType(),        type))
-                .filter(p -> filterOnRegexp(p.getTypeVersion(), typeVersion))
+                .filter(filterStringPred(name, ToscaPolicy::getName))
+                .filter(filterStringPred((LATEST_VERSION.equals(version) ? null : version), ToscaPolicy::getVersion))
+                .filter(filterPrefixPred(versionPrefix, ToscaPolicy::getVersion))
+                .filter(filterStringPred(type, ToscaPolicy::getType))
+                .filter(filterStringPred(typeVersion, ToscaPolicy::getTypeVersion))
                 .collect(Collectors.toList());
         // @formatter:off
 
         if (LATEST_VERSION.equals(version)) {
-            return this.latestVersionFilter(returnList);
-        }
-        else {
+            return this.latestVersionFilter(returnList, new ToscaPolicyComparator());
+        } else  {
             return returnList;
         }
     }