Search in sources :

Example 1 with JsonObj

use of org.opencastproject.util.JsonObj in project opencast by opencast.

the class OaiPmhRepositoryTest method validate.

private static boolean validate(String verb, XmlGen xmlgen, OaiPmhResponseStatus status) {
    logger.info("--- TALKING TO EXTERNAL OAI-PMH VALIDATION SERVICE ---");
    logger.info("--- " + VALIDATOR_SERVICE);
    final CloseableHttpClient client = HttpClients.createDefault();
    final String xml = xmlgen.generateAsString();
    final HttpPost post = HttpUtil.post(VALIDATOR_SERVICE, HttpUtil.param("xml", xml));
    logger.info("--- REQUEST ---");
    logger.info(xml);
    try {
        final HttpResponse res = client.execute(post);
        final String json = withResource(res.getEntity().getContent(), IoSupport.readToString);
        logger.info("--- RESPONSE ---");
        logger.info(json);
        boolean ok = true;
        for (JsonVal message : JsonObj.jsonObj(json).obj("json").arr("messages")) {
            if (message.isObj()) {
                final JsonObj messageObj = message.as(JsonVal.asJsonObj);
                if (messageObj.has("className")) {
                    final String className = messageObj.val("className").as(JsonVal.asString).trim();
                    final String text = messageObj.val("text").as(JsonVal.asString).trim();
                    logger.info(format("[%s] %s", className, text));
                    ok = ok && (eq(className, "correct") || // since the validator does not validate everything correctly here are some exclusions
                    (status == IsError && eq(text, "Could not find a valid OAI-PMH command."))) || (eq(verb, OaiPmhConstants.VERB_IDENTIFY) && eq(text, "Invalid OAI-PMH protocol version .")) || (eq(verb, OaiPmhConstants.VERB_IDENTIFY) && eq(text, "Invalid adminEmail ."));
                }
            }
        }
        return ok;
    } catch (Exception e) {
        return (Boolean) chuck(e);
    } finally {
        IoSupport.closeQuietly(client);
    }
}
Also used : JsonVal(org.opencastproject.util.JsonVal) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) JsonObj(org.opencastproject.util.JsonObj) HttpResponse(org.apache.http.HttpResponse) XpathReturnType.returningAString(org.xmlmatchers.xpath.XpathReturnType.returningAString) OaiPmhDatabaseException(org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Example 2 with JsonObj

use of org.opencastproject.util.JsonObj in project opencast by opencast.

the class IncidentDto method getParameters.

/**
 * @see org.opencastproject.job.api.Incident#getDescriptionParameters()
 */
public Map<String, String> getParameters() {
    Map<String, String> param = new HashMap<String, String>();
    JsonObj paramJson = JsonObj.jsonObj(parameters);
    for (Object k : paramJson.keySet()) {
        String key = JsonVal.asJsonVal.apply(k).as(asString);
        String value = paramJson.val(key).as(asString);
        param.put(key, value);
    }
    return param;
}
Also used : HashMap(java.util.HashMap) JsonObj(org.opencastproject.util.JsonObj) JsonVal.asString(org.opencastproject.util.JsonVal.asString)

Example 3 with JsonObj

use of org.opencastproject.util.JsonObj in project opencast by opencast.

the class IncidentDto method getTechnicalInformation.

/**
 * @see org.opencastproject.job.api.Incident#getDetails()
 */
public List<Tuple<String, String>> getTechnicalInformation() {
    final List<Tuple<String, String>> list = new ArrayList<Tuple<String, String>>();
    JsonObj messageJson = JsonObj.jsonObj(details);
    for (Object k : messageJson.keySet()) {
        String title = JsonVal.asJsonVal.apply(k).as(asString);
        String content = messageJson.val(title).as(asString);
        list.add(tuple(title, content));
    }
    return list;
}
Also used : JsonObj(org.opencastproject.util.JsonObj) ArrayList(java.util.ArrayList) JsonVal.asString(org.opencastproject.util.JsonVal.asString) Tuple(org.opencastproject.util.data.Tuple)

Aggregations

JsonObj (org.opencastproject.util.JsonObj)3 JsonVal.asString (org.opencastproject.util.JsonVal.asString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpResponse (org.apache.http.HttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 OaiPmhDatabaseException (org.opencastproject.oaipmh.persistence.OaiPmhDatabaseException)1 JsonVal (org.opencastproject.util.JsonVal)1 NotFoundException (org.opencastproject.util.NotFoundException)1 Tuple (org.opencastproject.util.data.Tuple)1 XpathReturnType.returningAString (org.xmlmatchers.xpath.XpathReturnType.returningAString)1