Search in sources :

Example 1 with MetadataParsingException

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));
    }
}
Also used : MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException)

Example 2 with MetadataParsingException

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 3 with MetadataParsingException

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;
}
Also used : MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) JSONObject(org.json.simple.JSONObject) ParseException(org.json.simple.parser.ParseException)

Example 4 with MetadataParsingException

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

Aggregations

JSONArray (org.json.simple.JSONArray)4 JSONObject (org.json.simple.JSONObject)4 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)4 JSONParser (org.json.simple.parser.JSONParser)3 ParseException (org.json.simple.parser.ParseException)3 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)1 EventHttpServletRequest (org.opencastproject.index.service.impl.index.event.EventHttpServletRequest)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1 MetadataCollection (org.opencastproject.metadata.dublincore.MetadataCollection)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1