Add extra authorative TOSCA concepts
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaPolicyTypeFilter.java
index baa9504..4e9810b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,22 +22,19 @@ 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.PfObjectFiler;
+import org.onap.policy.models.base.PfObjectFilter;
 
 /**
- * Filter class for searches for {@link ToscaPolicyType} instances.
- * If any fields are null, they are ignored.
+ * Filter class for searches for {@link ToscaPolicyType} instances. If any fields are null, they are ignored.
  *
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 @Builder
 @Data
-public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> {
+public class ToscaPolicyTypeFilter implements PfObjectFilter<ToscaPolicyType> {
     public static final String LATEST_VERSION = "LATEST";
 
     // Regular expression
@@ -50,10 +47,17 @@ public class ToscaPolicyTypeFilter implements PfObjectFiler<ToscaPolicyType> {
     public List<ToscaPolicyType> filter(@NonNull final List<ToscaPolicyType> originalList) {
 
         // @formatter:off
-        return originalList.stream()
-                .filter(p -> name    != null && p.getName()   .matches(name))
-                .filter(p -> version != null && p.getVersion().matches(version))
+        List<ToscaPolicyType> returnList = originalList.stream()
+                .filter(p -> filterString(p.getName(), name))
+                .filter(p -> LATEST_VERSION.equals(version)
+                        || filterString(p.getVersion(), version))
                 .collect(Collectors.toList());
         // @formatter:off
+
+        if (LATEST_VERSION.equals(version)) {
+            return this.latestVersionFilter(returnList, new ToscaPolicyTypeComparator());
+        } else  {
+            return returnList;
+        }
     }
 }