Search in sources :

Example 21 with MetadataCollection

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);
}
Also used : DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SearchQuery(org.opencastproject.matterhorn.search.SearchQuery) SearchResultItemImpl(org.opencastproject.matterhorn.search.impl.SearchResultItemImpl) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Capture(org.easymock.Capture) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Opt(com.entwinemedia.fn.data.Opt) SearchResultImpl(org.opencastproject.matterhorn.search.impl.SearchResultImpl) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 22 with MetadataCollection

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());
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 23 with MetadataCollection

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());
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 24 with MetadataCollection

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;
}
Also used : MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection)

Example 25 with MetadataCollection

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));
}
Also used : AbstractMetadataCollection(org.opencastproject.index.service.catalog.adapter.AbstractMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Test(org.junit.Test)

Aggregations

MetadataCollection (org.opencastproject.metadata.dublincore.MetadataCollection)36 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)16 Test (org.junit.Test)10 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)9 JSONArray (org.json.simple.JSONArray)7 JSONParser (org.json.simple.parser.JSONParser)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)7 EventCatalogUIAdapter (org.opencastproject.metadata.dublincore.EventCatalogUIAdapter)7 NotFoundException (org.opencastproject.util.NotFoundException)7 Path (javax.ws.rs.Path)6 AbstractMetadataCollection (org.opencastproject.index.service.catalog.adapter.AbstractMetadataCollection)6 RestQuery (org.opencastproject.util.doc.rest.RestQuery)6 IOException (java.io.IOException)5 JSONObject (org.json.simple.JSONObject)5 ParseException (org.json.simple.parser.ParseException)5 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)5 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4 GET (javax.ws.rs.GET)4