Search in sources :

Example 91 with UnderlyingStorageException

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

the class ServicesRelationStorage method autocreateJSON.

@Override
public String autocreateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject data, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        extractPaths(filePath, new String[] { "main" }, 0);
        Map<String, Document> in = new HashMap<String, Document>();
        Document datapath = dataToRelation(cache, null, data).toDocument();
        // log.info("AUTOCREATE"+datapath.asXML());
        in.put("relations_common", datapath);
        ReturnedURL out = conn.getMultipartURL(RequestMethod.POST, "/relations/", in, creds, cache);
        if (out.getStatus() > 299)
            throw new UnderlyingStorageException("Could not add relation status=" + out.getStatus(), out.getStatus(), "/relations/");
        return out.getURLTail();
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Could not add relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Could not retrieve data" + e.getLocalizedMessage());
    }
}
Also used : ReturnedURL(org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL) HashMap(java.util.HashMap) JSONException(org.json.JSONException) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 92 with UnderlyingStorageException

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

the class ServicesRelationStorage method deleteJSON.

@Override
public void deleteJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        String[] parts = extractPaths(filePath, new String[] { "main" }, 1);
        // log.info("DELETE"+parts[0]);
        int status = conn.getNone(RequestMethod.DELETE, "/relations/" + parts[0], null, creds, cache);
        if (status > 299)
            throw new UnderlyingStorageException("Could not delete relation, status=" + status, status, "/relations/" + parts[0]);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Could not delete relation" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    }
}
Also used : UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 93 with UnderlyingStorageException

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

the class UserStorage method updateJSON.

@Override
public void updateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        // XXX when CSPACE-1458 is fixed, remove the call to
        // xxx_cspace1458_fix, and just pass jsonObject as this arg. (fao
        // Chris or somoeone else at CARET).
        jsonObject = correctPassword(jsonObject);
        Document in = XmlJsonConversion.convertToXml(r, jsonObject, "common", "PUT");
        // Document
        // in=XmlJsonConversion.convertToXml(r,xxx_cspace1458_fix(filePath,jsonObject,creds,cache),"common");
        // log.info("Sending: " + in.asXML());
        ReturnedDocument doc = conn.getXMLDocument(RequestMethod.PUT, r.getServicesURL() + "/" + filePath, in, creds, cache);
        // ExistException("Not found: "+r.getServicesURL()+"/"+filePath);
        if (doc.getStatus() > 299 || doc.getStatus() < 200)
            throw new UnderlyingStorageException("Bad response ", doc.getStatus(), r.getServicesURL() + "/" + filePath);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JSONException e) {
        throw new UnimplementedException("JSONException" + e.getLocalizedMessage(), e);
    }
}
Also used : JSONException(org.json.JSONException) Document(org.dom4j.Document) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 94 with UnderlyingStorageException

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

the class UserStorage method autoCreateSub.

@Override
protected ReturnedURL autoCreateSub(CSPRequestCredentials creds, CSPRequestCache cache, JSONObject jsonObject, Document doc, String savePrefix, Record r) throws JSONException, UnderlyingStorageException, ConnectionException {
    ReturnedURL url;
    jsonObject = correctPassword(jsonObject);
    jsonObject = correctScreenName(jsonObject);
    jsonObject = correctUserId(jsonObject);
    doc = XmlJsonConversion.convertToXml(r, jsonObject, "common", "POST");
    url = conn.getURL(RequestMethod.POST, r.getServicesURL() + "/", doc, creds, cache);
    if (url.getStatus() > 299 || url.getStatus() < 200)
        throw new UnderlyingStorageException("Bad response ", url.getStatus(), r.getServicesURL() + "/");
    return url;
}
Also used : ReturnedURL(org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException)

Example 95 with UnderlyingStorageException

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

the class UserStorage method retrieveJSON.

@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        Boolean isUserRole = false;
        String[] parts = filePath.split("/");
        if (parts.length >= 2 && parts[1].equals("userrole")) {
            isUserRole = true;
            String path = r.getSpec().getRecord("userrole").getServicesURL();
            int len = parts.length - 1;
            int i = 0;
            for (i = 0; i < len; i++) {
                path = path.replace("*", parts[i]);
                i++;
            }
            if (len >= i) {
                path = path + "/" + parts[len];
            } else {
                path = path + "/";
            }
            filePath = path;
        } else {
            filePath = r.getServicesURL() + "/" + filePath;
        }
        ReturnedDocument doc = conn.getXMLDocument(RequestMethod.GET, filePath, null, creds, cache);
        JSONObject out = new JSONObject();
        Document xml = null;
        xml = doc.getDocument();
        if ((doc.getStatus() < 200 || doc.getStatus() >= 300))
            throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), filePath);
        if (isUserRole)
            out = XmlJsonConversion.convertToJson(r.getSpec().getRecord("userrole"), xml, "GET", "common", "", // XXX hardwired common section :(
            "");
        else
            // XXX hardwired common section :(
            out = XmlJsonConversion.convertToJson(r, xml, "GET", "common", "", "");
        return out;
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e);
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) Document(org.dom4j.Document) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) 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