Search in sources :

Example 76 with RestQuery

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

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

the class ServicesEndpoint method getServices.

@GET
@Path("services.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(description = "Returns the list of services", name = "services", restParameters = { @RestParameter(name = "limit", description = "The maximum number of items to return per page", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "offset", description = "The offset", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "filter", description = "Filter results by name, host, actions, status or free text query", isRequired = false, type = STRING), @RestParameter(name = "sort", description = "The sort order.  May include any " + "of the following: host, name, running, queued, completed,  meanRunTime, meanQueueTime, " + "status. The sort suffix must be :asc for ascending sort order and :desc for descending.", isRequired = false, type = STRING) }, reponses = { @RestResponse(description = "Returns the list of services from Opencast", responseCode = HttpServletResponse.SC_OK) }, returnDescription = "The list of services")
public Response getServices(@QueryParam("limit") final int limit, @QueryParam("offset") final int offset, @QueryParam("filter") String filter, @QueryParam("sort") String sort) throws Exception {
    Option<String> sortOpt = Option.option(StringUtils.trimToNull(sort));
    ServicesListQuery query = new ServicesListQuery();
    EndpointUtil.addRequestFiltersToQuery(filter, query);
    String fName = null;
    if (query.getName().isSome())
        fName = StringUtils.trimToNull(query.getName().get());
    String fHostname = null;
    if (query.getHostname().isSome())
        fHostname = StringUtils.trimToNull(query.getHostname().get());
    String fStatus = null;
    if (query.getStatus().isSome())
        fStatus = StringUtils.trimToNull(query.getStatus().get());
    String fFreeText = null;
    if (query.getFreeText().isSome())
        fFreeText = StringUtils.trimToNull(query.getFreeText().get());
    List<Service> services = new ArrayList<Service>();
    for (ServiceStatistics stats : serviceRegistry.getServiceStatistics()) {
        Service service = new Service(stats);
        if (fName != null && !StringUtils.equalsIgnoreCase(service.getName(), fName))
            continue;
        if (fHostname != null && !StringUtils.equalsIgnoreCase(service.getHost(), fHostname))
            continue;
        if (fStatus != null && !StringUtils.equalsIgnoreCase(service.getStatus().toString(), fStatus))
            continue;
        if (query.getActions().isSome()) {
            ServiceState serviceState = service.getStatus();
            if (query.getActions().get()) {
                if (ServiceState.NORMAL == serviceState)
                    continue;
            } else {
                if (ServiceState.NORMAL != serviceState)
                    continue;
            }
        }
        if (fFreeText != null && !StringUtils.containsIgnoreCase(service.getName(), fFreeText) && !StringUtils.containsIgnoreCase(service.getHost(), fFreeText) && !StringUtils.containsIgnoreCase(service.getStatus().toString(), fFreeText))
            continue;
        services.add(service);
    }
    int total = services.size();
    if (sortOpt.isSome()) {
        Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(sortOpt.get());
        if (!sortCriteria.isEmpty()) {
            try {
                SortCriterion sortCriterion = sortCriteria.iterator().next();
                Collections.sort(services, new ServiceStatisticsComparator(sortCriterion.getFieldName(), sortCriterion.getOrder() == SearchQuery.Order.Ascending));
            } catch (Exception ex) {
                logger.warn("Failed to sort services collection.", ex);
            }
        }
    }
    List<JValue> jsonList = new ArrayList<JValue>();
    for (Service s : new SmartIterator<Service>(limit, offset).applyLimitAndOffset(services)) {
        jsonList.add(s.toJSON());
    }
    return RestUtils.okJsonList(jsonList, offset, limit, total);
}
Also used : ServiceState(org.opencastproject.serviceregistry.api.ServiceState) ArrayList(java.util.ArrayList) RestService(org.opencastproject.util.doc.rest.RestService) ServiceStatistics(org.opencastproject.serviceregistry.api.ServiceStatistics) SortCriterion(org.opencastproject.matterhorn.search.SortCriterion) JValue(com.entwinemedia.fn.data.json.JValue) ServicesListQuery(org.opencastproject.index.service.resources.list.query.ServicesListQuery) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 78 with RestQuery

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

the class ThemesEndpoint method updateTheme.

@PUT
@Path("{themeId}")
@RestQuery(name = "updateTheme", description = "Updates a theme", returnDescription = "Return the updated theme", pathParameters = { @RestParameter(name = "themeId", description = "The theme identifier", isRequired = true, type = Type.INTEGER) }, restParameters = { @RestParameter(name = "default", description = "Whether the theme is default", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "name", description = "The theme name", isRequired = false, type = Type.STRING), @RestParameter(name = "description", description = "The theme description", isRequired = false, type = Type.TEXT), @RestParameter(name = "bumperActive", description = "Whether the theme bumper is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "trailerActive", description = "Whether the theme trailer is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "titleSlideActive", description = "Whether the theme title slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "licenseSlideActive", description = "Whether the theme license slide is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "watermarkActive", description = "Whether the theme watermark is active", isRequired = false, type = Type.BOOLEAN), @RestParameter(name = "bumperFile", description = "The theme bumper file", isRequired = false, type = Type.STRING), @RestParameter(name = "trailerFile", description = "The theme trailer file", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkFile", description = "The theme watermark file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideBackground", description = "The theme title slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideBackground", description = "The theme license slide background file", isRequired = false, type = Type.STRING), @RestParameter(name = "titleSlideMetadata", description = "The theme title slide metadata", isRequired = false, type = Type.STRING), @RestParameter(name = "licenseSlideDescription", description = "The theme license slide description", isRequired = false, type = Type.STRING), @RestParameter(name = "watermarkPosition", description = "The theme watermark position", isRequired = false, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Theme updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found.") })
public Response updateTheme(@PathParam("themeId") long themeId, @FormParam("default") Boolean isDefault, @FormParam("name") String name, @FormParam("description") String description, @FormParam("bumperActive") Boolean bumperActive, @FormParam("trailerActive") Boolean trailerActive, @FormParam("titleSlideActive") Boolean titleSlideActive, @FormParam("licenseSlideActive") Boolean licenseSlideActive, @FormParam("watermarkActive") Boolean watermarkActive, @FormParam("bumperFile") String bumperFile, @FormParam("trailerFile") String trailerFile, @FormParam("watermarkFile") String watermarkFile, @FormParam("titleSlideBackground") String titleSlideBackground, @FormParam("licenseSlideBackground") String licenseSlideBackground, @FormParam("titleSlideMetadata") String titleSlideMetadata, @FormParam("licenseSlideDescription") String licenseSlideDescription, @FormParam("watermarkPosition") String watermarkPosition) throws NotFoundException {
    try {
        Theme origTheme = themesServiceDatabase.getTheme(themeId);
        if (isDefault == null)
            isDefault = origTheme.isDefault();
        if (StringUtils.isBlank(name))
            name = origTheme.getName();
        if (StringUtils.isEmpty(description))
            description = origTheme.getDescription();
        if (bumperActive == null)
            bumperActive = origTheme.isBumperActive();
        if (StringUtils.isEmpty(bumperFile))
            bumperFile = origTheme.getBumperFile();
        if (trailerActive == null)
            trailerActive = origTheme.isTrailerActive();
        if (StringUtils.isEmpty(trailerFile))
            trailerFile = origTheme.getTrailerFile();
        if (titleSlideActive == null)
            titleSlideActive = origTheme.isTitleSlideActive();
        if (StringUtils.isEmpty(titleSlideMetadata))
            titleSlideMetadata = origTheme.getTitleSlideMetadata();
        if (StringUtils.isEmpty(titleSlideBackground))
            titleSlideBackground = origTheme.getTitleSlideBackground();
        if (licenseSlideActive == null)
            licenseSlideActive = origTheme.isLicenseSlideActive();
        if (StringUtils.isEmpty(licenseSlideBackground))
            licenseSlideBackground = origTheme.getLicenseSlideBackground();
        if (StringUtils.isEmpty(licenseSlideDescription))
            licenseSlideDescription = origTheme.getLicenseSlideDescription();
        if (watermarkActive == null)
            watermarkActive = origTheme.isWatermarkActive();
        if (StringUtils.isEmpty(watermarkFile))
            watermarkFile = origTheme.getWatermarkFile();
        if (StringUtils.isEmpty(watermarkPosition))
            watermarkPosition = origTheme.getWatermarkPosition();
        Theme theme = new Theme(origTheme.getId(), origTheme.getCreationDate(), isDefault, origTheme.getCreator(), name, StringUtils.trimToNull(description), BooleanUtils.toBoolean(bumperActive), StringUtils.trimToNull(bumperFile), BooleanUtils.toBoolean(trailerActive), StringUtils.trimToNull(trailerFile), BooleanUtils.toBoolean(titleSlideActive), StringUtils.trimToNull(titleSlideMetadata), StringUtils.trimToNull(titleSlideBackground), BooleanUtils.toBoolean(licenseSlideActive), StringUtils.trimToNull(licenseSlideBackground), StringUtils.trimToNull(licenseSlideDescription), BooleanUtils.toBoolean(watermarkActive), StringUtils.trimToNull(watermarkFile), StringUtils.trimToNull(watermarkPosition));
        try {
            updateReferencedFiles(origTheme, theme);
        } catch (IOException e) {
            logger.warn("Error while persisting file: {}", e.getMessage());
            return R.serverError();
        } catch (NotFoundException e) {
            logger.warn("A file that is referenced in theme '{}' was not found: {}", theme, e.getMessage());
            return R.badRequest("Referenced non-existing file");
        }
        Theme updatedTheme = themesServiceDatabase.updateTheme(theme);
        return RestUtils.okJson(themeToJSON(updatedTheme));
    } catch (ThemesServiceDatabaseException e) {
        logger.error("Unable to update theme {}: {}", themeId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
}
Also used : Theme(org.opencastproject.themes.Theme) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) ThemesServiceDatabaseException(org.opencastproject.themes.persistence.ThemesServiceDatabaseException) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 79 with RestQuery

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

the class ThemesEndpoint method getThemeUsage.

@GET
@Path("{themeId}/usage.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getThemeUsage", description = "Returns the theme usage by the given id as JSON", returnDescription = "The theme usage as JSON", pathParameters = { @RestParameter(name = "themeId", description = "The theme id", isRequired = true, type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(description = "Returns the theme usage as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Theme with the given id does not exist", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getThemeUsage(@PathParam("themeId") long themeId) throws Exception {
    Opt<org.opencastproject.index.service.impl.index.theme.Theme> theme = getTheme(themeId);
    if (theme.isNone())
        return notFound("Cannot find a theme with id {}", themeId);
    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));
        return RestUtil.R.serverError();
    }
    List<JValue> seriesValues = new ArrayList<JValue>();
    for (SearchResultItem<Series> item : results.getItems()) {
        Series series = item.getSource();
        seriesValues.add(obj(f("id", v(series.getIdentifier())), f("title", v(series.getTitle()))));
    }
    return okJson(obj(f("series", arr(seriesValues))));
}
Also used : SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SeriesSearchQuery(org.opencastproject.index.service.impl.index.series.SeriesSearchQuery) ArrayList(java.util.ArrayList) Series(org.opencastproject.index.service.impl.index.series.Series) JValue(com.entwinemedia.fn.data.json.JValue) Theme(org.opencastproject.themes.Theme) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 80 with RestQuery

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

the class ThemesEndpoint method deleteTheme.

@DELETE
@Path("{themeId}")
@RestQuery(name = "deleteTheme", description = "Deletes a theme", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "themeId", isRequired = true, description = "The theme identifier", type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "If the theme has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method does not return any content"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public Response deleteTheme(@PathParam("themeId") long themeId) throws NotFoundException, UnauthorizedException {
    try {
        Theme theme = themesServiceDatabase.getTheme(themeId);
        try {
            deleteReferencedFiles(theme);
        } catch (IOException e) {
            logger.warn("Error while deleting referenced file: {}", e.getMessage());
            return R.serverError();
        }
        themesServiceDatabase.deleteTheme(themeId);
        deleteThemeOnSeries(themeId);
        return RestUtil.R.noContent();
    } catch (NotFoundException e) {
        logger.warn("Unable to find a theme with id " + themeId);
        throw e;
    } catch (ThemesServiceDatabaseException e) {
        logger.error("Error getting theme {} during delete operation because: {}", themeId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
}
Also used : Theme(org.opencastproject.themes.Theme) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) ThemesServiceDatabaseException(org.opencastproject.themes.persistence.ThemesServiceDatabaseException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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