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);
}
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();
}
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;
}
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;
}
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;
}
Aggregations