Search in sources :

Example 31 with UIException

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

the class UserDetailsRead method getJSON.

/* Wrapper exists to decomplexify exceptions */
private JSONObject getJSON(Storage storage, String csid) throws UIException {
    JSONObject out = new JSONObject();
    try {
        if (record_type) {
            JSONObject fields = storage.retrieveJSON(base + "/" + csid, new JSONObject());
            // XXX remove this, subject to UI team approval?
            fields.put("csid", csid);
            JSONObject roles = storage.retrieveJSON(base + "/" + csid + "/" + "userrole", new JSONObject());
            JSONArray allroles = Generic.getRoles(storage, roles);
            fields.put("role", allroles);
            out.put("fields", fields);
            out.put("isError", false);
            JSONObject messages = new JSONObject();
            messages.put("message", "");
            messages.put("severity", "info");
            JSONArray arr = new JSONArray();
            arr.put(messages);
            out.put("messages", arr);
            out.put("relations", new JSONArray());
        } else {
            out = storage.retrieveJSON(base + "/" + csid, new JSONObject());
        }
    } catch (ExistException e) {
        throw new UIException("JSON Not found ", e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented", e);
    } 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);
    }
    if (out == null) {
        throw new UIException("No JSON Found");
    }
    return out;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) 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 32 with UIException

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

the class UserDetailsReset method getcsID.

private JSONObject getcsID(Storage storage, String emailparam) throws UIException {
    JSONObject restriction = new JSONObject();
    JSONObject failedJSON = new JSONObject();
    try {
        failedJSON.put("isError", true);
        if (emailparam != null && emailparam != "") {
            restriction.put("email", emailparam);
            restriction.put("pageSize", "40");
            int resultsize = 1;
            int pagenum = 0;
            String checkpagination = "";
            while (resultsize > 0) {
                restriction.put("pageNum", pagenum);
                /* XXX need to force it to only do an exact match */
                JSONObject data = storage.getPathsJSON(base, restriction);
                String[] paths = (String[]) data.get("listItems");
                pagenum++;
                if (paths.length == 0 || checkpagination.equals(paths[0])) {
                    resultsize = 0;
                // testing whether we have actually returned the same page or the next page - all csid returned should be unique
                } else {
                    checkpagination = paths[0];
                    /* make sure it is an exact match */
                    for (int i = 0; i < paths.length; i++) {
                        // GET full details
                        JSONObject fields = storage.retrieveJSON(base + "/" + paths[i], new JSONObject());
                        String emailtest = fields.getString("email");
                        if (emailtest.equals(emailparam)) {
                            JSONObject outputJSON = new JSONObject();
                            outputJSON.put("fields", fields);
                            outputJSON.put("isError", false);
                            outputJSON.put("csid", paths[i]);
                            return outputJSON;
                        }
                    }
                }
            }
            failedJSON.put("message", "Could not find a user with email " + emailparam);
        } else {
            failedJSON.put("message", "No email specified ");
        }
        return failedJSON;
    } catch (JSONException e) {
        throw new UIException("JSONException during search on email address", e);
    } catch (ExistException e) {
        throw new UIException("ExistException during search on email address", e);
    } catch (UnimplementedException e) {
        throw new UIException("UnimplementedException during search on email address", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        return uiexception.getJSON();
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) 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 33 with UIException

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

the class UserRolesRead method getJSON.

/* Wrapper exists to decomplexify exceptions */
private JSONObject getJSON(Storage storage, String csid) throws UIException {
    JSONObject out = new JSONObject();
    try {
        if (!record_type) {
            JSONObject fields = storage.retrieveJSON("base+/" + csid, new JSONObject());
            // XXX remove this, subject to UI team approval?
            fields.put("csid", csid);
            out.put("fields", fields);
            out.put("isError", false);
            JSONObject messages = new JSONObject();
            messages.put("message", "");
            messages.put("severity", "info");
            JSONArray arr = new JSONArray();
            arr.put(messages);
            out.put("messages", arr);
            out.put("relations", new JSONArray());
        } else {
            out = storage.retrieveJSON(this.sub_base + "/" + csid, new JSONObject());
        }
    } catch (ExistException e) {
        throw new UIException("ExistException " + e, e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented", e);
    } 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);
    }
    if (out == null) {
        throw new UIException("No JSON Found");
    }
    return out;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) 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 34 with UIException

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

the class StreamUIRequest method print.

private static void print(OutputStream stream, String x) throws UIException {
    try {
        stream.write(x.getBytes("UTF-8"));
        stream.flush();
    } catch (IOException e) {
        throw new UIException("IOException writing line", e);
    }
}
Also used : UIException(org.collectionspace.csp.api.ui.UIException) IOException(java.io.IOException)

Example 35 with UIException

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

the class DataGenerator method createAllRecords.

/**
 * Create all record types (that make sense)
 * @param storage
 * @param ui
 * @return
 * @throws UIException
 */
protected JSONObject createAllRecords(Storage storage, UIRequest ui) throws UIException {
    log.info("Lets make some records");
    tty.line("Lets make some records");
    tty.flush();
    JSONObject returnData = new JSONObject();
    try {
        for (Record r : spec.getAllRecords()) {
            if (r.isType("authority") || r.isType("authorizationdata") || r.isType("id") || r.isType("userdata")) {
            // don't do these yet (if ever)
            } else if (r.getID().equals("structureddate") || r.getID().equals("media") || r.getID().equals("hierarchy") || r.getID().equals("blobs") || r.getID().equals("dimension") || r.getID().equals("contacts") || r.isType("searchall")) {
            // and ignore these
            } else if (r.getID().equals("termlist") || r.getID().equals("termlistitem")) {
            // and ignore these
            } else {
                this.record = r;
                this.structureview = "screen";
                this.writer = new RecordCreateUpdate(r, true);
                JSONObject items = createRecords(storage, ui);
                returnData.put(r.getID(), items.getJSONObject(r.getID()));
            }
        }
        // lets create some relationships
        log.info("Initializing relationships");
        tty.line("Initializing relationships");
        tty.flush();
        createDataSetRelationships(returnData);
    } catch (JSONException x) {
        throw new UIException("Failed to parse json: ", x);
    } catch (ExistException x) {
        throw new UIException("Existence exception: ", x);
    } catch (UnimplementedException x) {
        throw new UIException("Unimplemented exception: ", x);
    } catch (UnderlyingStorageException x) {
        throw new UIException("Problem storing: " + x.getLocalizedMessage(), x.getStatus(), x.getUrl(), x);
    }
    return returnData;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) Record(org.collectionspace.chain.csp.schema.Record) RecordCreateUpdate(org.collectionspace.chain.csp.webui.record.RecordCreateUpdate) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

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