use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class TestRestService method newAuthorizationService.
private static AuthorizationService newAuthorizationService() {
AccessControlList acl = new AccessControlList();
Attachment attachment = new AttachmentImpl();
MediaPackage mediapackage;
try {
mediapackage = new MediaPackageBuilderImpl().createNew();
} catch (MediaPackageException e) {
throw new RuntimeException(e);
}
AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
EasyMock.expect(authorizationService.setAcl((MediaPackage) EasyMock.anyObject(), (AclScope) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andReturn(Tuple.tuple(mediapackage, attachment));
EasyMock.replay(authorizationService);
return authorizationService;
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class IngestRestService method addMediaPackageElement.
protected Response addMediaPackageElement(HttpServletRequest request, MediaPackageElement.Type type) {
MediaPackageElementFlavor flavor = null;
InputStream in = null;
try {
String fileName = null;
MediaPackage mp = null;
Long startTime = null;
String[] tags = null;
/* Only accept multipart/form-data */
if (!ServletFileUpload.isMultipartContent(request)) {
logger.trace("request isn't multipart-form-data");
return Response.serverError().status(Status.BAD_REQUEST).build();
}
boolean isDone = false;
for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
FileItemStream item = iter.next();
String fieldName = item.getFieldName();
if (item.isFormField()) {
if ("flavor".equals(fieldName)) {
String flavorString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("flavor: {}", flavorString);
if (flavorString != null) {
flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
}
} else if ("tags".equals(fieldName)) {
String tagsString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("tags: {}", tagsString);
tags = tagsString.split(",");
} else if ("mediaPackage".equals(fieldName)) {
try {
String mediaPackageString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("mediaPackage: {}", mediaPackageString);
mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageString);
} catch (MediaPackageException e) {
logger.debug("Unable to parse the 'mediaPackage' parameter: {}", ExceptionUtils.getMessage(e));
return Response.serverError().status(Status.BAD_REQUEST).build();
}
} else if ("startTime".equals(fieldName) && "/addPartialTrack".equals(request.getPathInfo())) {
String startTimeString = Streams.asString(item.openStream(), "UTF-8");
logger.trace("startTime: {}", startTime);
try {
startTime = Long.parseLong(startTimeString);
} catch (Exception e) {
logger.debug("Unable to parse the 'startTime' parameter: {}", ExceptionUtils.getMessage(e));
return Response.serverError().status(Status.BAD_REQUEST).build();
}
}
} else {
if (flavor == null) {
/* A flavor has to be specified in the request prior the video file */
logger.debug("A flavor has to be specified in the request prior to the content BODY");
return Response.serverError().status(Status.BAD_REQUEST).build();
}
fileName = item.getName();
in = item.openStream();
isDone = true;
}
if (isDone) {
break;
}
}
/*
* Check if we actually got a valid request including a message body and a valid mediapackage to attach the
* element to
*/
if (in == null || mp == null || MediaPackageSupport.sanityCheck(mp).isSome()) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
switch(type) {
case Attachment:
mp = ingestService.addAttachment(in, fileName, flavor, tags, mp);
break;
case Catalog:
mp = ingestService.addCatalog(in, fileName, flavor, tags, mp);
break;
case Track:
if (startTime == null) {
mp = ingestService.addTrack(in, fileName, flavor, tags, mp);
} else {
mp = ingestService.addPartialTrack(in, fileName, flavor, startTime, mp);
}
break;
default:
throw new IllegalStateException("Type must be one of track, catalog, or attachment");
}
return Response.ok(MediaPackageParser.getAsXml(mp)).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
IOUtils.closeQuietly(in);
}
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class IngestRestService method ingestZippedMediaPackage.
private Response ingestZippedMediaPackage(HttpServletRequest request, String wdID, String wiID) {
if (isIngestLimitEnabled()) {
setIngestLimit(getIngestLimit() - 1);
logger.debug("An ingest has started so remaining ingest limit is " + getIngestLimit());
}
InputStream in = null;
Date started = new Date();
logger.info("Received new request from {} to ingest a zipped mediapackage", request.getRemoteHost());
try {
String workflowDefinitionId = wdID;
String workflowIdAsString = wiID;
Long workflowInstanceIdAsLong = null;
Map<String, String> workflowConfig = new HashMap<>();
if (ServletFileUpload.isMultipartContent(request)) {
boolean isDone = false;
for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
FileItemStream item = iter.next();
if (item.isFormField()) {
String fieldName = item.getFieldName();
String value = Streams.asString(item.openStream(), "UTF-8");
logger.trace("{}: {}", fieldName, value);
if (WORKFLOW_INSTANCE_ID_PARAM.equals(fieldName)) {
workflowIdAsString = value;
continue;
} else if (WORKFLOW_DEFINITION_ID_PARAM.equals(fieldName)) {
workflowDefinitionId = value;
continue;
} else {
logger.debug("Processing form field: " + fieldName);
workflowConfig.put(fieldName, value);
}
} else {
logger.debug("Processing file item");
// once the body gets read iter.hasNext must not be invoked or the stream can not be read
// MH-9579
in = item.openStream();
isDone = true;
}
if (isDone)
break;
}
} else {
logger.debug("Processing file item");
in = request.getInputStream();
}
// Adding ingest start time to workflow configuration
DateFormat formatter = new SimpleDateFormat(IngestService.UTC_DATE_FORMAT);
workflowConfig.put(IngestService.START_DATE_KEY, formatter.format(started));
/* Legacy support: Try to convert the workflowId to integer */
if (!StringUtils.isBlank(workflowIdAsString)) {
try {
workflowInstanceIdAsLong = Long.parseLong(workflowIdAsString);
} catch (NumberFormatException e) {
// The workflowId is not a long value and might be the media package identifier
workflowConfig.put(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY, workflowIdAsString);
}
}
if (StringUtils.isBlank(workflowDefinitionId)) {
workflowDefinitionId = defaultWorkflowDefinitionId;
}
WorkflowInstance workflow;
if (workflowInstanceIdAsLong != null) {
workflow = ingestService.addZippedMediaPackage(in, workflowDefinitionId, workflowConfig, workflowInstanceIdAsLong);
} else {
workflow = ingestService.addZippedMediaPackage(in, workflowDefinitionId, workflowConfig);
}
return Response.ok(WorkflowParser.toXml(workflow)).build();
} catch (NotFoundException e) {
logger.info(e.getMessage());
return Response.status(Status.NOT_FOUND).build();
} catch (MediaPackageException e) {
logger.warn(e.getMessage());
return Response.serverError().status(Status.BAD_REQUEST).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
} finally {
IOUtils.closeQuietly(in);
if (isIngestLimitEnabled()) {
setIngestLimit(getIngestLimit() + 1);
logger.debug("An ingest has finished so increased ingest limit to " + getIngestLimit());
}
}
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class IngestServiceImpl method createMediaPackage.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#createMediaPackage()
*/
@Override
public MediaPackage createMediaPackage() throws MediaPackageException, ConfigurationException, HandleException {
MediaPackage mediaPackage;
try {
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
} catch (MediaPackageException e) {
logger.error("INGEST:Failed to create media package " + e.getLocalizedMessage());
throw e;
}
mediaPackage.setDate(new Date());
logger.info("Created mediapackage {}", mediaPackage);
return mediaPackage;
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class IngestServiceImpl method createMediaPackage.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#createMediaPackage()
*/
@Override
public MediaPackage createMediaPackage(String mediaPackageId) throws MediaPackageException, ConfigurationException, HandleException {
MediaPackage mediaPackage;
try {
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew(new UUIDIdBuilderImpl().fromString(mediaPackageId));
} catch (MediaPackageException e) {
logger.error("INGEST:Failed to create media package " + e.getLocalizedMessage());
throw e;
}
mediaPackage.setDate(new Date());
logger.info("Created mediapackage {}", mediaPackage);
return mediaPackage;
}
Aggregations