use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class ComposerServiceRemoteImpl method convertImage.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#convertImage(org.opencastproject.mediapackage.Attachment,
* java.lang.String)
*/
@Override
public Job convertImage(Attachment image, String profileId) throws EncoderException, MediaPackageException {
HttpPost post = new HttpPost("/convertimage");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("sourceImage", MediaPackageElementParser.getAsXml(image)));
params.add(new BasicNameValuePair("profileId", profileId));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Image conversion job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to convert image at " + image + " using the remote composer service proxy");
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class ComposerServiceRemoteImpl method image.
/**
* {@inheritDoc}
*
* @see org.opencastproject.composer.api.ComposerService#image(Track, String, Map)
*/
@Override
public Job image(Track sourceTrack, String profileId, Map<String, String> properties) throws EncoderException, MediaPackageException {
HttpPost post = new HttpPost("/image");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("sourceTrack", MediaPackageElementParser.getAsXml(sourceTrack)));
params.add(new BasicNameValuePair("profileId", profileId));
if (properties != null)
params.add(new BasicNameValuePair("properties", mapToString(properties)));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Image extraction job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to compose an image from track " + sourceTrack + " using the remote composer service proxy");
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class ComposerServiceRemoteImpl method imageToVideo.
@Override
public Job imageToVideo(Attachment sourceImageAttachment, String profileId, double time) throws EncoderException, MediaPackageException {
HttpPost post = new HttpPost("/imagetovideo");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("sourceAttachment", MediaPackageElementParser.getAsXml(sourceImageAttachment)));
params.add(new BasicNameValuePair("profileId", profileId));
params.add(new BasicNameValuePair("time", Double.toString(time)));
post.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
} catch (Exception e) {
throw new EncoderException(e);
}
HttpResponse response = null;
try {
response = getResponse(post);
if (response != null) {
Job r = JobParser.parseJob(response.getEntity().getContent());
logger.info("Image to video converting job {} started on a remote composer", r.getId());
return r;
}
} catch (Exception e) {
throw new EncoderException(e);
} finally {
closeConnection(response);
}
throw new EncoderException("Unable to convert an image to a video from attachment " + sourceImageAttachment + " using the remote composer service proxy");
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class CompositeWorkflowOperationHandler method composite.
private WorkflowOperationResult composite(MediaPackage src, WorkflowOperationInstance operation) throws EncoderException, IOException, NotFoundException, MediaPackageException, WorkflowOperationException {
MediaPackage mediaPackage = (MediaPackage) src.clone();
CompositeSettings compositeSettings;
try {
compositeSettings = new CompositeSettings(mediaPackage, operation);
} catch (IllegalArgumentException e) {
logger.warn("Unable to parse composite settings because {}", ExceptionUtils.getStackTrace(e));
return createResult(mediaPackage, Action.SKIP);
}
Option<Attachment> watermarkAttachment = Option.<Attachment>none();
Collection<Attachment> watermarkElements = compositeSettings.getWatermarkSelector().select(mediaPackage, false);
if (watermarkElements.size() > 1) {
logger.warn("More than one watermark attachment has been found for compositing, skipping compositing!: {}", watermarkElements);
return createResult(mediaPackage, Action.SKIP);
} else if (watermarkElements.size() == 0 && compositeSettings.getSourceUrlWatermark() != null) {
logger.info("No watermark found from flavor and tags, take watermark from URL {}", compositeSettings.getSourceUrlWatermark());
Attachment urlAttachment = new AttachmentImpl();
urlAttachment.setIdentifier(compositeSettings.getWatermarkIdentifier());
if (compositeSettings.getSourceUrlWatermark().startsWith("http")) {
urlAttachment.setURI(UrlSupport.uri(compositeSettings.getSourceUrlWatermark()));
} else {
InputStream in = null;
try {
in = UrlSupport.url(compositeSettings.getSourceUrlWatermark()).openStream();
URI imageUrl = workspace.putInCollection(COLLECTION, compositeSettings.getWatermarkIdentifier() + "." + FilenameUtils.getExtension(compositeSettings.getSourceUrlWatermark()), in);
urlAttachment.setURI(imageUrl);
} catch (Exception e) {
logger.warn("Unable to read watermark source url {}: {}", compositeSettings.getSourceUrlWatermark(), e);
throw new WorkflowOperationException("Unable to read watermark source url " + compositeSettings.getSourceUrlWatermark(), e);
} finally {
IOUtils.closeQuietly(in);
}
}
watermarkAttachment = Option.option(urlAttachment);
} else if (watermarkElements.size() == 0 && compositeSettings.getSourceUrlWatermark() == null) {
logger.info("No watermark to composite");
} else {
for (Attachment a : watermarkElements) watermarkAttachment = Option.option(a);
}
Collection<Track> upperElements = compositeSettings.getUpperTrackSelector().select(mediaPackage, false);
Collection<Track> lowerElements = compositeSettings.getLowerTrackSelector().select(mediaPackage, false);
// There is only a single track to work with.
if ((upperElements.size() == 1 && lowerElements.size() == 0) || (upperElements.size() == 0 && lowerElements.size() == 1)) {
for (Track t : upperElements) compositeSettings.setSingleTrack(t);
for (Track t : lowerElements) compositeSettings.setSingleTrack(t);
return handleSingleTrack(mediaPackage, operation, compositeSettings, watermarkAttachment);
} else {
// Look for upper elements matching the tags and flavor
if (upperElements.size() > 1) {
logger.warn("More than one upper track has been found for compositing, skipping compositing!: {}", upperElements);
return createResult(mediaPackage, Action.SKIP);
} else if (upperElements.size() == 0) {
logger.warn("No upper track has been found for compositing, skipping compositing!");
return createResult(mediaPackage, Action.SKIP);
}
for (Track t : upperElements) {
compositeSettings.setUpperTrack(t);
}
// Look for lower elements matching the tags and flavor
if (lowerElements.size() > 1) {
logger.warn("More than one lower track has been found for compositing, skipping compositing!: {}", lowerElements);
return createResult(mediaPackage, Action.SKIP);
} else if (lowerElements.size() == 0) {
logger.warn("No lower track has been found for compositing, skipping compositing!");
return createResult(mediaPackage, Action.SKIP);
}
for (Track t : lowerElements) {
compositeSettings.setLowerTrack(t);
}
return handleMultipleTracks(mediaPackage, operation, compositeSettings, watermarkAttachment);
}
}
use of org.opencastproject.mediapackage.MediaPackageException in project opencast by opencast.
the class SeriesUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
SearchQuery q = new SearchQuery().withSeriesId(seriesId);
SearchResult result = searchService.getForAdministrativeRead(q);
for (SearchResultItem item : result.getItems()) {
MediaPackage mp = item.getMediaPackage();
Organization org = organizationDirectoryService.getOrganization(item.getOrganization());
securityService.setOrganization(org);
// to the distribution channels as well
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
Attachment fileRepoCopy = authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl()).getB();
// Distribute the updated XACML file
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, fileRepoCopy.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(fileRepoCopy);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute XACML {}", fileRepoCopy.getIdentifier());
continue;
}
}
// Update the series dublin core
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
// Distribute the updated series dc
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, c.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(c);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute series catalog {}", c.getIdentifier());
continue;
}
}
}
// Remove the series catalog and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
boolean retractSeriesCatalog = retractSeriesCatalog(mp);
boolean updateEpisodeCatalog = updateEpisodeCatalog(mp);
if (!retractSeriesCatalog || !updateEpisodeCatalog)
continue;
}
// Update the search index with the modified mediapackage
Job searchJob = searchService.add(mp);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, searchJob);
barrier.waitForJobs();
}
} catch (SearchException e) {
logger.warn("Unable to find mediapackages in search: ", e.getMessage());
} catch (UnauthorizedException e) {
logger.warn(e.getMessage());
} catch (MediaPackageException e) {
logger.warn(e.getMessage());
} catch (ServiceRegistryException e) {
logger.warn(e.getMessage());
} catch (NotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} catch (DistributionException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
Aggregations