/*-
* ============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.
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)
*/
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
// @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;
}
}