Search in sources :

Example 6 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class ServicesBaseClass method setup.

protected void setup() throws ConnectionException {
    Spec spec = null;
    String ims_base = "";
    try {
        base = getBaseUrl();
        ims_base = getIMSBaseUrl();
        spec = getDefaultSpec();
    } catch (CSPDependencyException e) {
        assertNotNull("Base service url invalid in config file", base);
    }
    // XXX still yuck but centralised now
    log.info("ServicesBaseClass setting up connection using base URL:" + base);
    conn = new ServicesConnection(base, ims_base);
    creds = new ServicesRequestCredentials();
    creds.setCredential(ServicesStorageGenerator.CRED_USERID, spec.getAdminData().getAuthUser());
    creds.setCredential(ServicesStorageGenerator.CRED_PASSWORD, spec.getAdminData().getAuthPass());
    ReturnedDocument out = conn.getXMLDocument(RequestMethod.GET, "accounts/0/accountperms", null, creds, cache);
    Assume.assumeTrue(out.getStatus() == 200);
}
Also used : CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) ServicesConnection(org.collectionspace.chain.csp.persistence.services.connection.ServicesConnection) Spec(org.collectionspace.chain.csp.schema.Spec) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)

Example 7 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException 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 8 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException in project application by collectionspace.

the class TestDummyData method testDataCreation.

@Test
public void testDataCreation() {
    Storage ss;
    try {
        ss = makeServicesStorage();
        // create objects/procedures/
        String objectUrl = create("collectionobjects/", "collectionobjects_common", "dummydata-object1.xml", "collection-object");
        String acquisitionUrl = create("acquisitions/", "acquisitions_common", "dummydata-acquisition.xml", "acquisition");
        String intakeUrl = create("intakes/", "intakes_common", "dummydata-intake.xml", "intake");
        String loaninUrl = create("loansin/", "loansin_common", "dummydata-loanin.xml", "loanin");
        String loanoutUrl = create("loansout/", "loansout_common", "dummydata-loanout.xml", "loanout");
        String objectexitUrl = create("objectexit/", "objectexit_common", "dummydata-objectexit.xml", "objectexit");
        // String groupUrl = create("group/", "group_common", "dummydata-group.xml","group");
        // make relationships
        relate2way(ss, objectUrl, acquisitionUrl);
        relate2way(ss, objectUrl, intakeUrl);
        relate2way(ss, objectUrl, loaninUrl);
        relate2way(ss, objectUrl, loanoutUrl);
        relate2way(ss, objectUrl, objectexitUrl);
        testRelations(ss, objectUrl, acquisitionUrl, "affects");
        testRelations(ss, objectUrl, intakeUrl, "affects");
        testRelations(ss, objectUrl, loaninUrl, "affects");
        testRelations(ss, objectUrl, loanoutUrl, "affects");
        testRelations(ss, objectUrl, objectexitUrl, "affects");
    // testRelations(ss,objectUrl,groupUrl,"affects");
    } catch (CSPDependencyException e) {
        fail(e.getMessage());
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : Storage(org.collectionspace.csp.api.persistence.Storage) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) CSPDependencyException(org.collectionspace.csp.api.core.CSPDependencyException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) Test(org.junit.Test)

Example 9 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException 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 10 with CSPDependencyException

use of org.collectionspace.csp.api.core.CSPDependencyException 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)

Aggregations

CSPDependencyException (org.collectionspace.csp.api.core.CSPDependencyException)21 IOException (java.io.IOException)7 SAXException (org.xml.sax.SAXException)7 ConfigFinder (org.collectionspace.csp.helper.core.ConfigFinder)6 Spec (org.collectionspace.chain.csp.schema.Spec)5 JSONException (org.json.JSONException)5 File (java.io.File)4 ExistException (org.collectionspace.csp.api.persistence.ExistException)4 Storage (org.collectionspace.csp.api.persistence.Storage)4 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)4 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)4 JSONObject (org.json.JSONObject)4 InputSource (org.xml.sax.InputSource)4 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 CoreConfig (org.collectionspace.chain.csp.inner.CoreConfig)3 CSPManager (org.collectionspace.csp.api.container.CSPManager)3 CSPManagerImpl (org.collectionspace.csp.container.impl.CSPManagerImpl)3 TestConfigFinder (org.collectionspace.csp.helper.test.TestConfigFinder)3 FileNotFoundException (java.io.FileNotFoundException)2