Search in sources :

Example 16 with MediaPackage

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

the class AbstractAssetManagerSelectTest method testSelectSnapshotAndProperties.

@Test
public void testSelectSnapshotAndProperties() throws Exception {
    final MediaPackage mp1 = mkMediaPackage(mkCatalog());
    am.takeSnapshot(OWNER, mp1);
    // only select snapshots
    {
        final AResult r = q.select(q.snapshot()).run();
        assertEquals("One record should be found", 1, r.getSize());
        assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
        assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
    }
    // select snapshots and properties
    {
        final AResult r = q.select(q.snapshot(), p.allProperties()).run();
        assertEquals("One record should be found", 1, r.getSize());
        assertEquals("One snapshot should be found", 1, r.getRecords().bind(getSnapshot).toList().size());
        assertEquals("No properties should be found", 0, r.getRecords().bind(getProperties).toList().size());
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Test(org.junit.Test)

Example 17 with MediaPackage

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

the class AbstractAssetManagerSelectTest method testSelectSnapshots.

@Test
public void testSelectSnapshots() throws Exception {
    final MediaPackage mp = mkMediaPackage();
    final MediaPackageElement mpe = mkCatalog();
    mp.add(mpe);
    final Snapshot snapshot = am.takeSnapshot(OWNER, mp);
    final Version version = snapshot.getVersion();
    assertThat("Archival date should not be in the future", snapshot.getArchivalDate(), lessThanOrEqualTo(new Date()));
    assertThat("Snapshot should be available", snapshot.getAvailability(), equalTo(Availability.ONLINE));
    assertThat("Snapshot should belong to the default organization", snapshot.getOrganizationId(), equalTo(DefaultOrganization.DEFAULT_ORGANIZATION_ID));
    final Opt<Asset> asset = am.getAsset(version, mp.getIdentifier().toString(), mpe.getIdentifier());
    assertTrue("Asset should be found", asset.isSome());
    assertEquals("Media package element part of the asset ID should equal the element's ID", mpe.getIdentifier(), asset.get().getId().getMediaPackageElementId());
    assertEquals("Mime types should equal", mpe.getMimeType(), asset.get().getMimeType().get());
    assertFalse("Asset should not be found", am.getAsset(version, "id", "id").isSome());
    // try to find the catalog of the media package by checksum
    final MediaPackage mpCopy = MediaPackageSupport.copy(mp);
    am.calcChecksumsForMediaPackageElements(AbstractAssetManager.assetsOnly(mpCopy));
    assertEquals("Media package should be set up with a single catalog", 1, mpCopy.getCatalogs().length);
    final String checksum = mpCopy.getCatalogs()[0].getChecksum().toString();
    assertTrue("Media package element should be retrievable by checksum", am.getDb().findAssetByChecksum(checksum).isSome());
    // issue some queries
    {
        logger.info("Run a failing query");
        assertEquals("The result should not contain any records", 0, q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).where(q.mediaPackageId("12")).run().getSize());
    }
    {
        logger.info("Run query to find snapshot");
        final AResult r = q.select(q.snapshot()).where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
        assertEquals("The result set should contain exactly one record", 1, r.getSize());
        assertEquals("The media package IDs should be equal", mp.getIdentifier().toString(), r.getRecords().head2().getMediaPackageId());
        assertTrue("The snapshot should be contained in the record", r.getRecords().head2().getSnapshot().isSome());
        assertEquals("The media package IDs should be equal", mp.getIdentifier(), r.getRecords().head2().getSnapshot().get().getMediaPackage().getIdentifier());
    }
    {
        final AResult r = q.select().where(q.mediaPackageId(mp.getIdentifier().toString()).and(q.availability(Availability.ONLINE))).run();
        assertEquals("The result should contain one record", 1, r.getSize());
        assertTrue("The result should not contain a snapshot", r.getRecords().head2().getSnapshot().isNone());
    }
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) ARecords.getSnapshot(org.opencastproject.assetmanager.api.fn.ARecords.getSnapshot) Version(org.opencastproject.assetmanager.api.Version) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Asset(org.opencastproject.assetmanager.api.Asset) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Date(java.util.Date) Test(org.junit.Test)

Example 18 with MediaPackage

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

the class AbstractAssetManagerSelectTest method testSelectByVersion.

@Test
public void testSelectByVersion() throws Exception {
    final MediaPackage mp1 = mkMediaPackage(mkCatalog());
    logger.info("Create 4 versions");
    am.takeSnapshot(OWNER, mp1);
    am.takeSnapshot(OWNER, mp1);
    am.takeSnapshot(OWNER, mp1);
    am.takeSnapshot(OWNER, mp1);
    assertEquals("4 records should be found", 4, q.select(q.snapshot()).run().getSize());
    assertEquals("4 records should be found", 4, q.select().run().getSize());
    final Version latest;
    {
        AResult r = q.select(q.snapshot()).where(q.version().isLatest()).run();
        assertEquals("1 latest record should be found", 1, r.getSize());
        latest = r.getRecords().head2().getSnapshot().get().getVersion();
    }
    final Version first;
    {
        AResult r = q.select(q.snapshot()).where(q.version().isFirst()).run();
        assertEquals("1 first record should be found", 1, r.getSize());
        first = r.getRecords().head2().getSnapshot().get().getVersion();
    }
    assertTrue("The first version should be older", first.isOlder(latest));
    assertTrue("The last version should be younger", latest.isYounger(first));
    assertFalse("The versions should not be equal", latest.equals(first));
    // 
    assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest)).run().getSize());
    assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().le(latest)).run().getSize());
    assertEquals("Three younger records should be found", 3, q.select(q.snapshot()).where(q.version().gt(first)).run().getSize());
    assertEquals("4 records should be found", 4, q.select(q.snapshot()).where(q.version().ge(first)).run().getSize());
    assertEquals("2 intermediate records should be found", 2, q.select(q.snapshot()).where(q.version().gt(first).and(q.version().lt(latest))).run().getSize());
    // 
    logger.info("Now add another media package");
    am.takeSnapshot(OWNER, mkMediaPackage(mkCatalog()));
    assertEquals("Three older records should be found", 3, q.select(q.snapshot()).where(q.version().lt(latest).and(q.mediaPackageId(mp1.getIdentifier().toString()))).run().getSize());
    assertEquals("Two latest versions should be found", 2, q.select(q.snapshot()).where(q.version().isLatest()).run().getSize());
    assertEquals("Two first versions should be found", 2, q.select(q.snapshot()).where(q.version().isFirst()).run().getSize());
}
Also used : Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AResult(org.opencastproject.assetmanager.api.query.AResult) RichAResult(org.opencastproject.assetmanager.api.query.RichAResult) Test(org.junit.Test)

Example 19 with MediaPackage

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

the class IngestRestService method addMediaPackageCatalog.

@POST
@Produces(MediaType.TEXT_XML)
@Path("addCatalog")
@RestQuery(name = "addCatalogURL", description = "Add a metadata catalog to a given media package using an URL", restParameters = { @RestParameter(description = "The location of the catalog", isRequired = true, name = "url", type = RestParameter.Type.STRING), @RestParameter(description = "The kind of catalog", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackageCatalog(@FormParam("url") String url, @FormParam("flavor") String flavor, @FormParam("mediaPackage") String mpx) {
    logger.trace("add catalog with url: {} flavor: {} mediaPackage: {}", url, flavor, mpx);
    try {
        MediaPackage mp = factory.newMediaPackageBuilder().loadFromXml(mpx);
        if (MediaPackageSupport.sanityCheck(mp).isSome())
            return Response.serverError().status(Status.BAD_REQUEST).build();
        MediaPackage resultingMediaPackage = ingestService.addCatalog(new URI(url), MediaPackageElementFlavor.parseFlavor(flavor), mp);
        return Response.ok(resultingMediaPackage).build();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) URI(java.net.URI) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IngestException(org.opencastproject.ingest.api.IngestException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 20 with MediaPackage

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

the class IngestRestService method addDCCatalog.

/**
 * Adds a dublinCore metadata catalog to the MediaPackage and returns the grown mediaPackage. JQuery Ajax functions
 * doesn't support multipart/form-data encoding.
 *
 * @param mp
 *          MediaPackage
 * @param dc
 *          DublinCoreCatalog
 * @return grown MediaPackage XML
 */
@POST
@Produces(MediaType.TEXT_XML)
@Path("addDCCatalog")
@RestQuery(name = "addDCCatalog", description = "Add a dublincore episode catalog to a given media package using an url", restParameters = { @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT), @RestParameter(description = "DublinCore catalog as XML", isRequired = true, name = "dublinCore", type = RestParameter.Type.TEXT), @RestParameter(defaultValue = "dublincore/episode", description = "DublinCore Flavor", isRequired = false, name = "flavor", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addDCCatalog(@FormParam("mediaPackage") String mp, @FormParam("dublinCore") String dc, @FormParam("flavor") String flavor) {
    logger.trace("add DC catalog: {} with flavor: {} to media package: {}", dc, flavor, mp);
    MediaPackageElementFlavor dcFlavor = MediaPackageElements.EPISODE;
    if (flavor != null) {
        try {
            dcFlavor = MediaPackageElementFlavor.parseFlavor(flavor);
        } catch (IllegalArgumentException e) {
            logger.warn("Unable to set dublin core flavor to {}, using {} instead", flavor, MediaPackageElements.EPISODE);
        }
    }
    MediaPackage mediaPackage;
    /* Check if we got a proper mediapackage and try to parse it */
    try {
        mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mp);
    } catch (MediaPackageException e) {
        return Response.serverError().status(Status.BAD_REQUEST).build();
    }
    if (MediaPackageSupport.sanityCheck(mediaPackage).isSome()) {
        return Response.serverError().status(Status.BAD_REQUEST).build();
    }
    /* Check if we got a proper catalog */
    if (StringUtils.isBlank(dc)) {
        return Response.serverError().status(Status.BAD_REQUEST).build();
    }
    InputStream in = null;
    try {
        in = IOUtils.toInputStream(dc, "UTF-8");
        mediaPackage = ingestService.addCatalog(in, "dublincore.xml", dcFlavor, mediaPackage);
    } catch (MediaPackageException e) {
        return Response.serverError().status(Status.BAD_REQUEST).build();
    } catch (IOException e) {
        /* Return an internal server error if we could not write to disk */
        logger.error("Could not write catalog to disk: {}", e.getMessage());
        return Response.serverError().build();
    } catch (Exception e) {
        logger.error(e.getMessage());
        return Response.serverError().build();
    } finally {
        IOUtils.closeQuietly(in);
    }
    return Response.ok(mediaPackage).build();
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) IOException(java.io.IOException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IngestException(org.opencastproject.ingest.api.IngestException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

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