Search in sources :

Example 11 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addSmilCatalog.

/**
 * Adds a SMIL catalog to a mediapackage if it's not already existing.
 *
 * @param smilDocument
 *          the smil document
 * @param mediaPackage
 *          the mediapackage to extend with the SMIL catalog
 * @return the augmented mediapcakge
 * @throws IOException
 *           if reading or writing of the SMIL catalog fails
 * @throws IngestException
 *           if the SMIL catalog already exists
 */
private MediaPackage addSmilCatalog(org.w3c.dom.Document smilDocument, MediaPackage mediaPackage) throws IOException, IngestException {
    Option<org.w3c.dom.Document> optSmilDocument = loadSmilDocument(workingFileRepository, mediaPackage);
    if (optSmilDocument.isSome())
        throw new IngestException("SMIL already exists!");
    InputStream in = null;
    try {
        in = XmlUtil.serializeDocument(smilDocument);
        String elementId = UUID.randomUUID().toString();
        URI uri = workingFileRepository.put(mediaPackage.getIdentifier().compact(), elementId, PARTIAL_SMIL_NAME, in);
        MediaPackageElement mpe = mediaPackage.add(uri, MediaPackageElement.Type.Catalog, MediaPackageElements.SMIL);
        mpe.setIdentifier(elementId);
        // Reset the checksum since it changed
        mpe.setChecksum(null);
        mpe.setMimeType(MimeTypes.SMIL);
        return mediaPackage;
    } finally {
        IoSupport.closeQuietly(in);
    }
}
Also used : ProgressInputStream(org.opencastproject.util.ProgressInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) IngestException(org.opencastproject.ingest.api.IngestException) Document(org.jdom.Document) URI(java.net.URI)

Example 12 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addZippedMediaPackage.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addZippedMediaPackage(java.io.InputStream, java.lang.String,
 *      java.util.Map, java.lang.Long)
 */
@Override
public WorkflowInstance addZippedMediaPackage(InputStream zipStream, String workflowDefinitionId, Map<String, String> workflowConfig, Long workflowInstanceId) throws MediaPackageException, IOException, IngestException, NotFoundException, UnauthorizedException {
    // Start a job synchronously. We can't keep the open input stream waiting around.
    Job job = null;
    if (StringUtils.isNotBlank(workflowDefinitionId)) {
        try {
            workflowService.getWorkflowDefinitionById(workflowDefinitionId);
        } catch (WorkflowDatabaseException e) {
            throw new IngestException(e);
        } catch (NotFoundException nfe) {
            logger.warn("Workflow definition {} not found, using default workflow {} instead", workflowDefinitionId, defaultWorkflowDefinionId);
            workflowDefinitionId = defaultWorkflowDefinionId;
        }
    }
    if (workflowInstanceId != null) {
        logger.warn("Deprecated method! Ingesting zipped mediapackage with workflow {}", workflowInstanceId);
    } else {
        logger.info("Ingesting zipped mediapackage");
    }
    ZipArchiveInputStream zis = null;
    Set<String> collectionFilenames = new HashSet<>();
    try {
        // We don't need anybody to do the dispatching for us. Therefore we need to make sure that the job is never in
        // QUEUED state but set it to INSTANTIATED in the beginning and then manually switch it to RUNNING.
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_ZIP, null, null, false, ingestZipJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        // Create the working file target collection for this ingest operation
        String wfrCollectionId = Long.toString(job.getId());
        zis = new ZipArchiveInputStream(zipStream);
        ZipArchiveEntry entry;
        MediaPackage mp = null;
        Map<String, URI> uris = new HashMap<>();
        // Sequential number to append to file names so that, if two files have the same
        // name, one does not overwrite the other (see MH-9688)
        int seq = 1;
        // Folder name to compare with next one to figure out if there's a root folder
        String folderName = null;
        // Indicates if zip has a root folder or not, initialized as true
        boolean hasRootFolder = true;
        // While there are entries write them to a collection
        while ((entry = zis.getNextZipEntry()) != null) {
            try {
                if (entry.isDirectory() || entry.getName().contains("__MACOSX"))
                    continue;
                if (entry.getName().endsWith("manifest.xml") || entry.getName().endsWith("index.xml")) {
                    // Build the mediapackage
                    mp = loadMediaPackageFromManifest(new ZipEntryInputStream(zis, entry.getSize()));
                } else {
                    logger.info("Storing zip entry {}/{} in working file repository collection '{}'", job.getId(), entry.getName(), wfrCollectionId);
                    // Since the directory structure is not being mirrored, makes sure the file
                    // name is different than the previous one(s) by adding a sequential number
                    String fileName = FilenameUtils.getBaseName(entry.getName()) + "_" + seq++ + "." + FilenameUtils.getExtension(entry.getName());
                    URI contentUri = workingFileRepository.putInCollection(wfrCollectionId, fileName, new ZipEntryInputStream(zis, entry.getSize()));
                    collectionFilenames.add(fileName);
                    // Key is the zip entry name as it is
                    String key = entry.getName();
                    uris.put(key, contentUri);
                    ingestStatistics.add(entry.getSize());
                    logger.info("Zip entry {}/{} stored at {}", job.getId(), entry.getName(), contentUri);
                    // Figures out if there's a root folder. Does entry name starts with a folder?
                    int pos = entry.getName().indexOf('/');
                    if (pos == -1) {
                        // No, we can conclude there's no root folder
                        hasRootFolder = false;
                    } else if (hasRootFolder && folderName != null && !folderName.equals(entry.getName().substring(0, pos))) {
                        // Folder name different from previous so there's no root folder
                        hasRootFolder = false;
                    } else if (folderName == null) {
                        // Just initialize folder name
                        folderName = entry.getName().substring(0, pos);
                    }
                }
            } catch (IOException e) {
                logger.warn("Unable to process zip entry {}: {}", entry.getName(), e);
                throw e;
            }
        }
        if (mp == null)
            throw new MediaPackageException("No manifest found in this zip");
        // Determine the mediapackage identifier
        if (mp.getIdentifier() == null || isBlank(mp.getIdentifier().toString()))
            mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
        String mediaPackageId = mp.getIdentifier().toString();
        logger.info("Ingesting mediapackage {} is named '{}'", mediaPackageId, mp.getTitle());
        // Make sure there are tracks in the mediapackage
        if (mp.getTracks().length == 0) {
            logger.warn("Mediapackage {} has no media tracks", mediaPackageId);
        }
        // Update the element uris to point to their working file repository location
        for (MediaPackageElement element : mp.elements()) {
            // Key has root folder name if there is one
            URI uri = uris.get((hasRootFolder ? folderName + "/" : "") + element.getURI().toString());
            if (uri == null)
                throw new MediaPackageException("Unable to map element name '" + element.getURI() + "' to workspace uri");
            logger.info("Ingested mediapackage element {}/{} located at {}", mediaPackageId, element.getIdentifier(), uri);
            URI dest = workingFileRepository.moveTo(wfrCollectionId, FilenameUtils.getName(uri.toString()), mediaPackageId, element.getIdentifier(), FilenameUtils.getName(element.getURI().toString()));
            element.setURI(dest);
            // TODO: This should be triggered somehow instead of being handled here
            if (MediaPackageElements.SERIES.equals(element.getFlavor())) {
                logger.info("Ingested mediapackage {} contains updated series information", mediaPackageId);
                updateSeries(element.getURI());
            }
        }
        // Now that all elements are in place, start with ingest
        logger.info("Initiating processing of ingested mediapackage {}", mediaPackageId);
        WorkflowInstance workflowInstance = ingest(mp, workflowDefinitionId, workflowConfig, workflowInstanceId);
        logger.info("Ingest of mediapackage {} done", mediaPackageId);
        job.setStatus(Job.Status.FINISHED);
        return workflowInstance;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (MediaPackageException e) {
        job.setStatus(Job.Status.FAILED, Job.FailureReason.DATA);
        throw e;
    } catch (Exception e) {
        if (e instanceof IngestException)
            throw (IngestException) e;
        throw new IngestException(e);
    } finally {
        IOUtils.closeQuietly(zis);
        finallyUpdateJob(job);
        for (String filename : collectionFilenames) {
            workingFileRepository.deleteFromCollection(Long.toString(job.getId()), filename, true);
        }
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) IngestException(org.opencastproject.ingest.api.IngestException) HandleException(org.opencastproject.mediapackage.identifier.HandleException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet) UUIDIdBuilderImpl(org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl)

Example 13 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IndexServiceImpl method createEvent.

@Override
public String createEvent(EventHttpServletRequest eventHttpServletRequest) throws ParseException, IOException, MediaPackageException, IngestException, NotFoundException, SchedulerException, UnauthorizedException {
    // Preconditions
    if (eventHttpServletRequest.getAcl().isNone()) {
        throw new IllegalArgumentException("No access control list available to create new event.");
    }
    if (eventHttpServletRequest.getMediaPackage().isNone()) {
        throw new IllegalArgumentException("No mediapackage available to create new event.");
    }
    if (eventHttpServletRequest.getMetadataList().isNone()) {
        throw new IllegalArgumentException("No metadata list available to create new event.");
    }
    if (eventHttpServletRequest.getProcessing().isNone()) {
        throw new IllegalArgumentException("No processing metadata available to create new event.");
    }
    if (eventHttpServletRequest.getSource().isNone()) {
        throw new IllegalArgumentException("No source field metadata available to create new event.");
    }
    // Get Workflow
    String workflowTemplate = (String) eventHttpServletRequest.getProcessing().get().get("workflow");
    if (workflowTemplate == null)
        throw new IllegalArgumentException("No workflow template in metadata");
    // Get Type of Source
    SourceType type = getSourceType(eventHttpServletRequest.getSource().get());
    MetadataCollection eventMetadata = eventHttpServletRequest.getMetadataList().get().getMetadataByAdapter(eventCatalogUIAdapter).get();
    JSONObject sourceMetadata = (JSONObject) eventHttpServletRequest.getSource().get().get("metadata");
    if (sourceMetadata != null && (type.equals(SourceType.SCHEDULE_SINGLE) || type.equals(SourceType.SCHEDULE_MULTIPLE))) {
        try {
            MetadataField<?> current = eventMetadata.getOutputFields().get("location");
            eventMetadata.updateStringField(current, (String) sourceMetadata.get("device"));
        } catch (Exception e) {
            logger.warn("Unable to parse device {}", sourceMetadata.get("device"));
            throw new IllegalArgumentException("Unable to parse device");
        }
    }
    Date currentStartDate = null;
    MetadataField<?> starttime = eventMetadata.getOutputFields().get(DublinCore.PROPERTY_TEMPORAL.getLocalName());
    if (starttime != null && starttime.isUpdated() && starttime.getValue().isSome()) {
        DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod((DublinCoreValue) starttime.getValue().get());
        currentStartDate = period.getStart();
    }
    MetadataField<?> created = eventMetadata.getOutputFields().get(DublinCore.PROPERTY_CREATED.getLocalName());
    if (created == null || !created.isUpdated() || created.getValue().isNone()) {
        eventMetadata.removeField(created);
        MetadataField<String> newCreated = MetadataUtils.copyMetadataField(created);
        if (currentStartDate != null) {
            newCreated.setValue(EncodingSchemeUtils.encodeDate(currentStartDate, Precision.Second).getValue());
        } else {
            newCreated.setValue(EncodingSchemeUtils.encodeDate(new Date(), Precision.Second).getValue());
        }
        eventMetadata.addField(newCreated);
    }
    // Get presenter usernames for use as technical presenters
    Set<String> presenterUsernames = new HashSet<>();
    Opt<Set<String>> technicalPresenters = updatePresenters(eventMetadata);
    if (technicalPresenters.isSome()) {
        presenterUsernames = technicalPresenters.get();
    }
    eventHttpServletRequest.getMetadataList().get().add(eventCatalogUIAdapter, eventMetadata);
    updateMediaPackageMetadata(eventHttpServletRequest.getMediaPackage().get(), eventHttpServletRequest.getMetadataList().get());
    DublinCoreCatalog dc = getDublinCoreCatalog(eventHttpServletRequest);
    String captureAgentId = null;
    TimeZone tz = null;
    org.joda.time.DateTime start = null;
    org.joda.time.DateTime end = null;
    long duration = 0L;
    Properties caProperties = new Properties();
    RRule rRule = null;
    if (sourceMetadata != null && (type.equals(SourceType.SCHEDULE_SINGLE) || type.equals(SourceType.SCHEDULE_MULTIPLE))) {
        Properties configuration;
        try {
            captureAgentId = (String) sourceMetadata.get("device");
            configuration = captureAgentStateService.getAgentConfiguration((String) sourceMetadata.get("device"));
        } catch (Exception e) {
            logger.warn("Unable to parse device {}: because: {}", sourceMetadata.get("device"), getStackTrace(e));
            throw new IllegalArgumentException("Unable to parse device");
        }
        String durationString = (String) sourceMetadata.get("duration");
        if (StringUtils.isBlank(durationString))
            throw new IllegalArgumentException("No duration in source metadata");
        // Create timezone based on CA's reported TZ.
        String agentTimeZone = configuration.getProperty("capture.device.timezone");
        if (StringUtils.isNotBlank(agentTimeZone)) {
            tz = TimeZone.getTimeZone(agentTimeZone);
            dc.set(DublinCores.OC_PROPERTY_AGENT_TIMEZONE, tz.getID());
        } else {
            // No timezone was present, assume the serve's local timezone.
            tz = TimeZone.getDefault();
            logger.debug("The field 'capture.device.timezone' has not been set in the agent configuration. The default server timezone will be used.");
        }
        org.joda.time.DateTime now = new org.joda.time.DateTime(DateTimeZone.UTC);
        start = now.withMillis(DateTimeSupport.fromUTC((String) sourceMetadata.get("start")));
        end = now.withMillis(DateTimeSupport.fromUTC((String) sourceMetadata.get("end")));
        duration = Long.parseLong(durationString);
        DublinCoreValue period = EncodingSchemeUtils.encodePeriod(new DCMIPeriod(start.toDate(), start.plus(duration).toDate()), Precision.Second);
        String inputs = (String) sourceMetadata.get("inputs");
        caProperties.putAll(configuration);
        dc.set(DublinCore.PROPERTY_TEMPORAL, period);
        caProperties.put(CaptureParameters.CAPTURE_DEVICE_NAMES, inputs);
    }
    if (type.equals(SourceType.SCHEDULE_MULTIPLE)) {
        rRule = new RRule((String) sourceMetadata.get("rrule"));
    }
    Map<String, String> configuration = new HashMap<>();
    if (eventHttpServletRequest.getProcessing().get().get("configuration") != null) {
        configuration = new HashMap<>((JSONObject) eventHttpServletRequest.getProcessing().get().get("configuration"));
    }
    for (Entry<String, String> entry : configuration.entrySet()) {
        caProperties.put(WORKFLOW_CONFIG_PREFIX.concat(entry.getKey()), entry.getValue());
    }
    caProperties.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, workflowTemplate);
    eventHttpServletRequest.setMediaPackage(authorizationService.setAcl(eventHttpServletRequest.getMediaPackage().get(), AclScope.Episode, eventHttpServletRequest.getAcl().get()).getA());
    MediaPackage mediaPackage;
    switch(type) {
        case UPLOAD:
        case UPLOAD_LATER:
            eventHttpServletRequest.setMediaPackage(updateDublincCoreCatalog(eventHttpServletRequest.getMediaPackage().get(), dc));
            configuration.put("workflowDefinitionId", workflowTemplate);
            WorkflowInstance ingest = ingestService.ingest(eventHttpServletRequest.getMediaPackage().get(), workflowTemplate, configuration);
            return eventHttpServletRequest.getMediaPackage().get().getIdentifier().compact();
        case SCHEDULE_SINGLE:
            mediaPackage = updateDublincCoreCatalog(eventHttpServletRequest.getMediaPackage().get(), dc);
            eventHttpServletRequest.setMediaPackage(mediaPackage);
            try {
                schedulerService.addEvent(start.toDate(), start.plus(duration).toDate(), captureAgentId, presenterUsernames, mediaPackage, configuration, (Map) caProperties, Opt.<Boolean>none(), Opt.<String>none(), SchedulerService.ORIGIN);
            } finally {
                for (MediaPackageElement mediaPackageElement : mediaPackage.getElements()) {
                    try {
                        workspace.delete(mediaPackage.getIdentifier().toString(), mediaPackageElement.getIdentifier());
                    } catch (NotFoundException | IOException e) {
                        logger.warn("Failed to delete media package element", e);
                    }
                }
            }
            return mediaPackage.getIdentifier().compact();
        case SCHEDULE_MULTIPLE:
            List<Period> periods = schedulerService.calculatePeriods(rRule, start.toDate(), end.toDate(), duration, tz);
            Map<String, Period> scheduled = new LinkedHashMap<>();
            scheduled = schedulerService.addMultipleEvents(rRule, start.toDate(), end.toDate(), duration, tz, captureAgentId, presenterUsernames, eventHttpServletRequest.getMediaPackage().get(), configuration, (Map) caProperties, Opt.none(), Opt.none(), SchedulerService.ORIGIN);
            return StringUtils.join(scheduled.keySet(), ",");
        default:
            logger.warn("Unknown source type {}", type);
            throw new IllegalArgumentException("Unknown source type");
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) RRule(net.fortuna.ical4j.model.property.RRule) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) Properties(java.util.Properties) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) LinkedHashMap(java.util.LinkedHashMap) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) HashSet(java.util.HashSet) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) Period(net.fortuna.ical4j.model.Period) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) IOException(java.io.IOException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) EventCommentException(org.opencastproject.event.comment.EventCommentException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) Date(java.util.Date) DateTimeZone(org.joda.time.DateTimeZone) TimeZone(java.util.TimeZone) JSONObject(org.json.simple.JSONObject) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 14 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addCatalog.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addCatalog(java.net.URI,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addCatalog(URI uri, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_CATALOG_FROM_URI, Arrays.asList(uri.toString(), flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding catalog {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        if (MediaPackageElements.SERIES.equals(flavor)) {
            updateSeries(uri);
        }
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Catalog, flavor);
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added catalog {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 15 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method addAttachment.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addAttachment(java.net.URI,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addAttachment(URI uri, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_ATTACHMENT_FROM_URI, Arrays.asList(uri.toString(), flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding attachment {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Attachment, flavor);
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added attachment {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Aggregations

IngestException (org.opencastproject.ingest.api.IngestException)19 NotFoundException (org.opencastproject.util.NotFoundException)14 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)11 URI (java.net.URI)10 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 Job (org.opencastproject.job.api.Job)9 JobUtil.waitForJob (org.opencastproject.util.JobUtil.waitForJob)9 IOException (java.io.IOException)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)6 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)5 WorkflowException (org.opencastproject.workflow.api.WorkflowException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)4 JDOMException (org.jdom.JDOMException)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 HandleException (org.opencastproject.mediapackage.identifier.HandleException)3