use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class AssetManagerTestBase method mkCatalog.
public static Catalog mkCatalog() throws Exception {
final Catalog mpe = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(Type.Catalog, MediaPackageElements.EPISODE);
mpe.setURI(new URI("http://dummy.org"));
mpe.setMimeType(MimeTypes.XML);
return mpe;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class IndexServiceImplTest method testCreateEventInputNormalExpectsCreatedEvent.
@Test
public void testCreateEventInputNormalExpectsCreatedEvent() throws Exception {
String expectedTitle = "Test Event Creation";
String username = "akm220";
String org = "mh_default_org";
String[] creators = new String[] {};
Id mpId = new IdImpl("mp-id");
String testResourceLocation = "/events/create-event.json";
JSONObject metadataJson = (JSONObject) parser.parse(IOUtils.toString(IndexServiceImplTest.class.getResourceAsStream(testResourceLocation)));
Capture<Catalog> result = EasyMock.newCapture();
Capture<String> mediapackageIdResult = EasyMock.newCapture();
Capture<String> catalogIdResult = EasyMock.newCapture();
Capture<String> filenameResult = EasyMock.newCapture();
Capture<InputStream> catalogResult = EasyMock.newCapture();
Capture<String> mediapackageTitleResult = EasyMock.newCapture();
SecurityService securityService = setupSecurityService(username, org);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(EasyMock.capture(mediapackageIdResult), EasyMock.capture(catalogIdResult), EasyMock.capture(filenameResult), EasyMock.capture(catalogResult))).andReturn(new URI("catalog.xml"));
EasyMock.replay(workspace);
// Create Common Event Catalog UI Adapter
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
// Setup mediapackage.
MediaPackage mediapackage = EasyMock.createMock(MediaPackage.class);
mediapackage.add(EasyMock.capture(result));
EasyMock.expectLastCall();
EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {});
EasyMock.expect(mediapackage.getIdentifier()).andReturn(mpId).anyTimes();
EasyMock.expect(mediapackage.getCreators()).andReturn(creators);
mediapackage.addCreator("");
EasyMock.expectLastCall();
mediapackage.setTitle(EasyMock.capture(mediapackageTitleResult));
EasyMock.expectLastCall();
EasyMock.expect(mediapackage.getElements()).andReturn(new MediaPackageElement[] {}).anyTimes();
EasyMock.expect(mediapackage.getCatalogs(EasyMock.anyObject(MediaPackageElementFlavor.class))).andReturn(new Catalog[] {}).anyTimes();
EasyMock.expect(mediapackage.getSeries()).andReturn(null).anyTimes();
mediapackage.setSeries(EasyMock.anyString());
mediapackage.setSeriesTitle(EasyMock.anyString());
EasyMock.expectLastCall();
EasyMock.replay(mediapackage);
IngestService ingestService = setupIngestService(mediapackage, Capture.<InputStream>newInstance());
// Setup Authorization Service
Tuple<MediaPackage, Attachment> returnValue = new Tuple<MediaPackage, Attachment>(mediapackage, null);
AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue);
EasyMock.replay(authorizationService);
// Run Test
IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
indexServiceImpl.setAuthorizationService(setupAuthorizationService(mediapackage));
indexServiceImpl.setIngestService(ingestService);
indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
indexServiceImpl.addCatalogUIAdapter(commonEventCatalogUIAdapter);
indexServiceImpl.setUserDirectoryService(noUsersUserDirectoryService);
indexServiceImpl.setSecurityService(securityService);
indexServiceImpl.setWorkspace(workspace);
indexServiceImpl.createEvent(metadataJson, mediapackage);
assertTrue("The catalog must be added to the mediapackage", result.hasCaptured());
assertEquals("The catalog should have been added to the correct mediapackage", mpId.toString(), mediapackageIdResult.getValue());
assertTrue("The catalog should have a new id", catalogIdResult.hasCaptured());
assertTrue("The catalog should have a new filename", filenameResult.hasCaptured());
assertTrue("The catalog should have been added to the input stream", catalogResult.hasCaptured());
assertTrue("The mediapackage should have had its title updated", catalogResult.hasCaptured());
assertEquals("The mediapackage title should have been updated.", expectedTitle, mediapackageTitleResult.getValue());
assertTrue("The catalog should have been created", catalogResult.hasCaptured());
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class IngestServiceImplTest method testSmilCreation.
@Test
public void testSmilCreation() throws Exception {
service.setWorkingFileRepository(new WorkingFileRepositoryImpl() {
@Override
public URI put(String mediaPackageID, String mediaPackageElementID, String filename, InputStream in) throws IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
file.deleteOnExit();
FileUtils.write(file, IOUtils.toString(in), "UTF-8");
return file.toURI();
}
@Override
public InputStream get(String mediaPackageID, String mediaPackageElementID) throws NotFoundException, IOException {
File file = new File(FileUtils.getTempDirectory(), mediaPackageElementID);
return new FileInputStream(file);
}
});
URI presenterUri = URI.create("http://localhost:8080/presenter.mp4");
URI presenterUri2 = URI.create("http://localhost:8080/presenter2.mp4");
URI presentationUri = URI.create("http://localhost:8080/presentation.mp4");
MediaPackage mediaPackage = service.createMediaPackage();
Catalog[] catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
mediaPackage = service.addPartialTrack(presenterUri, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 60000L, mediaPackage);
mediaPackage = service.addPartialTrack(presenterUri2, MediaPackageElements.PRESENTER_SOURCE_PARTIAL, 120000L, mediaPackage);
mediaPackage = service.addPartialTrack(presentationUri, MediaPackageElements.PRESENTATION_SOURCE_PARTIAL, 0L, mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(0, catalogs.length);
service.ingest(mediaPackage);
catalogs = mediaPackage.getCatalogs(MediaPackageElements.SMIL);
Assert.assertEquals(1, catalogs.length);
Assert.assertEquals(MimeTypes.SMIL, catalogs[0].getMimeType());
Either<Exception, Document> eitherDoc = XmlUtil.parseNs(new InputSource(catalogs[0].getURI().toURL().openStream()));
Assert.assertTrue(eitherDoc.isRight());
Document document = eitherDoc.right().value();
Assert.assertEquals(1, document.getElementsByTagName("par").getLength());
Assert.assertEquals(2, document.getElementsByTagName("seq").getLength());
Assert.assertEquals(2, document.getElementsByTagName("video").getLength());
Assert.assertEquals(1, document.getElementsByTagName("audio").getLength());
}
use of org.opencastproject.mediapackage.Catalog 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);
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class TagByDublinCoreTermWOHTest method testMatchDefaultDCTerm.
@Test
public void testMatchDefaultDCTerm() throws Exception {
// Match == Default Value
operation.setConfiguration(TagByDublinCoreTermWOH.SOURCE_FLAVORS_PROPERTY, "dublincore/*");
operation.setConfiguration(TagByDublinCoreTermWOH.DCCATALOG_PROPERTY, "episode");
operation.setConfiguration(TagByDublinCoreTermWOH.DCTERM_PROPERTY, "source");
operation.setConfiguration(TagByDublinCoreTermWOH.DEFAULT_VALUE_PROPERTY, "Timbuktu");
operation.setConfiguration(TagByDublinCoreTermWOH.MATCH_VALUE_PROPERTY, "Timbuktu");
operation.setConfiguration(TagByDublinCoreTermWOH.TARGET_TAGS_PROPERTY, "tag1,tag2");
operation.setConfiguration(TagByDublinCoreTermWOH.COPY_PROPERTY, "false");
WorkflowOperationResult result = operationHandler.start(instance, null);
MediaPackage resultingMediapackage = result.getMediaPackage();
Catalog catalog = resultingMediapackage.getCatalog("catalog-1");
Assert.assertEquals(2, catalog.getTags().length);
Assert.assertEquals("tag1", catalog.getTags()[0]);
Assert.assertEquals("tag2", catalog.getTags()[1]);
}
Aggregations