Search in sources :

Example 26 with UnderlyingStorageException

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

the class ServicesRelationStorage method post_filter.

// Needed because of CSPACE-1080
// XXX is this still needed?CSPACE-1080 has been resolved...
private boolean post_filter(CSPRequestCredentials creds, CSPRequestCache cache, JSONObject restrictions, Node candidate) throws ExistException, UnderlyingStorageException, ConnectionException, JSONException {
    if (restrictions == null)
        return true;
    // Subject
    String src_csid = candidate.selectSingleNode("subjectCsid").getText();
    String rest_src = restrictions.optString("src");
    if (rest_src != null && !"".equals(rest_src)) {
        String[] data = rest_src.split("/");
        if (data[0].equals("")) {
            rest_src = rest_src.substring(1);
            data = rest_src.split("/");
        }
        if (!src_csid.equals(rest_src.split("/")[1]))
            return false;
    }
    String dst_csid = candidate.selectSingleNode("objectCsid").getText();
    String rest_dst = restrictions.optString("dst");
    if (rest_dst != null && !"".equals(rest_dst)) {
        String[] data2 = rest_dst.split("/");
        if (data2[0].equals("")) {
            rest_dst = rest_dst.substring(1);
            data2 = rest_dst.split("/");
        }
        if (!dst_csid.equals(rest_dst.split("/")[1]))
            return false;
    }
    // Retrieve the relation (CSPACE-1081)
    ReturnedMultipartDocument rel = conn.getMultipartXMLDocument(RequestMethod.GET, candidate.selectSingleNode("uri").getText(), null, creds, cache);
    if (rel.getStatus() == 404)
        throw new ExistException("Not found");
    Document rel_doc = rel.getDocument("relations_common");
    if (rel_doc == null)
        throw new UnderlyingStorageException("Could not retrieve relation, missing relations_common");
    String type = rel_doc.selectSingleNode("relations_common/relationshipType").getText();
    if (restrictions.has("type") && !type.equals(restrictions.optString("type")))
        return false;
    return true;
}
Also used : ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ExistException(org.collectionspace.csp.api.persistence.ExistException) 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)

Example 27 with UnderlyingStorageException

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

the class UserStorage method correctPassword.

private JSONObject correctPassword(JSONObject in) throws JSONException, UnderlyingStorageException {
    try {
        if (in.has("password")) {
            String password = in.getString("password");
            in.remove("password");
            password = new String(Base64.encodeBase64(password.getBytes("UTF-8")), "UTF-8");
            while (password.endsWith("\n") || password.endsWith("\r")) password = password.substring(0, password.length() - 1);
            in.put("password", password);
        }
        return in;
    } catch (UnsupportedEncodingException e) {
        throw new UnderlyingStorageException("Error generating Base 64", e);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException)

Example 28 with UnderlyingStorageException

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

the class UserStorage method getPaths.

@Override
@SuppressWarnings("unchecked")
public String[] getPaths(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String rootPath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        List<String> out = new ArrayList<String>();
        Iterator rit = restrictions.keys();
        StringBuffer args = new StringBuffer();
        while (rit.hasNext()) {
            String key = (String) rit.next();
            FieldSet fs = r.getFieldTopLevel(key);
            if (!(fs instanceof Field))
                continue;
            String filter = ((Field) fs).getServicesFilterParam();
            if (filter == null)
                continue;
            args.append('&');
            args.append(filter);
            args.append('=');
            args.append(URLEncoder.encode(restrictions.getString(key), "UTF-8"));
        }
        // pagination
        String tail = args.toString();
        String path = getRestrictedPath(r.getServicesURL(), restrictions, r.getServicesSearchKeyword(), tail, false, "");
        ReturnedDocument doc = conn.getXMLDocument(RequestMethod.GET, path, null, creds, cache);
        if (doc.getStatus() < 200 || doc.getStatus() > 399)
            throw new UnderlyingStorageException("Cannot retrieve account list", doc.getStatus(), path);
        Document list = doc.getDocument();
        List<Node> objects = list.selectNodes(r.getServicesListPath());
        for (Node object : objects) {
            List<Node> fields = object.selectNodes("*");
            String csid = object.selectSingleNode("csid").getText();
            for (Node field : fields) {
                if ("csid".equals(field.getName())) {
                    int idx = csid.lastIndexOf("/");
                    if (idx != -1)
                        csid = csid.substring(idx + 1);
                    out.add(csid);
                } else if ("uri".equals(field.getName())) {
                // Skip!
                } else {
                    String json_name = view_map.get(field.getName());
                    if (json_name != null) {
                        String value = field.getText();
                        // XXX hack to cope with multi values
                        if (value == null || "".equals(value)) {
                            List<Node> inners = field.selectNodes("*");
                            for (Node n : inners) {
                                value += n.getText();
                            }
                        }
                        setGleanedValue(cache, r.getServicesURL() + "/" + csid, json_name, value);
                    }
                }
            }
        }
        return out.toArray(new String[0]);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (UnsupportedEncodingException e) {
        throw new UnderlyingStorageException("Exception building query" + e.getLocalizedMessage(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Exception building query" + e.getLocalizedMessage(), e);
    }
}
Also used : Node(org.dom4j.Node) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) Document(org.dom4j.Document) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 29 with UnderlyingStorageException

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

the class UserStorage method getPathsJSON.

@Override
@SuppressWarnings("unchecked")
public JSONObject getPathsJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String rootPath, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        JSONObject out = new JSONObject();
        List<String> listitems = new ArrayList<String>();
        Iterator rit = restrictions.keys();
        StringBuffer args = new StringBuffer();
        while (rit.hasNext()) {
            String key = (String) rit.next();
            FieldSet fs = r.getFieldTopLevel(key);
            if (!(fs instanceof Field))
                continue;
            String filter = ((Field) fs).getServicesFilterParam();
            if (filter == null)
                continue;
            args.append('&');
            args.append(filter);
            args.append('=');
            args.append(URLEncoder.encode(restrictions.getString(key), "UTF-8"));
        }
        // pagination
        String tail = args.toString();
        String path = getRestrictedPath(r.getServicesURL(), restrictions, r.getServicesSearchKeyword(), tail, false, "");
        if (r.hasSoftDeleteMethod()) {
            path = softpath(path);
        }
        if (r.hasHierarchyUsed("screen")) {
            path = hierarchicalpath(path);
        }
        JSONObject data = getListView(creds, cache, path, r.getServicesListPath(), "csid", false, r);
        return data;
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (UnsupportedEncodingException e) {
        throw new UnderlyingStorageException("Exception building query" + e.getLocalizedMessage(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Exception building query" + e.getLocalizedMessage(), e);
    }
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JSONException(org.json.JSONException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 30 with UnderlyingStorageException

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

the class ConfiguredVocabStorage method transitionWorkflowJSON.

@Override
public void transitionWorkflowJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, String serviceurl, String workflowTransition) throws UnderlyingStorageException {
    String vocab = RefName.shortIdToPath(filePath.split("/")[0]);
    String url = null;
    try {
        url = generateURL(vocab, filePath.split("/")[1], "", this.r);
    } catch (ExistException e) {
        throw new UnderlyingStorageException("Exist exception" + e.getLocalizedMessage(), e.getStatus(), url, e);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Connection exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    }
    super.transitionWorkflowJSON(root, creds, cache, "", url, workflowTransition);
}
Also used : ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) 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