use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class TestAccount method testAccountSearch.
// XXX this test needs work
// @Test
public void testAccountSearch() {
Storage ss;
try {
ss = makeServicesStorage();
/*
* arggg how do I get it to do an exact match */
JSONObject data = ss.getPathsJSON("users/", new JSONObject("{\"email\":\"bob@indigo-e.co.uk\"}"));
String[] paths = (String[]) data.get("listItems");
if (paths.length >= 1) {
for (int i = 0; i < paths.length; i++) {
// log.info(paths[i] +" : "+ i +" of "+ paths.length);
}
}
} catch (CSPDependencyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExistException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnimplementedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnderlyingStorageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class TestPermissions method testPermissions.
@Test
public void testPermissions() throws Exception {
// create role
JSONObject roledata = createRole("role.json");
String role = roledata.getString("roleId");
log.info(roledata.toString());
assertFalse(roledata == null);
// list permissions for role
// cspace-services/authorization/roles/{csid}/permroles/xxx
Storage ss;
ss = makeServicesStorage();
JSONObject data = ss.getPathsJSON("roles/" + role + "/permrole", null);
String[] roleperms = (String[]) data.get("listItems");
log.info(data.toString());
if (roleperms.length > 0) {
log.info("has permissions already");
}
// add a permission
// get acquisition crudl
// /cspace-services/authorization/permissions?res=acquisition&actGrp=CRUDL
String resourceName = "acquisition";
JSONObject permrestrictions = new JSONObject();
permrestrictions.put("keywords", resourceName);
permrestrictions.put("queryString", "CRUDL");
permrestrictions.put("queryTerm", "actGrp");
JSONObject pdata = ss.getPathsJSON("permission", permrestrictions);
String[] perms = (String[]) pdata.get("listItems");
String permID = "";
if (perms.length > 0) {
permID = perms[0];
} else {
// need to create this permission type
fail("missing permission type Acquisition CRUDL " + permrestrictions.toString());
}
JSONObject permdata = new JSONObject();
permdata.put("permissionId", permID);
permdata.put("resourceName", resourceName);
JSONArray permarray = new JSONArray();
permarray.put(permdata);
JSONObject addperm = new JSONObject();
addperm.put("permission", permarray);
addperm.put("role", roledata);
log.info(addperm.toString());
// add permissions to role
String path = ss.autocreateJSON("permrole", addperm, null);
log.info(path);
assertNotNull(path);
// test permissions is in role
// delete role
ss.deleteJSON("role/" + role);
try {
ss.retrieveJSON("role/" + role, new JSONObject());
// XXX use JUnit exception annotation
assertFalse(true);
} catch (UnderlyingStorageException e) {
// XXX use JUnit exception annotation
assertTrue(true);
}
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class TestPermissions method createRole.
private JSONObject createRole(String jsonFile) {
Storage ss;
try {
// delete this role if exist
JSONObject u1 = getJSON(jsonFile);
String roleName = u1.getString("roleName");
JSONObject test = new JSONObject();
test.put("keywords", roleName);
ss = makeServicesStorage();
/* delete role if already exists */
JSONObject data = ss.getPathsJSON("role/", test);
String[] paths = (String[]) data.get("listItems");
log.info(data.toString());
if (paths.length > 0) {
ss.deleteJSON("role/" + paths[0]);
}
// create role
String path = ss.autocreateJSON("role/", u1, null);
assertNotNull(path);
JSONObject u3 = ss.retrieveJSON("role/" + path, new JSONObject());
assertNotNull(u3);
// return role path
JSONObject roledata = new JSONObject();
roledata.put("roleName", roleName);
roledata.put("roleId", path);
return roledata;
} catch (CSPDependencyException e) {
fail("CSPDependencyException:" + e.getMessage());
} catch (JSONException e) {
fail("JSONException:" + e.getMessage());
} catch (ExistException e) {
fail("ExistException:" + e.getMessage());
} catch (UnimplementedException e) {
fail("UnimplementedException:" + e.getMessage());
} catch (UnderlyingStorageException e) {
fail("UnderlyingStorageException:" + e.getMessage());
} catch (IOException e) {
fail("IOException:" + e.getMessage());
}
return null;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class TestPermissions method createUser.
private JSONObject createUser(String jsonFile) {
Storage ss;
try {
JSONObject u1 = getJSON(jsonFile);
String screenName = u1.getString("screenName");
String userId = u1.getString("userId");
JSONObject test = new JSONObject();
test.put("userId", userId);
ss = makeServicesStorage();
/* delete user if already exists */
JSONObject data = ss.getPathsJSON("users/", test);
String[] paths = (String[]) data.get("listItems");
if (paths.length > 0)
ss.deleteJSON("users/" + paths[0]);
/* create the user based on json */
/* will give a hidden 500 error if userid is not unique (useful eh?) */
String path = ss.autocreateJSON("users/", u1, null);
assertNotNull(path);
JSONObject u2 = getJSON(jsonFile);
ss.updateJSON("users/" + path, u2, new JSONObject());
JSONObject u3 = ss.retrieveJSON("users/" + path, new JSONObject());
assertNotNull(u3);
JSONObject userdata = new JSONObject();
userdata.put("screenName", screenName);
// csid
userdata.put("accountId", path);
// really email
userdata.put("userId", userId);
return userdata;
} catch (CSPDependencyException e) {
fail("CSPDependencyException:" + e.getMessage());
} catch (JSONException e) {
fail("JSONException:" + e.getMessage());
} catch (ExistException e) {
fail("ExistException:" + e.getMessage());
} catch (UnimplementedException e) {
fail("UnimplementedException:" + e.getMessage());
} catch (UnderlyingStorageException e) {
fail("UnderlyingStorageException:" + e.getMessage());
} catch (IOException e) {
fail("IOException:" + e.getMessage());
}
return null;
}
use of org.collectionspace.csp.api.persistence.UnderlyingStorageException in project application by collectionspace.
the class RecordAuthorities method store_get.
private void store_get(Storage storage, UIRequest ui, String path) throws UIException {
try {
JSONObject restriction = new JSONObject();
String key = "items";
Set<String> args = ui.getAllRequestArgument();
for (String restrict : args) {
if (ui.getRequestArgument(restrict) != null) {
String value = ui.getRequestArgument(restrict);
// }
if (restrict.equals(WebMethod.PAGE_SIZE_PARAM) || restrict.equals(WebMethod.PAGE_NUM_PARAM) || restrict.equals("keywords")) {
restriction.put(restrict, value);
} else if (restrict.equals(WebMethod.SEARCH_QUERY_PARAM)) {
// ignore - someone was doing something odd
} else {
// XXX I would so prefer not to restrict and just pass
// stuff up but I know it will cause issues later
restriction.put("queryTerm", restrict);
restriction.put("queryString", value);
}
}
}
// Get the data
JSONObject outputJSON = new JSONObject();
outputJSON.put("termsUsed", getTermsUsed(storage, base + "/" + path, restriction));
try {
outputJSON.put("csid", path);
} catch (JSONException e1) {
throw new UIException("Cannot add csid", e1);
}
// Write the requested JSON out
ui.sendJSONResponse(outputJSON);
} catch (JSONException e) {
throw new UIException("JSONException during store_get", e);
} catch (ExistException e) {
throw new UIException("ExistException during store_get", e);
} catch (UnimplementedException e) {
throw new UIException("UnimplementedException during store_get", e);
} catch (UnderlyingStorageException x) {
UIException uiexception = new UIException(x.getMessage(), x.getStatus(), x.getUrl(), x);
ui.sendJSONResponse(uiexception.getJSON());
}
}
Aggregations