Search in sources :

Example 61 with MediaPackageElementFlavor

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

the class LiveScheduleServiceImplTest method testReplaceVariables.

@Test
public void testReplaceVariables() throws Exception {
    replayServices();
    MediaPackageElementFlavor flavor = new MediaPackageElementFlavor("presenter", "delivery");
    String expectedStreamName = MP_ID + "-" + CAPTURE_AGENT_NAME + "-presenter-delivery-stream-3840x1080_suffix";
    String actualStreamName = service.replaceVariables(MP_ID, CAPTURE_AGENT_NAME, STREAM_NAME, flavor, "3840x1080");
    Assert.assertEquals(expectedStreamName, actualStreamName);
}
Also used : MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Test(org.junit.Test)

Example 62 with MediaPackageElementFlavor

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

the class IndexServiceImplTest method testAddAssetsToMp.

@Test
public void testAddAssetsToMp() throws org.json.simple.parser.ParseException, IOException, ConfigurationException, MediaPackageException, HandleException, IngestException, NotFoundException {
    MediaPackage mediapackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    JSONArray assetMetadata = (JSONArray) new JSONParser().parse("[{\"id\":\"attachment_attachment_notes\", " + "\"title\": \"class handout notes\"," + "\"flavorType\": \"attachment\"," + "\"flavorSubType\": \"notes\"," + "\"type\": \"attachment\"}]");
    // a test asset input stream
    List<String> assetList = new LinkedList<String>();
    assetList.add("attachment_attachment_notes");
    MediaPackageElementFlavor elemflavor = new MediaPackageElementFlavor("attachment_attachment_notes", "*");
    MediaPackageElementFlavor newElemflavor = new MediaPackageElementFlavor("attachment", "notes");
    // Set up the mock Ingest Service's attachment
    Attachment attachment = new AttachmentImpl();
    attachment.setFlavor(elemflavor);
    mediapackage.add(attachment);
    // Run Test
    IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
    indexServiceImpl.setIngestService(setupIngestService(mediapackage, Capture.<InputStream>newInstance()));
    mediapackage = indexServiceImpl.updateMpAssetFlavor(assetList, mediapackage, assetMetadata, true);
    assertTrue("The mediapackage attachment has the updated flavor", mediapackage.getAttachments(newElemflavor).length == 1);
}
Also used : InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 63 with MediaPackageElementFlavor

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

the class IngestRestService method addMediaPackageElement.

protected Response addMediaPackageElement(HttpServletRequest request, MediaPackageElement.Type type) {
    MediaPackageElementFlavor flavor = null;
    InputStream in = null;
    try {
        String fileName = null;
        MediaPackage mp = null;
        Long startTime = null;
        String[] tags = null;
        /* Only accept multipart/form-data */
        if (!ServletFileUpload.isMultipartContent(request)) {
            logger.trace("request isn't multipart-form-data");
            return Response.serverError().status(Status.BAD_REQUEST).build();
        }
        boolean isDone = false;
        for (FileItemIterator iter = new ServletFileUpload().getItemIterator(request); iter.hasNext(); ) {
            FileItemStream item = iter.next();
            String fieldName = item.getFieldName();
            if (item.isFormField()) {
                if ("flavor".equals(fieldName)) {
                    String flavorString = Streams.asString(item.openStream(), "UTF-8");
                    logger.trace("flavor: {}", flavorString);
                    if (flavorString != null) {
                        flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
                    }
                } else if ("tags".equals(fieldName)) {
                    String tagsString = Streams.asString(item.openStream(), "UTF-8");
                    logger.trace("tags: {}", tagsString);
                    tags = tagsString.split(",");
                } else if ("mediaPackage".equals(fieldName)) {
                    try {
                        String mediaPackageString = Streams.asString(item.openStream(), "UTF-8");
                        logger.trace("mediaPackage: {}", mediaPackageString);
                        mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageString);
                    } catch (MediaPackageException e) {
                        logger.debug("Unable to parse the 'mediaPackage' parameter: {}", ExceptionUtils.getMessage(e));
                        return Response.serverError().status(Status.BAD_REQUEST).build();
                    }
                } else if ("startTime".equals(fieldName) && "/addPartialTrack".equals(request.getPathInfo())) {
                    String startTimeString = Streams.asString(item.openStream(), "UTF-8");
                    logger.trace("startTime: {}", startTime);
                    try {
                        startTime = Long.parseLong(startTimeString);
                    } catch (Exception e) {
                        logger.debug("Unable to parse the 'startTime' parameter: {}", ExceptionUtils.getMessage(e));
                        return Response.serverError().status(Status.BAD_REQUEST).build();
                    }
                }
            } 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();
                }
                fileName = item.getName();
                in = item.openStream();
                isDone = true;
            }
            if (isDone) {
                break;
            }
        }
        /*
       * Check if we actually got a valid request including a message body and a valid mediapackage to attach the
       * element to
       */
        if (in == null || mp == null || MediaPackageSupport.sanityCheck(mp).isSome()) {
            return Response.serverError().status(Status.BAD_REQUEST).build();
        }
        switch(type) {
            case Attachment:
                mp = ingestService.addAttachment(in, fileName, flavor, tags, mp);
                break;
            case Catalog:
                mp = ingestService.addCatalog(in, fileName, flavor, tags, mp);
                break;
            case Track:
                if (startTime == null) {
                    mp = ingestService.addTrack(in, fileName, flavor, tags, mp);
                } else {
                    mp = ingestService.addPartialTrack(in, fileName, flavor, startTime, mp);
                }
                break;
            default:
                throw new IllegalStateException("Type must be one of track, catalog, or attachment");
        }
        return Response.ok(MediaPackageParser.getAsXml(mp)).build();
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    } finally {
        IOUtils.closeQuietly(in);
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) 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) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload) FileItemStream(org.apache.commons.fileupload.FileItemStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) FileItemIterator(org.apache.commons.fileupload.FileItemIterator)

Example 64 with MediaPackageElementFlavor

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

the class EventCatalogUIAdapterTest method setUp.

@Before
public void setUp() throws URISyntaxException, NotFoundException, IOException, ListProviderException {
    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.expect(listProvidersService.isTranslatable(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).anyTimes();
    EasyMock.expect(listProvidersService.getDefault(EasyMock.anyString())).andThrow(new ListProviderException("not implemented")).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]);
    URI eventDublincoreURI = getClass().getResource("/catalog-adapter/event-dublincore.xml").toURI();
    workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.read(eventDublincoreURI)).andAnswer(() -> new FileInputStream(new File(eventDublincoreURI)));
    EasyMock.replay(workspace);
    Catalog eventCatalog = EasyMock.createMock(Catalog.class);
    EasyMock.expect(eventCatalog.getURI()).andReturn(eventDublincoreURI).anyTimes();
    EasyMock.replay(eventCatalog);
    Catalog[] catalogs = { eventCatalog };
    mediapackage = EasyMock.createMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getCatalogs(mediaPackageElementFlavor)).andReturn(catalogs).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) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) TreeMap(java.util.TreeMap) Properties(java.util.Properties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) FileInputStream(java.io.FileInputStream) Catalog(org.opencastproject.mediapackage.Catalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) File(java.io.File) BundleContext(org.osgi.framework.BundleContext) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 65 with MediaPackageElementFlavor

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

the class IngestRestServiceTest method testAddMediaPackageTrackWithStartTime.

@Test
public void testAddMediaPackageTrackWithStartTime() throws Exception {
    IngestService ingestService = EasyMock.createNiceMock(IngestService.class);
    EasyMock.expect(ingestService.addPartialTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), EasyMock.anyLong(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
    EasyMock.expect(ingestService.addTrack((InputStream) EasyMock.anyObject(), (String) EasyMock.anyObject(), (MediaPackageElementFlavor) EasyMock.anyObject(), (String[]) EasyMock.anyObject(), (MediaPackage) EasyMock.anyObject())).andReturn(MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew()).once();
    EasyMock.replay(ingestService);
    restService.setIngestService(ingestService);
    MockHttpServletRequest request = newPartialMockRequest();
    request.setPathInfo("/addTrack");
    Response response = restService.addMediaPackageTrack(request);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    request = newPartialMockRequest();
    request.setPathInfo("/addPartialTrack");
    response = restService.addMediaPackageTrack(request);
    assertEquals(Status.OK.getStatusCode(), response.getStatus());
    EasyMock.verify(ingestService);
}
Also used : Response(javax.ws.rs.core.Response) IngestService(org.opencastproject.ingest.api.IngestService) ServletInputStream(javax.servlet.ServletInputStream) InputStream(java.io.InputStream) MockHttpServletRequest(org.apache.commons.fileupload.MockHttpServletRequest) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Test(org.junit.Test)

Aggregations

MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)109 MediaPackage (org.opencastproject.mediapackage.MediaPackage)49 Track (org.opencastproject.mediapackage.Track)34 URI (java.net.URI)31 Test (org.junit.Test)31 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)28 IOException (java.io.IOException)27 NotFoundException (org.opencastproject.util.NotFoundException)27 ArrayList (java.util.ArrayList)26 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)26 HashMap (java.util.HashMap)23 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)22 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)22 Job (org.opencastproject.job.api.Job)21 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 InputStream (java.io.InputStream)18 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)17 TrackSelector (org.opencastproject.mediapackage.selector.TrackSelector)16 File (java.io.File)13 Catalog (org.opencastproject.mediapackage.Catalog)13