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