Search in sources :

Example 31 with MetadataCollection

use of org.opencastproject.metadata.dublincore.MetadataCollection 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);
}
Also used : EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Properties(java.util.Properties) CatalogAdapterUtil.getCatalogProperties(org.opencastproject.index.service.util.CatalogAdapterUtil.getCatalogProperties) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 32 with MetadataCollection

use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.

the class MetadataListTest method testFromJson.

@Test
public void testFromJson() throws WebApplicationException, Exception {
    InputStream stream = SeriesEndpointTest.class.getResourceAsStream("/metadata-list-input.json");
    InputStreamReader reader = new InputStreamReader(stream);
    JSONArray inputJson = (JSONArray) new JSONParser().parse(reader);
    MetadataCollection abstractMetadataCollection = episodeDublinCoreCatalogUIAdapter.getRawFields();
    MetadataList metadataList = new MetadataList();
    metadataList.add(episodeDublinCoreCatalogUIAdapter, abstractMetadataCollection);
    metadataList.fromJSON(inputJson.toJSONString());
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Test(org.junit.Test)

Example 33 with MetadataCollection

use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.

the class MetadataList method fromJSON.

public void fromJSON(String json) throws MetadataParsingException {
    if (StringUtils.isBlank(json))
        throw new IllegalArgumentException("The JSON string must not be empty or null!");
    JSONParser parser = new JSONParser();
    JSONArray metadataJSON;
    try {
        metadataJSON = (JSONArray) parser.parse(json);
    } catch (ParseException e) {
        throw new MetadataParsingException("Not able to parse the given string as JSON metadata list.", e.getCause());
    }
    ListIterator<JSONObject> listIterator = metadataJSON.listIterator();
    while (listIterator.hasNext()) {
        JSONObject item = listIterator.next();
        MediaPackageElementFlavor flavor = MediaPackageElementFlavor.parseFlavor((String) item.get(KEY_METADATA_FLAVOR));
        String title = (String) item.get(KEY_METADATA_TITLE);
        if (flavor == null || title == null)
            continue;
        JSONArray value = (JSONArray) item.get(KEY_METADATA_FIELDS);
        if (value == null)
            continue;
        Tuple<String, MetadataCollection> metadata = metadataList.get(flavor.toString());
        if (metadata == null)
            continue;
        metadata.getB().fromJSON(value.toJSONString());
        metadataList.put(flavor.toString(), metadata);
    }
}
Also used : MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) ParseException(org.json.simple.parser.ParseException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Example 34 with MetadataCollection

use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.

the class MetadataList method toJSON.

public JValue toJSON() {
    List<JValue> catalogs = new ArrayList<>();
    for (Entry<String, Tuple<String, MetadataCollection>> metadata : metadataList.entrySet()) {
        List<Field> fields = new ArrayList<>();
        MetadataCollection metadataCollection = metadata.getValue().getB();
        if (!Locked.NONE.equals(locked)) {
            fields.add(f(KEY_METADATA_LOCKED, v(locked.getValue())));
            makeMetadataCollectionReadOnly(metadataCollection);
        }
        fields.add(f(KEY_METADATA_FLAVOR, v(metadata.getKey())));
        fields.add(f(KEY_METADATA_TITLE, v(metadata.getValue().getA())));
        fields.add(f(KEY_METADATA_FIELDS, metadataCollection.toJSON()));
        catalogs.add(obj(fields));
    }
    return arr(catalogs);
}
Also used : MetadataField(org.opencastproject.metadata.dublincore.MetadataField) Field(com.entwinemedia.fn.data.json.Field) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) Tuple(org.opencastproject.util.data.Tuple)

Example 35 with MetadataCollection

use of org.opencastproject.metadata.dublincore.MetadataCollection in project opencast by opencast.

the class IndexServiceImpl method createSeries.

@Override
public String createSeries(MetadataList metadataList, Map<String, String> options, Opt<AccessControlList> optAcl, Opt<Long> optThemeId) throws IndexServiceException {
    DublinCoreCatalog dc = DublinCores.mkOpencastSeries().getCatalog();
    dc.set(PROPERTY_IDENTIFIER, UUID.randomUUID().toString());
    dc.set(DublinCore.PROPERTY_CREATED, EncodingSchemeUtils.encodeDate(new Date(), Precision.Second));
    for (Entry<String, String> entry : options.entrySet()) {
        dc.set(new EName(DublinCores.OC_PROPERTY_NS_URI, entry.getKey()), entry.getValue());
    }
    Opt<MetadataCollection> seriesMetadata = metadataList.getMetadataByFlavor(MediaPackageElements.SERIES.toString());
    if (seriesMetadata.isSome()) {
        DublinCoreMetadataUtil.updateDublincoreCatalog(dc, seriesMetadata.get());
    }
    AccessControlList acl;
    if (optAcl.isSome()) {
        acl = optAcl.get();
    } else {
        acl = new AccessControlList();
    }
    String seriesId;
    try {
        DublinCoreCatalog createdSeries = seriesService.updateSeries(dc);
        seriesId = createdSeries.getFirst(PROPERTY_IDENTIFIER);
        seriesService.updateAccessControl(seriesId, acl);
        for (Long id : optThemeId) seriesService.updateSeriesProperty(seriesId, THEME_PROPERTY_NAME, Long.toString(id));
    } catch (Exception e) {
        logger.error("Unable to create new series: {}", getStackTrace(e));
        throw new IndexServiceException("Unable to create new series");
    }
    updateSeriesMetadata(seriesId, metadataList);
    return seriesId;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) EName(org.opencastproject.mediapackage.EName) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) EventCommentException(org.opencastproject.event.comment.EventCommentException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

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