@Test public void updatePresenters() throws IOException, org.osgi.service.cm.ConfigurationException { String nonUser1 = "Non User 1"; String nonUser2 = "Non User 2"; String nonUser3 = "Non User 3"; Properties eventProperties = new Properties(); InputStream in = getClass().getResourceAsStream("/episode-catalog.properties"); eventProperties.load(in); in.close(); Dictionary<String, String> properties = PropertiesUtil.toDictionary(eventProperties); SecurityService securityService = EasyMock.createMock(SecurityService.class); EasyMock.expect(securityService.getOrganization()).andStubReturn(organization); EasyMock.replay(securityService); UserDirectoryService userDirectoryService = EasyMock.createMock(UserDirectoryService.class); EasyMock.expect(userDirectoryService.loadUser(user1.getUsername())).andStubReturn(user1); EasyMock.expect(userDirectoryService.loadUser(user2.getUsername())).andStubReturn(user2); EasyMock.expect(userDirectoryService.loadUser(user3.getUsername())).andStubReturn(user3); EasyMock.expect(userDirectoryService.loadUser(nonUser1)).andStubReturn(null); EasyMock.expect(userDirectoryService.loadUser(nonUser2)).andStubReturn(null); EasyMock.expect(userDirectoryService.loadUser(nonUser3)).andStubReturn(null); EasyMock.replay(userDirectoryService); IndexServiceImpl indexServiceImpl = new IndexServiceImpl(); CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter(); commonEventCatalogUIAdapter.updated(properties); indexServiceImpl.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter); indexServiceImpl.setUserDirectoryService(userDirectoryService); indexServiceImpl.setSecurityService(securityService); DublinCoreMetadataCollection metadata = commonEventCatalogUIAdapter.getRawFields(); MetadataField emptyUpdatedPresenter = createCreatorMetadataField(new ArrayList<String>()); ArrayList<String> oneNonUserList = new ArrayList<>(); oneNonUserList.add(nonUser1); MetadataField nonUserUpdatedPresenter = createCreatorMetadataField(oneNonUserList); ArrayList<String> multiNonUserList = new ArrayList<>(); multiNonUserList.add(nonUser1); multiNonUserList.add(nonUser2); multiNonUserList.add(nonUser3); MetadataField multiNonUserUpdatedPresenter = createCreatorMetadataField(multiNonUserList); ArrayList<String> oneUserList = new ArrayList<>(); oneUserList.add(user1.getUsername()); MetadataField userUpdatedPresenter = createCreatorMetadataField(oneUserList); ArrayList<String> multiUserList = new ArrayList<>(); multiUserList.add(user1.getUsername()); multiUserList.add(user2.getUsername()); multiUserList.add(user3.getUsername()); MetadataField multiUserUpdatedPresenter = createCreatorMetadataField(multiUserList); ArrayList<String> mixedUserList = new ArrayList<>(); mixedUserList.add(user1.getUsername()); mixedUserList.add(nonUser1); mixedUserList.add(user2.getUsername()); mixedUserList.add(nonUser2); mixedUserList.add(nonUser3); mixedUserList.add(user3.getUsername()); MetadataField mixedPresenters = createCreatorMetadataField(mixedUserList); ArrayList<String> userFullNames = new ArrayList<>(); userFullNames.add(user1.getName()); userFullNames.add(user2.getName()); userFullNames.add(user3.getUsername()); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(emptyUpdatedPresenter); Tuple<List<String>, Set<String>> updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertTrue("The presenters dublincore metadata should be empty", updatedPresenters.getA().isEmpty()); assertTrue("The technical presenters should be empty", updatedPresenters.getB().isEmpty()); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(nonUserUpdatedPresenter); updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertTrue("There should be one presenter", updatedPresenters.getA().size() == 1); assertTrue("There should be no technical presenters", updatedPresenters.getB().isEmpty()); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(multiNonUserUpdatedPresenter); updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertTrue("There should be three presenters", updatedPresenters.getA().size() == 3); assertTrue("The value for technical presenters should be empty", updatedPresenters.getB().isEmpty()); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(userUpdatedPresenter); updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertTrue("There should be one presenter", updatedPresenters.getA().size() == 1); assertEquals("The one presenter should have the user's full name", "User 1", updatedPresenters.getA().get(0)); assertTrue("The one technical presenter", updatedPresenters.getB().size() == 1); assertEquals("The one technical presenter has the correct username", "user1", updatedPresenters.getB().iterator().next()); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(multiUserUpdatedPresenter); updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertEquals("There should be three presenters", 3, updatedPresenters.getA().size()); assertEquals("There should be three technical presenters", 3, updatedPresenters.getB().size()); assertTrue("The list of technical presenters should contain all of the user names", updatedPresenters.getB().containsAll(multiUserList)); metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName())); metadata.addField(mixedPresenters); updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata); assertEquals("There should be six presenters", 6, updatedPresenters.getA().size()); assertEquals("There should be three technical presenters", 3, updatedPresenters.getB().size()); assertTrue("The list of presenters should contain all of the non-user names", updatedPresenters.getA().containsAll(multiNonUserList)); assertTrue("The list of presenters should contain all of the user full names", updatedPresenters.getA().containsAll(userFullNames)); assertTrue("The list of technical presenters should contain all of the usernames", updatedPresenters.getB().containsAll(multiUserList)); }
private Opt<Set<String>> updatePresenters(DublinCoreMetadataCollection eventMetadata) { MetadataField presentersMetadataField = eventMetadata.getOutputFields() .get(DublinCore.PROPERTY_CREATOR.getLocalName()); if (presentersMetadataField.isUpdated()) { Set<String> presenterUsernames = new HashSet<>(); Tuple<List<String>, Set<String>> updatedPresenters = getTechnicalPresenters(eventMetadata); presenterUsernames = updatedPresenters.getB(); eventMetadata.removeField(presentersMetadataField); MetadataField newPresentersMetadataField = new MetadataField(presentersMetadataField); newPresentersMetadataField.setValue(updatedPresenters.getA()); eventMetadata.addField(newPresentersMetadataField); return Opt.some(presenterUsernames); } else { return Opt.none(); } }
IndexServiceImpl implements IndexService { private Opt<Set<String>> updatePresenters(DublinCoreMetadataCollection eventMetadata) { MetadataField presentersMetadataField = eventMetadata.getOutputFields() .get(DublinCore.PROPERTY_CREATOR.getLocalName()); if (presentersMetadataField.isUpdated()) { Set<String> presenterUsernames = new HashSet<>(); Tuple<List<String>, Set<String>> updatedPresenters = getTechnicalPresenters(eventMetadata); presenterUsernames = updatedPresenters.getB(); eventMetadata.removeField(presentersMetadataField); MetadataField newPresentersMetadataField = new MetadataField(presentersMetadataField); newPresentersMetadataField.setValue(updatedPresenters.getA()); eventMetadata.addField(newPresentersMetadataField); return Opt.some(presenterUsernames); } else { return Opt.none(); } } }
IndexServiceImpl implements IndexService { private Opt<Set<String>> updatePresenters(DublinCoreMetadataCollection eventMetadata) { MetadataField presentersMetadataField = eventMetadata.getOutputFields() .get(DublinCore.PROPERTY_CREATOR.getLocalName()); if (presentersMetadataField.isUpdated()) { Set<String> presenterUsernames = new HashSet<>(); Tuple<List<String>, Set<String>> updatedPresenters = getTechnicalPresenters(eventMetadata); presenterUsernames = updatedPresenters.getB(); eventMetadata.removeField(presentersMetadataField); MetadataField newPresentersMetadataField = new MetadataField(presentersMetadataField); newPresentersMetadataField.setValue(updatedPresenters.getA()); eventMetadata.addField(newPresentersMetadataField); return Opt.some(presenterUsernames); } else { return Opt.none(); } }  }
IndexServiceImpl implements IndexService { private Opt<Set<String>> updatePresenters(DublinCoreMetadataCollection eventMetadata) { MetadataField presentersMetadataField = eventMetadata.getOutputFields() .get(DublinCore.PROPERTY_CREATOR.getLocalName()); if (presentersMetadataField.isUpdated()) { Set<String> presenterUsernames = new HashSet<>(); Tuple<List<String>, Set<String>> updatedPresenters = getTechnicalPresenters(eventMetadata); presenterUsernames = updatedPresenters.getB(); eventMetadata.removeField(presentersMetadataField); MetadataField newPresentersMetadataField = new MetadataField(presentersMetadataField); newPresentersMetadataField.setValue(updatedPresenters.getA()); eventMetadata.addField(newPresentersMetadataField); return Opt.some(presenterUsernames); } else { return Opt.none(); } }  void setAclServiceFactory(AclServiceFactory aclServiceFactory); void setAuthorizationService(AuthorizationService authorizationService); void setCaptureAgentStateService(CaptureAgentStateService captureAgentStateService); void setEventCommentService(EventCommentService eventCommentService); void setCommonEventCatalogUIAdapter(CommonEventCatalogUIAdapter eventCatalogUIAdapter); void setCommonSeriesCatalogUIAdapter(CommonSeriesCatalogUIAdapter seriesCatalogUIAdapter); void addCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void removeCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void addCatalogUIAdapter(SeriesCatalogUIAdapter catalogUIAdapter); void removeCatalogUIAdapter(SeriesCatalogUIAdapter catalogUIAdapter); void setIngestService(IngestService ingestService); void setListProvidersService(ListProvidersService listProvidersService); void setAssetManager(AssetManager assetManager); void setSchedulerService(SchedulerService schedulerService); void setSecurityService(SecurityService securityService); void setSeriesService(SeriesService seriesService); void setWorkflowService(WorkflowService workflowService); void setWorkspace(Workspace workspace); void setUserDirectoryService(UserDirectoryService userDirectoryService); void setGroupRoleProvider(JpaGroupRoleProvider jpaGroupRoleProvider); AclService getAclService(); List<EventCatalogUIAdapter> getEventCatalogUIAdapters(String organization); List<SeriesCatalogUIAdapter> getSeriesCatalogUIAdapters(String organization); @Override List<EventCatalogUIAdapter> getEventCatalogUIAdapters(); @Override List<SeriesCatalogUIAdapter> getSeriesCatalogUIAdapters(); @Override EventCatalogUIAdapter getCommonEventCatalogUIAdapter(); @Override SeriesCatalogUIAdapter getCommonSeriesCatalogUIAdapter(); void activate(ComponentContext cc); void deactivate(ComponentContext cc); @Override String createEvent(HttpServletRequest request); @Override String updateEventAssets(MediaPackage mp, HttpServletRequest request); String createEvent(JSONObject metadataJson, MediaPackage mp); @Override String createEvent(EventHttpServletRequest eventHttpServletRequest); @Override MetadataList updateAllEventMetadata(
          final String id, final String metadataJSON, final AbstractSearchIndex index); @Override void removeCatalogByFlavor(Event event, MediaPackageElementFlavor flavor); @Override void removeCatalogByFlavor(Series series, MediaPackageElementFlavor flavor); @Override MetadataList updateEventMetadata(String id, MetadataList metadataList, AbstractSearchIndex index); @Override AccessControlList updateEventAcl(String id, AccessControlList acl, AbstractSearchIndex index); @Override Map<String, Map<String, String>> getEventWorkflowProperties(final List<String> eventIds); @Override SearchResult<Group> getGroups(String filter, Opt<Integer> optLimit, Opt<Integer> optOffset,
          Opt<String> optSort, AbstractSearchIndex index); @Override Opt<Group> getGroup(String id, AbstractSearchIndex index); @Override void removeGroup(String id); @Override void updateGroup(String id, String name, String description, String roles, String members); @Override void createGroup(String name, String description, String roles, String members); @Override Opt<Event> getEvent(String id, AbstractSearchIndex index); @Override EventRemovalResult removeEvent(Event event, Runnable doOnNotFound, String retractWorkflowId); @Override boolean removeEvent(String id); @Override MediaPackage getEventMediapackage(Event event); @Override Source getEventSource(Event event); @Override String createSeries(MetadataList metadataList, Map<String, String> options, Opt<AccessControlList> optAcl,
          Opt<Long> optThemeId); @Override String createSeries(String metadata); @Override Opt<Series> getSeries(String seriesId, AbstractSearchIndex searchIndex); @Override void removeSeries(String id); @Override MetadataList updateAllSeriesMetadata(String id, String metadataJSON, AbstractSearchIndex index); @Override MetadataList updateAllSeriesMetadata(String id, MetadataList metadataList, AbstractSearchIndex index); @Override void updateCommentCatalog(final Event event, final List<EventComment> comments); @Override MetadataList getMetadataListWithAllSeriesCatalogUIAdapters(); @Override MetadataList getMetadataListWithAllEventCatalogUIAdapters(); boolean isWorkflowActive(String workflowState); }
IndexServiceImpl implements IndexService { private Opt<Set<String>> updatePresenters(DublinCoreMetadataCollection eventMetadata) { MetadataField presentersMetadataField = eventMetadata.getOutputFields() .get(DublinCore.PROPERTY_CREATOR.getLocalName()); if (presentersMetadataField.isUpdated()) { Set<String> presenterUsernames = new HashSet<>(); Tuple<List<String>, Set<String>> updatedPresenters = getTechnicalPresenters(eventMetadata); presenterUsernames = updatedPresenters.getB(); eventMetadata.removeField(presentersMetadataField); MetadataField newPresentersMetadataField = new MetadataField(presentersMetadataField); newPresentersMetadataField.setValue(updatedPresenters.getA()); eventMetadata.addField(newPresentersMetadataField); return Opt.some(presenterUsernames); } else { return Opt.none(); } }  void setAclServiceFactory(AclServiceFactory aclServiceFactory); void setAuthorizationService(AuthorizationService authorizationService); void setCaptureAgentStateService(CaptureAgentStateService captureAgentStateService); void setEventCommentService(EventCommentService eventCommentService); void setCommonEventCatalogUIAdapter(CommonEventCatalogUIAdapter eventCatalogUIAdapter); void setCommonSeriesCatalogUIAdapter(CommonSeriesCatalogUIAdapter seriesCatalogUIAdapter); void addCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void removeCatalogUIAdapter(EventCatalogUIAdapter catalogUIAdapter); void addCatalogUIAdapter(SeriesCatalogUIAdapter catalogUIAdapter); void removeCatalogUIAdapter(SeriesCatalogUIAdapter catalogUIAdapter); void setIngestService(IngestService ingestService); void setListProvidersService(ListProvidersService listProvidersService); void setAssetManager(AssetManager assetManager); void setSchedulerService(SchedulerService schedulerService); void setSecurityService(SecurityService securityService); void setSeriesService(SeriesService seriesService); void setWorkflowService(WorkflowService workflowService); void setWorkspace(Workspace workspace); void setUserDirectoryService(UserDirectoryService userDirectoryService); void setGroupRoleProvider(JpaGroupRoleProvider jpaGroupRoleProvider); AclService getAclService(); List<EventCatalogUIAdapter> getEventCatalogUIAdapters(String organization); List<SeriesCatalogUIAdapter> getSeriesCatalogUIAdapters(String organization); @Override List<EventCatalogUIAdapter> getEventCatalogUIAdapters(); @Override List<SeriesCatalogUIAdapter> getSeriesCatalogUIAdapters(); @Override EventCatalogUIAdapter getCommonEventCatalogUIAdapter(); @Override SeriesCatalogUIAdapter getCommonSeriesCatalogUIAdapter(); void activate(ComponentContext cc); void deactivate(ComponentContext cc); @Override String createEvent(HttpServletRequest request); @Override String updateEventAssets(MediaPackage mp, HttpServletRequest request); String createEvent(JSONObject metadataJson, MediaPackage mp); @Override String createEvent(EventHttpServletRequest eventHttpServletRequest); @Override MetadataList updateAllEventMetadata(
          final String id, final String metadataJSON, final AbstractSearchIndex index); @Override void removeCatalogByFlavor(Event event, MediaPackageElementFlavor flavor); @Override void removeCatalogByFlavor(Series series, MediaPackageElementFlavor flavor); @Override MetadataList updateEventMetadata(String id, MetadataList metadataList, AbstractSearchIndex index); @Override AccessControlList updateEventAcl(String id, AccessControlList acl, AbstractSearchIndex index); @Override Map<String, Map<String, String>> getEventWorkflowProperties(final List<String> eventIds); @Override SearchResult<Group> getGroups(String filter, Opt<Integer> optLimit, Opt<Integer> optOffset,
          Opt<String> optSort, AbstractSearchIndex index); @Override Opt<Group> getGroup(String id, AbstractSearchIndex index); @Override void removeGroup(String id); @Override void updateGroup(String id, String name, String description, String roles, String members); @Override void createGroup(String name, String description, String roles, String members); @Override Opt<Event> getEvent(String id, AbstractSearchIndex index); @Override EventRemovalResult removeEvent(Event event, Runnable doOnNotFound, String retractWorkflowId); @Override boolean removeEvent(String id); @Override MediaPackage getEventMediapackage(Event event); @Override Source getEventSource(Event event); @Override String createSeries(MetadataList metadataList, Map<String, String> options, Opt<AccessControlList> optAcl,
          Opt<Long> optThemeId); @Override String createSeries(String metadata); @Override Opt<Series> getSeries(String seriesId, AbstractSearchIndex searchIndex); @Override void removeSeries(String id); @Override MetadataList updateAllSeriesMetadata(String id, String metadataJSON, AbstractSearchIndex index); @Override MetadataList updateAllSeriesMetadata(String id, MetadataList metadataList, AbstractSearchIndex index); @Override void updateCommentCatalog(final Event event, final List<EventComment> comments); @Override MetadataList getMetadataListWithAllSeriesCatalogUIAdapters(); @Override MetadataList getMetadataListWithAllEventCatalogUIAdapters(); boolean isWorkflowActive(String workflowState); static final String THEME_PROPERTY_NAME; }