Search in sources :

Example 1 with StructuredDateInternal

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);
}
Also used : StructuredDateFormatException(org.collectionspace.services.structureddate.StructuredDateFormatException) JSONObject(org.json.JSONObject) UIRequest(org.collectionspace.csp.api.ui.UIRequest) Request(org.collectionspace.chain.csp.webui.main.Request) StructuredDateInternal(org.collectionspace.services.structureddate.StructuredDateInternal) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) UIRequest(org.collectionspace.csp.api.ui.UIRequest)

Aggregations

Request (org.collectionspace.chain.csp.webui.main.Request)1 UIException (org.collectionspace.csp.api.ui.UIException)1 UIRequest (org.collectionspace.csp.api.ui.UIRequest)1 StructuredDateFormatException (org.collectionspace.services.structureddate.StructuredDateFormatException)1 StructuredDateInternal (org.collectionspace.services.structureddate.StructuredDateInternal)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1