use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.
the class LiveScheduleServiceImpl method addAndDistributeElements.
MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException {
try {
MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone();
Set<String> elementIds = new HashSet<String>();
// Then, add series catalog if needed
if (StringUtils.isNotEmpty(mp.getSeries())) {
DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries());
// Create temporary catalog and save to workspace
mp.add(catalog);
URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "series.xml", dublinCoreService.serialize(catalog));
catalog.setURI(uri);
catalog.setChecksum(null);
catalog.setFlavor(MediaPackageElements.SERIES);
elementIds.add(catalog.getIdentifier());
}
if (mp.getCatalogs(MediaPackageElements.EPISODE).length > 0)
elementIds.add(mp.getCatalogs(MediaPackageElements.EPISODE)[0].getIdentifier());
if (mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE).length > 0)
elementIds.add(mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE)[0].getIdentifier());
// Distribute element(s)
Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, elementIds, false);
if (!waitForStatus(distributionJob).isSuccess())
throw new LiveScheduleException("Element(s) for live media package " + mp.getIdentifier() + " could not be distributed");
for (String id : elementIds) {
MediaPackageElement e = mp.getElementById(id);
// Cleanup workspace/wfr
mp.remove(e);
workspace.delete(e.getURI());
}
// Add distributed element(s) to mp
List<MediaPackageElement> distributedElements = (List<MediaPackageElement>) MediaPackageElementParser.getArrayFromXml(distributionJob.getPayload());
for (MediaPackageElement mpe : distributedElements) mp.add(mpe);
return mp;
} catch (LiveScheduleException e) {
throw e;
} catch (Exception e) {
throw new LiveScheduleException(e);
}
}
use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.
the class LiveScheduleServiceImpl method replaceAndDistributeAcl.
MediaPackage replaceAndDistributeAcl(MediaPackage previousMp, AccessControlList acl) throws LiveScheduleException {
try {
// This is the mp from the search index
MediaPackage mp = (MediaPackage) previousMp.clone();
// Remove previous Acl from the mp
Attachment[] atts = mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
if (atts.length > 0)
mp.remove(atts[0]);
// Attach current ACL to mp, acl will be created in the ws/wfr
authService.setAcl(mp, AclScope.Episode, acl);
atts = mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
if (atts.length > 0) {
String aclId = atts[0].getIdentifier();
// Distribute new acl
Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, aclId, false);
if (!waitForStatus(distributionJob).isSuccess())
throw new LiveScheduleException("Acl for live media package " + mp.getIdentifier() + " could not be distributed");
MediaPackageElement e = mp.getElementById(aclId);
// Cleanup workspace/wfr
mp.remove(e);
workspace.delete(e.getURI());
// Add distributed acl to mp
mp.add(MediaPackageElementParser.getFromXml(distributionJob.getPayload()));
}
return mp;
} catch (LiveScheduleException e) {
throw e;
} catch (Exception e) {
throw new LiveScheduleException(e);
}
}
use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.
the class LiveScheduleServiceImpl method getSnapshot.
Snapshot getSnapshot(String mpId) throws LiveScheduleException {
AQueryBuilder query = assetManager.createQuery();
AResult result = query.select(query.snapshot()).where(query.mediaPackageId(mpId).and(query.version().isLatest())).run();
if (result.getSize() == 0) {
// Media package not archived?.
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
Opt<ARecord> record = result.getRecords().head();
if (record.isNone()) {
// No snapshot?
throw new LiveScheduleException(String.format("Unexpected error: media package %s has not been archived.", mpId));
}
return record.get().getSnapshot().get();
}
use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.
the class LiveScheduleServiceImpl method retractLiveEvent.
boolean retractLiveEvent(MediaPackage mp) throws LiveScheduleException {
if (!isLive(mp)) {
logger.debug("Media package {} is not live. Not retracting.", mp.getIdentifier().compact());
return false;
}
retract(mp);
// Get latest mp from the asset manager if there to remove the publication
try {
String mpId = mp.getIdentifier().toString();
Snapshot snapshot = getSnapshot(mpId);
MediaPackage archivedMp = snapshot.getMediaPackage();
removeLivePublicationChannel(archivedMp);
logger.debug("Removed live pub channel from archived media package {}", mp);
// Take a snapshot with the publication removed and put its version in our local cache
// so that we ignore notifications for this snapshot version.
snapshotVersionCache.put(mpId, assetManager.takeSnapshot(archivedMp).getVersion());
} catch (LiveScheduleException e) {
// It was not found in asset manager. This is ok.
}
return true;
}
use of org.opencastproject.liveschedule.api.LiveScheduleException in project opencast by opencast.
the class LiveScheduleServiceImpl method getMediaPackageFromSearch.
/**
* Retrieves the media package from the search index.
*
* @param mediaPackageId
* the media package id
* @return the media package in the search index or null if not there
* @throws LiveException
* if found many media packages with the same id
*/
MediaPackage getMediaPackageFromSearch(String mediaPackageId) throws LiveScheduleException {
// Look for the media package in the search index
SearchQuery query = new SearchQuery().withId(mediaPackageId);
SearchResult result = searchService.getByQuery(query);
if (result.size() == 0) {
logger.debug("The search service doesn't know live mediapackage {}", mediaPackageId);
return null;
} else if (result.size() > 1) {
logger.warn("More than one live mediapackage with id {} returned from search service", mediaPackageId);
throw new LiveScheduleException("More than one live mediapackage with id " + mediaPackageId + " found");
}
return result.getItems()[0].getMediaPackage();
}
Aggregations