@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: + "<mimetype>text/xml</mimetype>" + "<url>http: + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http: + "<mimetype>text/xml</mimetype>" + "<url>http: + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http: + "<mimetype>text/xml</mimetype>" + "<url>http: 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: 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: 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: att.getURI().toString()); Assert.assertEquals("security/xacml+episode", att.getFlavor().toString()); EasyMock.verify(downloadDistributionService, workspace); }
MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException { try { MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone(); Set<String> elementIds = new HashSet<String>(); if (StringUtils.isNotEmpty(mp.getSeries())) { DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries()); 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()); 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); mp.remove(e); workspace.delete(e.getURI()); } 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); } }
LiveScheduleServiceImpl implements LiveScheduleService { MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException { try { MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone(); Set<String> elementIds = new HashSet<String>(); if (StringUtils.isNotEmpty(mp.getSeries())) { DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries()); 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()); 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); mp.remove(e); workspace.delete(e.getURI()); } 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); } } }
LiveScheduleServiceImpl implements LiveScheduleService { MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException { try { MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone(); Set<String> elementIds = new HashSet<String>(); if (StringUtils.isNotEmpty(mp.getSeries())) { DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries()); 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()); 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); mp.remove(e); workspace.delete(e.getURI()); } 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); } }  }
LiveScheduleServiceImpl implements LiveScheduleService { MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException { try { MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone(); Set<String> elementIds = new HashSet<String>(); if (StringUtils.isNotEmpty(mp.getSeries())) { DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries()); 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()); 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); mp.remove(e); workspace.delete(e.getURI()); } 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); } }  @Override boolean createOrUpdateLiveEvent(String mpId, DublinCoreCatalog episodeDC); @Override boolean deleteLiveEvent(String mpId); @Override boolean updateLiveEventAcl(String mpId, AccessControlList acl); void setDublinCoreService(DublinCoreCatalogService service); void setSearchService(SearchService service); void setSeriesService(SeriesService service); void setServiceRegistry(ServiceRegistry service); void setCaptureAgentService(CaptureAgentStateService service); void setDownloadDistributionService(DownloadDistributionService service); void setWorkspace(Workspace ws); void setAssetManager(AssetManager assetManager); void setAuthorizationService(AuthorizationService service); void setOrganizationService(OrganizationDirectoryService service); }
LiveScheduleServiceImpl implements LiveScheduleService { MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException { try { MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone(); Set<String> elementIds = new HashSet<String>(); if (StringUtils.isNotEmpty(mp.getSeries())) { DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries()); 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()); 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); mp.remove(e); workspace.delete(e.getURI()); } 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); } }  @Override boolean createOrUpdateLiveEvent(String mpId, DublinCoreCatalog episodeDC); @Override boolean deleteLiveEvent(String mpId); @Override boolean updateLiveEventAcl(String mpId, AccessControlList acl); void setDublinCoreService(DublinCoreCatalogService service); void setSearchService(SearchService service); void setSeriesService(SeriesService service); void setServiceRegistry(ServiceRegistry service); void setCaptureAgentService(CaptureAgentStateService service); void setDownloadDistributionService(DownloadDistributionService service); void setWorkspace(Workspace ws); void setAssetManager(AssetManager assetManager); void setAuthorizationService(AuthorizationService service); void setOrganizationService(OrganizationDirectoryService service); static final String CA_PROPERTY_RESOLUTION_URL_PREFIX; static final String REPLACE_ID; static final String REPLACE_FLAVOR; static final String REPLACE_CA_NAME; static final String REPLACE_RESOLUTION; static final String LIVE_STREAMING_URL; static final String LIVE_STREAM_NAME; static final String LIVE_STREAM_MIME_TYPE; static final String LIVE_STREAM_RESOLUTION; static final String LIVE_TARGET_FLAVORS; static final String LIVE_DISTRIBUTION_SERVICE; static final String LIVE_PUBLISH_STREAMING; }