use of org.opencastproject.metadata.dublincore.MetadataCollection 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.metadata.dublincore.MetadataCollection in project opencast by opencast.
the class AbstractEventEndpoint method getNewMetadata.
@GET
@Path("new/metadata")
@RestQuery(name = "getNewMetadata", description = "Returns all the data related to the metadata tab in the new event modal as JSON", returnDescription = "All the data related to the event metadata tab as JSON", reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the event metadata tab as JSON") })
public Response getNewMetadata() {
MetadataList metadataList = getIndexService().getMetadataListWithAllEventCatalogUIAdapters();
Opt<MetadataCollection> optMetadataByAdapter = metadataList.getMetadataByAdapter(getIndexService().getCommonEventCatalogUIAdapter());
if (optMetadataByAdapter.isSome()) {
MetadataCollection collection = optMetadataByAdapter.get();
if (collection.getOutputFields().containsKey(DublinCore.PROPERTY_CREATED.getLocalName()))
collection.removeField(collection.getOutputFields().get(DublinCore.PROPERTY_CREATED.getLocalName()));
if (collection.getOutputFields().containsKey("duration"))
collection.removeField(collection.getOutputFields().get("duration"));
if (collection.getOutputFields().containsKey(DublinCore.PROPERTY_IDENTIFIER.getLocalName()))
collection.removeField(collection.getOutputFields().get(DublinCore.PROPERTY_IDENTIFIER.getLocalName()));
if (collection.getOutputFields().containsKey(DublinCore.PROPERTY_SOURCE.getLocalName()))
collection.removeField(collection.getOutputFields().get(DublinCore.PROPERTY_SOURCE.getLocalName()));
if (collection.getOutputFields().containsKey("startDate"))
collection.removeField(collection.getOutputFields().get("startDate"));
if (collection.getOutputFields().containsKey("startTime"))
collection.removeField(collection.getOutputFields().get("startTime"));
if (collection.getOutputFields().containsKey("location"))
collection.removeField(collection.getOutputFields().get("location"));
metadataList.add(getIndexService().getCommonEventCatalogUIAdapter(), collection);
}
return okJson(metadataList.toJSON());
}
use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.
the class SeriesEndpoint method getNewMetadata.
@GET
@Path("new/metadata")
@RestQuery(name = "getNewMetadata", description = "Returns all the data related to the metadata tab in the new series modal as JSON", returnDescription = "All the data related to the series metadata tab as JSON", reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the series metadata tab as JSON") })
public Response getNewMetadata() {
MetadataList metadataList = indexService.getMetadataListWithAllSeriesCatalogUIAdapters();
Opt<MetadataCollection> metadataByAdapter = metadataList.getMetadataByAdapter(indexService.getCommonSeriesCatalogUIAdapter());
if (metadataByAdapter.isSome()) {
MetadataCollection collection = metadataByAdapter.get();
safelyRemoveField(collection, "identifier");
metadataList.add(indexService.getCommonSeriesCatalogUIAdapter(), collection);
}
return okJson(metadataList.toJSON());
}
use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.
the class SeriesEndpoint method getSeriesMetadata.
/**
* Loads the metadata for the given series
*
* @param series
* the source {@link Series}
* @return a {@link MetadataCollection} instance with all the series metadata
*/
@SuppressWarnings("unchecked")
private MetadataCollection getSeriesMetadata(Series series) {
MetadataCollection metadata = indexService.getCommonSeriesCatalogUIAdapter().getRawFields();
MetadataField<?> title = metadata.getOutputFields().get(DublinCore.PROPERTY_TITLE.getLocalName());
metadata.removeField(title);
MetadataField<String> newTitle = MetadataUtils.copyMetadataField(title);
newTitle.setValue(series.getTitle());
metadata.addField(newTitle);
MetadataField<?> subject = metadata.getOutputFields().get(DublinCore.PROPERTY_SUBJECT.getLocalName());
metadata.removeField(subject);
MetadataField<String> newSubject = MetadataUtils.copyMetadataField(subject);
newSubject.setValue(series.getSubject());
metadata.addField(newSubject);
MetadataField<?> description = metadata.getOutputFields().get(DublinCore.PROPERTY_DESCRIPTION.getLocalName());
metadata.removeField(description);
MetadataField<String> newDescription = MetadataUtils.copyMetadataField(description);
newDescription.setValue(series.getDescription());
metadata.addField(newDescription);
MetadataField<?> language = metadata.getOutputFields().get(DublinCore.PROPERTY_LANGUAGE.getLocalName());
metadata.removeField(language);
MetadataField<String> newLanguage = MetadataUtils.copyMetadataField(language);
newLanguage.setValue(series.getLanguage());
metadata.addField(newLanguage);
MetadataField<?> rightsHolder = metadata.getOutputFields().get(DublinCore.PROPERTY_RIGHTS_HOLDER.getLocalName());
metadata.removeField(rightsHolder);
MetadataField<String> newRightsHolder = MetadataUtils.copyMetadataField(rightsHolder);
newRightsHolder.setValue(series.getRightsHolder());
metadata.addField(newRightsHolder);
MetadataField<?> license = metadata.getOutputFields().get(DublinCore.PROPERTY_LICENSE.getLocalName());
metadata.removeField(license);
MetadataField<String> newLicense = MetadataUtils.copyMetadataField(license);
newLicense.setValue(series.getLicense());
metadata.addField(newLicense);
MetadataField<?> organizers = metadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName());
metadata.removeField(organizers);
MetadataField<String> newOrganizers = MetadataUtils.copyMetadataField(organizers);
newOrganizers.setValue(StringUtils.join(series.getOrganizers(), ", "));
metadata.addField(newOrganizers);
MetadataField<?> contributors = metadata.getOutputFields().get(DublinCore.PROPERTY_CONTRIBUTOR.getLocalName());
metadata.removeField(contributors);
MetadataField<String> newContributors = MetadataUtils.copyMetadataField(contributors);
newContributors.setValue(StringUtils.join(series.getContributors(), ", "));
metadata.addField(newContributors);
MetadataField<?> publishers = metadata.getOutputFields().get(DublinCore.PROPERTY_PUBLISHER.getLocalName());
metadata.removeField(publishers);
MetadataField<String> newPublishers = MetadataUtils.copyMetadataField(publishers);
newPublishers.setValue(StringUtils.join(series.getPublishers(), ", "));
metadata.addField(newPublishers);
// Admin UI only field
MetadataField<String> createdBy = MetadataField.createTextMetadataField("createdBy", Opt.<String>none(), "EVENTS.SERIES.DETAILS.METADATA.CREATED_BY", true, false, Opt.<Boolean>none(), Opt.<Map<String, String>>none(), Opt.<String>none(), Opt.some(CREATED_BY_UI_ORDER), Opt.<String>none());
createdBy.setValue(series.getCreator());
metadata.addField(createdBy);
MetadataField<?> uid = metadata.getOutputFields().get(DublinCore.PROPERTY_IDENTIFIER.getLocalName());
metadata.removeField(uid);
MetadataField<String> newUID = MetadataUtils.copyMetadataField(uid);
newUID.setValue(series.getIdentifier());
metadata.addField(newUID);
return metadata;
}
use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.
the class AbstractMetadataCollectionTest method testOrderOfFieldsInputFieldOrderTwoExpectsInMiddle.
@Test
public void testOrderOfFieldsInputFieldOrderTwoExpectsInMiddle() {
MetadataCollection collection = getAbstractMetadataCollection();
collection.addField(unorderedOne);
collection.addField(unorderedTwo);
collection.addField(unorderedThree);
collection.addField(third);
assertEquals(4, collection.getFields().size());
assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection.getFields().get(2));
collection = getAbstractMetadataCollection();
collection.addField(third);
collection.addField(unorderedOne);
collection.addField(unorderedTwo);
collection.addField(unorderedThree);
assertEquals(4, collection.getFields().size());
assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection.getFields().get(2));
collection = getAbstractMetadataCollection();
collection.addField(unorderedOne);
collection.addField(third);
collection.addField(unorderedTwo);
collection.addField(unorderedThree);
assertEquals(4, collection.getFields().size());
assertEquals("A field with an order value of 2 should be in that position in the list of fields", third, collection.getFields().get(2));
}
Aggregations