use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class LiveScheduleServiceImpl method addAndDistributeElements.
MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException {
try {
MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone();
Set<String> elementIds = new HashSet<String>();
// Then, add series catalog if needed
if (StringUtils.isNotEmpty(mp.getSeries())) {
DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries());
// Create temporary catalog and save to workspace
mp.add(catalog);
URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "series.xml", dublinCoreService.serialize(catalog));
catalog.setURI(uri);
catalog.setChecksum(null);
catalog.setFlavor(MediaPackageElements.SERIES);
elementIds.add(catalog.getIdentifier());
}
if (mp.getCatalogs(MediaPackageElements.EPISODE).length > 0)
elementIds.add(mp.getCatalogs(MediaPackageElements.EPISODE)[0].getIdentifier());
if (mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE).length > 0)
elementIds.add(mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE)[0].getIdentifier());
// Distribute element(s)
Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, elementIds, false);
if (!waitForStatus(distributionJob).isSuccess())
throw new LiveScheduleException("Element(s) for live media package " + mp.getIdentifier() + " could not be distributed");
for (String id : elementIds) {
MediaPackageElement e = mp.getElementById(id);
// Cleanup workspace/wfr
mp.remove(e);
workspace.delete(e.getURI());
}
// Add distributed element(s) to mp
List<MediaPackageElement> distributedElements = (List<MediaPackageElement>) MediaPackageElementParser.getArrayFromXml(distributionJob.getPayload());
for (MediaPackageElement mpe : distributedElements) mp.add(mpe);
return mp;
} catch (LiveScheduleException e) {
throw e;
} catch (Exception e) {
throw new LiveScheduleException(e);
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerUpdateHandler method execute.
@Override
protected void execute(MessageItem messageItem) {
SchedulerItem schedulerItem = (SchedulerItem) messageItem;
String mpId = schedulerItem.getMediaPackageId();
try {
logger.debug("Scheduler message handler START for mp {} event type {} in thread {}", mpId, schedulerItem.getType(), Thread.currentThread().getId());
switch(schedulerItem.getType()) {
case UpdateCatalog:
if (isLive(mpId))
liveScheduleService.createOrUpdateLiveEvent(mpId, schedulerItem.getEvent());
break;
case UpdateAcl:
if (isLive(mpId))
liveScheduleService.updateLiveEventAcl(mpId, schedulerItem.getAcl());
break;
case UpdateProperties:
// Workflow properties may have been updated (publishLive configuration)
String publishLive = schedulerItem.getProperties().get(PUBLISH_LIVE_PROPERTY);
if (publishLive == null)
// Not specified so we do nothing. We don't want to delete if we got incomplete props.
return;
else if (BooleanUtils.toBoolean(publishLive)) {
DublinCoreCatalog episodeDC = schedulerService.getDublinCore(mpId);
liveScheduleService.createOrUpdateLiveEvent(mpId, episodeDC);
} else
liveScheduleService.deleteLiveEvent(mpId);
break;
case Delete:
case DeleteRecordingStatus:
if (isLive(mpId))
liveScheduleService.deleteLiveEvent(mpId);
break;
case UpdateAgentId:
case UpdateStart:
case UpdateEnd:
if (isLive(mpId)) {
DublinCoreCatalog episodeDC = schedulerService.getDublinCore(mpId);
liveScheduleService.createOrUpdateLiveEvent(mpId, episodeDC);
}
break;
case UpdateRecordingStatus:
String state = schedulerItem.getRecordingState();
if (RecordingState.CAPTURE_FINISHED.equals(state) || RecordingState.UPLOADING.equals(state) || RecordingState.UPLOADING.equals(state) || RecordingState.CAPTURE_ERROR.equals(state) || RecordingState.UPLOAD_ERROR.equals(state))
if (isLive(mpId))
liveScheduleService.deleteLiveEvent(mpId);
break;
case UpdateOptOut:
case UpdateBlacklist:
case UpdatePresenters:
case UpdateReviewStatus:
break;
default:
throw new IllegalArgumentException("Unhandled type of SchedulerItem");
}
} catch (Exception e) {
logger.warn(String.format("Exception occurred for mp %s, event type %s", mpId, schedulerItem.getType()), e);
} finally {
logger.debug("Scheduler message handler END for mp {} event type {} in thread {}", mpId, schedulerItem.getType(), Thread.currentThread().getId());
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class LiveScheduleServiceImplTest method testAddAndDistributeElements.
@Test
public void testAddAndDistributeElements() throws Exception {
URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
replayServices();
Snapshot s = EasyMock.createNiceMock(Snapshot.class);
EasyMock.expect(s.getMediaPackage()).andReturn(mp);
EasyMock.replay(s);
service.setDownloadDistributionService(downloadDistributionService);
MediaPackage mp1 = service.addAndDistributeElements(s);
Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
Assert.assertNotNull(catalogs);
Assert.assertEquals(1, catalogs.length);
Catalog catalog = catalogs[0];
Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml", catalog.getURI().toString());
Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
Assert.assertNotNull(catalogs);
Assert.assertEquals(1, catalogs.length);
catalog = catalogs[0];
Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
Assert.assertNotNull(atts);
Assert.assertEquals(1, atts.length);
Attachment att = atts[0];
Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml", att.getURI().toString());
Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
EasyMock.verify(downloadDistributionService, workspace);
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SchedulerMigrationService method transform.
/**
* Transform the event result set into {@link Event}s.
*/
List<Event> transform(ResultSet resultSet) {
try {
List<Event> events = new ArrayList<>();
while (resultSet.next()) {
DublinCoreCatalog dc = readDublinCoreSilent(resultSet.getString(5));
dc.setIdentifier(UUID.randomUUID().toString());
dc.setFlavor(MediaPackageElements.EPISODE);
dc.remove(DublinCore.PROPERTY_IDENTIFIER);
Properties properties = parseProperties(resultSet.getString(4));
AccessControlList acl = resultSet.getString(2) != null ? AccessControlParser.parseAclSilent(resultSet.getString(2)) : null;
events.add(new Event(resultSet.getLong(1), resultSet.getString(6), dc, properties, acl, resultSet.getBoolean(7), ReviewStatus.valueOf(resultSet.getString(9)), resultSet.getDate(8)));
}
return events;
} catch (Exception e) {
return chuck(e);
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class IndexServiceImplTest method testUpdateMediaPackageMetadata.
@Test
public void testUpdateMediaPackageMetadata() throws Exception {
// mock/initialize dependencies
String username = "user1";
String org = "mh_default_org";
String testResourceLocation = "/events/update-event.json";
String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
String eventId = "event-1";
Event event = new Event(eventId, org);
event.setTitle("Test Event 1");
SearchQuery query = EasyMock.createMock(SearchQuery.class);
EasyMock.expect(query.getLimit()).andReturn(100);
EasyMock.expect(query.getOffset()).andReturn(0);
EasyMock.replay(query);
SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
searchResult.addResultItem(searchResultItem);
SecurityService securityService = setupSecurityService(username, org);
AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
EasyMock.replay(index);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
EasyMock.replay(workspace);
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
// Using scheduler as the source of the media package here.
SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
EasyMock.expectLastCall();
EasyMock.replay(schedulerService);
SeriesService seriesService = EasyMock.createMock(SeriesService.class);
DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
EasyMock.replay(seriesService);
// create service
IndexServiceImpl indexService = new IndexServiceImpl();
indexService.setSecurityService(securityService);
indexService.setSchedulerService(schedulerService);
indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.setSeriesService(seriesService);
indexService.setWorkspace(workspace);
MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
Assert.assertTrue(mpCapture.hasCaptured());
Assert.assertEquals("series-1", mp.getSeries());
Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
Aggregations