Search in sources :

Example 6 with ListProviderException

use of org.opencastproject.index.service.exception.ListProviderException in project opencast by opencast.

the class EventCatalogUIAdapterTest method setUp.

@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
    TreeMap<String, String> collection = new TreeMap<String, String>();
    collection.put("Entry 1", "Value 1");
    collection.put("Entry 2", "Value 2");
    collection.put("Entry 3", "Value 3");
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.replay(bundleContext);
    listProvidersService = EasyMock.createMock(ListProvidersService.class);
    EasyMock.expect(listProvidersService.getList(EasyMock.anyString(), EasyMock.anyObject(ResourceListQueryImpl.class), EasyMock.anyObject(Organization.class), EasyMock.anyBoolean())).andReturn(collection).anyTimes();
    EasyMock.expect(listProvidersService.isTranslatable(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
    EasyMock.expect(listProvidersService.getDefault(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
    EasyMock.replay(listProvidersService);
    Properties props = new Properties();
    InputStream in = getClass().getResourceAsStream("/catalog-adapter/event.properties");
    props.load(in);
    in.close();
    eventProperties = PropertiesUtil.toDictionary(props);
    mediaPackageElementFlavor = new MediaPackageElementFlavor(FLAVOR_STRING.split("/")[0], FLAVOR_STRING.split("/")[1]);
    URI eventDublincoreURI = getClass().getResource("/catalog-adapter/event-dublincore.xml").toURI();
    workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
    EasyMock.replay(workspace);
    Catalog eventCatalog = EasyMock.createMock(Catalog.class);
    EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
    EasyMock.replay(eventCatalog);
    Catalog[] catalogs = { eventCatalog };
    mediapackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).anyTimes();
    EasyMock.replay(mediapackage);
    dictionary = new Hashtable<String, String>();
    dictionary.put(CONF_ORGANIZATION_KEY, ORGANIZATION_STRING);
    dictionary.put(CONF_FLAVOR_KEY, FLAVOR_STRING);
    dictionary.put(CONF_TITLE_KEY, TITLE_STRING);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_INPUT_ID_KEY, title);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LABEL_KEY, label);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_TYPE_KEY, type);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_READ_ONLY_KEY, readOnly);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_REQUIRED_KEY, required);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LIST_PROVIDER_KEY, listProvider);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_COLLECTION_ID_KEY, collectionID);
}
Also used : ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) TreeMap(java.util.TreeMap) Properties(java.util.Properties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) FileInputStream(java.io.FileInputStream) Catalog(org.opencastproject.mediapackage.Catalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 7 with ListProviderException

use of org.opencastproject.index.service.exception.ListProviderException 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)

Example 8 with ListProviderException

use of org.opencastproject.index.service.exception.ListProviderException in project opencast by opencast.

the class ListProvidersServiceImpl method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization, boolean inverseValueKey) throws ListProviderException {
    ResourceListProvider provider = providers.get(listName);
    if (provider == null)
        throw new ListProviderException("No resources list found with the name " + listName);
    Map<String, String> list = provider.getList(listName, query, organization);
    if (inverseValueKey) {
        list = invertMap(list);
    }
    return list;
}
Also used : ResourceListProvider(org.opencastproject.index.service.resources.list.api.ResourceListProvider) ListProviderException(org.opencastproject.index.service.exception.ListProviderException)

Example 9 with ListProviderException

use of org.opencastproject.index.service.exception.ListProviderException in project opencast by opencast.

the class ServersListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> list = new HashMap<String, String>();
    if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) {
        list.put(SERVER_STATUS_ONLINE, SERVER_STATUS_LABEL_ONLINE);
        list.put(SERVER_STATUS_OFFLINE, SERVER_STATUS_LABEL_OFFLINE);
        list.put(SERVER_STATUS_MAINTENANCE, SERVER_STATUS_LABEL_MAINTENANCE);
        return list;
    }
    ServersListQuery serversQuery;
    try {
        serversQuery = (ServersListQuery) query;
    } catch (ClassCastException ex) {
        serversQuery = new ServersListQuery(query);
    }
    Option<String> fHostname = serversQuery.getHostname();
    Option<String> fStatus = serversQuery.getStatus();
    List<HostRegistration> allServers;
    try {
        allServers = serviceRegistry.getHostRegistrations();
    } catch (ServiceRegistryException e) {
        throw new ListProviderException("Not able to get the list of the hosts from the services registry");
    }
    for (HostRegistration server : allServers) {
        boolean vOnline = server.isOnline();
        boolean vMaintenance = server.isMaintenanceMode();
        String vHostname = server.getBaseUrl();
        if (fHostname.isSome() && !StringUtils.equalsIgnoreCase(StringUtils.trimToEmpty(fHostname.get()), vHostname))
            continue;
        if (fStatus.isSome()) {
            switch(StringUtils.trimToEmpty(fStatus.get())) {
                case SERVER_STATUS_ONLINE:
                    if (!vOnline)
                        continue;
                    break;
                case SERVER_STATUS_OFFLINE:
                    if (vOnline)
                        continue;
                    break;
                case SERVER_STATUS_MAINTENANCE:
                    if (!vMaintenance)
                        continue;
                    break;
                default:
                    break;
            }
        }
        switch(listName) {
            case LIST_HOSTNAME:
            default:
                list.put(vHostname, vHostname);
                break;
        }
    }
    return list;
}
Also used : HashMap(java.util.HashMap) HostRegistration(org.opencastproject.serviceregistry.api.HostRegistration) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) ServersListQuery(org.opencastproject.index.service.resources.list.query.ServersListQuery) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 10 with ListProviderException

use of org.opencastproject.index.service.exception.ListProviderException in project opencast by opencast.

the class ThemesListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> list = new HashMap<String, String>();
    if (NAME.equals(listName)) {
        ThemeSearchQuery themeQuery = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
        themeQuery.withOffset(query.getOffset().getOrElse(0));
        int limit = query.getLimit().getOrElse(Integer.MAX_VALUE - themeQuery.getOffset());
        themeQuery.withLimit(limit);
        themeQuery.sortByName(SearchQuery.Order.Ascending);
        SearchResult<Theme> results = null;
        try {
            results = searchIndex.getByQuery(themeQuery);
        } catch (SearchIndexException e) {
            logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
            throw new ListProviderException("No themes list for list name " + listName + " found!");
        }
        for (SearchResultItem<Theme> item : results.getItems()) {
            Theme theme = item.getSource();
            list.put(Long.toString(theme.getIdentifier()), theme.getName());
        }
    } else if (DESCRIPTION.equals(listName)) {
        ThemeSearchQuery themeQuery = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
        themeQuery.withOffset(query.getOffset().getOrElse(0));
        int limit = query.getLimit().getOrElse(Integer.MAX_VALUE - themeQuery.getOffset());
        themeQuery.withLimit(limit);
        themeQuery.sortByName(SearchQuery.Order.Ascending);
        SearchResult<Theme> results = null;
        try {
            results = searchIndex.getByQuery(themeQuery);
        } catch (SearchIndexException e) {
            logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
            throw new ListProviderException("No themes list for list name " + listName + " found!");
        }
        for (SearchResultItem<Theme> item : results.getItems()) {
            Theme theme = item.getSource();
            if (theme.getDescription() == null) {
                theme.setDescription("");
            } else {
                theme.getDescription();
            }
            list.put(Long.toString(theme.getIdentifier()), theme.getDescription());
        }
    }
    return list;
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) HashMap(java.util.HashMap) ThemeSearchQuery(org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery) SearchResultItem(org.opencastproject.matterhorn.search.SearchResultItem) Theme(org.opencastproject.index.service.impl.index.theme.Theme) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) SearchResult(org.opencastproject.matterhorn.search.SearchResult)

Aggregations

ListProviderException (org.opencastproject.index.service.exception.ListProviderException)11 HashMap (java.util.HashMap)7 ResourceListQueryImpl (org.opencastproject.index.service.resources.list.query.ResourceListQueryImpl)3 ArrayList (java.util.ArrayList)2 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 ResourceListQuery (org.opencastproject.index.service.resources.list.api.ResourceListQuery)2 StringListFilter (org.opencastproject.index.service.resources.list.query.StringListFilter)2 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)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 FileInputStream (java.io.FileInputStream)1