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