Search in sources :

Example 56 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class VocabulariesRead method getInstance.

private JSONObject getInstance(Storage storage, JSONObject restriction) throws UIException {
    JSONObject out = new JSONObject();
    try {
        String refPath = n.getRecord().getID() + "/" + n.getTitleRef() + "/";
        if (getInfoMode == GET_FULL_INFO || getInfoMode == GET_BASIC_INFO) {
            JSONObject fields = storage.retrieveJSON(refPath, restriction);
            if (fields.has("csid")) {
                String csid = fields.getString("csid");
                out.put("fields", fields);
                out.put("csid", csid);
            }
        }
    } catch (ExistException e) {
        UIException uiexception = new UIException(e.getMessage(), e);
        return uiexception.getJSON();
    } catch (UnimplementedException e) {
        UIException uiexception = new UIException(e.getMessage(), e);
        return uiexception.getJSON();
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        return uiexception.getJSON();
    } catch (JSONException e) {
        throw new UIException("Could not create JSON" + e, e);
    }
    return out;
}
Also used : JSONObject(org.json.JSONObject) UIException(org.collectionspace.csp.api.ui.UIException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 57 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class VocabulariesWorkflowTransition method store_transition.

private void store_transition(Storage storage, UIRequest request, String path, String transition) throws UIException {
    try {
        String url = n.getRecord().getID() + "/" + n.getTitleRef() + "/" + path;
        storage.transitionWorkflowJSON(url, transition);
    } catch (ExistException e) {
        throw new UIException("JSON Not found " + e, e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    }
}
Also used : UIException(org.collectionspace.csp.api.ui.UIException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 58 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class WebTermList method termlist.

private void termlist(CSPRequestCache cache, Storage storage, UIRequest request, String path) throws UIException {
    try {
        // {tenant}/{tenantname}/{recordType}/termList/{termListType}
        // needs to be {tenant}/{tenantname}/{recordType}/termList/{fieldname}
        // as blanks etc are on a field basis not a vocab basis
        String[] bits = path.split("/");
        Record vb = this.spec.getRecord("vocab");
        Field f = (Field) r.getFieldTopLevel(bits[0]);
        if (f == null) {
            f = (Field) r.getFieldFullList(bits[0]);
        }
        // If the field isn't in this record, look for it in subrecords (e.g. contacts).
        if (f == null) {
            FieldSet[] subRecordFields = r.getAllSubRecords("GET");
            for (int i = 0; i < subRecordFields.length; i++) {
                FieldSet subRecordField = subRecordFields[i];
                Group group = (Group) subRecordField;
                if (group.usesRecord()) {
                    Record subRecord = group.usesRecordId();
                    f = (Field) subRecord.getFieldTopLevel(bits[0]);
                    if (f == null) {
                        f = (Field) subRecord.getFieldFullList(bits[0]);
                    }
                    if (f != null) {
                        break;
                    }
                }
            }
        }
        JSONArray result = new JSONArray();
        if (f.getAllAutocompleteInstances() != null && f.getAllAutocompleteInstances()[0] != null) {
            for (Instance ins : f.getAllAutocompleteInstances()) {
                JSONArray getallnames = ctl.get(storage, ins.getTitleRef(), vb);
                for (int i = 0; i < getallnames.length(); i++) {
                    result.put(getallnames.get(i));
                }
            }
        } else {
            String msg = String.format("Dynamic term list(s) (aka, \"autocomplete\" list) for the field '%s' of record '%s' does not exist.  Check that it is defined in the Application layer configuration.", f.toString(), r.whoamI);
            log.error(msg);
        }
        JSONObject out = generateENUMField(storage, f, result, false);
        request.sendJSONResponse(out);
        int cacheMaxAgeSeconds = spec.getAdminData().getTermListCacheAge();
        if (cacheMaxAgeSeconds > 0) {
            request.setCacheMaxAgeSeconds(cacheMaxAgeSeconds);
        }
    } catch (JSONException e) {
        throw new UIException("JSONException during autocompletion", e);
    }
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) Instance(org.collectionspace.chain.csp.schema.Instance) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) UIException(org.collectionspace.csp.api.ui.UIException) Record(org.collectionspace.chain.csp.schema.Record)

Example 59 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class CompositeWebUIRequestPart method getPostBody.

@Override
public JSONObject getPostBody() throws UIException {
    JSONObject jsondata = new JSONObject();
    String jsonString = body_in;
    try {
        if (jsonString.length() > 0) {
            String[] data = jsonString.split("&");
            for (String item : data) {
                String[] itembits = item.split("=");
                jsondata.put(URLDecoder.decode(itembits[0], "UTF-8"), URLDecoder.decode(itembits[1], "UTF-8"));
            }
        }
    } catch (JSONException e) {
        throw new UIException("Cannot get request body, JSONException", e);
    } catch (UnsupportedEncodingException e) {
        throw new UIException("Cannot get request body, UnsupportedEncodingException", e);
    }
    return jsondata;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 60 with UIException

use of org.collectionspace.csp.api.ui.UIException in project application by collectionspace.

the class CompositeWebUIRequestPart method sendUnknown.

@Override
public void sendUnknown(byte[] data, String contenttype, String contentDisposition) throws UIException {
    mime_type_out = contenttype;
    try {
        body_out.write(data);
        body_out.flush();
    } catch (IOException e) {
        throw new UIException("Could not write data", e);
    }
}
Also used : UIException(org.collectionspace.csp.api.ui.UIException) IOException(java.io.IOException)

Aggregations

UIException (org.collectionspace.csp.api.ui.UIException)72 JSONObject (org.json.JSONObject)51 JSONException (org.json.JSONException)50 ExistException (org.collectionspace.csp.api.persistence.ExistException)39 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)39 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)39 JSONArray (org.json.JSONArray)19 IOException (java.io.IOException)10 Record (org.collectionspace.chain.csp.schema.Record)7 Instance (org.collectionspace.chain.csp.schema.Instance)6 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 Field (org.collectionspace.chain.csp.schema.Field)4 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)4 UIRequest (org.collectionspace.csp.api.ui.UIRequest)4 MessageDigest (java.security.MessageDigest)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)3 AdminData (org.collectionspace.chain.csp.schema.AdminData)3 Structure (org.collectionspace.chain.csp.schema.Structure)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2