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);
}
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());
}
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);
}
}
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);
}
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;
}
Aggregations