Search in sources :

Example 6 with ResourceListQueryImpl

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));
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter) Test(org.junit.Test)

Example 7 with ResourceListQueryImpl

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));
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter) Test(org.junit.Test)

Example 8 with ResourceListQueryImpl

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;
}
Also used : EndpointUtil.generateJSONObject(org.opencastproject.adminui.endpoint.EndpointUtil.generateJSONObject) JSONObject(org.json.simple.JSONObject) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) JsonCreationException(org.opencastproject.adminui.exception.JsonCreationException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 9 with ResourceListQueryImpl

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"));
}
Also used : Organization(org.opencastproject.security.api.Organization) ResourceListProvider(org.opencastproject.index.service.resources.list.api.ResourceListProvider) ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) File(java.io.File) Capture(org.easymock.Capture) Test(org.junit.Test)

Example 10 with ResourceListQueryImpl

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());
}
Also used : ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) Test(org.junit.Test)

Aggregations

ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)15 Test (org.junit.Test)12 StringListFilter (org.opencastproject.index.service.resources.list.query.StringListFilter)7 ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)4 HashMap (java.util.HashMap)3 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 JSONObject (org.json.simple.JSONObject)2 EndpointUtil.generateJSONObject (org.opencastproject.adminui.endpoint.EndpointUtil.generateJSONObject)2 JsonCreationException (org.opencastproject.adminui.exception.JsonCreationException)2 ResourceListProvider (org.opencastproject.index.service.resources.list.api.ResourceListProvider)2 Organization (org.opencastproject.security.api.Organization)2 RestQuery (org.opencastproject.util.doc.rest.RestQuery)2 JValue (com.entwinemedia.fn.data.json.JValue)1 SimpleSerializer (com.entwinemedia.fn.data.json.SimpleSerializer)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1