Search in sources :

Example 6 with Group

use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.

the class ConfiguredVocabStorage method updateJSON.

public void updateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, JSONObject jsonObject, JSONObject restrictions, Record thisr, String savePath) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        String csid = savePath.split("/")[3];
        Map<String, Document> body = new HashMap<String, Document>();
        for (String section : r.getServicesRecordPathKeys()) {
            String path = r.getServicesRecordPath(section);
            String[] record_path = path.split(":", 2);
            String[] tag_path = record_path[1].split(",", 2);
            Document temp = createEntry(section, tag_path[0], tag_path[1], jsonObject, null, null, thisr, false);
            if (temp != null) {
                body.put(record_path[0], temp);
            // log.info(temp.asXML());
            }
        }
        handleHierarchyPayloadSend(thisr, body, jsonObject, csid);
        ReturnedMultipartDocument out = conn.getMultipartXMLDocument(RequestMethod.PUT, savePath, body, creds, cache);
        if (out.isErrorStatus()) {
            if (out.isTransactionFailedStatus()) {
                throw new UnderlyingStorageException(VOCABULARY_UPDATE_FAILED_MESSAGE + ": " + out.TRANSACTION_FAILED_MESSAGE, out.getStatus(), savePath);
            } else {
                throw new UnderlyingStorageException(VOCABULARY_UPDATE_FAILED_MESSAGE, out.getStatus(), savePath);
            }
        }
        // subrecord update
        for (FieldSet fs : thisr.getAllSubRecords("PUT")) {
            Record sr = fs.usesRecordId();
            // get list of existing subrecords
            JSONObject existingcsid = new JSONObject();
            JSONObject updatecsid = new JSONObject();
            JSONArray createcsid = new JSONArray();
            String getPath = savePath + "/" + sr.getServicesURL();
            Integer subcount = 0;
            String firstfile = "";
            while (!getPath.equals("")) {
                JSONObject data = getListView(creds, cache, getPath, sr.getServicesListPath(), "csid", false, sr);
                String[] filepaths = (String[]) data.get("listItems");
                subcount += filepaths.length;
                if (firstfile.equals("") && subcount != 0) {
                    firstfile = filepaths[0];
                }
                for (String uri : filepaths) {
                    String path = uri;
                    if (path != null && path.startsWith("/"))
                        path = path.substring(1);
                    existingcsid.put(path, "original");
                }
                if (data.has("pagination")) {
                    Integer ps = Integer.valueOf(data.getJSONObject("pagination").getString("pageSize"));
                    Integer pn = Integer.valueOf(data.getJSONObject("pagination").getString("pageNum"));
                    Integer ti = Integer.valueOf(data.getJSONObject("pagination").getString("totalItems"));
                    if (ti > (ps * (pn + 1))) {
                        JSONObject pgRestrictions = new JSONObject();
                        pgRestrictions.put("pageSize", Integer.toString(ps));
                        pgRestrictions.put("pageNum", Integer.toString(pn + 1));
                        getPath = getRestrictedPath(getPath, pgRestrictions, sr.getServicesSearchKeyword(), "", false, "");
                    // need more values
                    } else {
                        getPath = "";
                    }
                }
            }
            // how does that compare to what we need
            if (sr.isType("authority")) {
                if (fs instanceof Field) {
                    JSONObject subdata = new JSONObject();
                    // loop thr jsonObject and find the fields I need
                    for (FieldSet subfs : sr.getAllFieldTopLevel("PUT")) {
                        String key = subfs.getID();
                        if (jsonObject.has(key)) {
                            subdata.put(key, jsonObject.get(key));
                        }
                    }
                    if (subcount == 0) {
                        // create
                        createcsid.put(subdata);
                    } else {
                        // update - there should only be one
                        String firstcsid = firstfile;
                        updatecsid.put(firstcsid, subdata);
                        existingcsid.remove(firstcsid);
                    }
                } else if (fs instanceof Group) {
                    // subrecorddata.put(value);
                    if (jsonObject.has(fs.getID())) {
                        Object subdata = jsonObject.get(fs.getID());
                        if (subdata instanceof JSONObject) {
                            if (((JSONObject) subdata).has("_subrecordcsid")) {
                                String thiscsid = ((JSONObject) subdata).getString("_subrecordcsid");
                                // update
                                if (existingcsid.has(thiscsid)) {
                                    updatecsid.put(thiscsid, (JSONObject) subdata);
                                    existingcsid.remove(thiscsid);
                                } else {
                                    // something has gone wrong... best just create it from scratch
                                    createcsid.put(subdata);
                                }
                            } else {
                                // create
                                createcsid.put(subdata);
                            }
                        }
                    }
                } else {
                    // need to find if we have csid's for each one
                    if (jsonObject.has(fs.getID())) {
                        Object subdata = jsonObject.get(fs.getID());
                        if (subdata instanceof JSONArray) {
                            JSONArray subarray = (JSONArray) subdata;
                            for (int i = 0; i < subarray.length(); i++) {
                                JSONObject subrecord = subarray.getJSONObject(i);
                                if (subrecord.has("_subrecordcsid")) {
                                    String thiscsid = subrecord.getString("_subrecordcsid");
                                    // update
                                    if (existingcsid.has(thiscsid)) {
                                        updatecsid.put(thiscsid, (JSONObject) subdata);
                                        existingcsid.remove(thiscsid);
                                    } else {
                                        // something has gone wrong... best just create it from scratch
                                        createcsid.put(subdata);
                                    }
                                } else {
                                    // create
                                    createcsid.put(subdata);
                                }
                            }
                        }
                    }
                }
                String savePathSr = savePath + "/" + sr.getServicesURL() + "/";
                // do delete JSONObject existingcsid = new JSONObject();
                Iterator<String> rit = existingcsid.keys();
                while (rit.hasNext()) {
                    String key = rit.next();
                    deleteJSON(root, creds, cache, key, savePathSr, sr);
                }
                // do update JSONObject updatecsid = new JSONObject();
                Iterator<String> keys = updatecsid.keys();
                while (keys.hasNext()) {
                    String key = keys.next();
                    JSONObject value = updatecsid.getJSONObject(key);
                    String thissave = savePathSr + key;
                    updateJSON(root, creds, cache, value, new JSONObject(), sr, thissave);
                // updateJSON( root, creds, cache, key,  value, sr, savePathSr);
                }
                // do create JSONArray createcsid = new JSONArray();
                for (int i = 0; i < createcsid.length(); i++) {
                    JSONObject value = createcsid.getJSONObject(i);
                    subautocreateJSON(root, creds, cache, sr, value, savePathSr);
                }
            }
        }
    // XXX dont currently update the shortID???
    // cache.setCached(getClass(),new String[]{"shortId",vocab,filePath.split("/")[1]},shortId);
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Connection exception " + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Cannot parse surrounding JSON " + e.getLocalizedMessage(), e);
    } catch (UnsupportedEncodingException e) {
        throw new UnimplementedException("UnsupportedEncodingException" + e.getLocalizedMessage(), e);
    }
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) Record(org.collectionspace.chain.csp.schema.Record) JSONObject(org.json.JSONObject) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 7 with Group

use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.

the class XmlJsonConversion method addRepeatedNodeToJson.

private static JSONArray addRepeatedNodeToJson(Element container, Repeat f, String permlevel, JSONObject tempSon) throws JSONException {
    JSONArray node = new JSONArray();
    List<FieldSet> children = getChildrenWithGroupFields(f, permlevel);
    JSONArray elementlist = extractRepeatData(container, f, permlevel);
    JSONObject siblingitem = new JSONObject();
    for (int i = 0; i < elementlist.length(); i++) {
        JSONObject element = elementlist.getJSONObject(i);
        Iterator<?> rit = element.keys();
        while (rit.hasNext()) {
            String key = (String) rit.next();
            JSONArray arrvalue = new JSONArray();
            for (FieldSet fs : children) {
                if (fs instanceof Repeat && ((Repeat) fs).hasServicesParent()) {
                    if (!((Repeat) fs).getServicesParent()[0].equals(key)) {
                        continue;
                    }
                    Object value = element.get(key);
                    arrvalue = (JSONArray) value;
                } else {
                    if (!fs.getID().equals(key)) {
                        continue;
                    }
                    Object value = element.get(key);
                    arrvalue = (JSONArray) value;
                }
                if (fs instanceof Field) {
                    for (int j = 0; j < arrvalue.length(); j++) {
                        JSONObject repeatitem = new JSONObject();
                        // XXX remove when service layer supports primary tags
                        if (f.hasPrimary() && j == 0) {
                            repeatitem.put("_primary", true);
                        }
                        Element child = (Element) arrvalue.get(j);
                        Object val = child.getText();
                        Field field = (Field) fs;
                        String id = field.getID();
                        if (f.asSibling()) {
                            addExtraToJson(siblingitem, child, field, tempSon);
                            if (field.getDataType().equals("boolean")) {
                                siblingitem.put(id, (Boolean.parseBoolean((String) val) ? true : false));
                            } else {
                                siblingitem.put(id, val);
                            }
                        } else {
                            addExtraToJson(repeatitem, child, field, tempSon);
                            if (field.getDataType().equals("boolean")) {
                                repeatitem.put(id, (Boolean.parseBoolean((String) val) ? true : false));
                            } else {
                                repeatitem.put(id, val);
                            }
                            node.put(repeatitem);
                        }
                        tempSon = addtemp(tempSon, fs.getID(), child.getText());
                    }
                } else if (fs instanceof Group) {
                    JSONObject tout = new JSONObject();
                    JSONObject tempSon2 = new JSONObject();
                    Group rp = (Group) fs;
                    addRepeatToJson(tout, container, rp, permlevel, tempSon2, "", "");
                    if (f.asSibling()) {
                        JSONArray a1 = tout.getJSONArray(rp.getID());
                        JSONObject o1 = a1.getJSONObject(0);
                        siblingitem.put(fs.getID(), o1);
                    } else {
                        JSONObject repeatitem = new JSONObject();
                        repeatitem.put(fs.getID(), tout.getJSONArray(rp.getID()));
                        node.put(repeatitem);
                    }
                    tempSon = addtemp(tempSon, rp.getID(), tout.getJSONArray(rp.getID()));
                // log.info(f.getID()+":"+rp.getID()+":"+tempSon.toString());
                } else if (fs instanceof Repeat) {
                    JSONObject tout = new JSONObject();
                    JSONObject tempSon2 = new JSONObject();
                    Repeat rp = (Repeat) fs;
                    addRepeatToJson(tout, container, rp, permlevel, tempSon2, "", "");
                    if (f.asSibling()) {
                        siblingitem.put(fs.getID(), tout.getJSONArray(rp.getID()));
                    } else {
                        JSONObject repeatitem = new JSONObject();
                        repeatitem.put(fs.getID(), tout.getJSONArray(rp.getID()));
                        node.put(repeatitem);
                    }
                    tempSon = addtemp(tempSon, rp.getID(), tout.getJSONArray(rp.getID()));
                // log.info(f.getID()+":"+rp.getID()+":"+tempSon.toString());
                }
            }
        }
    }
    if (f.asSibling()) {
        node.put(siblingitem);
    }
    return node;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) Group(org.collectionspace.chain.csp.schema.Group) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) Element(org.dom4j.Element) JSONArray(org.json.JSONArray) Repeat(org.collectionspace.chain.csp.schema.Repeat) JSONObject(org.json.JSONObject)

Example 8 with Group

use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.

the class XmlJsonConversion method getChildrenWithGroupFields.

// merges in the pseudo sub records 'groupfields' with the normal fields unless they need to be nested
private static List<FieldSet> getChildrenWithGroupFields(Repeat parent, String operation) {
    List<FieldSet> children = new ArrayList<FieldSet>();
    if (parent.getUIType().startsWith("groupfield")) {
        String[] parts = parent.getUIType().split("/");
        Record subitems = parent.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
        for (FieldSet fd : subitems.getAllFieldTopLevel(operation)) {
            children.add(fd);
        }
    }
    for (FieldSet fs : parent.getChildren(operation)) {
        if (fs.getUIType().startsWith("groupfield")) {
            String[] parts = fs.getUIType().split("/");
            Record subitems = fs.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
            if (fs instanceof Group) {
                if (((Group) fs).getXxxServicesNoRepeat()) {
                    for (FieldSet fd : subitems.getAllFieldTopLevel(operation)) {
                        // non-nested groupfields?
                        children.add(fd);
                    }
                    // groups with xxx-services-no-repeat set to true.
                    for (FieldSet fd : ((Group) fs).getChildren(operation)) {
                        children.add(fd);
                    }
                } else {
                    // this one should be nested
                    children.add(fs);
                }
            } else {
                for (FieldSet fd : subitems.getAllFieldTopLevel(operation)) {
                    // what about nested groupfields?
                    children.add(fd);
                }
            }
        } else {
            children.add(fs);
        }
    }
    return children;
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) ArrayList(java.util.ArrayList) Record(org.collectionspace.chain.csp.schema.Record)

Example 9 with Group

use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.

the class GenericStorage method simpleRetrieveJSON.

/**
 * return data just as the service layer gives it to the App layer
 * no extra columns required
 * @param creds
 * @param cache
 * @param filePath
 * @param servicesurl
 * @param thisr
 * @return
 * @throws ExistException
 * @throws UnimplementedException
 * @throws UnderlyingStorageException
 */
public JSONObject simpleRetrieveJSON(CSPRequestCredentials creds, CSPRequestCache cache, String filePath, String servicesurl, Record thisr) throws ExistException, UnimplementedException, UnderlyingStorageException {
    String csid = "";
    if (filePath == null) {
        filePath = "";
    }
    String[] path_parts = filePath.split("/");
    if (path_parts.length > 1)
        csid = path_parts[1];
    else
        csid = filePath;
    JSONObject out = new JSONObject();
    try {
        String softpath = filePath;
        if (thisr.hasSoftDeleteMethod()) {
            softpath = softpath(filePath);
        }
        if (thisr.hasHierarchyUsed("screen")) {
            softpath = hierarchicalpath(softpath);
        }
        if (thisr.isMultipart()) {
            ReturnedMultipartDocument doc = conn.getMultipartXMLDocument(RequestMethod.GET, servicesurl + softpath, null, creds, cache);
            if ((doc.getStatus() < 200 || doc.getStatus() >= 300))
                throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), softpath);
            for (String section : thisr.getServicesRecordPathKeys()) {
                String path = thisr.getServicesRecordPath(section);
                String[] parts = path.split(":", 2);
                if (doc.getDocument(parts[0]) != null) {
                    convertToJson(out, doc.getDocument(parts[0]), thisr, "GET", section, csid);
                }
            }
            // If this record has hierarchy, will pull out the relations section and map it to the hierarchy
            // fields (special case handling of XML-JSON
            handleHierarchyPayloadRetrieve(thisr, doc, out, csid);
        } else {
            ReturnedDocument doc = conn.getXMLDocument(RequestMethod.GET, servicesurl + softpath, null, creds, cache);
            if ((doc.getStatus() < 200 || doc.getStatus() >= 300))
                throw new UnderlyingStorageException("Does not exist ", doc.getStatus(), softpath);
            convertToJson(out, doc.getDocument(), thisr, "GET", "common", csid);
        }
    } catch (ConnectionException e) {
        throw new UnderlyingStorageException("Service layer exception" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (JSONException e) {
        throw new UnderlyingStorageException("Service layer exception", e);
    }
    /*
		 * Get data for any sub records that are part of this record e.g. contact in person, blob in media
		 */
    try {
        for (FieldSet fs : thisr.getAllSubRecords("GET")) {
            Boolean validator = true;
            Record sr = fs.usesRecordId();
            if (fs.usesRecordValidator() != null) {
                validator = false;
                if (out.has(fs.usesRecordValidator())) {
                    String test = out.getString(fs.usesRecordValidator());
                    if (test != null && !test.equals("")) {
                        validator = true;
                    }
                }
            }
            if (validator) {
                String getPath = servicesurl + filePath + "/" + sr.getServicesURL();
                if (null != fs.getServicesUrl()) {
                    getPath = fs.getServicesUrl();
                }
                if (fs.getWithCSID() != null) {
                    getPath = getPath + "/" + out.getString(fs.getWithCSID());
                }
                // need to get update and delete working? tho not going to be used for media as handling blob seperately
                if (fs instanceof Group) {
                    JSONObject outer = simpleRetrieveJSON(creds, cache, getPath, "", sr);
                    JSONArray group = new JSONArray();
                    group.put(outer);
                    out.put(fs.getID(), group);
                }
                if (fs instanceof Repeat) {
                    // NEED TO GET A LIST OF ALL THE THINGS
                    JSONArray repeat = new JSONArray();
                    String path = getPath;
                    while (!path.equals("")) {
                        JSONObject data = getListView(creds, cache, path, sr.getServicesListPath(), "csid", false, r);
                        if (data.has("listItems")) {
                            String[] results = (String[]) data.get("listItems");
                            for (String result : results) {
                                JSONObject rout = simpleRetrieveJSON(creds, cache, getPath + "/" + result, "", sr);
                                // add in csid so I can do update with a modicum of confidence
                                rout.put("_subrecordcsid", result);
                                repeat.put(rout);
                            }
                        }
                        if (data.has("pagination")) {
                            Integer ps = Integer.valueOf(data.getJSONObject("pagination").getString("pageSize"));
                            Integer pn = Integer.valueOf(data.getJSONObject("pagination").getString("pageNum"));
                            Integer ti = Integer.valueOf(data.getJSONObject("pagination").getString("totalItems"));
                            if (ti > (ps * (pn + 1))) {
                                JSONObject restrictions = new JSONObject();
                                restrictions.put("pageSize", Integer.toString(ps));
                                restrictions.put("pageNum", Integer.toString(pn + 1));
                                path = getRestrictedPath(getPath, restrictions, sr.getServicesSearchKeyword(), "", false, "");
                            // need more values
                            } else {
                                path = "";
                            }
                        }
                    }
                    // group.put(outer);
                    out.put(fs.getID(), repeat);
                }
            }
        }
    } catch (Exception e) {
    // ignore exceptions for sub records at the moment - make it more intelligent later
    // throw new UnderlyingStorageException("Service layer exception",e);
    }
    return out;
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) Repeat(org.collectionspace.chain.csp.schema.Repeat) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) DocumentException(org.dom4j.DocumentException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) IOException(java.io.IOException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) Record(org.collectionspace.chain.csp.schema.Record) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Example 10 with Group

use of org.collectionspace.chain.csp.schema.Group in project application by collectionspace.

the class GenericStorage method autocreateJSON.

/**
 * Convert the JSON from the UI Layer into XML for the Service layer while using the XML structure from cspace-config.xml
 * Send the XML through to the Service Layer to store it in the database
 * The Service Layer returns a url to the object we just stored.
 * @param {ContextualisedStorage} root
 * @param {CSPRequestCredentials} creds
 * @param {CSPRequestCache} cache
 * @param {String} filePath part of the path to the Service URL (containing the type of object)
 * @param {JSONObject} jsonObject The JSON string coming in from the UI Layer, containing the object to be stored
 * @return {String} csid The id of the object in the database
 */
@Override
public String autocreateJSON(ContextualisedStorage root, CSPRequestCredentials creds, CSPRequestCache cache, String filePath, JSONObject jsonObject, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException {
    try {
        ReturnedURL url = null;
        Document doc = null;
        // used by userroles and permroles as they have complex urls
        if (r.hasPrimaryField()) {
            for (String section : r.getServicesRecordPathKeys()) {
                doc = XmlJsonConversion.convertToXml(r, jsonObject, section, "POST");
                String path = r.getServicesURL();
                path = path.replace("*", getSubCsid(jsonObject, r.getPrimaryField()));
                String restrictedPath = getRestrictedPath(path, restrictions, null);
                deleteJSON(root, creds, cache, restrictedPath);
                url = conn.getURL(RequestMethod.POST, restrictedPath, doc, creds, cache);
            }
        } else {
            String restrictedPath = getRestrictedPath(r.getServicesURL(), restrictions, null);
            // REM - We need a way to send query params (restrictions) on POST and UPDATE
            url = autoCreateSub(creds, cache, jsonObject, doc, restrictedPath, r);
        }
        // I am developing this.. it might not work...
        for (FieldSet fs : r.getAllSubRecords("POST")) {
            Record sr = fs.usesRecordId();
            // sr.getID()
            if (sr.isType("authority")) {
            // need to use code from configuredVocabStorage
            } else {
                String savePath = url.getURL() + "/" + sr.getServicesURL();
                if (fs instanceof Field) {
                    // get the fields form inline XXX untested - might not work...
                    JSONObject subdata = new JSONObject();
                    // loop thr jsonObject and find the fields I need
                    for (FieldSet subfs : sr.getAllFieldTopLevel("POST")) {
                        String key = subfs.getID();
                        if (jsonObject.has(key)) {
                            subdata.put(key, jsonObject.get(key));
                        }
                    }
                    subautocreateJSON(root, creds, cache, sr, subdata, savePath);
                } else if (fs instanceof Group) {
                    // JSONObject
                    if (jsonObject.has(fs.getID())) {
                        Object subdata = jsonObject.get(fs.getID());
                        if (subdata instanceof JSONObject) {
                            JSONObject subrecord = (JSONObject) subdata;
                            subautocreateJSON(root, creds, cache, sr, subrecord, savePath);
                        }
                    }
                } else {
                    // JSONArray
                    if (jsonObject.has(fs.getID())) {
                        Object subdata = jsonObject.get(fs.getID());
                        if (subdata instanceof JSONArray) {
                            JSONArray subarray = (JSONArray) subdata;
                            for (int i = 0; i < subarray.length(); i++) {
                                JSONObject subrecord = subarray.getJSONObject(i);
                                subautocreateJSON(root, creds, cache, sr, subrecord, savePath);
                            }
                        }
                    }
                }
            }
        }
        return url.getURLTail();
    } catch (ConnectionException e) {
        String msg = e.getMessage();
        if (e.getStatus() == 403) {
            // permissions error
            msg += " permissions error";
        }
        throw new UnderlyingStorageException(msg, e.getStatus(), e.getUrl(), e);
    } catch (UnderlyingStorageException e) {
        // REM - CSPACE-5632: Need to catch and rethrow this exception type to prevent throwing an "UnimplementedException" exception below.
        throw e;
    } catch (Exception e) {
        throw new UnimplementedException("JSONException", e);
    }
}
Also used : ReturnedURL(org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL) Group(org.collectionspace.chain.csp.schema.Group) JSONArray(org.json.JSONArray) Document(org.dom4j.Document) ReturnedMultipartDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument) ReturnedDocument(org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) DocumentException(org.dom4j.DocumentException) JSONException(org.json.JSONException) ExistException(org.collectionspace.csp.api.persistence.ExistException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) IOException(java.io.IOException) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject) Record(org.collectionspace.chain.csp.schema.Record) JSONObject(org.json.JSONObject) UnimplementedException(org.collectionspace.csp.api.persistence.UnimplementedException) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)

Aggregations

Group (org.collectionspace.chain.csp.schema.Group)20 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)17 JSONObject (org.json.JSONObject)13 Field (org.collectionspace.chain.csp.schema.Field)12 Record (org.collectionspace.chain.csp.schema.Record)12 JSONArray (org.json.JSONArray)10 Repeat (org.collectionspace.chain.csp.schema.Repeat)9 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)7 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)6 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)6 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)6 JSONException (org.json.JSONException)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 Document (org.dom4j.Document)5 HashMap (java.util.HashMap)4 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)4 ArrayList (java.util.ArrayList)3 ExistException (org.collectionspace.csp.api.persistence.ExistException)3 IOException (java.io.IOException)2 ReturnedURL (org.collectionspace.chain.csp.persistence.services.connection.ReturnedURL)2