Search in sources :

Example 11 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ServiceTest method testNegativeFreetextFilter.

@Test
public void testNegativeFreetextFilter() {
    ResourceListQueryImpl query = makeQuery(new StringListFilter("doesnt exist"));
    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 12 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ServiceTest method testNegativeConcreteFilter.

@Test
public void testNegativeConcreteFilter() {
    ResourceListQueryImpl query = makeQuery(new StringListFilter("name", "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 13 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ListProvidersServiceTest method testQuery.

@Test
public void testQuery() throws ListProviderException {
    ResourceListQueryImpl query = new ResourceListQueryImpl();
    final String providerName1 = "test1";
    final Map<String, String> list1 = new HashMap<String, String>();
    list1.put("1", "x test34");
    list1.put("2", "a test12");
    list1.put("3", "c ok");
    list1.put("4", "z essai test");
    listProviderService.addProvider(getResourceListProvider(providerName1, list1));
    query.setLimit(2);
    query.setOffset(1);
    Assert.assertEquals(2, listProviderService.getList(providerName1, query, null, false).size());
    query.setLimit(1);
    query.setOffset(5);
    Assert.assertEquals(0, listProviderService.getList(providerName1, query, null, false).size());
    query.setLimit(2);
    query.setOffset(1);
    Assert.assertEquals(2, listProviderService.getList(providerName1, query, null, false).size());
    query.setLimit(12);
    query.setOffset(0);
    query.addFilter(new StringListFilter(TEST_FILTER_NAME, "test"));
    Assert.assertEquals(3, listProviderService.getList(providerName1, query, null, false).size());
// query.setSortedBy(TEST_SORTBY);
// Map<String, String> list = listProviderService.getList(providerName1, query, null);
// int i = 0;
// Iterator<Entry<String, String>> iterator = list.entrySet().iterator();
// Assert.assertEquals(list1.get("2"), iterator.next().getValue());
}
Also used : HashMap(java.util.HashMap) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter) Test(org.junit.Test)

Example 14 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ListProvidersServiceTest method testAddandRemove.

@Test
public void testAddandRemove() throws ListProviderException {
    final String providerName1 = "test1";
    final Map<String, String> list1 = new HashMap<String, String>();
    list1.put("1", "test");
    list1.put("2", "test");
    list1.put("3", "test");
    list1.put("4", "test");
    final String providerName2 = "test2";
    final Map<String, String> list2 = new HashMap<String, String>();
    list2.put("1", "test");
    list2.put("2", "test");
    list2.put("3", "test");
    list2.put("4", "test");
    int baseNumber = listProviderService.getAvailableProviders().size();
    ResourceListQuery query = new ResourceListQueryImpl();
    listProviderService.addProvider(getResourceListProvider(providerName1, list1));
    listProviderService.addProvider(getResourceListProvider(providerName2, list2));
    Assert.assertEquals(baseNumber + 2, listProviderService.getAvailableProviders().size());
    Assert.assertTrue(listProviderService.hasProvider(providerName1));
    Assert.assertTrue(listProviderService.hasProvider(providerName2));
    Assert.assertEquals(list1, listProviderService.getList(providerName1, query, null, false));
    Assert.assertEquals(list2, listProviderService.getList(providerName2, query, null, false));
    listProviderService.removeProvider(providerName2);
    Assert.assertEquals(baseNumber + 1, listProviderService.getAvailableProviders().size());
    Assert.assertFalse(listProviderService.hasProvider(providerName2));
}
Also used : HashMap(java.util.HashMap) ResourceListQueryImpl(org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) Test(org.junit.Test)

Example 15 with ResourceListQueryImpl

use of org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl in project opencast by opencast.

the class ListProvidersEndpoint method getComponents.

@GET
@Path("components.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "components", description = "Provides a set of constants lists (right now only eventCommentReasons) for use in the admin UI", reponses = { @RestResponse(description = "Returns a set of constants lists (right now only eventCommentReasons) for use in the admin UI", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "")
public Response getComponents(@Context HttpHeaders headers) {
    String[] sources = { "eventCommentReasons" };
    ResourceListQuery query = new ResourceListQueryImpl();
    JSONObject list = new JSONObject();
    for (String source : sources) {
        if (listProvidersService.hasProvider(source)) {
            JSONObject subList;
            try {
                subList = generateJSONObject(listProvidersService.getList(source, query, securityService.getOrganization(), true));
                list.put(source, subList);
            } catch (JsonCreationException e) {
                logger.error("Not able to generate resources list JSON from source {}: {}", source, e);
                return SERVER_ERROR;
            } catch (ListProviderException e) {
                logger.error("Not able to get list from provider {}: {}", source, e);
                return SERVER_ERROR;
            }
        } else {
            return NOT_FOUND;
        }
    }
    return Response.ok(list.toString()).build();
}
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) ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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