Search in sources :

Example 1 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class IngestRestService method updateMediaPackageID.

/**
 * Try updating the identifier of a mediapackage with the identifier from a episode DublinCore catalog.
 *
 * @param mp
 *          MediaPackage to modify
 * @param is
 *          InputStream containing the episode DublinCore catalog
 */
private void updateMediaPackageID(MediaPackage mp, InputStream is) throws IOException {
    DublinCoreCatalog dc = DublinCores.read(is);
    EName en = new EName(DublinCore.TERMS_NS_URI, "identifier");
    String id = dc.getFirst(en);
    if (id != null) {
        mp.setIdentifier(new IdImpl(id));
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl)

Example 2 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class IngestRestService method addMediaPackage.

@POST
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("addMediaPackage/{wdID}")
@RestQuery(name = "addMediaPackage", description = "<p>Create and ingest media package from media tracks with additional Dublin Core metadata. It is " + "mandatory to set a title for the recording. This can be done with the 'title' form field or by supplying a DC " + "catalog with a title included.  The identifier of the newly created media package will be taken from the " + "<em>identifier</em> field or the episode DublinCore catalog (deprecated<sup>*</sup>). If no identifier is " + "set, a newa randumm UUIDv4 will be generated. This endpoint is not meant to be used by capture agents for " + "scheduled recordings. It's primary use is for manual ingests with command line tools like curl.</p> " + "<p>Multiple tracks can be ingested by using multiple form fields. It's important, however, to always set the " + "flavor of the next media file <em>before</em> sending the media file itself.</p>" + "<b>(*)</b> The special treatment of the identifier field is deprecated any may be removed in future versions " + "without further notice in favor of a random UUID generation to ensure uniqueness of identifiers. " + "<h3>Example curl command:</h3>" + "<p>Ingest one video file:</p>" + "<p><pre>\n" + "curl -f -i --digest -u opencast_system_account:CHANGE_ME -H 'X-Requested-Auth: Digest' \\\n" + "    http://localhost:8080/ingest/addMediaPackage/fast -F creator='John Doe' -F title='Test Recording' \\\n" + "    -F 'flavor=presentation/source' -F 'BODY=@test-recording.mp4' \n" + "</pre></p>" + "<p>Ingest two video files:</p>" + "<p><pre>\n" + "curl -f -i --digest -u opencast_system_account:CHANGE_ME -H 'X-Requested-Auth: Digest' \\\n" + "    http://localhost:8080/ingest/addMediaPackage/fast -F creator='John Doe' -F title='Test Recording' \\\n" + "    -F 'flavor=presentation/source' -F 'BODY=@test-recording-vga.mp4' \\\n" + "    -F 'flavor=presenter/source' -F 'BODY=@test-recording-camera.mp4' \n" + "</pre></p>", pathParameters = { @RestParameter(description = "Workflow definition id", isRequired = true, name = "wdID", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The kind of media track. This has to be specified prior to each media track", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "abstract", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "accessRights", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "available", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "contributor", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "coverage", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "created", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "creator", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "date", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "description", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "extent", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "format", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "identifier", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isPartOf", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isReferencedBy", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "isReplacedBy", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "language", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "license", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "publisher", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "relation", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "replaces", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "rights", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "rightsHolder", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "source", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "spatial", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "subject", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "temporal", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "title", type = RestParameter.Type.STRING), @RestParameter(description = "Episode metadata value", isRequired = false, name = "type", type = RestParameter.Type.STRING), @RestParameter(description = "URL of episode DublinCore Catalog", isRequired = false, name = "episodeDCCatalogUri", type = RestParameter.Type.STRING), @RestParameter(description = "Episode DublinCore Catalog", isRequired = false, name = "episodeDCCatalog", type = RestParameter.Type.STRING), @RestParameter(description = "URL of series DublinCore Catalog", isRequired = false, name = "seriesDCCatalogUri", type = RestParameter.Type.STRING), @RestParameter(description = "Series DublinCore Catalog", isRequired = false, name = "seriesDCCatalog", type = RestParameter.Type.STRING), @RestParameter(description = "URL of a media track file", isRequired = false, name = "mediaUri", type = RestParameter.Type.STRING) }, bodyParameter = @RestParameter(description = "The media track file", isRequired = true, name = "BODY", type = RestParameter.Type.FILE), reponses = { @RestResponse(description = "Ingest successfull. Returns workflow instance as XML", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Ingest failed due to invalid requests.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "Ingest failed. Something went wrong internally. Please have a look at the log files", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackage(@Context HttpServletRequest request, @PathParam("wdID") String wdID) {
    logger.trace("add mediapackage as multipart-form-data with workflow definition id: {}", wdID);
    MediaPackageElementFlavor flavor = null;
    try {
        MediaPackage mp = ingestService.createMediaPackage();
        DublinCoreCatalog dcc = null;
        Map<String, String> workflowProperties = new HashMap<>();
        int seriesDCCatalogNumber = 0;
        int episodeDCCatalogNumber = 0;
        boolean hasMedia = false;
        if (ServletFileUpload.isMultipartContent(request)) {
            for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
                FileItemStream item = iter.next();
                if (item.isFormField()) {
                    String fieldName = item.getFieldName();
                    String value = Streams.asString(item.openStream(), "UTF-8");
                    logger.trace("form field {}: {}", fieldName, value);
                    /* Ignore empty fields */
                    if ("".equals(value)) {
                        continue;
                    }
                    /* “Remember” the flavor for the next media. */
                    if ("flavor".equals(fieldName)) {
                        flavor = MediaPackageElementFlavor.parseFlavor(value);
                    /* Fields for DC catalog */
                    } else if (dcterms.contains(fieldName)) {
                        if ("identifier".equals(fieldName)) {
                            /* Use the identifier for the mediapackage */
                            mp.setIdentifier(new IdImpl(value));
                        }
                        EName en = new EName(DublinCore.TERMS_NS_URI, fieldName);
                        if (dcc == null) {
                            dcc = dublinCoreService.newInstance();
                        }
                        dcc.add(en, value);
                    /* Episode metadata by URL */
                    } else if ("episodeDCCatalogUri".equals(fieldName)) {
                        try {
                            URI dcurl = new URI(value);
                            updateMediaPackageID(mp, dcurl);
                            ingestService.addCatalog(dcurl, MediaPackageElements.EPISODE, mp);
                            episodeDCCatalogNumber += 1;
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                    /* Episode metadata DC catalog (XML) as string */
                    } else if ("episodeDCCatalog".equals(fieldName)) {
                        InputStream is = new ByteArrayInputStream(value.getBytes("UTF-8"));
                        updateMediaPackageID(mp, is);
                        is.reset();
                        String fileName = "episode" + episodeDCCatalogNumber + ".xml";
                        episodeDCCatalogNumber += 1;
                        ingestService.addCatalog(is, fileName, MediaPackageElements.EPISODE, mp);
                    /* Series by URL */
                    } else if ("seriesDCCatalogUri".equals(fieldName)) {
                        try {
                            URI dcurl = new URI(value);
                            ingestService.addCatalog(dcurl, MediaPackageElements.SERIES, mp);
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                    /* Series DC catalog (XML) as string */
                    } else if ("seriesDCCatalog".equals(fieldName)) {
                        String fileName = "series" + seriesDCCatalogNumber + ".xml";
                        seriesDCCatalogNumber += 1;
                        InputStream is = new ByteArrayInputStream(value.getBytes("UTF-8"));
                        ingestService.addCatalog(is, fileName, MediaPackageElements.SERIES, mp);
                    /* Add media files by URL */
                    } else if ("mediaUri".equals(fieldName)) {
                        if (flavor == null) {
                            /* A flavor has to be specified in the request prior the media file */
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                        URI mediaUrl;
                        try {
                            mediaUrl = new URI(value);
                        } catch (java.net.URISyntaxException e) {
                            /* Parameter was not a valid URL: Return 400 Bad Request */
                            logger.warn(e.getMessage(), e);
                            return Response.serverError().status(Status.BAD_REQUEST).build();
                        }
                        ingestService.addTrack(mediaUrl, flavor, mp);
                        hasMedia = true;
                    } else {
                        /* Tread everything else as workflow properties */
                        workflowProperties.put(fieldName, value);
                    }
                /* Media files as request parameter */
                } else {
                    if (flavor == null) {
                        /* A flavor has to be specified in the request prior the video file */
                        logger.debug("A flavor has to be specified in the request prior to the content BODY");
                        return Response.serverError().status(Status.BAD_REQUEST).build();
                    }
                    ingestService.addTrack(item.openStream(), item.getName(), flavor, mp);
                    hasMedia = true;
                }
            }
            /* Check if we got any media. Fail if not. */
            if (!hasMedia) {
                logger.warn("Rejected ingest without actual media.");
                return Response.serverError().status(Status.BAD_REQUEST).build();
            }
            /* Add episode mediapackage if metadata were send separately */
            if (dcc != null) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                dcc.toXml(out, true);
                InputStream in = new ByteArrayInputStream(out.toByteArray());
                ingestService.addCatalog(in, "dublincore.xml", MediaPackageElements.EPISODE, mp);
            /* Check if we have metadata for the episode */
            } else if (episodeDCCatalogNumber == 0) {
                logger.warn("Rejected ingest without episode metadata. At least provide a title.");
                return Response.serverError().status(Status.BAD_REQUEST).build();
            }
            WorkflowInstance workflow = (wdID == null) ? ingestService.ingest(mp) : ingestService.ingest(mp, wdID, workflowProperties);
            return Response.ok(workflow).build();
        }
        return Response.serverError().status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) AbstractJobProducerEndpoint(org.opencastproject.rest.AbstractJobProducerEndpoint) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) 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) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) ByteArrayInputStream(java.io.ByteArrayInputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) FileItemIterator(org.apache.commons.fileupload.FileItemIterator) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 3 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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 4 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class IngestServiceImpl method schedule.

@Override
public void schedule(MediaPackage mediaPackage, String workflowDefinitionID, Map<String, String> properties) throws IllegalStateException, IngestException, NotFoundException, UnauthorizedException, SchedulerException {
    MediaPackageElement[] mediaPackageElements = mediaPackage.getElementsByFlavor(MediaPackageElements.EPISODE);
    if (mediaPackageElements.length != 1) {
        logger.debug("There can be only one (and exactly one) episode dublin core catalog: https://youtu.be/_J3VeogFUOs");
        throw new IngestException("There can be only one (and exactly one) episode dublin core catalog");
    }
    InputStream inputStream;
    DublinCoreCatalog dublinCoreCatalog;
    try {
        inputStream = workingFileRepository.get(mediaPackage.getIdentifier().toString(), mediaPackageElements[0].getIdentifier());
        dublinCoreCatalog = dublinCoreService.load(inputStream);
    } catch (IOException e) {
        throw new IngestException(e);
    }
    EName temporal = new EName(DublinCore.TERMS_NS_URI, "temporal");
    List<DublinCoreValue> periods = dublinCoreCatalog.get(temporal);
    if (periods.size() != 1) {
        logger.debug("There can be only one (and exactly one) period");
        throw new IngestException("There can be only one (and exactly one) period");
    }
    DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(periods.get(0));
    if (!period.hasStart() || !period.hasEnd()) {
        logger.debug("A scheduled recording needs to have a start and end.");
        throw new IngestException("A scheduled recording needs to have a start and end.");
    }
    EName createdEName = new EName(DublinCore.TERMS_NS_URI, "created");
    List<DublinCoreValue> created = dublinCoreCatalog.get(createdEName);
    if (created.size() == 0) {
        logger.debug("Created not set");
    } else if (created.size() == 1) {
        Date date = EncodingSchemeUtils.decodeMandatoryDate(created.get(0));
        if (date.getTime() != period.getStart().getTime()) {
            logger.debug("start and created date differ ({} vs {})", date.getTime(), period.getStart().getTime());
            throw new IngestException("Temporal start and created date differ");
        }
    } else {
        logger.debug("There can be only one created date");
        throw new IngestException("There can be only one created date");
    }
    // spatial
    EName spatial = new EName(DublinCore.TERMS_NS_URI, "spatial");
    List<DublinCoreValue> captureAgents = dublinCoreCatalog.get(spatial);
    if (captureAgents.size() != 1) {
        logger.debug("Exactly one capture agent needs to be set");
        throw new IngestException("Exactly one capture agent needs to be set");
    }
    String captureAgent = captureAgents.get(0).getValue();
    // Go through properties
    Map<String, String> agentProperties = new HashMap<>();
    Map<String, String> workflowProperties = new HashMap<>();
    for (String key : properties.keySet()) {
        if (key.startsWith("org.opencastproject.workflow.config.")) {
            workflowProperties.put(key, properties.get(key));
        } else {
            agentProperties.put(key, properties.get(key));
        }
    }
    try {
        schedulerService.addEvent(period.getStart(), period.getEnd(), captureAgent, new HashSet<>(), mediaPackage, workflowProperties, agentProperties, Opt.none(), Opt.none(), "ingest-service");
    } finally {
        for (MediaPackageElement mediaPackageElement : mediaPackage.getElements()) {
            try {
                workingFileRepository.delete(mediaPackage.getIdentifier().toString(), mediaPackageElement.getIdentifier());
            } catch (IOException e) {
                logger.warn("Failed to delete media package element", e);
            }
        }
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) HashMap(java.util.HashMap) ProgressInputStream(org.opencastproject.util.ProgressInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) IOException(java.io.IOException) Date(java.util.Date) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) IngestException(org.opencastproject.ingest.api.IngestException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 5 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class IngestServiceImplTest method testSeriesUpdateNewAndExisting.

/**
 * Test method for {@link org.opencastproject.ingest.impl.IngestServiceImpl#updateSeries(java.net.URI)}
 */
private void testSeriesUpdateNewAndExisting(Dictionary<String, String> properties) throws Exception {
    // default expectation for series overwrite is True
    boolean isExpectSeriesOverwrite = true;
    if (properties != null) {
        service.updated(properties);
        try {
            boolean testForValue = Boolean.parseBoolean(properties.get(IngestServiceImpl.PROPKEY_OVERWRITE_SERIES).trim());
            isExpectSeriesOverwrite = testForValue;
        } catch (Exception e) {
        // If key or value not found or not boolean, use the default overwrite expectation
        }
    }
    // Get test series dublin core for the mock return value
    File catalogFile = new File(urlCatalog2);
    if (!catalogFile.exists() || !catalogFile.canRead())
        throw new Exception("Unable to access test catalog " + urlCatalog2.getPath());
    FileInputStream in = new FileInputStream(catalogFile);
    DublinCoreCatalog series = DublinCores.read(in);
    IOUtils.closeQuietly(in);
    // Set dublinCore service to return test dublin core
    dublinCoreService = org.easymock.EasyMock.createNiceMock(DublinCoreCatalogService.class);
    org.easymock.EasyMock.expect(dublinCoreService.load((InputStream) EasyMock.anyObject())).andReturn(series).anyTimes();
    org.easymock.EasyMock.replay(dublinCoreService);
    service.setDublinCoreService(dublinCoreService);
    // Test with mock found series
    seriesService = EasyMock.createNiceMock(SeriesService.class);
    EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andReturn(series).once();
    EasyMock.expect(seriesService.updateSeries(series)).andReturn(series).once();
    EasyMock.replay(seriesService);
    service.setSeriesService(seriesService);
    // This is true or false depending on the isOverwrite value
    Assert.assertEquals("Desire to update series is " + String.valueOf(isExpectSeriesOverwrite) + ".", isExpectSeriesOverwrite, service.updateSeries(urlCatalog2));
    // Test with mock not found exception
    EasyMock.reset(seriesService);
    EasyMock.expect(seriesService.updateSeries(series)).andReturn(series).once();
    EasyMock.expect(seriesService.getSeries((String) EasyMock.anyObject())).andThrow(new NotFoundException()).once();
    EasyMock.replay(seriesService);
    service.setSeriesService(seriesService);
    // This should be true, i.e. create new series, in all cases
    Assert.assertEquals("Always create a new series catalog.", true, service.updateSeries(urlCatalog2));
}
Also used : SeriesService(org.opencastproject.series.api.SeriesService) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) File(java.io.File) URISyntaxException(java.net.URISyntaxException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DublinCoreCatalogService(org.opencastproject.metadata.dublincore.DublinCoreCatalogService)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14