Search in sources :

Example 1 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AssetManagerSnapshotWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance wi, JobContext ctx) throws WorkflowOperationException {
    final MediaPackage mpWorkflow = wi.getMediaPackage();
    final WorkflowOperationInstance currentOperation = wi.getCurrentOperation();
    // Check which tags have been configured
    final String tags = StringUtils.trimToNull(currentOperation.getConfiguration("source-tags"));
    final String sourceFlavorsString = StringUtils.trimToEmpty(currentOperation.getConfiguration("source-flavors"));
    final String[] sourceFlavors = StringUtils.split(sourceFlavorsString, ",");
    if (sourceFlavors.length < 1 && tags == null)
        logger.debug("No source tags have been specified, so everything will be added to the AssetManager");
    final List<String> tagSet;
    // If a set of tags has been specified, use it
    if (tags != null) {
        tagSet = asList(tags);
    } else {
        tagSet = new ArrayList<>();
    }
    try {
        final MediaPackage mpAssetManager = getMediaPackageForArchival(mpWorkflow, tagSet, sourceFlavors);
        if (mpAssetManager != null) {
            logger.info("Take snapshot of media package {}", mpAssetManager);
            // adding media package to the episode service
            assetManager.takeSnapshot(DEFAULT_OWNER, mpAssetManager);
            logger.debug("Snapshot operation complete");
            return createResult(mpWorkflow, Action.CONTINUE);
        } else {
            return createResult(mpWorkflow, Action.CONTINUE);
        }
    } catch (Throwable t) {
        throw new WorkflowOperationException(t);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

Example 2 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AclServiceImpl method getFromAssetManagerByMpId.

/**
 * Return media package with id <code>mpId</code> from asset manager.
 *
 * @return single element list or empty list
 */
private Option<MediaPackage> getFromAssetManagerByMpId(String mpId) {
    final AQueryBuilder q = assetManager.createQuery();
    final Opt<MediaPackage> mp = enrich(q.select(q.snapshot()).where(q.mediaPackageId(mpId).and(q.version().isLatest())).run()).getSnapshots().head().map(Snapshots.getMediaPackage);
    return Option.fromOpt(mp);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder)

Example 3 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AclServiceImpl method applyAclToEpisode.

@Override
public boolean applyAclToEpisode(String episodeId, AccessControlList acl, Option<ConfiguredWorkflowRef> workflow) throws AclServiceException {
    try {
        Option<MediaPackage> mediaPackage = Option.none();
        if (assetManager != null)
            mediaPackage = getFromAssetManagerByMpId(episodeId);
        Option<AccessControlList> aclOpt = Option.option(acl);
        // the episode service is the source of authority for the retrieval of media packages
        for (final MediaPackage episodeSvcMp : mediaPackage) {
            aclOpt.fold(new Option.EMatch<AccessControlList>() {

                // set the new episode ACL
                @Override
                public void esome(final AccessControlList acl) {
                    // update in episode service
                    MediaPackage mp = authorizationService.setAcl(episodeSvcMp, AclScope.Episode, acl).getA();
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }

                // if none EpisodeACLTransition#isDelete returns true so delete the episode ACL
                @Override
                public void enone() {
                    // update in episode service
                    MediaPackage mp = authorizationService.removeAcl(episodeSvcMp, AclScope.Episode);
                    if (assetManager != null)
                        assetManager.takeSnapshot(mp);
                }
            });
            // apply optional workflow
            for (ConfiguredWorkflowRef workflowRef : workflow) applyWorkflow(list(episodeSvcMp), workflowRef);
            return true;
        }
        // not found
        return false;
    } catch (Exception e) {
        logger.error("Error applying episode ACL", e);
        throw new AclServiceException(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Option(org.opencastproject.util.data.Option) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 4 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerBasicTest method testSetAvailability.

@Test
public void testSetAvailability() throws Exception {
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    final Version v1 = am.takeSnapshot(OWNER, mp).getVersion();
    am.setAvailability(v1, mp.getIdentifier().toString(), Availability.OFFLINE);
    assertEquals("One offline snapshot should be found", 1, q.select(q.snapshot()).where(q.availability(Availability.OFFLINE)).run().getSize());
    assertEquals("No online snapshot should be found", 0, q.select(q.snapshot()).where(q.availability(Availability.ONLINE)).run().getSize());
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Example 5 with MediaPackage

use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.

the class AbstractAssetManagerBasicTest method testVersioning.

@Test
public void testVersioning() throws Exception {
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    final Version v1 = am.takeSnapshot(OWNER, mp).getVersion();
    final Version v2 = am.takeSnapshot(OWNER, mp).getVersion();
    assertTrue("First version must be older", v1.isOlder(v2));
    assertTrue("Second version must be younger", v2.isYounger(v1));
    assertTrue(v1.equals(v1));
    assertFalse(v1.equals(v2));
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Test(org.junit.Test)

Aggregations

MediaPackage (org.opencastproject.mediapackage.MediaPackage)407 Test (org.junit.Test)180 NotFoundException (org.opencastproject.util.NotFoundException)108 Job (org.opencastproject.job.api.Job)89 Date (java.util.Date)82 IOException (java.io.IOException)77 URI (java.net.URI)74 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)72 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)70 ArrayList (java.util.ArrayList)69 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)60 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)59 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)55 Path (javax.ws.rs.Path)53 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)52 RestQuery (org.opencastproject.util.doc.rest.RestQuery)52 Track (org.opencastproject.mediapackage.Track)48 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)48 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)45 HashSet (java.util.HashSet)43