Commit a92ddec0 by Diego Marino Monetti Committed by Madhan Neethiraj

ATLAS-3180: enhanced typedef retrieval to support filter by serviceType

parent be9df1c3
...@@ -43,7 +43,9 @@ public class SearchFilter { ...@@ -43,7 +43,9 @@ public class SearchFilter {
public static final String PARAM_TYPE = "type"; public static final String PARAM_TYPE = "type";
public static final String PARAM_NAME = "name"; public static final String PARAM_NAME = "name";
public static final String PARAM_SUPERTYPE = "supertype"; public static final String PARAM_SUPERTYPE = "supertype";
public static final String PARAM_SERVICETYPE = "servicetype";
public static final String PARAM_NOT_SUPERTYPE = "notsupertype"; public static final String PARAM_NOT_SUPERTYPE = "notsupertype";
public static final String PARAM_NOT_SERVICETYPE = "notservicetype";
public static final String PARAM_NOT_NAME = "notname"; public static final String PARAM_NOT_NAME = "notname";
/** /**
......
...@@ -40,7 +40,9 @@ public class FilterUtil { ...@@ -40,7 +40,9 @@ public class FilterUtil {
final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE); final String type = searchFilter.getParam(SearchFilter.PARAM_TYPE);
final String name = searchFilter.getParam(SearchFilter.PARAM_NAME); final String name = searchFilter.getParam(SearchFilter.PARAM_NAME);
final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE); final String supertype = searchFilter.getParam(SearchFilter.PARAM_SUPERTYPE);
final String serviceType = searchFilter.getParam(SearchFilter.PARAM_SERVICETYPE);
final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE); final String notSupertype = searchFilter.getParam(SearchFilter.PARAM_NOT_SUPERTYPE);
final String notServiceType = searchFilter.getParam(SearchFilter.PARAM_NOT_SERVICETYPE);
final List<String> notNames = searchFilter.getParams(SearchFilter.PARAM_NOT_NAME); final List<String> notNames = searchFilter.getParams(SearchFilter.PARAM_NOT_NAME);
// Add filter for the type/category // Add filter for the type/category
...@@ -53,6 +55,11 @@ public class FilterUtil { ...@@ -53,6 +55,11 @@ public class FilterUtil {
predicates.add(getNamePredicate(name)); predicates.add(getNamePredicate(name));
} }
// Add filter for the serviceType
if(StringUtils.isNotBlank(serviceType)) {
predicates.add(getServiceTypePredicate(serviceType));
}
// Add filter for the supertype // Add filter for the supertype
if (StringUtils.isNotBlank(supertype)) { if (StringUtils.isNotBlank(supertype)) {
predicates.add(getSuperTypePredicate(supertype)); predicates.add(getSuperTypePredicate(supertype));
...@@ -63,6 +70,16 @@ public class FilterUtil { ...@@ -63,6 +70,16 @@ public class FilterUtil {
predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype))); predicates.add(new NotPredicate(getSuperTypePredicate(notSupertype)));
} }
// Add filter for the serviceType negation
// NOTE: Creating code for the exclusion of multiple service types is currently useless.
// In fact the getSearchFilter in TypeREST.java uses the HttpServletRequest.getParameter(key)
// that if the key takes more values it takes only the first the value. Could be useful
// to change the getSearchFilter to use getParameterValues instead of getParameter.
if (StringUtils.isNotBlank(notServiceType)) {
predicates.add(new NotPredicate(getServiceTypePredicate(notServiceType)));
}
// Add filter for the type negation // Add filter for the type negation
if (CollectionUtils.isNotEmpty(notNames)) { if (CollectionUtils.isNotEmpty(notNames)) {
for (String notName : notNames) { for (String notName : notNames) {
...@@ -86,6 +103,19 @@ public class FilterUtil { ...@@ -86,6 +103,19 @@ public class FilterUtil {
}; };
} }
private static Predicate getServiceTypePredicate(final String serviceType) {
return new Predicate() {
private boolean isAtlasType(Object o) {
return o instanceof AtlasType;
}
@Override
public boolean evaluate(Object o) {
return isAtlasType(o) && Objects.equals(((AtlasType) o).getServiceType(), serviceType);
}
};
}
private static Predicate getSuperTypePredicate(final String supertype) { private static Predicate getSuperTypePredicate(final String supertype) {
return new Predicate() { return new Predicate() {
private boolean isClassificationType(Object o) { private boolean isClassificationType(Object o) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment