use of org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter in project opencast by opencast.
the class IndexServiceImplTest method updatePresenters.
@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);
MetadataCollection metadata = commonEventCatalogUIAdapter.getRawFields();
// Possible presenter combinations
MetadataField<Iterable<String>> emptyUpdatedPresenter = createCreatorMetadataField(new ArrayList<String>());
ArrayList<String> oneNonUserList = new ArrayList<>();
oneNonUserList.add(nonUser1);
MetadataField<Iterable<String>> nonUserUpdatedPresenter = createCreatorMetadataField(oneNonUserList);
ArrayList<String> multiNonUserList = new ArrayList<>();
multiNonUserList.add(nonUser1);
multiNonUserList.add(nonUser2);
multiNonUserList.add(nonUser3);
MetadataField<Iterable<String>> multiNonUserUpdatedPresenter = createCreatorMetadataField(multiNonUserList);
ArrayList<String> oneUserList = new ArrayList<>();
oneUserList.add(user1.getUsername());
MetadataField<Iterable<String>> userUpdatedPresenter = createCreatorMetadataField(oneUserList);
ArrayList<String> multiUserList = new ArrayList<>();
multiUserList.add(user1.getUsername());
multiUserList.add(user2.getUsername());
multiUserList.add(user3.getUsername());
MetadataField<Iterable<String>> 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<Iterable<String>> mixedPresenters = createCreatorMetadataField(mixedUserList);
ArrayList<String> userFullNames = new ArrayList<>();
userFullNames.add(user1.getName());
userFullNames.add(user2.getName());
userFullNames.add(user3.getUsername());
// Empty presenters
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());
// Non-user presenter
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());
// Multi non-user presenter
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());
// User presenter
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());
// Multi user presenter
metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
metadata.addField(multiUserUpdatedPresenter);
updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
assertTrue("There should be three presenters", updatedPresenters.getA().size() == 3);
assertTrue("There should be three technical presenters", updatedPresenters.getB().size() == 3);
assertTrue("The list of technical presenters should contain all of the user names", updatedPresenters.getB().containsAll(multiUserList));
// Mixed non-user and user presenters
metadata.removeField(metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName()));
metadata.addField(mixedPresenters);
updatedPresenters = indexServiceImpl.getTechnicalPresenters(metadata);
assertTrue("There should be six presenters", updatedPresenters.getA().size() == 6);
assertTrue("There should be three technical presenters", updatedPresenters.getB().size() == 3);
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));
}
use of org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter in project opencast by opencast.
the class IndexServiceImplTest method setupCommonCatalogUIAdapter.
private Tuple<CommonEventCatalogUIAdapter, VCell<Option<MetadataCollection>>> setupCommonCatalogUIAdapter(Workspace workspace) throws org.osgi.service.cm.ConfigurationException {
// Create Common Event Catalog UI Adapter
final VCell<Option<MetadataCollection>> metadataCell = VCell.ocell();
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter() {
@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection metadata) {
metadataCell.set(Option.some(metadata));
return super.storeFields(mediaPackage, metadata);
}
};
Properties episodeCatalogProperties = new Properties();
InputStream in = null;
try {
in = getClass().getResourceAsStream("/episode-catalog.properties");
episodeCatalogProperties.load(in);
} catch (IOException e) {
throw new ComponentException(e);
} finally {
IoSupport.closeQuietly(in);
}
commonEventCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
commonEventCatalogUIAdapter.setWorkspace(workspace);
return Tuple.tuple(commonEventCatalogUIAdapter, metadataCell);
}
use of org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter in project opencast by opencast.
the class IndexServiceImplTest method testUpdateMediaPackageMetadata.
@Test
public void testUpdateMediaPackageMetadata() throws Exception {
// mock/initialize dependencies
String username = "user1";
String org = "mh_default_org";
String testResourceLocation = "/events/update-event.json";
String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
String eventId = "event-1";
Event event = new Event(eventId, org);
event.setTitle("Test Event 1");
SearchQuery query = EasyMock.createMock(SearchQuery.class);
EasyMock.expect(query.getLimit()).andReturn(100);
EasyMock.expect(query.getOffset()).andReturn(0);
EasyMock.replay(query);
SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
searchResult.addResultItem(searchResultItem);
SecurityService securityService = setupSecurityService(username, org);
AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
EasyMock.replay(index);
Workspace workspace = EasyMock.createMock(Workspace.class);
EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
EasyMock.replay(workspace);
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
// Using scheduler as the source of the media package here.
SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
EasyMock.expectLastCall();
EasyMock.replay(schedulerService);
SeriesService seriesService = EasyMock.createMock(SeriesService.class);
DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
EasyMock.replay(seriesService);
// create service
IndexServiceImpl indexService = new IndexServiceImpl();
indexService.setSecurityService(securityService);
indexService.setSchedulerService(schedulerService);
indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
indexService.setSeriesService(seriesService);
indexService.setWorkspace(workspace);
MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
Assert.assertTrue(mpCapture.hasCaptured());
Assert.assertEquals("series-1", mp.getSeries());
Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
use of org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter in project opencast by opencast.
the class TestEventsEndpoint method setupEventCatalogUIAdapters.
private void setupEventCatalogUIAdapters() throws ConfigurationException {
// Setup common event catalog
CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter();
Properties episodeCatalogProperties = getCatalogProperties(getClass(), "/episode-catalog.properties");
commonEventCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
this.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
addCatalogUIAdapter(commonEventCatalogUIAdapter);
// Setup catalog to be deleted.
EventCatalogUIAdapter deleteAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
EasyMock.expect(deleteAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor(DELETE_CATALOG_TYPE, "episode")).anyTimes();
MetadataCollection collectionMock = EasyMock.createNiceMock(MetadataCollection.class);
EasyMock.expect(deleteAdapter.getOrganization()).andReturn(defaultOrg.getId()).anyTimes();
EasyMock.expect(deleteAdapter.getFields(EasyMock.anyObject(MediaPackage.class))).andReturn(null).anyTimes();
EasyMock.expect(deleteAdapter.getUITitle()).andReturn(null).anyTimes();
EasyMock.replay(deleteAdapter);
addCatalogUIAdapter(deleteAdapter);
}
use of org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter in project opencast by opencast.
the class MetadataListTest method setUp.
@Before
public void setUp() throws Exception {
episodeDublinCoreCatalogUIAdapter = new CommonEventCatalogUIAdapter();
Properties episodeCatalogProperties = new Properties();
InputStream in = null;
try {
in = getClass().getResourceAsStream("/episode-catalog.properties");
episodeCatalogProperties.load(in);
} catch (IOException e) {
throw new ComponentException(e);
} finally {
IoSupport.closeQuietly(in);
}
episodeDublinCoreCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
}
Aggregations