Search in sources :

Example 86 with UnderlyingStorageException

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

the class VocabulariesRead method getJSON.

private JSONObject getJSON(Storage storage, String csid, 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 + csid, restriction);
            // add in equivalent hierarchy if relevant
            csid = fields.getString("csid");
            fields = getHierarchy(storage, fields);
            // fields.put("csid",csid);
            // JSONObject relations=createRelations(storage,csid);
            out.put("fields", fields);
            out.put("csid", csid);
            out.put("namespace", n.getWebURL());
        }
        if (getInfoMode == GET_FULL_INFO) {
            out.put("relations", new JSONArray());
        // out.put("relations",relations);
        }
        if (getInfoMode == GET_FULL_INFO) {
            JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, new JSONObject());
            out.put("termsUsed", tusd.getJSONArray("results"));
        }
        if (getInfoMode == GET_TERMS_USED_INFO) {
            JSONObject tusd = this.termsused.getTermsUsed(storage, refPath + csid, restriction);
            out.put("termsUsed", tusd);
        }
        if (getInfoMode == GET_FULL_INFO) {
            getRefObjs(storage, refPath + csid, out, "refobjs", false, restriction);
        } else if (getInfoMode == GET_REF_OBJS_INFO) {
            getRefObjs(storage, refPath + csid, out, "items", true, restriction);
        }
    } 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) 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 87 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 88 with UnderlyingStorageException

use of org.collectionspace.csp.api.persistence.UnderlyingStorageException 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 89 with UnderlyingStorageException

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

the class ServicesRelationStorage method extractPaths.

// XXX refactor
private String[] extractPaths(String in, String[] prefixes, int var) throws UnderlyingStorageException {
    if (in == null)
        throw new UnderlyingStorageException("null is not a path");
    if (in.startsWith("/"))
        in = in.substring(1);
    if (in.endsWith("/"))
        in = in.substring(0, in.length() - 1);
    String[] split = in.split("/");
    if (split.length != prefixes.length + var)
        throw new UnderlyingStorageException("Path is incorrect length (should be " + (prefixes.length + var) + " but is " + split.length);
    for (int i = 0; i < prefixes.length; i++) if (!prefixes[i].equals(split[i]))
        throw new UnderlyingStorageException("Path component " + i + " must be " + prefixes[i] + " but is " + split[i]);
    if (var == 0)
        return new String[0];
    String[] ret = new String[var];
    System.arraycopy(split, prefixes.length, ret, 0, var);
    return ret;
}
Also used : UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException)

Example 90 with UnderlyingStorageException

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

the class ServicesRelationStorage method retrieveJSON.

@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        Boolean isHierarchical = false;
        String[] parts = null;
        if (isPathType(filePath, new String[] { "main" }, 1)) {
            parts = extractPaths(filePath, new String[] { "main" }, 1);
        } else if (isPathType(filePath, new String[] { "hierarchical" }, 1)) {
            parts = extractPaths(filePath, new String[] { "hierarchical" }, 1);
            isHierarchical = true;
        }
        ReturnedMultipartDocument out = conn.getMultipartXMLDocument(RequestMethod.GET, "/relations/" + parts[0], null, creds, cache);
        if (out.getStatus() == 404)
            throw new UnderlyingStorageException("Could not retrieve relation", out.getStatus(), "/relations/" + parts[0]);
        Document doc = out.getDocument("relations_common");
        if (doc == null)
            throw new UnderlyingStorageException("Could not retrieve relation, missing relations_common", out.getStatus(), "/relations/" + parts[0]);
        return relationToData(cache, factory.load(parts[0], doc));
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JaxenException e) {
        throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Could not retrieve relation" + e.getLocalizedMessage(), e);
    }
}
Also used : ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) JaxenException(org.jaxen.JaxenException) JSONException(org.json.JSONException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Aggregations

UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)108 JSONObject (org.json.JSONObject)75 JSONException (org.json.JSONException)73 ExistException (org.collectionspace.csp.api.persistence.ExistException)57 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)55 UIException (org.collectionspace.csp.api.ui.UIException)40 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)39 JSONArray (org.json.JSONArray)34 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)30 Document (org.dom4j.Document)29 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)23 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)17 UnsupportedEncodingException (java.io.UnsupportedEncodingException)16 Field (org.collectionspace.chain.csp.schema.Field)14 Record (org.collectionspace.chain.csp.schema.Record)14 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)11 Node (org.dom4j.Node)10 ReturnedURL (org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL)9 IOException (java.io.IOException)7