use of org.opencastproject.index.service.resources.list.query.StringListFilter in project opencast by opencast.
the class JSONUtilsTest method testFiltersToJSON.
/**
* Test method for
* {@link JSONUtils#filtersToJSON(org.opencastproject.index.service.resources.list.api.ResourceListQuery, org.opencastproject.index.service.resources.list.api.ListProvidersService, org.opencastproject.security.api.Organization)}
* (filters, listProviderService, query, org)}
*/
@Test
public void testFiltersToJSON() throws Exception {
String expectedJSON = IOUtils.toString(getClass().getResource("/filters.json"));
JaxbOrganization defaultOrganization = new DefaultOrganization();
ListProvidersServiceImpl listProvidersService = new ListProvidersServiceImpl();
SimpleSerializer serializer = new SimpleSerializer();
final Map<String, String> license = new HashMap<String, String>();
license.put("contributor1", "My first contributor");
license.put("contributor2", "My second contributor");
license.put("contributor3", "My third contributor");
// Create test list provider
listProvidersService.addProvider(new ResourceListProvider() {
@Override
public String[] getListNames() {
return new String[] { ContributorsListProvider.DEFAULT };
}
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
return ListProviderUtil.filterMap(license, query);
}
@Override
public boolean isTranslatable(String listName) {
return false;
}
@Override
public String getDefault() {
return null;
}
});
// Prepare mock query
List<ResourceListFilter<?>> filters = new ArrayList<ResourceListFilter<?>>();
filters.add(SeriesListQuery.createContributorsFilter(Option.<String>none()));
filters.add(new StringListFilter(""));
ResourceListQueryImpl query = EasyMock.createNiceMock(ResourceListQueryImpl.class);
EasyMock.expect(query.getAvailableFilters()).andReturn(filters).anyTimes();
EasyMock.expect(query.getFilters()).andReturn(new ArrayList<ResourceListFilter<?>>()).anyTimes();
EasyMock.expect(query.getLimit()).andReturn(Option.<Integer>none()).anyTimes();
EasyMock.expect(query.getOffset()).andReturn(Option.<Integer>none()).anyTimes();
EasyMock.replay(query);
JValue result = JSONUtils.filtersToJSON(query, listProvidersService, defaultOrganization);
StreamingOutput stream = RestUtils.stream(serializer.fn.toJson(result));
ByteArrayOutputStream resultStream = new ByteArrayOutputStream();
try {
stream.write(resultStream);
assertThat(expectedJSON, SameJSONAs.sameJSONAs(resultStream.toString()));
} finally {
IOUtils.closeQuietly(resultStream);
}
}
use of org.opencastproject.index.service.resources.list.query.StringListFilter in project opencast by opencast.
the class ServiceTest method testConcreteFilter.
@Test
public void testConcreteFilter() {
ResourceListQueryImpl query = makeQuery(new StringListFilter("host", "HOST 1"));
assertTrue(service.isCompliant(query));
}
use of org.opencastproject.index.service.resources.list.query.StringListFilter in project opencast by opencast.
the class ServiceTest method testWrongCriterion.
@Test
public void testWrongCriterion() {
ResourceListQueryImpl query = makeQuery(new StringListFilter("doesntExist", "HOST 1"));
assertFalse(service.isCompliant(query));
}
use of org.opencastproject.index.service.resources.list.query.StringListFilter in project opencast by opencast.
the class ServiceTest method testPositiveFreetextFilter.
@Test
public void testPositiveFreetextFilter() {
ResourceListQueryImpl query = makeQuery(new StringListFilter("HOST 1"));
assertTrue(service.isCompliant(query));
}
use of org.opencastproject.index.service.resources.list.query.StringListFilter in project opencast by opencast.
the class SeriesListProvider method getList.
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
Map<String, String> series = new HashMap<String, String>();
SeriesQuery q = new SeriesQuery().setCount(Integer.MAX_VALUE);
if (query != null) {
if (query.hasFilter(FILTER_TEXT)) {
StringListFilter filter = (StringListFilter) query.getFilter(FILTER_TEXT);
if (filter.getValue().isSome())
q.setText(filter.getValue().get());
}
if (query.getLimit().isSome())
q.setCount(query.getLimit().get());
if (query.getOffset().isSome())
q.setStartPage(query.getOffset().get());
}
List<DublinCoreCatalog> result = null;
try {
if (!CONTRIBUTORS.equals(listName) && !ORGANIZERS.equals(listName) && !TITLE_EXTENDED.equals(listName)) {
return seriesService.getIdTitleMapOfAllSeries();
}
result = seriesService.getSeries(q).getCatalogList();
} catch (SeriesException e) {
throw new ListProviderException("Error appends on the series service: " + e);
} catch (UnauthorizedException e) {
throw new ListProviderException("Unauthorized access to series service: " + e);
}
for (DublinCoreCatalog dc : result) {
if (CONTRIBUTORS.equals(listName)) {
String contributor = dc.getFirst(DublinCore.PROPERTY_CONTRIBUTOR);
if (StringUtils.isNotBlank(contributor))
series.put(contributor, contributor);
} else if (ORGANIZERS.equals(listName)) {
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
if (StringUtils.isNotBlank(organizer))
series.put(organizer, organizer);
} else if (TITLE_EXTENDED.equals(listName)) {
String created = dc.getFirst(DublinCoreCatalog.PROPERTY_CREATED);
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
StringBuilder sb = new StringBuilder(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
if (StringUtils.isNotBlank(created) && StringUtils.isNotBlank(organizer)) {
List<String> extendedTitleData = new ArrayList<>();
if (StringUtils.isNotBlank(created)) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(EncodingSchemeUtils.decodeDate(created));
extendedTitleData.add(Integer.toString(calendar.get(Calendar.YEAR)));
}
if (StringUtils.isNotBlank(organizer))
extendedTitleData.add(organizer);
sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
}
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), sb.toString());
} else {
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
}
}
return series;
}
Aggregations