Search in sources :

Example 71 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class SeriesEndpoint method getSeriesMetadata.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{seriesId}/metadata.json")
@RestQuery(name = "getseriesmetadata", description = "Returns the series metadata as JSON", returnDescription = "Returns the series metadata as JSON", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series metadata as JSON."), @RestResponse(responseCode = SC_NOT_FOUND, description = "The series has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public Response getSeriesMetadata(@PathParam("seriesId") String series) throws UnauthorizedException, NotFoundException, SearchIndexException {
    Opt<Series> optSeries = indexService.getSeries(series, searchIndex);
    if (optSeries.isNone())
        return notFound("Cannot find a series with id '%s'.", series);
    MetadataList metadataList = new MetadataList();
    List<SeriesCatalogUIAdapter> catalogUIAdapters = indexService.getSeriesCatalogUIAdapters();
    catalogUIAdapters.remove(indexService.getCommonSeriesCatalogUIAdapter());
    for (SeriesCatalogUIAdapter adapter : catalogUIAdapters) {
        final Opt<MetadataCollection> optSeriesMetadata = adapter.getFields(series);
        if (optSeriesMetadata.isSome()) {
            metadataList.add(adapter.getFlavor(), adapter.getUITitle(), optSeriesMetadata.get());
        }
    }
    metadataList.add(indexService.getCommonSeriesCatalogUIAdapter(), getSeriesMetadata(optSeries.get()));
    return okJson(metadataList.toJSON());
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) Series(org.opencastproject.index.service.impl.index.series.Series) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) SeriesCatalogUIAdapter(org.opencastproject.metadata.dublincore.SeriesCatalogUIAdapter) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 72 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class SeriesEndpoint method changeOptOuts.

@POST
@Path("optouts")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "changeOptOuts", description = "Change the opt out status of many series", returnDescription = "A JSON array listing which series were or were not opted out.", restParameters = { @RestParameter(name = "seriesIds", description = "A JSON array of ids of the series to opt out or in", defaultValue = "[]", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "optout", description = "Whether to opt out or not either true or false.", defaultValue = "false", isRequired = true, type = RestParameter.Type.BOOLEAN) }, reponses = { @RestResponse(description = "Returns a JSON object with the results for the different opted out or in elements such as ok, notFound or error.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Unable to parse boolean value to opt out, or parse JSON array of opt out series", responseCode = HttpServletResponse.SC_BAD_REQUEST) })
public Response changeOptOuts(@FormParam("optout") boolean optout, @FormParam("seriesIds") String seriesIds) {
    JSONParser parser = new JSONParser();
    JSONArray seriesIdsArray;
    try {
        seriesIdsArray = (JSONArray) parser.parse(seriesIds);
    } catch (org.json.simple.parser.ParseException e) {
        logger.warn("Unable to parse series ids {} : {}", seriesIds, ExceptionUtils.getStackTrace(e));
        return Response.status(Status.BAD_REQUEST).build();
    } catch (NullPointerException e) {
        logger.warn("Unable to parse series ids because it was null {}", seriesIds);
        return Response.status(Status.BAD_REQUEST).build();
    } catch (ClassCastException e) {
        logger.warn("Unable to parse series ids because it was the wrong class {} : {}", seriesIds, ExceptionUtils.getStackTrace(e));
        return Response.status(Status.BAD_REQUEST).build();
    }
    BulkOperationResult result = new BulkOperationResult();
    for (Object seriesId : seriesIdsArray) {
        try {
            seriesService.updateOptOutStatus(seriesId.toString(), optout);
            result.addOk(seriesId.toString());
        } catch (NotFoundException e) {
            result.addNotFound(seriesId.toString());
        } catch (Exception e) {
            logger.error("Could not update opt out status of series {}: {}", seriesId.toString(), ExceptionUtils.getStackTrace(e));
            result.addServerError(seriesId.toString());
        }
    }
    return Response.ok(result.toJson()).build();
}
Also used : JSONArray(org.json.simple.JSONArray) NotFoundException(org.opencastproject.util.NotFoundException) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) BulkOperationResult(org.opencastproject.rest.BulkOperationResult) 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) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 73 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.

the class SeriesEndpoint method getSeriesParticipationInformation.

@GET
@Path("{seriesId}/participation.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getseriesparticipationinformation", description = "Get the particition information of a series", returnDescription = "The participation information", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series identifier", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the series has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") })
public Response getSeriesParticipationInformation(@PathParam("seriesId") String seriesId) throws Exception {
    if (StringUtils.isBlank(seriesId))
        return RestUtil.R.badRequest("Path parameter series ID is missing");
    Opt<Series> optSeries = indexService.getSeries(seriesId, searchIndex);
    if (optSeries.isNone()) {
        logger.warn("Unable to find the series '{}'", seriesId);
        return notFound();
    }
    Series series = optSeries.get();
    return okJson(obj(f("opt_out", v(series.isOptedOut()))));
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 74 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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 75 with RestQuery

use of org.opencastproject.util.doc.rest.RestQuery 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)

Aggregations

RestQuery (org.opencastproject.util.doc.rest.RestQuery)228 Path (javax.ws.rs.Path)226 Produces (javax.ws.rs.Produces)172 GET (javax.ws.rs.GET)97 POST (javax.ws.rs.POST)89 WebApplicationException (javax.ws.rs.WebApplicationException)83 NotFoundException (org.opencastproject.util.NotFoundException)83 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 MediaPackage (org.opencastproject.mediapackage.MediaPackage)52 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)46 Event (org.opencastproject.index.service.impl.index.event.Event)34 ParseException (java.text.ParseException)33 JSONObject (org.json.simple.JSONObject)33 IOException (java.io.IOException)32 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)32 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)31 Job (org.opencastproject.job.api.Job)30 Date (java.util.Date)29 ArrayList (java.util.ArrayList)28 PUT (javax.ws.rs.PUT)28