Search in sources :

Example 6 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery 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 7 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class ServersListProviderTest method testStatusList.

@Test
public void testStatusList() throws ListProviderException {
    ResourceListQuery query = new ServersListQuery();
    Map<String, String> list = serverListProvider.getList(ServersListProvider.LIST_STATUS, query, null);
    assertEquals(ServersListProvider.SERVER_STATUS_LABEL_ONLINE, list.get(ServersListProvider.SERVER_STATUS_ONLINE));
    assertEquals(ServersListProvider.SERVER_STATUS_LABEL_OFFLINE, list.get(ServersListProvider.SERVER_STATUS_OFFLINE));
    assertEquals(ServersListProvider.SERVER_STATUS_LABEL_MAINTENANCE, list.get(ServersListProvider.SERVER_STATUS_MAINTENANCE));
}
Also used : ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) ServersListQuery(org.opencastproject.index.service.resources.list.query.ServersListQuery) Test(org.junit.Test)

Example 8 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery 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 9 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery in project opencast by opencast.

the class JobsListProviderTest method testStatusListName.

@Test
public void testStatusListName() throws ListProviderException, WorkflowDatabaseException {
    ResourceListQuery query = new JobsListQuery();
    assertEquals(4, jobsListProvider.getList(JobsListProvider.LIST_STATUS, query, null).size());
    for (Entry<String, String> entry : jobsListProvider.getList(JobsListProvider.LIST_STATUS, query, null).entrySet()) {
        try {
            Job.Status.valueOf(entry.getKey());
        } catch (IllegalArgumentException ex) {
            fail("Can not parse job state");
        }
        assertTrue(StringUtils.startsWith(entry.getValue(), JobsListProvider.JOB_STATUS_FILTER_PREFIX));
    }
}
Also used : ResourceListQuery(org.opencastproject.index.service.resources.list.api.ResourceListQuery) JobsListQuery(org.opencastproject.index.service.resources.list.query.JobsListQuery) Test(org.junit.Test)

Example 10 with ResourceListQuery

use of org.opencastproject.index.service.resources.list.api.ResourceListQuery 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

ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)10 Test (org.junit.Test)8 ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)4 HashMap (java.util.HashMap)3 ResourceListProvider (org.opencastproject.index.service.resources.list.api.ResourceListProvider)3 ServersListQuery (org.opencastproject.index.service.resources.list.query.ServersListQuery)3 Organization (org.opencastproject.security.api.Organization)3 Map (java.util.Map)2 ListProviderException (org.opencastproject.index.service.exception.ListProviderException)2 ListProvidersServiceImpl (org.opencastproject.index.service.resources.list.impl.ListProvidersServiceImpl)2 JobsListQuery (org.opencastproject.index.service.resources.list.query.JobsListQuery)2 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)2 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)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 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1