use of org.collectionspace.services.structureddate.StructuredDateInternal in project application by collectionspace.
the class StructuredDateParser method run.
@Override
public void run(Object in, String[] tail) throws UIException {
UIRequest request = ((Request) in).getUIRequest();
String displayDate = request.getRequestArgument("displayDate");
JSONObject output = new JSONObject();
StructuredDateInternal structuredDate = null;
StructuredDateFormatException formatException = null;
try {
structuredDate = StructuredDateInternal.parse(displayDate);
} catch (StructuredDateFormatException e) {
formatException = e;
}
try {
if (formatException != null) {
// The convention in app layer error responses appears to be to
// send a boolean isError, and an array of error messages.
output.put("isError", true);
output.put("messages", new String[] { "Unrecognized date format", formatException.getMessage() });
}
if (structuredDate != null) {
String tenantDomain = request.getTenant();
output.put("structuredDate", structuredDateToJSON(tenantDomain, structuredDate));
}
} catch (JSONException e) {
throw new UIException("Error building JSON", e);
}
request.sendJSONResponse(output);
}
Aggregations