use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class GroupsEndpoint method getGroups.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("groups.json")
@RestQuery(name = "allgroupsasjson", description = "Returns a list of groups", returnDescription = "List of groups for the current user's organization as JSON.", restParameters = { @RestParameter(name = "filter", isRequired = false, type = STRING, description = "Filter used for the query, formatted like: 'filter1:value1,filter2:value2'"), @RestParameter(name = "sort", isRequired = false, type = STRING, description = "The sort order. May include any of the following: NAME, DESCRIPTION, ROLE. " + "Add '_DESC' to reverse the sort order (e.g. NAME_DESC)."), @RestParameter(name = "limit", isRequired = false, type = INTEGER, defaultValue = "100", description = "The maximum number of items to return per page."), @RestParameter(name = "offset", isRequired = false, type = INTEGER, defaultValue = "0", description = "The page number.") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The groups.") })
public Response getGroups(@QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("offset") int offset, @QueryParam("limit") int limit) throws IOException {
GroupSearchQuery query = new GroupSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
Opt<String> optSort = Opt.nul(trimToNull(sort));
Option<Integer> optOffset = Option.option(offset);
Option<Integer> optLimit = Option.option(limit);
// If the limit is set to 0, this is not taken into account
if (optLimit.isSome() && limit == 0) {
optLimit = Option.none();
}
Map<String, String> filters = RestUtils.parseFilter(filter);
for (String name : filters.keySet()) {
if (GroupsListQuery.FILTER_NAME_NAME.equals(name)) {
query.withName(filters.get(name));
} else if (GroupsListQuery.FILTER_TEXT_NAME.equals(name)) {
query.withText(QueryPreprocessor.sanitize(filters.get(name)));
}
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case GroupIndexSchema.NAME:
query.sortByName(criterion.getOrder());
break;
case GroupIndexSchema.DESCRIPTION:
query.sortByDescription(criterion.getOrder());
break;
case GroupIndexSchema.ROLE:
query.sortByRole(criterion.getOrder());
break;
case GroupIndexSchema.MEMBERS:
query.sortByMembers(criterion.getOrder());
break;
case GroupIndexSchema.ROLES:
query.sortByRoles(criterion.getOrder());
break;
default:
throw new WebApplicationException(Status.BAD_REQUEST);
}
}
}
if (optLimit.isSome())
query.withLimit(optLimit.get());
if (optOffset.isSome())
query.withOffset(optOffset.get());
SearchResult<Group> results;
try {
results = searchIndex.getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The External Search Index was not able to get the groups list.", e);
return RestUtil.R.serverError();
}
List<JValue> groupsJSON = new ArrayList<>();
for (SearchResultItem<Group> item : results.getItems()) {
Group group = item.getSource();
List<Field> fields = new ArrayList<>();
fields.add(f("id", v(group.getIdentifier())));
fields.add(f("name", v(group.getName(), Jsons.BLANK)));
fields.add(f("description", v(group.getDescription(), Jsons.BLANK)));
fields.add(f("role", v(group.getRole())));
fields.add(f("users", membersToJSON(group.getMembers())));
groupsJSON.add(obj(fields));
}
return okJsonList(groupsJSON, offset, limit, results.getHitCount());
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class SeriesEndpoint method getSeriesTheme.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{seriesId}/theme.json")
@RestQuery(name = "getSeriesTheme", description = "Returns the series theme id and name as JSON", returnDescription = "Returns the series theme name and id as JSON", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series theme id and name as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series or theme has not been found") })
public Response getSeriesTheme(@PathParam("seriesId") String seriesId) {
Long themeId;
try {
Opt<Series> series = indexService.getSeries(seriesId, searchIndex);
if (series.isNone())
return notFound("Cannot find a series with id {}", seriesId);
themeId = series.get().getTheme();
} catch (SearchIndexException e) {
logger.error("Unable to get series {}: {}", seriesId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
// If no theme is set return empty JSON
if (themeId == null)
return okJson(obj());
try {
Opt<Theme> themeOpt = getTheme(themeId);
if (themeOpt.isNone())
return notFound("Cannot find a theme with id {}", themeId);
return getSimpleThemeJsonResponse(themeOpt.get());
} catch (SearchIndexException e) {
logger.error("Unable to get theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class SeriesEndpoint method getNewThemes.
@GET
@Path("new/themes")
@SuppressWarnings("unchecked")
@RestQuery(name = "getNewThemes", description = "Returns all the data related to the themes tab in the new series modal as JSON", returnDescription = "All the data related to the series themes tab as JSON", reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the series themes tab as JSON") })
public Response getNewThemes() {
ThemeSearchQuery query = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
// need to set limit because elasticsearch limit results by 10 per default
query.withLimit(Integer.MAX_VALUE);
query.withOffset(0);
query.sortByName(SearchQuery.Order.Ascending);
SearchResult<Theme> results = null;
try {
results = searchIndex.getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
JSONObject themesJson = new JSONObject();
for (SearchResultItem<Theme> item : results.getItems()) {
JSONObject themeInfoJson = new JSONObject();
Theme theme = item.getSource();
themeInfoJson.put("name", theme.getName());
themeInfoJson.put("description", theme.getDescription());
themesJson.put(theme.getIdentifier(), themeInfoJson);
}
return Response.ok(themesJson.toJSONString()).build();
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class SeriesEndpoint method applyAclToSeries.
@POST
@Path("/{seriesId}/access")
@RestQuery(name = "applyAclToSeries", description = "Immediate application of an ACL to a series", returnDescription = "Status code", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING), @RestParameter(name = "override", isRequired = false, defaultValue = "false", description = "If true the series ACL will take precedence over any existing episode ACL", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToSeries(@PathParam("seriesId") String seriesId, @FormParam("acl") String acl, @DefaultValue("false") @FormParam("override") boolean override) throws SearchIndexException {
AccessControlList accessControlList;
try {
accessControlList = AccessControlParser.parseAcl(acl);
} catch (Exception e) {
logger.warn("Unable to parse ACL '{}'", acl);
return badRequest();
}
Opt<Series> series = indexService.getSeries(seriesId, searchIndex);
if (series.isNone())
return notFound("Cannot find a series with id {}", seriesId);
if (hasProcessingEvents(seriesId)) {
logger.warn("Can not update the ACL from series {}. Events being part of the series are currently processed.", seriesId);
return conflict();
}
try {
if (getAclService().applyAclToSeries(seriesId, accessControlList, override, Option.none()))
return ok();
else {
logger.warn("Unable to find series '{}' to apply the ACL.", seriesId);
return notFound();
}
} catch (AclServiceException e) {
logger.error("Error applying acl to series {}", seriesId);
return serverError();
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class ThemesEndpoint method deleteThemeOnSeries.
/**
* Deletes all related series theme entries
*
* @param themeId
* the theme id
*/
private void deleteThemeOnSeries(long themeId) throws UnauthorizedException {
SeriesSearchQuery query = new SeriesSearchQuery(securityService.getOrganization().getId(), securityService.getUser()).withTheme(themeId);
SearchResult<Series> results = null;
try {
results = searchIndex.getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The admin UI Search Index was not able to get the series with theme '{}': {}", themeId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
for (SearchResultItem<Series> item : results.getItems()) {
String seriesId = item.getSource().getIdentifier();
try {
seriesService.deleteSeriesProperty(seriesId, SeriesEndpoint.THEME_KEY);
} catch (NotFoundException e) {
logger.warn("Theme {} already deleted on series {}", themeId, seriesId);
} catch (SeriesException e) {
logger.error("Unable to remove theme from series {}: {}", seriesId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
}
Aggregations