use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class SearchFilterFactory method getFilter.
/**
* Returns a SearchFilter that matches the search string provided.
*
* Supports the following syntax:
* [attribute name][operator][attribute value]
*
* Where operator can be one of the following:
* Equals - =
* Less Than - <
* Greater Than - >
*
* @param filter Non null String representing a search filter.
* @return Non null parsed SearchFilter.
* @throws EntitlementException If there was an error pasing the filter.
*/
public SearchFilter getFilter(String filter) throws EntitlementException {
Object[] parts = parseFilter(filter);
String name = (String) parts[0];
SearchFilter.Operator operator = (SearchFilter.Operator) parts[1];
String value = (String) parts[2];
if (isAttributeNumeric(name)) {
// The < and > operators only apply to numeric attributes
try {
return new SearchFilter(getSearchAttribute(name), Long.parseLong(value), operator);
} catch (NumberFormatException e) {
throw new EntitlementException(INVALID_SEARCH_FILTER, new Object[] { "Invalid value for attribute", name, value });
}
} else {
// Everything else is assumed to be equals.
return new SearchFilter(getSearchAttribute(name), value);
}
}
use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class SearchFilterFactoryTest method shouldConsiderWhiteSpaceOK.
@Test
public void shouldConsiderWhiteSpaceOK() throws EntitlementException {
String filter = "badger = another badger";
SearchFilter result = factory.getFilter(filter);
assertThat(result.getName()).isEqualTo("badger");
}
use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class SearchFilterFactoryTest method shouldParseEquals.
@Test
public void shouldParseEquals() throws EntitlementException {
String filter = "badger=mammal";
SearchFilter result = factory.getFilter(filter);
assertThat(result.getOperator()).isEqualTo(SearchFilter.Operator.EQUALS_OPERATOR);
}
use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldHandleStringEquality.
@Test
public void shouldHandleStringEquality() throws Exception {
// Given
String value = "testValue";
QueryRequest request = mockQueryRequest(equalTo(new JsonPointer(STRING_ATTRIBUTE), value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(STRING_ATTRIBUTE, "ou"), value);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
use of com.sun.identity.entitlement.util.SearchFilter in project OpenAM by OpenRock.
the class ApplicationsResourceTest method shouldTranslateSupportedOperators.
@Test(dataProvider = "SupportedQueryOperators")
public void shouldTranslateSupportedOperators(String queryOperator, SearchFilter.Operator expectedOperator) throws Exception {
// Given
long value = 123l;
QueryRequest request = mockQueryRequest(comparisonFilter(new JsonPointer(NUMERIC_ATTRIBUTE), queryOperator, value));
Subject subject = new Subject();
// When
applicationsResource.query(request, subject, "/abc");
// Then
SearchFilter searchFilter = new SearchFilter(new SearchAttribute(NUMERIC_ATTRIBUTE, "ou"), value, expectedOperator);
verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), eq(asSet(searchFilter)));
}
Aggregations