Search in sources :

Example 11 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class IngestServiceImpl method addCatalog.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addCatalog(java.io.InputStream, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addCatalog(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_CATALOG, null, null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding catalog {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        if (MediaPackageElements.SERIES.equals(flavor)) {
            updateSeries(newUrl);
        }
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Catalog, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getCatalog(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        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 : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) 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 12 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class IngestServiceImpl method addTrack.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addTrack(java.net.URI,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, String[] ,
 *      org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addTrack(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : 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 track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getTrack(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (IOException e) {
        throw e;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 13 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class IngestServiceImpl method mergeScheduledMediaPackage.

/**
 * Merges the ingested mediapackage with the scheduled mediapackage. The ingested mediapackage takes precedence over
 * the scheduled mediapackage.
 *
 * @param mp
 *          the ingested mediapackage
 * @return the merged mediapackage
 */
private MediaPackage mergeScheduledMediaPackage(MediaPackage mp) throws IngestException {
    if (schedulerService == null) {
        logger.warn("No scheduler service available to merge mediapackage!");
        return mp;
    }
    try {
        MediaPackage scheduledMp = schedulerService.getMediaPackage(mp.getIdentifier().compact());
        logger.info("Found matching scheduled event for id '{}', merging mediapackage...", mp.getIdentifier().compact());
        mergeMediaPackageElements(mp, scheduledMp);
        mergeMediaPackageMetadata(mp, scheduledMp);
        return mp;
    } catch (NotFoundException e) {
        logger.debug("No scheduler mediapackage found with id {}, skip merging", mp.getIdentifier().compact());
        return mp;
    } catch (Exception e) {
        logger.error("Unable to get event mediapackage from scheduler event {}", mp.getIdentifier().compact(), e);
        throw new IngestException(e);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) 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)

Example 14 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class IngestServiceImpl method updateSeries.

/**
 * Updates the persistent representation of a series based on a potentially modified dublin core document.
 *
 * @param uri
 *          the URI to the dublin core document containing series metadata.
 * @return
 *         true, if the series is created or overwritten, false if the existing series remains intact.
 */
protected boolean updateSeries(URI uri) throws IOException, IngestException {
    HttpResponse response = null;
    InputStream in = null;
    boolean isUpdated = false;
    try {
        HttpGet getDc = new HttpGet(uri);
        response = httpClient.execute(getDc);
        in = response.getEntity().getContent();
        DublinCoreCatalog dc = dublinCoreService.load(in);
        String id = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
        if (id == null) {
            logger.warn("Series dublin core document contains no identifier, rejecting ingested series cagtalog.");
        } else {
            try {
                try {
                    seriesService.getSeries(id);
                    if (isOverwriteSeries) {
                        // Update existing series
                        seriesService.updateSeries(dc);
                        isUpdated = true;
                        logger.debug("Ingest is overwriting the existing series {} with the ingested series", id);
                    } else {
                        logger.debug("Series {} already exists. Ignoring series catalog from ingest.", id);
                    }
                } catch (NotFoundException e) {
                    logger.info("Creating new series {} with default ACL", id);
                    seriesService.updateSeries(dc);
                    isUpdated = true;
                    String anonymousRole = securityService.getOrganization().getAnonymousRole();
                    AccessControlList acl = new AccessControlList(new AccessControlEntry(anonymousRole, "read", true));
                    seriesService.updateAccessControl(id, acl);
                }
            } catch (Exception e) {
                throw new IngestException(e);
            }
        }
        in.close();
    } catch (IOException e) {
        logger.error("Error updating series from DublinCoreCatalog: {}", e.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
        httpClient.close(response);
    }
    return isUpdated;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ProgressInputStream(org.opencastproject.util.ProgressInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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)

Example 15 with NotFoundException

use of org.opencastproject.util.NotFoundException in project opencast by opencast.

the class IngestServiceImpl method addPartialTrack.

@Override
public MediaPackage addPartialTrack(InputStream in, String fileName, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK, null, null, false);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding partial track {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        job.setStatus(Job.Status.FINISHED);
        // store startTime
        partialTrackStartTimes.put(elementId, startTime);
        logger.debug("Added start time {} for track {}", startTime, elementId);
        logger.info("Successful added partial track {} 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

NotFoundException (org.opencastproject.util.NotFoundException)382 IOException (java.io.IOException)137 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)130 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)79 MediaPackage (org.opencastproject.mediapackage.MediaPackage)69 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)67 EntityManager (javax.persistence.EntityManager)55 SeriesException (org.opencastproject.series.api.SeriesException)53 Path (javax.ws.rs.Path)52 WebApplicationException (javax.ws.rs.WebApplicationException)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)51 ConfigurationException (org.osgi.service.cm.ConfigurationException)51 URI (java.net.URI)50 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)50 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)49 Date (java.util.Date)48 Test (org.junit.Test)47 File (java.io.File)46 HttpResponse (org.apache.http.HttpResponse)46 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)46