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;
}
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);
}
}
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);
}
}
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);
}
}
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);
}
Aggregations