Search in sources :

Example 6 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class IndexServiceImpl method getEventMediapackage.

@Override
public MediaPackage getEventMediapackage(Event event) throws IndexServiceException {
    switch(getEventSource(event)) {
        case WORKFLOW:
            Opt<WorkflowInstance> currentWorkflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
            if (currentWorkflowInstance.isNone()) {
                logger.error("No workflow instance for event {} found!", event.getIdentifier());
                throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
            }
            return currentWorkflowInstance.get().getMediaPackage();
        case ARCHIVE:
            final AQueryBuilder q = assetManager.createQuery();
            final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(event.getIdentifier()).and(q.version().isLatest())).run();
            if (r.getSize() > 0) {
                logger.debug("Found event in archive with id {}", event.getIdentifier());
                return enrich(r).getSnapshots().head2().getMediaPackage();
            }
            logger.error("No event with id {} found from archive!", event.getIdentifier());
            throw new IndexServiceException("No archived event found with id " + event.getIdentifier());
        case SCHEDULE:
            try {
                MediaPackage mediaPackage = schedulerService.getMediaPackage(event.getIdentifier());
                logger.debug("Found event in scheduler with id {}", event.getIdentifier());
                return mediaPackage;
            } catch (NotFoundException e) {
                logger.error("No scheduled event with id {} found!", event.getIdentifier());
                throw new IndexServiceException(e.getMessage(), e);
            } catch (UnauthorizedException e) {
                logger.error("Unauthorized to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException(e.getMessage(), e);
            } catch (SchedulerException e) {
                logger.error("Unable to get event with id {} from scheduler because {}", event.getIdentifier(), getStackTrace(e));
                throw new IndexServiceException(e.getMessage(), e);
            }
        default:
            throw new IllegalStateException("Unknown event type!");
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) AResult(org.opencastproject.assetmanager.api.query.AResult) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 7 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class EventHttpServletRequest method createFromHttpServletRequest.

/**
 * Create a {@link EventHttpServletRequest} from a {@link HttpServletRequest} to create a new {@link Event}.
 *
 * @param request
 *          The multipart request that should result in a new {@link Event}
 * @param ingestService
 *          The {@link IngestService} to use to ingest {@link Event} media.
 * @param eventCatalogUIAdapters
 *          The catalog ui adapters to use for getting the event metadata.
 * @param startDatePattern
 *          The pattern to use to parse the start date from the request.
 * @param startTimePattern
 *          The pattern to use to parse the start time from the request.
 * @return An {@link EventHttpServletRequest} populated from the request.
 * @throws IndexServiceException
 *           Thrown if unable to create the event for an internal reason.
 * @throws IllegalArgumentException
 *           Thrown if the multi part request doesn't have the necessary data.
 */
public static EventHttpServletRequest createFromHttpServletRequest(HttpServletRequest request, IngestService ingestService, List<EventCatalogUIAdapter> eventCatalogUIAdapters, JSONObject source, Opt<String> startDatePattern, Opt<String> startTimePattern) throws IndexServiceException {
    EventHttpServletRequest eventHttpServletRequest = new EventHttpServletRequest();
    eventHttpServletRequest.setSource(source);
    try {
        if (ServletFileUpload.isMultipartContent(request)) {
            eventHttpServletRequest.setMediaPackage(ingestService.createMediaPackage());
            if (eventHttpServletRequest.getMediaPackage().isNone()) {
                throw new IndexServiceException("Unable to create a new mediapackage to store the new event's media.");
            }
            for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
                FileItemStream item = iter.next();
                String fieldName = item.getFieldName();
                if (item.isFormField()) {
                    setFormField(eventCatalogUIAdapters, eventHttpServletRequest, item, fieldName, startDatePattern, startTimePattern);
                } else {
                    ingestFile(ingestService, eventHttpServletRequest, item);
                }
            }
        } else {
            throw new IllegalArgumentException("No multipart content");
        }
        return eventHttpServletRequest;
    } catch (Exception e) {
        throw new IndexServiceException("Unable to parse new event.", e);
    }
}
Also used : ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) ParseException(org.json.simple.parser.ParseException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IngestException(org.opencastproject.ingest.api.IngestException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) FileUploadException(org.apache.commons.fileupload.FileUploadException)

Example 8 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class ToolsEndpoint method editVideo.

@POST
@Path("{mediapackageid}/editor.json")
@Consumes(MediaType.APPLICATION_JSON)
@RestQuery(name = "editVideo", description = "Takes editing information from the client side and processes it", returnDescription = "", pathParameters = { @RestParameter(name = "mediapackageid", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Editing information saved and processed", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not found", responseCode = HttpServletResponse.SC_NOT_FOUND), @RestResponse(description = "The editing information cannot be parsed", responseCode = HttpServletResponse.SC_BAD_REQUEST) })
public Response editVideo(@PathParam("mediapackageid") final String mediaPackageId, @Context HttpServletRequest request) throws IndexServiceException, NotFoundException {
    String details;
    try (InputStream is = request.getInputStream()) {
        details = IOUtils.toString(is);
    } catch (IOException e) {
        logger.error("Error reading request body: {}", getStackTrace(e));
        return R.serverError();
    }
    JSONParser parser = new JSONParser();
    EditingInfo editingInfo;
    try {
        JSONObject detailsJSON = (JSONObject) parser.parse(details);
        editingInfo = EditingInfo.parse(detailsJSON);
    } catch (Exception e) {
        logger.warn("Unable to parse concat information ({}): {}", details, ExceptionUtils.getStackTrace(e));
        return R.badRequest("Unable to parse details");
    }
    final Opt<Event> optEvent = getEvent(mediaPackageId);
    if (optEvent.isNone()) {
        return R.notFound();
    } else {
        MediaPackage mediaPackage = index.getEventMediapackage(optEvent.get());
        Smil smil;
        try {
            smil = createSmilCuttingCatalog(editingInfo, mediaPackage);
        } catch (Exception e) {
            logger.warn("Unable to create a SMIL cutting catalog ({}): {}", details, getStackTrace(e));
            return R.badRequest("Unable to create SMIL cutting catalog");
        }
        try {
            addSmilToArchive(mediaPackage, smil);
        } catch (IOException e) {
            logger.warn("Unable to add SMIL cutting catalog to archive: {}", getStackTrace(e));
            return R.serverError();
        }
        if (editingInfo.getPostProcessingWorkflow().isSome()) {
            final String workflowId = editingInfo.getPostProcessingWorkflow().get();
            try {
                final Workflows workflows = new Workflows(assetManager, workspace, workflowService);
                workflows.applyWorkflowToLatestVersion($(mediaPackage.getIdentifier().toString()), ConfiguredWorkflow.workflow(workflowService.getWorkflowDefinitionById(workflowId))).run();
            } catch (AssetManagerException e) {
                logger.warn("Unable to start workflow '{}' on archived media package '{}': {}", workflowId, mediaPackage, getStackTrace(e));
                return R.serverError();
            } catch (WorkflowDatabaseException e) {
                logger.warn("Unable to load workflow '{}' from workflow service: {}", workflowId, getStackTrace(e));
                return R.serverError();
            } catch (NotFoundException e) {
                logger.warn("Workflow '{}' not found", workflowId);
                return R.badRequest("Workflow not found");
            }
        }
    }
    return R.ok();
}
Also used : Workflows(org.opencastproject.assetmanager.util.Workflows) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) SmilException(org.opencastproject.smil.api.SmilException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) JAXBException(javax.xml.bind.JAXBException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) SAXException(org.xml.sax.SAXException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JSONObject(org.json.simple.JSONObject) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) JSONParser(org.json.simple.parser.JSONParser) Smil(org.opencastproject.smil.entity.api.Smil) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 9 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class SeriesEndpoint method createNewSeries.

@POST
@Path("")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "createseries", description = "Creates a series.", returnDescription = "", restParameters = { @RestParameter(name = "metadata", isRequired = true, description = "Series metadata", type = STRING), @RestParameter(name = "acl", description = "A collection of roles with their possible action", isRequired = false, type = STRING), @RestParameter(name = "theme", description = "The theme ID to be applied to the series", isRequired = false, type = STRING) }, reponses = { @RestResponse(description = "A new series is created and its identifier is returned in the Location header.", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "The request is invalid or inconsistent..", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "The user doesn't have the rights to create the series.", responseCode = HttpServletResponse.SC_UNAUTHORIZED) })
public Response createNewSeries(@HeaderParam("Accept") String acceptHeader, @FormParam("metadata") String metadataParam, @FormParam("acl") String aclParam, @FormParam("theme") String themeIdParam) throws UnauthorizedException, NotFoundException {
    if (isBlank(metadataParam))
        return R.badRequest("Required parameter 'metadata' is missing or invalid");
    MetadataList metadataList;
    try {
        metadataList = deserializeMetadataList(metadataParam);
    } catch (ParseException e) {
        logger.debug("Unable to parse series metadata '{}' because: {}", metadataParam, ExceptionUtils.getStackTrace(e));
        return R.badRequest(String.format("Unable to parse metadata because '%s'", e.toString()));
    } catch (NotFoundException e) {
        // One of the metadata fields could not be found in the catalogs or one of the catalogs cannot be found.
        return R.badRequest(e.getMessage());
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to create series with metadata '{}' because: {}", metadataParam, ExceptionUtils.getStackTrace(e));
        return R.badRequest(e.getMessage());
    }
    Map<String, String> options = new TreeMap<>();
    Opt<Long> optThemeId = Opt.none();
    if (StringUtils.trimToNull(themeIdParam) != null) {
        try {
            Long themeId = Long.parseLong(themeIdParam);
            optThemeId = Opt.some(themeId);
        } catch (NumberFormatException e) {
            return R.badRequest(String.format("Unable to parse the theme id '%s' into a number", themeIdParam));
        }
    }
    AccessControlList acl;
    try {
        acl = AclUtils.deserializeJsonToAcl(aclParam, false);
    } catch (ParseException e) {
        logger.debug("Unable to parse acl '{}' because: '{}'", aclParam, ExceptionUtils.getStackTrace(e));
        return R.badRequest(String.format("Unable to parse acl '%s' because '%s'", aclParam, e.getMessage()));
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to create new series with acl '{}' because: '{}'", aclParam, ExceptionUtils.getStackTrace(e));
        return R.badRequest(e.getMessage());
    }
    try {
        String seriesId = indexService.createSeries(metadataList, options, Opt.some(acl), optThemeId);
        return ApiResponses.Json.created(VERSION_1_0_0, URI.create(getSeriesUrl(seriesId)), obj(f("identifier", v(seriesId, BLANK))));
    } catch (IndexServiceException e) {
        logger.error("Unable to create series with metadata '{}', acl '{}', theme '{}' because: ", metadataParam, aclParam, themeIdParam, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) WebApplicationException(javax.ws.rs.WebApplicationException) NotFoundException(org.opencastproject.util.NotFoundException) TreeMap(java.util.TreeMap) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) ParseException(org.json.simple.parser.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 10 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class AbstractEventEndpoint method applyAclToEvent.

@POST
@Path("{eventId}/access")
@RestQuery(name = "applyAclToEvent", description = "Immediate application of an ACL to an event", returnDescription = "Status code", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING) }, 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 the event has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "Not authorized to perform this action"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEvent(@PathParam("eventId") String eventId, @FormParam("acl") String acl) throws NotFoundException, UnauthorizedException, SearchIndexException, IndexServiceException {
    final AccessControlList accessControlList;
    try {
        accessControlList = AccessControlParser.parseAcl(acl);
    } catch (Exception e) {
        logger.warn("Unable to parse ACL '{}'", acl);
        return badRequest();
    }
    try {
        final Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
        if (optEvent.isNone()) {
            logger.warn("Unable to find the event '{}'", eventId);
            return notFound();
        }
        Source eventSource = getIndexService().getEventSource(optEvent.get());
        if (eventSource == Source.ARCHIVE) {
            if (getAclService().applyAclToEpisode(eventId, accessControlList, Option.<ConfiguredWorkflowRef>none())) {
                return ok();
            } else {
                logger.warn("Unable to find the event '{}'", eventId);
                return notFound();
            }
        } else if (eventSource == Source.WORKFLOW) {
            logger.warn("An ACL cannot be edited while an event is part of a current workflow because it might" + " lead to inconsistent ACLs i.e. changed after distribution so that the old ACL is still " + "being used by the distribution channel.");
            JSONObject json = new JSONObject();
            json.put("Error", "Unable to edit an ACL for a current workflow.");
            return conflict(json.toJSONString());
        } else {
            MediaPackage mediaPackage = getIndexService().getEventMediapackage(optEvent.get());
            mediaPackage = getAuthorizationService().setAcl(mediaPackage, AclScope.Episode, accessControlList).getA();
            getSchedulerService().updateEvent(eventId, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
            return ok();
        }
    } catch (AclServiceException e) {
        logger.error("Error applying acl '{}' to event '{}' because: {}", accessControlList, eventId, ExceptionUtils.getStackTrace(e));
        return serverError();
    } catch (SchedulerException e) {
        logger.error("Error applying ACL to scheduled event {} because {}", eventId, ExceptionUtils.getStackTrace(e));
        return serverError();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) Set(java.util.Set) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) Source(org.opencastproject.index.service.api.IndexService.Source) Date(java.util.Date) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)21 NotFoundException (org.opencastproject.util.NotFoundException)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 IOException (java.io.IOException)11 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)11 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)11 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)11 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)9 IngestException (org.opencastproject.ingest.api.IngestException)9 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)9 WorkflowException (org.opencastproject.workflow.api.WorkflowException)9 ParseException (java.text.ParseException)8 JSONException (org.codehaus.jettison.json.JSONException)8 EventCommentException (org.opencastproject.event.comment.EventCommentException)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)8 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)7 SeriesException (org.opencastproject.series.api.SeriesException)7 JSONObject (org.json.simple.JSONObject)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6