Search in sources :

Example 61 with UnderlyingStorageException

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();
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 62 with UnderlyingStorageException

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);
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) Test(org.junit.Test)

Example 63 with UnderlyingStorageException

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;
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) JSONException(org.json.JSONException) IOException(java.io.IOException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 64 with UnderlyingStorageException

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;
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) JSONObject(org.json.JSONObject) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) JSONException(org.json.JSONException) IOException(java.io.IOException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 65 with UnderlyingStorageException

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());
    }
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

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