Search in sources :

Example 61 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class UserDetailsSearchList method search_or_list.

private void search_or_list(Storage storage, UIRequest ui, String param, String pageSize, String pageNum) throws UIException {
    try {
        JSONObject restriction = new JSONObject();
        String key = "items";
        if (param != null) {
            restriction.put("screenName", param);
            key = "results";
        }
        if (pageSize != null) {
            restriction.put("pageSize", pageSize);
        }
        if (pageNum != null) {
            restriction.put("pageNum", pageNum);
        }
        JSONObject data = storage.getPathsJSON(base, restriction);
        String[] paths = (String[]) data.get("listItems");
        JSONObject pagination = new JSONObject();
        if (data.has("pagination")) {
            pagination = data.getJSONObject("pagination");
        }
        JSONObject resultsObject = new JSONObject();
        resultsObject = pathsToJSON(storage, base, paths, key, pagination);
        ui.sendJSONResponse(resultsObject);
    } catch (JSONException e) {
        throw new UIException("JSONException during autocompletion", e);
    } catch (ExistException e) {
        throw new UIException("ExistException during autocompletion", e);
    } catch (UnimplementedException e) {
        throw new UIException("UnimplementedException during autocompletion", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        ui.sendJSONResponse(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 62 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class UserRolesCreate method store_set.

private void store_set(Storage storage, UIRequest request, String path) throws UIException {
    JSONObject data = null;
    data = request.getJSONBody();
    boolean notfailed = true;
    String msg = "";
    try {
        path = sendJSON(storage, null, data);
        if (path == null) {
            throw new UIException("Insufficient data for create (no fields?)");
        }
        data.put("csid", path);
        boolean isError = !notfailed;
        data.put("isError", isError);
        JSONObject messages = new JSONObject();
        messages.put("message", msg);
        if (notfailed) {
            messages.put("severity", "info");
        } else {
            messages.put("severity", "error");
        }
        JSONArray arr = new JSONArray();
        arr.put(messages);
        data.put("messages", arr);
        request.sendJSONResponse(data);
        request.setOperationPerformed(Operation.CREATE);
        if (notfailed)
            request.setSecondaryRedirectPath(new String[] { url_base, path });
    } catch (JSONException x) {
        throw new UIException("Failed to parse json: " + x, x);
    } catch (ExistException x) {
        throw new UIException("Existence exception: ", x);
    } catch (UnimplementedException x) {
        throw new UIException("Unimplemented exception: ", x);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    }
}
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 63 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class UserRolesSearchList method search_or_list.

private void search_or_list(Storage storage, UIRequest ui, String param, String pageSize, String pageNum) throws UIException {
    try {
        JSONObject restriction = new JSONObject();
        String key = "items";
        if (param != null) {
            restriction.put("screenName", param);
            key = "results";
        }
        if (pageSize != null) {
            restriction.put("pageSize", pageSize);
        }
        if (pageNum != null) {
            restriction.put("pageNum", pageNum);
        }
        JSONObject data = storage.getPathsJSON(base, restriction);
        String[] paths = (String[]) data.get("listItems");
        for (int i = 0; i < paths.length; i++) {
            if (paths[i].startsWith(base + "/"))
                paths[i] = paths[i].substring((base + "/").length());
        }
        JSONObject resultsObject = new JSONObject();
        resultsObject = pathsToJSON(storage, base, paths, key);
        ui.sendJSONResponse(resultsObject);
    } catch (JSONException e) {
        throw new UIException("JSONException during autocompletion", e);
    } catch (ExistException e) {
        throw new UIException("ExistException during autocompletion", e);
    } catch (UnimplementedException e) {
        throw new UIException("UnimplementedException during autocompletion", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        ui.sendJSONResponse(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 64 with ExistException

use of org.collectionspace.csp.api.persistence.ExistException in project application by collectionspace.

the class StubJSONStore method deleteJSON.

public void deleteJSON(String filePath) throws ExistException, UnimplementedException, UnderlyingStorageException {
    if (idRequest(filePath))
        id.deleteJSON(filePath);
    File jsonFile = fileFromPath(filePath);
    if (!jsonFile.exists()) {
        throw new ExistException("No such file: " + filePath);
    }
    jsonFile.delete();
}
Also used : ExistException(org.collectionspace.csp.api.persistence.ExistException) File(java.io.File)

Aggregations

ExistException (org.collectionspace.csp.api.persistence.ExistException)64 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)57 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)50 JSONObject (org.json.JSONObject)50 JSONException (org.json.JSONException)49 UIException (org.collectionspace.csp.api.ui.UIException)40 JSONArray (org.json.JSONArray)23 IOException (java.io.IOException)10 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 Record (org.collectionspace.chain.csp.schema.Record)9 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)8 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)8 Document (org.dom4j.Document)7 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)5 File (java.io.File)4 Field (org.collectionspace.chain.csp.schema.Field)4 Instance (org.collectionspace.chain.csp.schema.Instance)4 Storage (org.collectionspace.csp.api.persistence.Storage)4 RefName (org.collectionspace.services.common.api.RefName)4