Search in sources :

Example 6 with AttachmentImpl

use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.

the class TestRestService method newAuthorizationService.

private static AuthorizationService newAuthorizationService() {
    AccessControlList acl = new AccessControlList();
    Attachment attachment = new AttachmentImpl();
    MediaPackage mediapackage;
    try {
        mediapackage = new MediaPackageBuilderImpl().createNew();
    } catch (MediaPackageException e) {
        throw new RuntimeException(e);
    }
    AuthorizationService authorizationService = EasyMock.createNiceMock(AuthorizationService.class);
    EasyMock.expect(authorizationService.getActiveAcl((MediaPackage) EasyMock.anyObject())).andReturn(Tuple.tuple(acl, AclScope.Series)).anyTimes();
    EasyMock.expect(authorizationService.setAcl((MediaPackage) EasyMock.anyObject(), (AclScope) EasyMock.anyObject(), (AccessControlList) EasyMock.anyObject())).andReturn(Tuple.tuple(mediapackage, attachment));
    EasyMock.replay(authorizationService);
    return authorizationService;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackageBuilderImpl(org.opencastproject.mediapackage.MediaPackageBuilderImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl)

Example 7 with AttachmentImpl

use of org.opencastproject.mediapackage.attachment.AttachmentImpl 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 8 with AttachmentImpl

use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.

the class ImportWorkflowPropertiesWOHTest method testStartOp.

@Test
public void testStartOp() throws Exception {
    final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
    expect(woi.getConfiguration("source-flavor")).andStubReturn(FLAVOR);
    expect(woi.getConfiguration("keys")).andStubReturn("chapter, presenter_position, cover_marker_in_s");
    replay(woi);
    final Attachment att = new AttachmentImpl();
    att.setURI(new URI(WF_PROPS_ATT_URI));
    att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.add(att);
    WorkflowInstance wi = createMock(WorkflowInstance.class);
    expect(wi.getCurrentOperation()).andStubReturn(woi);
    expect(wi.getMediaPackage()).andStubReturn(mp);
    replay(wi);
    try (InputStream is = ImportWorkflowPropertiesWOHTest.class.getResourceAsStream("/workflow-properties.xml")) {
        Files.copy(is, tmpPropsFile, StandardCopyOption.REPLACE_EXISTING);
    }
    final Workspace workspace = createNiceMock(Workspace.class);
    expect(workspace.get(new URI(WF_PROPS_ATT_URI))).andStubReturn(tmpPropsFile.toFile());
    replay(workspace);
    final ImportWorkflowPropertiesWOH woh = new ImportWorkflowPropertiesWOH();
    woh.setWorkspace(workspace);
    WorkflowOperationResult result = woh.start(wi, null);
    Map<String, String> properties = result.getProperties();
    Assert.assertTrue(properties.containsKey("chapter"));
    Assert.assertEquals("true", properties.get("chapter"));
    Assert.assertTrue(properties.containsKey("presenter_position"));
    Assert.assertEquals("left", properties.get("presenter_position"));
    Assert.assertTrue(properties.containsKey("cover_marker_in_s"));
    Assert.assertEquals("30.674", properties.get("cover_marker_in_s"));
    verify(wi);
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 9 with AttachmentImpl

use of org.opencastproject.mediapackage.attachment.AttachmentImpl in project opencast by opencast.

the class ExportWorkflowPropertiesWOHTest method testExport.

@Test
public void testExport() throws Exception {
    final WorkflowOperationInstance woi = createMock(WorkflowOperationInstance.class);
    expect(woi.getConfiguration("target-flavor")).andStubReturn(FLAVOR);
    expect(woi.getConfiguration("target-tags")).andStubReturn("archive");
    expect(woi.getConfiguration("keys")).andStubReturn("chapter,presenter_position");
    replay(woi);
    final Attachment att = new AttachmentImpl();
    att.setURI(uri);
    att.setFlavor(MediaPackageElementFlavor.parseFlavor(FLAVOR));
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.add(att);
    WorkflowInstance wi = createMock(WorkflowInstance.class);
    expect(wi.getCurrentOperation()).andStubReturn(woi);
    expect(wi.getMediaPackage()).andStubReturn(mp);
    Set<String> keys = new HashSet<>();
    keys.add("presenter_position");
    keys.add("cover_marker_in_s");
    expect(wi.getConfigurationKeys()).andStubReturn(keys);
    expect(wi.getConfiguration("presenter_position")).andStubReturn("right");
    expect(wi.getConfiguration("cover_marker_in_s")).andStubReturn("30.674");
    replay(wi);
    final ExportWorkflowPropertiesWOH woh = new ExportWorkflowPropertiesWOH();
    woh.setWorkspace(workspace);
    WorkflowOperationResult result = woh.start(wi, null);
    Attachment[] attachments = result.getMediaPackage().getAttachments();
    Assert.assertTrue(attachments.length == 1);
    Attachment attachment = attachments[0];
    assertEquals("processing/defaults", attachment.getFlavor().toString());
    assertEquals("archive", attachment.getTags()[0]);
    Assert.assertNotNull(attachment.getURI());
    File file = workspace.get(attachment.getURI());
    Properties props = new Properties();
    try (InputStream is = new FileInputStream(file)) {
        props.loadFromXML(is);
    }
    assertEquals("30.674", props.get("cover_marker_in_s"));
    assertEquals("right", props.get("presenter_position"));
    Assert.assertFalse(props.contains("chapter"));
    verify(wi);
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Properties(java.util.Properties) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) FileInputStream(java.io.FileInputStream) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)9 Attachment (org.opencastproject.mediapackage.Attachment)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 InputStream (java.io.InputStream)4 URI (java.net.URI)4 Test (org.junit.Test)4 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)3 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)3 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)3 Job (org.opencastproject.job.api.Job)2 MediaPackageBuilderImpl (org.opencastproject.mediapackage.MediaPackageBuilderImpl)2 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)2 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)2 Track (org.opencastproject.mediapackage.Track)2 IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)2 TrackImpl (org.opencastproject.mediapackage.track.TrackImpl)2 Workspace (org.opencastproject.workspace.api.Workspace)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1