use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl 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.ResourceListQueryImpl 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.ResourceListQueryImpl in project opencast by opencast.
the class ListProvidersEndpoint method getList.
@GET
@Path("{source}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "list", description = "Provides key-value list from the given source", pathParameters = { @RestParameter(name = "source", description = "The source for the key-value list", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The maximum number of items to return per page", isRequired = false, name = "limit", type = RestParameter.Type.INTEGER), @RestParameter(description = "The offset", isRequired = false, name = "offset", type = RestParameter.Type.INTEGER), @RestParameter(description = "Filters", isRequired = false, name = "filter", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the key-value list for the given source.", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response getList(@PathParam("source") final String source, @QueryParam("limit") final int limit, @QueryParam("filter") final String filter, @QueryParam("offset") final int offset, @Context HttpHeaders headers) {
if (listProvidersService.hasProvider(source)) {
ResourceListQueryImpl query = new ResourceListQueryImpl();
query.setLimit(limit);
query.setOffset(offset);
addRequestFiltersToQuery(filter, query);
Map<String, String> autocompleteList;
try {
autocompleteList = listProvidersService.getList(source, query, securityService.getOrganization(), false);
} catch (ListProviderException e) {
logger.error("Not able to get list from provider {}: {}", source, e);
return SERVER_ERROR;
}
JSONObject jsonList;
try {
jsonList = generateJSONObject(autocompleteList);
} catch (JsonCreationException e) {
logger.error("Not able to generate resources list JSON from source {}: {}", source, e);
return SERVER_ERROR;
}
return Response.ok(jsonList.toString()).build();
}
return NOT_FOUND;
}
use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.
the class ListProvidersScannerTest method testInstallInputOrgInPropertiesFileExpectsAddedToService.
@Test
public void testInstallInputOrgInPropertiesFileExpectsAddedToService() throws Exception {
Organization org1 = EasyMock.createMock(Organization.class);
EasyMock.expect(org1.getId()).andReturn("org1").anyTimes();
EasyMock.replay(org1);
Organization org2 = EasyMock.createMock(Organization.class);
EasyMock.expect(org2.getId()).andReturn("org2").anyTimes();
EasyMock.replay(org2);
String listName = "BLACKLISTS.USERS.REASONS";
File file = new File(ListProvidersScannerTest.class.getResource("/ListProvidersScannerTest-WithOrg.properties").toURI());
Capture<ResourceListProvider> resourceListProvider = new Capture<>();
Capture<String> captureListName = new Capture<>();
ListProvidersService listProvidersService = EasyMock.createNiceMock(ListProvidersService.class);
listProvidersService.addProvider(EasyMock.capture(captureListName), EasyMock.capture(resourceListProvider));
EasyMock.expectLastCall();
EasyMock.replay(listProvidersService);
ListProvidersScanner listProvidersScanner = new ListProvidersScanner();
listProvidersScanner.setListProvidersService(listProvidersService);
listProvidersScanner.install(file);
ResourceListQuery query = new ResourceListQueryImpl();
assertEquals(1, resourceListProvider.getValues().size());
assertEquals(listName, resourceListProvider.getValue().getListNames()[0]);
Map<String, String> stuff = resourceListProvider.getValue().getList(listName, query, org1);
for (String key : stuff.keySet()) {
logger.info("Key: {}, Value {}.", key, stuff.get(key));
}
assertEquals(3, resourceListProvider.getValue().getList(listName, query, org1).size());
assertNull(resourceListProvider.getValue().getList(listName, query, org2));
assertNull(resourceListProvider.getValue().getList(listName, query, null));
assertEquals("Sick Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.SICK_LEAVE"));
assertEquals("Leave", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.LEAVE"));
assertEquals("Family Emergency", resourceListProvider.getValue().getList(listName, null, org1).get("PM.BLACKLIST.REASONS.FAMILY_EMERGENCY"));
}
use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.
the class ContributorsListProviderTest method testListQuery.
@Test
public void testListQuery() {
ResourceListQueryImpl query = new ResourceListQueryImpl();
query.setLimit(0);
query.setOffset(0);
Assert.assertEquals(5, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query, null).size());
query.setOffset(3);
Assert.assertEquals(2, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query, null).size());
query.setOffset(0);
query.setLimit(1);
Assert.assertEquals(1, contributorsListProvider.getList(ContributorsListProvider.NAMES_TO_USERNAMES, query, null).size());
}
Aggregations