use of org.opencastproject.assetmanager.api.AssetManagerException in project opencast by opencast.
the class AbstractAssetManager method storeAssets.
/**
* Store all elements of <code>pmp</code> under the given version.
*/
private void storeAssets(final PartialMediaPackage pmp, final Version version) throws Exception {
final String mpId = pmp.getMediaPackage().getIdentifier().toString();
final String orgId = getCurrentOrgId();
for (final MediaPackageElement e : pmp.getElements()) {
logger.debug(format("Archiving %s %s %s", e.getFlavor(), e.getMimeType(), e.getURI()));
final StoragePath storagePath = StoragePath.mk(orgId, mpId, version, e.getIdentifier());
final Opt<StoragePath> existingAssetOpt = findAssetInVersions(e.getChecksum().toString());
if (existingAssetOpt.isSome()) {
final StoragePath existingAsset = existingAssetOpt.get();
logger.debug("Content of asset {} with checksum {} has been archived before", existingAsset.getMediaPackageElementId(), e.getChecksum());
if (!getAssetStore().copy(existingAsset, storagePath)) {
throw new AssetManagerException(format("An asset with checksum %s has already been archived but trying to copy or link asset %s to it failed", e.getChecksum(), existingAsset));
}
} else {
final Opt<Long> size = e.getSize() > 0 ? Opt.some(e.getSize()) : Opt.<Long>none();
getAssetStore().put(storagePath, Source.mk(e.getURI(), size, Opt.nul(e.getMimeType())));
}
}
}
use of org.opencastproject.assetmanager.api.AssetManagerException in project opencast by opencast.
the class AbstractAssetManager method addInternal.
/**
* Mutates mp and its elements, so make sure to work on a copy.
*/
private SnapshotDto addInternal(String owner, final MediaPackage mp) throws Exception {
final Date now = new Date();
// claim a new version for the media package
final String mpId = mp.getIdentifier().toString();
final VersionImpl version = getDb().claimVersion(mpId);
logger.info("Creating new version {} of media package {}", version, mp);
final PartialMediaPackage pmp = assetsOnly(mp);
// make sure they have a checksum
calcChecksumsForMediaPackageElements(pmp);
// download and archive elements
storeAssets(pmp, version);
// store mediapackage in db
final SnapshotDto snapshotDto;
try {
rewriteUrisForArchival(pmp, version);
snapshotDto = getDb().saveSnapshot(getCurrentOrgId(), pmp, now, version, Availability.ONLINE, owner);
} catch (AssetManagerException e) {
logger.error("Could not take snapshot {}: {}", mpId, e);
throw new AssetManagerException(e);
}
// save manifest to element store
// this is done at the end after the media package element ids have been rewritten to neutral URNs
storeManifest(pmp, version);
return snapshotDto;
}
use of org.opencastproject.assetmanager.api.AssetManagerException in project opencast by opencast.
the class ToolsEndpoint method addSmilToArchive.
/**
* Adds the SMIL file as {@link Catalog} to the media package and sends the updated media package to the archive.
*
* @param mediaPackage
* the media package to at the SMIL catalog
* @param smil
* the SMIL catalog
* @return the updated media package
* @throws IOException
* if the SMIL catalog cannot be read or not be written to the archive
*/
MediaPackage addSmilToArchive(MediaPackage mediaPackage, final Smil smil) throws IOException {
MediaPackageElementFlavor mediaPackageElementFlavor = adminUIConfiguration.getSmilCatalogFlavor();
// set default catalog Id if there is none existing
String catalogId = smil.getId();
Catalog[] catalogs = mediaPackage.getCatalogs();
// get the first smil/cutting catalog-ID to overwrite it with new smil info
for (Catalog p : catalogs) {
if (p.getFlavor().matches(mediaPackageElementFlavor)) {
logger.debug("Set Idendifier for Smil-Catalog to: " + p.getIdentifier());
catalogId = p.getIdentifier();
break;
}
}
Catalog catalog = mediaPackage.getCatalog(catalogId);
URI smilURI;
try (InputStream is = IOUtils.toInputStream(smil.toXML(), "UTF-8")) {
smilURI = workspace.put(mediaPackage.getIdentifier().compact(), catalogId, TARGET_FILE_NAME, is);
} catch (SAXException e) {
logger.error("Error while serializing the SMIL catalog to XML: {}", e.getMessage());
throw new IOException(e);
} catch (JAXBException e) {
logger.error("Error while serializing the SMIL catalog to XML: {}", e.getMessage());
throw new IOException(e);
}
if (catalog == null) {
MediaPackageElementBuilder mpeBuilder = MediaPackageElementBuilderFactory.newInstance().newElementBuilder();
catalog = (Catalog) mpeBuilder.elementFromURI(smilURI, MediaPackageElement.Type.Catalog, adminUIConfiguration.getSmilCatalogFlavor());
mediaPackage.add(catalog);
}
catalog.setURI(smilURI);
catalog.setIdentifier(catalogId);
catalog.setMimeType(MimeTypes.XML);
for (String tag : adminUIConfiguration.getSmilCatalogTags()) {
catalog.addTag(tag);
}
// setting the URI to a new source so the checksum will most like be invalid
catalog.setChecksum(null);
try {
// FIXME SWITCHP-333: Start in new thread
assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
} catch (AssetManagerException e) {
logger.error("Error while adding the updated media package ({}) to the archive: {}", mediaPackage.getIdentifier(), e.getMessage());
throw new IOException(e);
}
return mediaPackage;
}
use of org.opencastproject.assetmanager.api.AssetManagerException 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.assetmanager.api.AssetManagerException in project opencast by opencast.
the class AbstractAssetManagerBasicTest method testUnwrapException.
@Test
public void testUnwrapException() {
assertTrue(AbstractAssetManager.unwrapExceptionUntil(Exception.class, new AssetManagerException()).isSome());
assertThat(AbstractAssetManager.unwrapExceptionUntil(Exception.class, new AssetManagerException()).get(), instanceOf(AssetManagerException.class));
assertEquals("error", AbstractAssetManager.unwrapExceptionUntil(AssetManagerException.class, new AssetManagerException("error")).get().getMessage());
assertEquals("error", AbstractAssetManager.unwrapExceptionUntil(AssetManagerException.class, new Exception(new AssetManagerException("error"))).get().getMessage());
assertEquals("wrapper", AbstractAssetManager.unwrapExceptionUntil(AssetManagerException.class, new AssetManagerException("wrapper", new AssetManagerException("error"))).get().getMessage());
}
Aggregations