Search in sources :

Example 36 with UnimplementedException

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

the class RecordSearchList method search_or_list.

/**
 * This function is the general function that calls the correct funtions to
 * get all the data that the UI requested and get it in the correct format
 * for the UI.
 *
 * @param {Storage} storage The type of storage requested (e.g.
 * RecordStorage, AuthorizationStorage,...)
 * @param {UIRequest} ui The request from the ui to which we send a
 * response.
 * @param {String} param If a querystring has been added to the
 * URL(e.g.'?query='), it will be in this param
 * @param {String} pageSize The amount of results per page requested.
 * @param {String} pageNum The amount of pages requested.
 * @throws UIException
 */
private void search_or_list(Storage storage, UIRequest ui, String path) throws UIException {
    try {
        JSONObject restrictedkey = GenericSearch.setRestricted(ui, null, null, null, (mode == MODE_SEARCH), this.r);
        JSONObject restriction = restrictedkey.getJSONObject("restriction");
        String key = restrictedkey.getString("key");
        JSONObject results = getResults(ui, storage, restriction, key, path);
        // cache for record traverser
        if (results.has("pagination") && results.getJSONObject("pagination").has("separatelists")) {
            GenericSearch.createTraverser(ui, this.r.getID(), "", results, restriction, key, 1);
        }
        ui.sendJSONResponse(results);
    } catch (JSONException e) {
        throw new UIException("JSONException during search_or_list", e);
    } catch (ExistException e) {
        throw new UIException("ExistException during search_or_list", e);
    } catch (UnimplementedException e) {
        throw new UIException("UnimplementedException during search_or_list", 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 37 with UnimplementedException

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

the class RecordSearchList method generateMiniRecord.

/**
 * Retrieve the mini summary information e.g. summary and number and append
 * the csid and recordType to it
 *
 * @param {Storage} storage Type of storage (e.g. AuthorizationStorage,
 * RecordStorage,...)
 * @param {String} type The type of record requested (e.g. permission)
 * @param {String} csid The csid of the record
 * @return {JSONObject} The JSON string containing the mini record
 * @throws ExistException
 * @throws UnimplementedException
 * @throws UnderlyingStorageException
 * @throws JSONException
 */
private JSONObject generateMiniRecord(Storage storage, String type, String csid) throws JSONException {
    String postfix = "list";
    if (this.mode == MODE_SEARCH) {
        postfix = "search";
    }
    JSONObject restrictions = new JSONObject();
    JSONObject out = new JSONObject();
    try {
        if (csid == null || csid.equals("")) {
            return out;
        }
        out = storage.retrieveJSON(type + "/" + csid + "/view/" + postfix, restrictions);
        out.put("csid", csid);
        String recordtype = null;
        if (!r.isType("searchall")) {
            recordtype = type_to_url.get(type);
        } else {
            JSONObject summarylist = out.getJSONObject("summarylist");
            String uri = summarylist.getString("uri");
            if (uri != null && uri.startsWith("/")) {
                uri = uri.substring(1);
            }
            String[] parts = uri.split("/");
            String recordurl = parts[0];
            Record itemr = r.getSpec().getRecordByServicesUrl(recordurl);
            if (itemr == null) {
                String docType = summarylist.getString("docType");
                itemr = r.getSpec().getRecordByServicesDocType(docType);
            }
            if (itemr == null) {
                recordtype = UNKNOWN_RECORD_TYPE;
                log.warn("Could not get record type for record with services URI " + uri);
            } else {
                recordtype = type_to_url.get(itemr.getID());
                String refName = null;
                if (summarylist.has("refName")) {
                    refName = summarylist.getString("refName");
                }
                // For an authority item (i.e. an item in a vocabulary),
                // include the name of its parent vocabulary in a
                // "namespace" value within the mini summary.
                RefName.AuthorityItem item = null;
                if (refName != null) {
                    item = RefName.AuthorityItem.parse(refName);
                }
                // authority item refName, then include the "namespace" value.
                if (item != null) {
                    String namespace = item.getParentShortIdentifier();
                    if (namespace != null) {
                        out.put("namespace", namespace);
                    } else {
                        log.warn("Could not get vocabulary namespace for record with services URI " + uri);
                    }
                }
            }
        }
        out.put("recordtype", recordtype);
        // CSPACE-2894
        if (this.r.getID().equals("permission")) {
            String summary = out.getString("summary");
            String name = Generic.ResourceNameUI(this.r.getSpec(), summary);
            if (name.contains(WORKFLOW_SUB_RESOURCE)) {
                return null;
            }
            out.put("summary", name);
            out.put("display", Generic.getPermissionView(this.r.getSpec(), summary));
        }
    } catch (ExistException e) {
        out.put("csid", csid);
        out.put("isError", true);
        JSONObject msg = new JSONObject();
        msg.put("severity", "error");
        msg.put("message", "Exist Exception:" + e.getMessage());
        JSONArray msgs = new JSONArray();
        msgs.put(msg);
        out.put("messages", msgs);
    } catch (UnimplementedException e) {
        out.put("csid", csid);
        out.put("isError", true);
        JSONObject msg = new JSONObject();
        msg.put("severity", "error");
        msg.put("message", "Exist Exception:" + e.getMessage());
        JSONArray msgs = new JSONArray();
        msgs.put(msg);
        out.put("messages", msgs);
    } catch (UnderlyingStorageException e) {
        out.put("csid", csid);
        out.put("isError", true);
        JSONObject msg = new JSONObject();
        msg.put("severity", "error");
        msg.put("message", "Exist Exception:" + e.getMessage());
        JSONArray msgs = new JSONArray();
        msgs.put(msg);
        out.put("messages", msgs);
    }
    return out;
}
Also used : JSONObject(org.json.JSONObject) RefName(org.collectionspace.services.common.api.RefName) JSONArray(org.json.JSONArray) Record(org.collectionspace.chain.csp.schema.Record) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 38 with UnimplementedException

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

the class RelateCreateUpdate method relate.

private void relate(Storage storage, UIRequest request, String path) throws UIException {
    try {
        JSONObject data = request.getJSONBody();
        boolean and_reverse = false;
        if (!data.optBoolean("one-way"))
            and_reverse = true;
        if (data.has("type")) {
            // Single
            if (!create) {
                // Update may mean tinkering with other relations because of two-way-ness
                /* NOTE at the moment there's no support in the service to indicate partner, so we assume that
					 * an opposite relation is evidence of a two way relationship. This creates a potential bug if
					 * the user has set up two independent one way relationships and wants to maintain them
					 * independently. It's arguable that this is the behaviour they expect, arguable that it is not.
					 */
                // Delete the reverse record for an update
                log.debug("forward is " + path);
                String csid_rev = find_reverse(storage, path);
                log.debug("reverse is " + csid_rev);
                if (csid_rev != null)
                    storage.deleteJSON("/relations/main/" + csid_rev);
            }
            relate_one(storage, data, path, false);
            if (and_reverse) {
                /* If we're not one way and we're updating, create reverse (we just deleted the old one) */
                relate_one(storage, data, null, true);
            }
        } else if (data.has("items")) {
            // Multiple
            JSONArray relations = data.getJSONArray("items");
            for (int i = 0; i < relations.length(); i++) {
                JSONObject itemdata = relations.getJSONObject(i);
                if (!create)
                    throw new UIException("Cannot use multiple syntax for update");
                if (!itemdata.optBoolean("one-way")) {
                    and_reverse = true;
                }
                relate_one(storage, relations.getJSONObject(i), path, false);
                if (and_reverse)
                    relate_one(storage, relations.getJSONObject(i), path, true);
            }
        } else
            throw new UIException("Bad JSON data");
        request.sendJSONResponse(data);
        request.setOperationPerformed(create ? Operation.CREATE : Operation.UPDATE);
        if (create)
            // XXX should be derivable
            request.setSecondaryRedirectPath(new String[] { "relationships", path });
    } 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) {
        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 39 with UnimplementedException

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

the class RelateDelete method relate_delete.

private void relate_delete(Storage storage, UIRequest request, String path) throws UIException {
    try {
        String source = request.getRequestArgument(RELATION_SOURCE_PARAM);
        String target = request.getRequestArgument(RELATION_TARGET_PARAM);
        String type = request.getRequestArgument(RELATION_TYPE_PARAM);
        String oneway = request.getRequestArgument(RELATION_ONE_WAY_PARAM);
        if (oneway != null && oneway != "") {
            one_way = Boolean.parseBoolean(oneway);
        }
        if (request.isJSON()) {
            JSONObject data = request.getJSONBody();
            if (data.has("source") && data.has("target") && data.has("type")) {
                source = data.getJSONObject("source").getString("recordtype") + "/" + data.getJSONObject("source").getString("csid");
                target = data.getJSONObject("target").getString("recordtype") + "/" + data.getJSONObject("target").getString("csid");
                type = data.getString("type");
                if (data.has("one-way")) {
                    one_way = data.getBoolean("one-way");
                }
            }
        }
        if (source != null && target != null && type != null && source != "" && target != "" && type != "") {
            path = getRelationShipID(storage, source, target, type);
            if (!one_way) {
                // easier to find reverse if have actually sub items
                String reverse = getRelationShipID(storage, target, source, type);
                if (reverse != null)
                    storage.deleteJSON("/relations/main/" + reverse);
            }
        } else {
            // find csids' if delete sent with just relationship csid rather than sub items
            if (!one_way) {
                String rev = findReverse(storage, path);
                if (rev != null)
                    storage.deleteJSON("/relations/main/" + rev);
            }
        }
        storage.deleteJSON("/relations/main/" + path);
        request.setOperationPerformed(Operation.DELETE);
    } catch (ExistException e) {
        throw new UIException("Exist exception deleting ", e);
    } catch (UnimplementedException e) {
        throw new UIException("Unimplemented exception deleting ", e);
    } catch (UnderlyingStorageException x) {
        UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
        request.sendJSONResponse(uiexception.getJSON());
    } catch (JSONException e) {
        throw new UIException("Exception building JSON ", e);
    }
}
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 40 with UnimplementedException

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

the class RelateRead method relate_get.

private void relate_get(Storage storage, UIRequest request, String path) throws UIException {
    try {
        JSONObject relation = convertPayload(storage, storage.retrieveJSON("/relations/" + searchPath + "/" + path, new JSONObject()), path);
        request.sendJSONResponse(relation);
    } 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);
        request.sendJSONResponse(uiexception.getJSON());
    } catch (JSONException e) {
        throw new UIException("Could not build JSON ", e);
    }
}
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)

Aggregations

UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)56 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)55 ExistException (org.collectionspace.csp.api.persistence.ExistException)50 JSONException (org.json.JSONException)50 JSONObject (org.json.JSONObject)48 UIException (org.collectionspace.csp.api.ui.UIException)40 JSONArray (org.json.JSONArray)25 Record (org.collectionspace.chain.csp.schema.Record)11 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 IOException (java.io.IOException)7 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)6 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)6 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)5 Field (org.collectionspace.chain.csp.schema.Field)5 Document (org.dom4j.Document)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Group (org.collectionspace.chain.csp.schema.Group)4 Instance (org.collectionspace.chain.csp.schema.Instance)4 Storage (org.collectionspace.csp.api.persistence.Storage)4