Search in sources :

Example 36 with MediaPackage

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

the class IngestServiceImplTest method testMergeScheduledMediaPackage.

@Test
public void testMergeScheduledMediaPackage() throws Exception {
    MediaPackage ingestMediaPackage = MediaPackageParser.getFromXml(IOUtils.toString(getClass().getResourceAsStream("/source-manifest-partial.xml"), "UTF-8"));
    WorkflowInstance instance = service.ingest(ingestMediaPackage);
    MediaPackage mergedMediaPackage = instance.getMediaPackage();
    Assert.assertEquals(4, mergedMediaPackage.getTracks().length);
    Track track = mergedMediaPackage.getTrack("track-1");
    Assert.assertEquals("/vonlya1.mov", track.getURI().toString());
    Assert.assertEquals(3, mergedMediaPackage.getCatalogs().length);
    Assert.assertEquals(1, mergedMediaPackage.getAttachments().length);
    Attachment attachment = mergedMediaPackage.getAttachment("cover");
    Assert.assertEquals("attachments/cover.png", attachment.getURI().toString());
    // Validate fields
    Assert.assertEquals(new Date(DateTimeSupport.fromUTC("2007-12-05T13:45:00")), mergedMediaPackage.getDate());
    Assert.assertEquals(10045L, mergedMediaPackage.getDuration().doubleValue(), 0L);
    Assert.assertEquals("t2", mergedMediaPackage.getTitle());
    Assert.assertEquals("s2", mergedMediaPackage.getSeries());
    Assert.assertEquals("st2", mergedMediaPackage.getSeriesTitle());
    Assert.assertEquals("l2", mergedMediaPackage.getLicense());
    Assert.assertEquals(1, mergedMediaPackage.getSubjects().length);
    Assert.assertEquals("s2", mergedMediaPackage.getSubjects()[0]);
    Assert.assertEquals(1, mergedMediaPackage.getContributors().length);
    Assert.assertEquals("sd2", mergedMediaPackage.getContributors()[0]);
    Assert.assertEquals(1, mergedMediaPackage.getCreators().length);
    Assert.assertEquals("p2", mergedMediaPackage.getCreators()[0]);
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Track(org.opencastproject.mediapackage.Track) Date(java.util.Date) Test(org.junit.Test)

Example 37 with MediaPackage

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

the class IngestRestServiceTest method testLegacyMediaPackageIdPropertyUsingIngest.

@Test
public void testLegacyMediaPackageIdPropertyUsingIngest() throws Exception {
    // Create a mock ingest service
    Capture<Map<String, String>> workflowConfigCapture = EasyMock.newCapture();
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    EasyMock.expect(ingestService.createMediaPackage()).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew());
    EasyMock.expect(ingestService.ingest(EasyMock.anyObject(MediaPackage.class), EasyMock.anyString(), EasyMock.capture(workflowConfigCapture))).andReturn(new WorkflowInstanceImpl());
    EasyMock.replay(ingestService);
    restService.setIngestService(ingestService);
    String mpId = "6f7a7850-3232-4719-9064-24c9bad2832f";
    MultivaluedMap<String, String> metadataMap = new MetadataMap<>();
    Response createMediaPackage = restService.createMediaPackage();
    MediaPackage mp = (MediaPackage) createMediaPackage.getEntity();
    metadataMap.add("mediaPackage", MediaPackageParser.getAsXml(mp));
    metadataMap.add(IngestRestService.WORKFLOW_INSTANCE_ID_PARAM, mpId);
    Response response = restService.ingest(metadataMap);
    Assert.assertEquals(Status.OK.getStatusCode(), response.getStatus());
    Map<String, String> config = workflowConfigCapture.getValue();
    Assert.assertFalse(config.isEmpty());
    Assert.assertEquals(mpId, config.get(IngestServiceImpl.LEGACY_MEDIAPACKAGE_ID_KEY));
}
Also used : Response(javax.ws.rs.core.Response) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) IngestService(org.opencastproject.ingest.api.IngestService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.Test)

Example 38 with MediaPackage

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

the class IngestRestServiceTest method newPartialMockRequest.

private MockHttpServletRequest newPartialMockRequest() throws Exception {
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    StringBuilder requestBody = new StringBuilder();
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"flavor\"\r\n");
    requestBody.append("\r\ntest/flavor\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"mediaPackage\"\r\n");
    requestBody.append("\r\n");
    requestBody.append(MediaPackageParser.getAsXml(mp));
    requestBody.append("\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"startTime\"\r\n");
    requestBody.append("\r\n2000\r\n");
    requestBody.append("-----1234\r\n");
    requestBody.append("Content-Disposition: form-data; name=\"file\"; filename=\"catalog.txt\"\r\n");
    requestBody.append("Content-Type: text/whatever\r\n");
    requestBody.append("\r\n");
    requestBody.append("This is the content of the file\n");
    requestBody.append("\r\n");
    requestBody.append("-----1234");
    return new MockHttpServletRequest(requestBody.toString().getBytes("UTF-8"), "multipart/form-data; boundary=---1234");
}
Also used : MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Example 39 with MediaPackage

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

the class IngestDownloadWorkflowOperationHandler method start.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.AbstractWorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
 *      JobContext)
 */
@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    MediaPackage mediaPackage = workflowInstance.getMediaPackage();
    WorkflowOperationInstance currentOperation = workflowInstance.getCurrentOperation();
    boolean deleteExternal = BooleanUtils.toBoolean(currentOperation.getConfiguration(DELETE_EXTERNAL));
    String baseUrl = workspace.getBaseUri().toString();
    List<URI> externalUris = new ArrayList<URI>();
    for (MediaPackageElement element : mediaPackage.getElements()) {
        if (element.getURI() == null)
            continue;
        if (element.getElementType() == MediaPackageElement.Type.Publication) {
            logger.debug("Skipping downloading media package element {} from media package {} " + "because it is a publication: {}", element.getIdentifier(), mediaPackage.getIdentifier().compact(), element.getURI());
            continue;
        }
        URI originalElementUri = element.getURI();
        if (originalElementUri.toString().startsWith(baseUrl)) {
            logger.info("Skipping downloading already existing element {}", originalElementUri);
            continue;
        }
        // Download the external URI
        File file;
        try {
            file = workspace.get(element.getURI());
        } catch (Exception e) {
            logger.warn("Unable to download the external element {}", element.getURI());
            throw new WorkflowOperationException("Unable to download the external element " + element.getURI(), e);
        }
        // Put to working file repository and rewrite URI on element
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            URI uri = workspace.put(mediaPackage.getIdentifier().compact(), element.getIdentifier(), FilenameUtils.getName(element.getURI().getPath()), in);
            element.setURI(uri);
        } catch (Exception e) {
            logger.warn("Unable to store downloaded element '{}': {}", element.getURI(), e.getMessage());
            throw new WorkflowOperationException("Unable to store downloaded element " + element.getURI(), e);
        } finally {
            IOUtils.closeQuietly(in);
            try {
                workspace.delete(originalElementUri);
            } catch (Exception e) {
                logger.warn("Unable to delete ingest-downloaded element {}: {}", element.getURI(), e);
            }
        }
        logger.info("Downloaded the external element {}", originalElementUri);
        // Store origianl URI for deletion
        externalUris.add(originalElementUri);
    }
    if (!deleteExternal || externalUris.size() == 0)
        return createResult(mediaPackage, Action.CONTINUE);
    // Find all external working file repository base Urls
    logger.debug("Assembling list of external working file repositories");
    List<String> externalWfrBaseUrls = new ArrayList<String>();
    try {
        for (ServiceRegistration reg : serviceRegistry.getServiceRegistrationsByType(WorkingFileRepository.SERVICE_TYPE)) {
            if (baseUrl.startsWith(reg.getHost())) {
                logger.trace("Skpping local working file repository");
                continue;
            }
            externalWfrBaseUrls.add(UrlSupport.concat(reg.getHost(), reg.getPath()));
        }
        logger.debug("{} external working file repositories found", externalWfrBaseUrls.size());
    } catch (ServiceRegistryException e) {
        logger.error("Unable to load WFR services from service registry: {}", e.getMessage());
        throw new WorkflowOperationException(e);
    }
    for (URI uri : externalUris) {
        String elementUri = uri.toString();
        // Delete external working file repository URI's
        String wfrBaseUrl = null;
        for (String url : externalWfrBaseUrls) {
            if (elementUri.startsWith(url)) {
                wfrBaseUrl = url;
                break;
            }
        }
        if (wfrBaseUrl == null) {
            logger.info("Unable to delete external URI {}, no working file repository found", elementUri);
            continue;
        }
        HttpDelete delete;
        if (elementUri.startsWith(UrlSupport.concat(wfrBaseUrl, WorkingFileRepository.MEDIAPACKAGE_PATH_PREFIX))) {
            String wfrDeleteUrl = elementUri.substring(0, elementUri.lastIndexOf("/"));
            delete = new HttpDelete(wfrDeleteUrl);
        } else if (elementUri.startsWith(UrlSupport.concat(wfrBaseUrl, WorkingFileRepository.COLLECTION_PATH_PREFIX))) {
            delete = new HttpDelete(elementUri);
        } else {
            logger.info("Unable to handle working file repository URI {}", elementUri);
            continue;
        }
        HttpResponse response = null;
        try {
            response = client.execute(delete);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == HttpStatus.SC_NO_CONTENT || statusCode == HttpStatus.SC_OK) {
                logger.info("Sucessfully deleted external URI {}", delete.getURI());
            } else if (statusCode == HttpStatus.SC_NOT_FOUND) {
                logger.info("External URI {} has already been deleted", delete.getURI());
            } else {
                logger.info("Unable to delete external URI {}, status code '{}' returned", delete.getURI(), statusCode);
            }
        } catch (TrustedHttpClientException e) {
            logger.warn("Unable to execute DELETE request on external URI {}", delete.getURI());
            throw new WorkflowOperationException(e);
        } finally {
            client.close(response);
        }
    }
    return createResult(mediaPackage, Action.CONTINUE);
}
Also used : HttpDelete(org.apache.http.client.methods.HttpDelete) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) FileInputStream(java.io.FileInputStream) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) File(java.io.File) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration)

Example 40 with MediaPackage

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

the class DublinCoreCatalogUIAdapterTest method setUp.

@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
    startDateTimeDurationCatalog = new FileInputStream(new File(getClass().getResource("/catalog-adapter/start-date-time-duration.xml").toURI()));
    dc = DublinCores.read(startDateTimeDurationCatalog);
    metadata = new DublinCoreMetadataCollection();
    startDateMetadataField = MetadataField.createTemporalStartDateMetadata(TEMPORAL_DUBLIN_CORE_KEY, Opt.some("startDate"), "START_DATE_LABEL", false, false, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Opt.<Integer>none(), Opt.<String>none());
    durationMetadataField = MetadataField.createDurationMetadataField(TEMPORAL_DUBLIN_CORE_KEY, Opt.some("duration"), "DURATION_LABEL", false, false, Opt.<Integer>none(), Opt.<String>none());
    TreeMap<String, String> collection = new TreeMap<String, String>();
    collection.put("Entry 1", "Value 1");
    collection.put("Entry 2", "Value 2");
    collection.put("Entry 3", "Value 3");
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.replay(bundleContext);
    listProvidersService = EasyMock.createMock(ListProvidersService.class);
    EasyMock.expect(listProvidersService.getList(EasyMock.anyString(), EasyMock.anyObject(ResourceListQueryImpl.class), EasyMock.anyObject(Organization.class), EasyMock.anyBoolean())).andReturn(collection).anyTimes();
    EasyMock.replay(listProvidersService);
    Properties props = new Properties();
    InputStream in = getClass().getResourceAsStream("/catalog-adapter/event.properties");
    props.load(in);
    in.close();
    eventProperties = PropertiesUtil.toDictionary(props);
    mediaPackageElementFlavor = new MediaPackageElementFlavor(FLAVOR_STRING.split("/")[0], FLAVOR_STRING.split("/")[1]);
    eventDublincoreURI = getClass().getResource("/catalog-adapter/dublincore.xml").toURI();
    outputCatalog = testFolder.newFile("out.xml");
    Capture<String> mediapackageIDCapture = EasyMock.newCapture();
    Capture<String> catalogIDCapture = EasyMock.newCapture();
    Capture<String> filenameCapture = EasyMock.newCapture();
    writtenCatalog = EasyMock.newCapture();
    workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
    EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIDCapture), EasyMock.capture(catalogIDCapture), EasyMock.capture(filenameCapture), EasyMock.capture(writtenCatalog))).andReturn(outputCatalog.toURI());
    EasyMock.replay(workspace);
    Catalog eventCatalog = EasyMock.createMock(Catalog.class);
    EasyMock.expect(eventCatalog.getIdentifier()).andReturn("CatalogID").anyTimes();
    EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
    eventCatalog.setURI(outputCatalog.toURI());
    EasyMock.expectLastCall();
    eventCatalog.setChecksum(null);
    EasyMock.expectLastCall();
    EasyMock.replay(eventCatalog);
    Catalog[] catalogs = { eventCatalog };
    Id id = EasyMock.createMock(Id.class);
    EasyMock.replay(id);
    mediapackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).anyTimes();
    EasyMock.expect(mediapackage.getIdentifier()).andReturn(id).anyTimes();
    EasyMock.replay(mediapackage);
    dictionary = new Hashtable<String, String>();
    dictionary.put(CONF_ORGANIZATION_KEY, ORGANIZATION_STRING);
    dictionary.put(CONF_FLAVOR_KEY, FLAVOR_STRING);
    dictionary.put(CONF_TITLE_KEY, TITLE_STRING);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_INPUT_ID_KEY, title);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LABEL_KEY, label);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_TYPE_KEY, type);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_READ_ONLY_KEY, readOnly);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_REQUIRED_KEY, required);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_LIST_PROVIDER_KEY, listProvider);
    dictionary.put(MetadataField.CONFIG_PROPERTY_PREFIX + ".title." + MetadataField.CONFIG_COLLECTION_ID_KEY, collectionID);
}
Also used : ListProvidersService(org.opencastproject.index.service.resources.list.api.ListProvidersService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TreeMap(java.util.TreeMap) Properties(java.util.Properties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) FileInputStream(java.io.FileInputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

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