use of org.opencastproject.message.broker.api.assetmanager.AssetManagerItem in project opencast by opencast.
the class AssetManagerItemTest method testSerializeUpdate.
@Test
public void testSerializeUpdate() throws Exception {
final Workspace workspace = EasyMock.createNiceMock(Workspace.class);
EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(new File(getClass().getResource("/dublincore-a.xml").toURI())).once();
EasyMock.expect(workspace.read(EasyMock.anyObject(URI.class))).andAnswer(() -> getClass().getResourceAsStream("/dublincore-a.xml")).once();
EasyMock.replay(workspace);
final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
mp.add(DublinCores.mkOpencastEpisode().getCatalog());
final AccessControlList acl = new AccessControlList(new AccessControlEntry("admin", "read", true));
final Date now = new Date();
final AssetManagerItem item = AssetManagerItem.add(workspace, mp, acl, 10L, now);
final AssetManagerItem deserialized = IoSupport.serializeDeserialize(item);
assertEquals(item.getDate(), deserialized.getDate());
assertEquals(item.getType(), deserialized.getType());
assertEquals(item.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier(), deserialized.decompose(TakeSnapshot.getMediaPackage, null, null).getIdentifier());
assertEquals(item.decompose(TakeSnapshot.getAcl, null, null).getEntries(), deserialized.decompose(TakeSnapshot.getAcl, null, null).getEntries());
assertTrue(DublinCoreUtil.equals(item.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get(), deserialized.decompose(TakeSnapshot.getEpisodeDublincore, null, null).get()));
}
use of org.opencastproject.message.broker.api.assetmanager.AssetManagerItem in project opencast by opencast.
the class AssetManagerItemTest method testSerializeDeleteEpisode.
@Test
public void testSerializeDeleteEpisode() throws Exception {
final Date now = new Date();
final AssetManagerItem item = AssetManagerItem.deleteEpisode("id", now);
final AssetManagerItem deserialized = IoSupport.serializeDeserialize(item);
assertEquals(item.getDate(), deserialized.getDate());
assertEquals(item.getType(), deserialized.getType());
assertEquals(item.decompose(null, null, DeleteEpisode.getMediaPackageId), deserialized.decompose(null, null, DeleteEpisode.getMediaPackageId));
}
use of org.opencastproject.message.broker.api.assetmanager.AssetManagerItem in project opencast by opencast.
the class AssetManagerItemTest method testSerializeDeleteSnapshot.
@Test
public void testSerializeDeleteSnapshot() throws Exception {
final Date now = new Date();
final AssetManagerItem item = AssetManagerItem.deleteSnapshot("id", 0L, now);
final AssetManagerItem deserialized = IoSupport.serializeDeserialize(item);
assertEquals(item.getDate(), deserialized.getDate());
assertEquals(item.getType(), deserialized.getType());
assertEquals(item.decompose(null, DeleteSnapshot.getMediaPackageId, null), deserialized.decompose(null, DeleteSnapshot.getMediaPackageId, null));
}
use of org.opencastproject.message.broker.api.assetmanager.AssetManagerItem in project opencast by opencast.
the class AssetManagerUpdateHandler method execute.
@Override
protected void execute(MessageItem messageItem) {
AssetManagerItem item = (AssetManagerItem) messageItem;
String mpId = item.getId();
try {
logger.debug("Asset Manager message handler START for mp {} event type {} in thread {}", mpId, item.getType(), Thread.currentThread().getId());
switch(item.getType()) {
case Update:
if (item instanceof TakeSnapshot) {
// Check class just in case
TakeSnapshot snapshotItem = (TakeSnapshot) item;
// If no episopde dc, there's nothing to do.
if (snapshotItem.getEpisodeDublincore().isNone())
break;
// notifications, only when getting scheduler notifications
for (Publication pub : snapshotItem.getMediapackage().getPublications()) {
if (LiveScheduleService.CHANNEL_ID.equals(pub.getChannel()))
liveScheduleService.createOrUpdateLiveEvent(mpId, snapshotItem.getEpisodeDublincore().get());
}
}
break;
case Delete:
if (item instanceof DeleteEpisode)
// Episode is being deleted
liveScheduleService.deleteLiveEvent(mpId);
// No action needed when a snapshot is deleted
break;
default:
throw new IllegalArgumentException("Unhandled type of AssetManagerItem");
}
} catch (Exception e) {
logger.warn(String.format("Exception occurred for mp %s, event type %s", mpId, item.getType()), e);
} finally {
logger.debug("Asset Manager message handler END for mp {} event type {} in thread {}", mpId, item.getType(), Thread.currentThread().getId());
}
}
Aggregations