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