Search in sources :

Example 26 with UnimplementedException

use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.

the class DirectRedirector method retrieveJSON.

@Override
public JSONObject retrieveJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String path, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    /* Find relevant controller, and call */
    String[] url = path.split("/");
    RefName.AuthorityItem itemParsed = RefName.AuthorityItem.parse(url[2]);
    String thisShortid = itemParsed.getShortIdentifier();
    String thisparent = itemParsed.getParentShortIdentifier();
    String displayName = itemParsed.displayName;
    String test = itemParsed.inAuthority.resource;
    String vocab = RefName.shortIdToPath(thisparent);
    String csid = RefName.shortIdToPath(thisShortid);
    Record r = spec.getRecordByServicesUrl(itemParsed.inAuthority.resource);
    String storageID = r.getID();
    if (r.isType("vocabulary")) {
        url[0] = r.getServicesURL();
        storageID = "vocab";
    }
    if (!r.isType("authority") && !r.isType("vocabulary"))
        throw new UnimplementedException("Only authorities and vocabularies supported at direct at the moment");
    return root.retrieveJSON(root, creds, cache, storageID + "/_direct/" + url[0] + "/" + vocab + "/" + csid, restrictions);
}
Also used : RefName(org.collectionspace.services.common.api.RefName) Record(org.collectionspace.chain.csp.schema.Record) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 27 with UnimplementedException

use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.

the class DataGenerator method createAllRecords.

/**
 * Create all record types (that make sense)
 * @param storage
 * @param ui
 * @return
 * @throws UIException
 */
protected JSONObject createAllRecords(Storage storage, UIRequest ui) throws UIException {
    log.info("Lets make some records");
    tty.line("Lets make some records");
    tty.flush();
    JSONObject returnData = new JSONObject();
    try {
        for (Record r : spec.getAllRecords()) {
            if (r.isType("authority") || r.isType("authorizationdata") || r.isType("id") || r.isType("userdata")) {
            // don't do these yet (if ever)
            } else if (r.getID().equals("structureddate") || r.getID().equals("media") || r.getID().equals("hierarchy") || r.getID().equals("blobs") || r.getID().equals("dimension") || r.getID().equals("contacts") || r.isType("searchall")) {
            // and ignore these
            } else if (r.getID().equals("termlist") || r.getID().equals("termlistitem")) {
            // and ignore these
            } else {
                this.record = r;
                this.structureview = "screen";
                this.writer = new RecordCreateUpdate(r, true);
                JSONObject items = createRecords(storage, ui);
                returnData.put(r.getID(), items.getJSONObject(r.getID()));
            }
        }
        // lets create some relationships
        log.info("Initializing relationships");
        tty.line("Initializing relationships");
        tty.flush();
        createDataSetRelationships(returnData);
    } catch (JSONException x) {
        throw new UIException("Failed to parse json: ", x);
    } catch (ExistException x) {
        throw new UIException("Existence exception: ", x);
    } catch (UnimplementedException x) {
        throw new UIException("Unimplemented exception: ", x);
    } catch (UnderlyingStorageException x) {
        throw new UIException("Problem storing: " + x.getLocalizedMessage(), x.getStatus(), x.getUrl(), x);
    }
    return returnData;
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) Record(org.collectionspace.chain.csp.schema.Record) RecordCreateUpdate(org.collectionspace.chain.csp.webui.record.RecordCreateUpdate) ExistException(org.collectionspace.csp.api.persistence.ExistException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException)

Example 28 with UnimplementedException

use of org.collectionspace.csp.api.persistence.UnimplementedException in project application by collectionspace.

the class DataGenerator method createRecords.

/**
 * generate records of a specific type
 * @param storage
 * @param ui
 * @return
 * @throws UIException
 */
protected JSONObject createRecords(Storage storage, UIRequest ui) throws UIException {
    log.info("Making " + this.record.getID());
    tty.line("Making " + this.record.getID());
    tty.flush();
    JSONObject returnData = new JSONObject();
    JSONObject out = datagenerator(storage, ui);
    try {
        // make it a record
        JSONObject data = new JSONObject();
        Iterator rit = out.keys();
        JSONObject dataitems = new JSONObject();
        while (rit.hasNext()) {
            String key = (String) rit.next();
            data.put("fields", out.getJSONObject(key));
            String path = writer.sendJSON(storage, null, data, null);
            dataitems.put(key, path);
            // log.info(path);
            log.info("created " + this.record.getID() + " with csid of: " + path);
            tty.line("created " + this.record.getID() + " with csid of: " + path);
            tty.flush();
        }
        returnData.put(this.record.getID(), dataitems);
    } catch (JSONException x) {
        tty.line("JSONException(Failed to parse json: " + x);
        log.info("JSONException(Failed to parse json: " + x);
        throw new UIException("Failed to parse json: " + x, x);
    } catch (ExistException x) {
        log.info("ExistException(Existence exception: " + x);
        tty.line("ExistException(Existence exception: " + x);
        throw new UIException("Existence exception: " + x, x);
    } catch (UnimplementedException x) {
        tty.line("UnimplementedException(UnimplementedException: " + x);
        log.info("UnimplementedException(UnimplementedException: " + x);
        throw new UIException("Unimplemented exception: " + x, x);
    } catch (UnderlyingStorageException x) {
        tty.line("UnderlyingStorageException(UnderlyingStorageException: " + x);
        log.info("UnderlyingStorageException(UnderlyingStorageException: " + x);
        throw new UIException("Problem storing: " + x.getLocalizedMessage(), x.getStatus(), x.getUrl(), x);
    }
    // return something to screen
    return returnData;
}
Also used : JSONObject(org.json.JSONObject) Iterator(java.util.Iterator) 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)

Example 29 with UnimplementedException

use of org.collectionspace.csp.api.persistence.UnimplementedException 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 30 with UnimplementedException

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

Aggregations

UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)56 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)55 ExistException (org.collectionspace.csp.api.persistence.ExistException)50 JSONException (org.json.JSONException)50 JSONObject (org.json.JSONObject)48 UIException (org.collectionspace.csp.api.ui.UIException)40 JSONArray (org.json.JSONArray)25 Record (org.collectionspace.chain.csp.schema.Record)11 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 IOException (java.io.IOException)7 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)6 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)6 ConfigException (org.collectionspace.chain.csp.config.ConfigException)5 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)5 Field (org.collectionspace.chain.csp.schema.Field)5 Document (org.dom4j.Document)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 Group (org.collectionspace.chain.csp.schema.Group)4 Instance (org.collectionspace.chain.csp.schema.Instance)4 Storage (org.collectionspace.csp.api.persistence.Storage)4