Search in sources :

Example 1 with AssetManagerItem

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()));
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) File(java.io.File) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 2 with AssetManagerItem

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));
}
Also used : AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) Date(java.util.Date) Test(org.junit.Test)

Example 3 with AssetManagerItem

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));
}
Also used : AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) Date(java.util.Date) Test(org.junit.Test)

Example 4 with AssetManagerItem

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());
    }
}
Also used : TakeSnapshot(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot) AssetManagerItem(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem) Publication(org.opencastproject.mediapackage.Publication) DeleteEpisode(org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.DeleteEpisode)

Aggregations

AssetManagerItem (org.opencastproject.message.broker.api.assetmanager.AssetManagerItem)4 Date (java.util.Date)3 Test (org.junit.Test)3 File (java.io.File)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 Publication (org.opencastproject.mediapackage.Publication)1 DeleteEpisode (org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.DeleteEpisode)1 TakeSnapshot (org.opencastproject.message.broker.api.assetmanager.AssetManagerItem.TakeSnapshot)1 AccessControlEntry (org.opencastproject.security.api.AccessControlEntry)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1 Workspace (org.opencastproject.workspace.api.Workspace)1