@Test public void testEpisodeNotKnownByOaiPmh() throws Exception { Catalog episodeCatalog = CatalogImpl.newInstance(); episodeCatalog.setURI(URI.create("/episode.xml")); episodeCatalog.setFlavor(MediaPackageElementFlavor.parseFlavor("dublincore/episode")); episodeCatalog.addTag("archive"); MediaPackage updatedMp = createMediaPackage(episodeCatalog); mockAssetManager(updatedMp); mockSecurityService(); SearchResult searchResultMock = mock(MockType.NICE, SearchResult.class); expect(searchResultMock.getItems()).andReturn(Collections.EMPTY_LIST).anyTimes(); queryCapture = Capture.newInstance(); expect(oaiPmhDatabaseMock.search(capture(queryCapture))).andReturn(searchResultMock); replayAll(); cut.handleEvent(createSnapshot(updatedMp)); verifyAll(); }
public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) { if (!propagateEpisode) { logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off."); return; } logger.debug("Handling update event for media package {}", snapshotItem.getId()); final User prevUser = securityService.getUser(); final Organization prevOrg = securityService.getOrganization(); try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); String versionStr = Long.toString(snapshotItem.getVersion()); AQueryBuilder q = assetManager.createQuery(); AResult snapshotQueryResult = q.select(q.snapshot()) .where(q.organizationId().eq(prevOrg.getId()) .and(q.mediaPackageId(snapshotItem.getId()) .and(q.version().eq(assetManager.toVersion(versionStr).get())))).run(); Opt<ARecord> snapshotRecordOpt = snapshotQueryResult.getRecords().head(); if (snapshotRecordOpt.isSome()) { Snapshot snapshot = snapshotRecordOpt.get().getSnapshot().get(); MediaPackage snapshotMp = snapshot.getMediaPackage(); SimpleElementSelector mpeSelector = new SimpleElementSelector(); for (String flavor : flavors) { mpeSelector.addFlavor(flavor); } for (String tag : tags) { mpeSelector.addTag(tag); } Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true); if (elementsToUpdate == null || elementsToUpdate.isEmpty()) { logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().toString()); return; } SearchResult result = oaiPmhPersistence.search( QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build()); for (SearchResultItem searchResultItem : result.getItems()) { try { Job job = oaiPmhPublicationService .updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false); } catch (Exception e) { logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getId(), searchResultItem.getRepository(), e); } } } } finally { securityService.setOrganization(prevOrg); securityService.setUser(prevUser); } }
OaiPmhUpdatedEventHandler implements ManagedService { public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) { if (!propagateEpisode) { logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off."); return; } logger.debug("Handling update event for media package {}", snapshotItem.getId()); final User prevUser = securityService.getUser(); final Organization prevOrg = securityService.getOrganization(); try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); String versionStr = Long.toString(snapshotItem.getVersion()); AQueryBuilder q = assetManager.createQuery(); AResult snapshotQueryResult = q.select(q.snapshot()) .where(q.organizationId().eq(prevOrg.getId()) .and(q.mediaPackageId(snapshotItem.getId()) .and(q.version().eq(assetManager.toVersion(versionStr).get())))).run(); Opt<ARecord> snapshotRecordOpt = snapshotQueryResult.getRecords().head(); if (snapshotRecordOpt.isSome()) { Snapshot snapshot = snapshotRecordOpt.get().getSnapshot().get(); MediaPackage snapshotMp = snapshot.getMediaPackage(); SimpleElementSelector mpeSelector = new SimpleElementSelector(); for (String flavor : flavors) { mpeSelector.addFlavor(flavor); } for (String tag : tags) { mpeSelector.addTag(tag); } Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true); if (elementsToUpdate == null || elementsToUpdate.isEmpty()) { logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().toString()); return; } SearchResult result = oaiPmhPersistence.search( QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build()); for (SearchResultItem searchResultItem : result.getItems()) { try { Job job = oaiPmhPublicationService .updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false); } catch (Exception e) { logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getId(), searchResultItem.getRepository(), e); } } } } finally { securityService.setOrganization(prevOrg); securityService.setUser(prevUser); } } }
OaiPmhUpdatedEventHandler implements ManagedService { public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) { if (!propagateEpisode) { logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off."); return; } logger.debug("Handling update event for media package {}", snapshotItem.getId()); final User prevUser = securityService.getUser(); final Organization prevOrg = securityService.getOrganization(); try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); String versionStr = Long.toString(snapshotItem.getVersion()); AQueryBuilder q = assetManager.createQuery(); AResult snapshotQueryResult = q.select(q.snapshot()) .where(q.organizationId().eq(prevOrg.getId()) .and(q.mediaPackageId(snapshotItem.getId()) .and(q.version().eq(assetManager.toVersion(versionStr).get())))).run(); Opt<ARecord> snapshotRecordOpt = snapshotQueryResult.getRecords().head(); if (snapshotRecordOpt.isSome()) { Snapshot snapshot = snapshotRecordOpt.get().getSnapshot().get(); MediaPackage snapshotMp = snapshot.getMediaPackage(); SimpleElementSelector mpeSelector = new SimpleElementSelector(); for (String flavor : flavors) { mpeSelector.addFlavor(flavor); } for (String tag : tags) { mpeSelector.addTag(tag); } Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true); if (elementsToUpdate == null || elementsToUpdate.isEmpty()) { logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().toString()); return; } SearchResult result = oaiPmhPersistence.search( QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build()); for (SearchResultItem searchResultItem : result.getItems()) { try { Job job = oaiPmhPublicationService .updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false); } catch (Exception e) { logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getId(), searchResultItem.getRepository(), e); } } } } finally { securityService.setOrganization(prevOrg); securityService.setUser(prevUser); } }  }
OaiPmhUpdatedEventHandler implements ManagedService { public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) { if (!propagateEpisode) { logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off."); return; } logger.debug("Handling update event for media package {}", snapshotItem.getId()); final User prevUser = securityService.getUser(); final Organization prevOrg = securityService.getOrganization(); try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); String versionStr = Long.toString(snapshotItem.getVersion()); AQueryBuilder q = assetManager.createQuery(); AResult snapshotQueryResult = q.select(q.snapshot()) .where(q.organizationId().eq(prevOrg.getId()) .and(q.mediaPackageId(snapshotItem.getId()) .and(q.version().eq(assetManager.toVersion(versionStr).get())))).run(); Opt<ARecord> snapshotRecordOpt = snapshotQueryResult.getRecords().head(); if (snapshotRecordOpt.isSome()) { Snapshot snapshot = snapshotRecordOpt.get().getSnapshot().get(); MediaPackage snapshotMp = snapshot.getMediaPackage(); SimpleElementSelector mpeSelector = new SimpleElementSelector(); for (String flavor : flavors) { mpeSelector.addFlavor(flavor); } for (String tag : tags) { mpeSelector.addTag(tag); } Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true); if (elementsToUpdate == null || elementsToUpdate.isEmpty()) { logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().toString()); return; } SearchResult result = oaiPmhPersistence.search( QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build()); for (SearchResultItem searchResultItem : result.getItems()) { try { Job job = oaiPmhPublicationService .updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false); } catch (Exception e) { logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getId(), searchResultItem.getRepository(), e); } } } } finally { securityService.setOrganization(prevOrg); securityService.setUser(prevUser); } }  @Override void updated(Dictionary<String, ?> dictionary); void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem); void setAssetManager(AssetManager assetManager); void setOaiPmhPersistence(OaiPmhDatabase oaiPmhPersistence); void setOaiPmhPublicationService(OaiPmhPublicationService oaiPmhPublicationService); void setSecurityService(SecurityService securityService); }
OaiPmhUpdatedEventHandler implements ManagedService { public void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem) { if (!propagateEpisode) { logger.trace("Skipping automatic propagation of episode meta data to OAI-PMH since it is turned off."); return; } logger.debug("Handling update event for media package {}", snapshotItem.getId()); final User prevUser = securityService.getUser(); final Organization prevOrg = securityService.getOrganization(); try { securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg)); String versionStr = Long.toString(snapshotItem.getVersion()); AQueryBuilder q = assetManager.createQuery(); AResult snapshotQueryResult = q.select(q.snapshot()) .where(q.organizationId().eq(prevOrg.getId()) .and(q.mediaPackageId(snapshotItem.getId()) .and(q.version().eq(assetManager.toVersion(versionStr).get())))).run(); Opt<ARecord> snapshotRecordOpt = snapshotQueryResult.getRecords().head(); if (snapshotRecordOpt.isSome()) { Snapshot snapshot = snapshotRecordOpt.get().getSnapshot().get(); MediaPackage snapshotMp = snapshot.getMediaPackage(); SimpleElementSelector mpeSelector = new SimpleElementSelector(); for (String flavor : flavors) { mpeSelector.addFlavor(flavor); } for (String tag : tags) { mpeSelector.addTag(tag); } Collection<MediaPackageElement> elementsToUpdate = mpeSelector.select(snapshotMp, true); if (elementsToUpdate == null || elementsToUpdate.isEmpty()) { logger.debug("The media package {} does not contain any elements matching the given flavors and tags", snapshotMp.getIdentifier().toString()); return; } SearchResult result = oaiPmhPersistence.search( QueryBuilder.query().mediaPackageId(snapshotMp).isDeleted(false).build()); for (SearchResultItem searchResultItem : result.getItems()) { try { Job job = oaiPmhPublicationService .updateMetadata(snapshotMp, searchResultItem.getRepository(), flavors, tags, false); } catch (Exception e) { logger.error("Unable to update OAI-PMH publication for the media package {} in repository {}", snapshotItem.getId(), searchResultItem.getRepository(), e); } } } } finally { securityService.setOrganization(prevOrg); securityService.setUser(prevUser); } }  @Override void updated(Dictionary<String, ?> dictionary); void handleEvent(AssetManagerItem.TakeSnapshot snapshotItem); void setAssetManager(AssetManager assetManager); void setOaiPmhPersistence(OaiPmhDatabase oaiPmhPersistence); void setOaiPmhPublicationService(OaiPmhPublicationService oaiPmhPublicationService); void setSecurityService(SecurityService securityService);  }