Search in sources :

Example 16 with SearchIndexException

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());
}
Also used : Group(org.opencastproject.index.service.impl.index.group.Group) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ArrayList(java.util.ArrayList) GroupSearchQuery(org.opencastproject.index.service.impl.index.group.GroupSearchQuery) Field(com.entwinemedia.fn.data.json.Field) SortCriterion(org.opencastproject.matterhorn.search.SortCriterion) JValue(com.entwinemedia.fn.data.json.JValue) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 17 with SearchIndexException

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);
    }
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) WebApplicationException(javax.ws.rs.WebApplicationException) Theme(org.opencastproject.index.service.impl.index.theme.Theme) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 18 with SearchIndexException

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();
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) JSONObject(org.json.simple.JSONObject) ThemeSearchQuery(org.opencastproject.index.service.impl.index.theme.ThemeSearchQuery) Theme(org.opencastproject.index.service.impl.index.theme.Theme) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 19 with SearchIndexException

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();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Series(org.opencastproject.index.service.impl.index.series.Series) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SeriesException(org.opencastproject.series.api.SeriesException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 20 with SearchIndexException

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);
        }
    }
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) WebApplicationException(javax.ws.rs.WebApplicationException) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) NotFoundException(org.opencastproject.util.NotFoundException) SeriesException(org.opencastproject.series.api.SeriesException)

Aggregations

SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)43 NotFoundException (org.opencastproject.util.NotFoundException)18 WebApplicationException (javax.ws.rs.WebApplicationException)15 Path (javax.ws.rs.Path)14 RestQuery (org.opencastproject.util.doc.rest.RestQuery)14 Event (org.opencastproject.index.service.impl.index.event.Event)11 IOException (java.io.IOException)10 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)10 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)10 SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)9 Produces (javax.ws.rs.Produces)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)8 User (org.opencastproject.security.api.User)8 GET (javax.ws.rs.GET)7 ParseException (java.text.ParseException)6 ArrayList (java.util.ArrayList)6 JSONException (org.codehaus.jettison.json.JSONException)6 EventCommentException (org.opencastproject.event.comment.EventCommentException)6 Series (org.opencastproject.index.service.impl.index.series.Series)6 Theme (org.opencastproject.index.service.impl.index.theme.Theme)6