use of org.collectionspace.csp.api.persistence.ExistException 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.ExistException 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.ExistException 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.ExistException in project application by collectionspace.
the class TestVocab method testAllAuthorities.
private void testAllAuthorities(Storage ss, String path, String testField) throws Exception {
// Create
log.info("testAuthorities_" + path + "_create");
JSONObject data = new JSONObject();
data.put("shortIdentifier", "TEST3");
data.put(testField, "TEST3");
data.put("termStatus", "Provisional");
String id = ss.autocreateJSON(path, data, null);
// Read
log.info("testAuthorities_" + path + "_read");
JSONObject out = ss.retrieveJSON(path + "/" + id, new JSONObject());
assertEquals("TEST3", out.getString(testField));
assertEquals("Provisional", out.getString("termStatus"));
// Update
log.info("testAuthorities_" + path + "_update");
data.remove(testField);
data.put(testField, "TEST2");
data.put("termStatus", "Provisional2");
ss.updateJSON(path + "/" + id, data, new JSONObject());
out = ss.retrieveJSON(path + "/" + id, new JSONObject());
assertEquals("TEST2", out.getString(testField));
assertEquals("Provisional2", out.getString("termStatus"));
String id3 = out.getString("csid");
// List
log.info("testAuthorities_" + path + "_list");
data.remove(testField);
data.put(testField, "TEST4");
data.put("shortIdentifier", "TEST4");
String id2 = ss.autocreateJSON(path, data, null);
out = ss.retrieveJSON(path + "/" + id2, new JSONObject());
assertEquals("TEST4", out.getString(testField));
boolean found1 = false, found2 = false;
JSONObject myjs = new JSONObject();
myjs.put("pageSize", "100");
myjs.put("pageNum", "0");
int resultsize = 1;
int check = 0;
String checkpagination = "";
while (resultsize > 0) {
log.info("testAuthorities_" + path + "_page: " + check);
myjs.put("pageNum", check);
check++;
JSONObject items = ss.getPathsJSON(path, myjs);
String[] res = (String[]) items.get("listItems");
if (res.length == 0 || checkpagination.equals(res[0])) {
resultsize = 0;
// testing whether we have actually returned the same page or the next page - all csid returned should be unique
} else {
checkpagination = res[0];
}
resultsize = res.length;
for (String u : res) {
if (id3.equals(u)) {
found1 = true;
}
if (id2.equals(u)) {
found2 = true;
}
}
if (found1 && found2) {
resultsize = 0;
}
}
assertTrue(found1);
assertTrue(found2);
// Delete
log.info("testAuthorities_" + path + "_delete");
ss.deleteJSON(path + "/" + id2);
ss.deleteJSON(path + "/" + id3);
try {
out = ss.retrieveJSON(path + "/" + id2, new JSONObject());
out = ss.retrieveJSON(path + "/" + id3, new JSONObject());
assertTrue(false);
} catch (ExistException x) {
assertTrue(true);
}
}
use of org.collectionspace.csp.api.persistence.ExistException 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