use of org.opencastproject.metadata.dublincore.MetadataParsingException in project opencast by opencast.
the class MetadataList method fromJSON.
private void fromJSON(MetadataCollection metadata, 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();
String flavor = (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;
metadata.fromJSON(value.toJSONString());
metadataList.put(flavor, Tuple.tuple(title, metadata));
}
}
use of org.opencastproject.metadata.dublincore.MetadataParsingException in project opencast by opencast.
the class IndexServiceImpl method createEvent.
@Override
public String createEvent(JSONObject metadataJson, MediaPackage mp) throws ParseException, IOException, MediaPackageException, IngestException, NotFoundException, SchedulerException, UnauthorizedException {
if (metadataJson == null)
throw new IllegalArgumentException("No metadata set");
JSONObject source = (JSONObject) metadataJson.get("source");
if (source == null)
throw new IllegalArgumentException("No source field in metadata");
JSONObject processing = (JSONObject) metadataJson.get("processing");
if (processing == null)
throw new IllegalArgumentException("No processing field in metadata");
JSONArray allEventMetadataJson = (JSONArray) metadataJson.get("metadata");
if (allEventMetadataJson == null)
throw new IllegalArgumentException("No metadata field in metadata");
AccessControlList acl = getAccessControlList(metadataJson);
MetadataList metadataList = getMetadataListWithAllEventCatalogUIAdapters();
try {
metadataList.fromJSON(allEventMetadataJson.toJSONString());
} catch (MetadataParsingException e) {
logger.warn("Unable to parse event metadata {}", allEventMetadataJson.toJSONString());
throw new IllegalArgumentException("Unable to parse metadata set");
}
EventHttpServletRequest eventHttpServletRequest = new EventHttpServletRequest();
eventHttpServletRequest.setAcl(acl);
eventHttpServletRequest.setMetadataList(metadataList);
eventHttpServletRequest.setMediaPackage(mp);
eventHttpServletRequest.setProcessing(processing);
eventHttpServletRequest.setSource(source);
return createEvent(eventHttpServletRequest);
}
use of org.opencastproject.metadata.dublincore.MetadataParsingException in project opencast by opencast.
the class AbstractMetadataCollection method fromJSON.
@Override
public MetadataCollection 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 event metadata.", e.getCause());
}
ListIterator<JSONObject> listIterator = metadataJSON.listIterator();
while (listIterator.hasNext()) {
JSONObject item = listIterator.next();
String fieldId = (String) item.get(KEY_METADATA_ID);
MetadataField<?> target = null;
if (fieldId == null)
continue;
Object value = item.get(KEY_METADATA_VALUE);
if (value == null)
continue;
target = outputFields.get(fieldId);
if (target == null)
continue;
target.fromJSON(value);
}
return this;
}
use of org.opencastproject.metadata.dublincore.MetadataParsingException 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);
}
}
Aggregations