Search in sources :

Example 11 with Group

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

the class GenericStorage method refObjViewRetrieveJSON.

/**
 * get data needed for list of objects related to a termUsed
 * @param storage
 * @param creds
 * @param cache
 * @param path
 * @return
 * @throws ExistException
 * @throws UnderlyingStorageException
 * @throws JSONException
 * @throws UnimplementedException
 */
public JSONObject refObjViewRetrieveJSON(ContextualisedStorage storage, CSPRequestCredentials creds, CSPRequestCache cache, String path, JSONObject restrictions, Record vr) throws ExistException, UnderlyingStorageException, JSONException, UnimplementedException {
    JSONObject out = new JSONObject();
    try {
        // map of servicenames of fields to descriptors
        Map<String, String> refObj_view_good = new HashMap<String, String>();
        // map of csid to service name of field
        Map<String, String> refObj_view_map = new HashMap<String, String>();
        if (vr.hasRefObjUsed()) {
            path = getRestrictedPath(path, restrictions, "kw", "", false, "");
            // XXX need a way to append the data needed from the field,
            // which we don't know until after we have got the information...
            refObj_view_map.put("docType", "docType");
            refObj_view_map.put("docId", "docId");
            refObj_view_map.put("docName", "docName");
            refObj_view_map.put("docNumber", "docNumber");
            refObj_view_map.put("sourceField", "sourceField");
            refObj_view_map.put("uri", "uri");
            refObj_view_map.put("refName", "refName");
            refObj_view_good.put("terms_docType", "docType");
            refObj_view_good.put("terms_docId", "docId");
            refObj_view_good.put("terms_docName", "docName");
            refObj_view_good.put("terms_docNumber", "docNumber");
            refObj_view_good.put("terms_sourceField", "sourceField");
            refObj_view_good.put("terms_refName", "refName");
            // XXX this might be the wrong record to pass to checkf or hard/soft delet listing
            JSONObject data = getRepeatableListView(storage, creds, cache, path, "authority-ref-doc-list/authority-ref-doc-item", "uri", true, vr, refObj_view_map);
            JSONArray recs = data.getJSONArray("listItems");
            if (data.has("pagination")) {
                out.put("pagination", data.getJSONObject("pagination"));
            }
            JSONArray items = new JSONArray();
            // String[] filepaths = (String[]) data.get("listItems");
            for (int i = 0; i < recs.length(); ++i) {
                String uri = recs.getJSONObject(i).getString("csid");
                // recs.getJSONObject(i).getString("csid");
                String filePath = uri;
                if (filePath != null && filePath.startsWith("/"))
                    filePath = filePath.substring(1);
                String[] parts = filePath.split("/");
                String recordurl = parts[0];
                Record thisr = vr.getSpec().getRecordByServicesUrl(recordurl);
                // Set up the glean maps required for this record. We need to reset these each time
                // through the loop, because every record could be a different type.
                Map<String, String> thisr_view_good = new HashMap<String, String>(refObj_view_good);
                Map<String, String> thisr_view_map = new HashMap<String, String>(refObj_view_map);
                Set<String> thisr_xxx_view_deurn = new HashSet<String>();
                Set<String> thisr_view_search_optional = new HashSet<String>();
                Map<String, List<String>> thisr_view_merge = new HashMap<String, List<String>>();
                Map<String, List<String>> thisr_view_useCsid = new HashMap<String, List<String>>();
                initializeGlean(thisr, thisr_view_good, thisr_view_map, thisr_xxx_view_deurn, thisr_view_search_optional, thisr_view_merge, thisr_view_useCsid);
                String csid = parts[parts.length - 1];
                JSONObject dataitem = miniViewRetrieveJSON(cache, creds, csid, "terms", uri, thisr, thisr_view_good, thisr_xxx_view_deurn, thisr_view_search_optional, thisr_view_merge, thisr_view_useCsid);
                dataitem.getJSONObject("summarylist").put("uri", filePath);
                String key = recs.getJSONObject(i).getString("sourceField");
                dataitem.getJSONObject("summarylist").put("sourceField", key);
                String fieldName = "unknown";
                String fieldSelector = "unknown";
                if (key.contains(":")) {
                    fieldName = key.split(":")[1];
                    // FIXME: We might remove the following if CSPACE-2909's fix makes this moot - ADR 2012-07-19
                    while (thisr.getFieldFullList(fieldName) instanceof Repeat || thisr.getFieldFullList(fieldName) instanceof Group) {
                        fieldName = ((Repeat) thisr.getFieldFullList(fieldName)).getChildren("GET")[0].getID();
                    }
                    Field fieldinstance = (Field) thisr.getFieldFullList(fieldName);
                    fieldSelector = fieldinstance.getSelector();
                }
                dataitem.put("csid", csid);
                dataitem.put("sourceFieldselector", fieldSelector);
                dataitem.put("sourceFieldName", fieldName);
                dataitem.put("sourceFieldType", dataitem.getJSONObject("summarylist").getString("docType"));
                dataitem.put("sourceFieldType", dataitem.getJSONObject("summarylist").getString("docType"));
                // items.put(csid+":"+key,dataitem);
                items.put(dataitem);
            }
            out.put("items", items);
        }
        return out;
    } catch (ConnectionException e) {
        log.error("failed to retrieve refObjs for " + path);
        JSONObject dataitem = new JSONObject();
        dataitem.put("csid", "");
        dataitem.put("sourceFieldselector", "Functionality Failed");
        dataitem.put("sourceFieldName", "Functionality Failed");
        dataitem.put("sourceFieldType", "Functionality Failed");
        dataitem.put("message", e.getMessage());
        out.put("Functionality Failed", dataitem);
        // return out;
        throw new UnderlyingStorageException("Connection problem" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
    } catch (UnsupportedEncodingException uae) {
        log.error("failed to retrieve refObjs for " + path);
        JSONObject dataitem = new JSONObject();
        dataitem.put("message", uae.getMessage());
        out.put("Functionality Failed", dataitem);
        throw new UnderlyingStorageException("Problem building query" + uae.getLocalizedMessage(), uae);
    }
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) HashMap(java.util.HashMap) JSONArray(org.json.JSONArray) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Repeat(org.collectionspace.chain.csp.schema.Repeat) UnderlyingStorageException(org.collectionspace.csp.api.persistence.UnderlyingStorageException) Field(org.collectionspace.chain.csp.schema.Field) JSONObject(org.json.JSONObject) Record(org.collectionspace.chain.csp.schema.Record) ArrayList(java.util.ArrayList) List(java.util.List) ConnectionException(org.collectionspace.chain.csp.persistence.services.connection.ConnectionException) HashSet(java.util.HashSet)

Example 12 with Group

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

the class SchemaStructure method makeASubRecordEntry.

/**
 * Do all the magic to make a sub record thing first is it nested directly
 * in the data or one level under
 *
 * @param out
 * @param fs
 * @param context
 * @throws JSONException
 */
protected void makeASubRecordEntry(JSONObject out, FieldSet fs, UISpecRunContext context, JSONObject outerlayer) throws JSONException {
    // create group item or field at the same level as parent fields - do not nest
    UISpecRunContext sub = context;
    if (!fs.getUISpecInherit()) {
        // default behaviour do group or field as expected by changing the context (adds more info to the selectors etc)
        sub = context.createChild();
        if (!fs.getSelectorAffix().equals("")) {
            sub.setUIAffix(fs.getSelectorAffix());
        }
        String sp = fs.getUISpecPrefix();
        if (sp != null)
            sub.setUIPrefix(sp);
    }
    Record subrecord = fs.usesRecordId();
    Boolean repeated = false;
    if (fs.getParent() instanceof Repeat || (fs instanceof Repeat && !(fs instanceof Group))) {
        repeated = true;
    }
    if (outerlayer == null) {
        outerlayer = out;
    }
    if (fs instanceof Group) {
        Group gp = (Group) fs;
        if (gp.isGrouped()) {
            sub.setPad(false);
        }
    }
    actualSubRecordField(out, fs, sub, subrecord, repeated, outerlayer);
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) Record(org.collectionspace.chain.csp.schema.Record) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 13 with Group

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

the class UISchema method actualSubRecordField.

@Override
protected void actualSubRecordField(JSONObject out, FieldSet fs, UISpecRunContext context, Record subr, Boolean repeated, JSONObject parent) throws JSONException {
    if (fs instanceof Group) {
        Group gp = (Group) fs;
        if (!gp.isGrouped()) {
            makeASubRecord(subr, out, repeated, context, parent);
            return;
        }
    }
    JSONObject insidebit = new JSONObject();
    makeASubRecord(subr, insidebit, repeated, context, parent);
    JSONObject chooser = new JSONObject();
    actualSchemaObject("object", null, insidebit, null, chooser);
    out.put(getSelector(fs, context), chooser);
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) JSONObject(org.json.JSONObject)

Example 14 with Group

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

the class UISpec method actualRepeatNonSiblingEntry.

/**
 * Overwrite with the output you need for the thing you are doing.
 * @param out
 * @param r
 * @param context
 * @param preProtoTree
 * @throws JSONException
 */
@Override
protected void actualRepeatNonSiblingEntry(JSONObject out, Repeat r, UISpecRunContext context, JSONObject preProtoTree) throws JSONException {
    JSONArray decorators = new JSONArray();
    JSONObject content = new JSONObject();
    JSONObject options = new JSONObject();
    JSONObject expander = new JSONObject();
    expander.put("type", "fluid.noexpand");
    expander.put("tree", preProtoTree);
    JSONObject repeatTree = new JSONObject();
    repeatTree.put("expander", expander);
    if (r.getParent() instanceof Record) {
        options.put("elPath", displayAsveryplainWithoutEnclosure(r, context));
    } else {
        options.put("elPath", r.getID());
        options.put("root", "{row}");
    }
    options.put("repeatTree", repeatTree);
    // is this a uispec for search - if so no primary tags wanted
    if (r.getSearchType().startsWith("repeator") && this.spectype.equals("search")) {
        options.put("hidePrimary", true);
    }
    JSONObject decorator = getDecorator("fluid", null, "cspace.makeRepeatable", options, r.isReadOnly());
    decorators.put(decorator);
    content.put(DECORATORS_KEY, decorators);
    String selector = getSelector(r, context);
    // CSPACE-2619 scalar repeatables are different from group repeats
    if (r.getChildren("").length == 1) {
        FieldSet child = getFirstChild(r);
        if (child instanceof Field || child instanceof Group) {
            selector = getSelector(child, context);
        }
    }
    if (r.isExpander()) {
        JSONArray expanders = out.getJSONArray("expander");
        makeExpander(out, expanders);
    } else {
        out.put(selector, content);
    }
}
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) JSONArray(org.json.JSONArray) Record(org.collectionspace.chain.csp.schema.Record)

Example 15 with Group

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

the class UISpec method actualStructuredDate.

/**
 * Overwrite with output you need for this thing you are doing
 * @param fs
 * @param out
 * @param sub
 * @param subexpander
 * @param subitems
 * @param options
 * @throws JSONException
 */
@Override
protected void actualStructuredDate(FieldSet fs, JSONObject out, UISpecRunContext sub, JSONObject subexpander, Record subitems, JSONObject options) throws JSONException {
    out.put("value", displayAsveryplain("fields." + fs.getPrimaryKey()));
    Boolean truerepeat = false;
    FieldParent fsp = fs.getParent();
    if (fsp instanceof Repeat && !(fsp instanceof Group)) {
        // remove bogus repeats used in search
        Repeat rp = (Repeat) fsp;
        if (isATrueRepeat(rp)) {
            String prefix = "";
            if (fs instanceof Group && !((Group) fs).getXxxServicesNoRepeat()) {
                // XXX refacetor with some idea of UIContext.
                // add a prefix for nested non repeatables
                prefix = fs.getID() + ".";
            }
            truerepeat = true;
            for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
                subexpander.put(getSelector(fs2, sub), prefix + fs2.getID());
            }
            if (fs instanceof Group && !((Group) fs).getXxxServicesNoRepeat()) {
                options.put("elPath", prefix + fs.getPrimaryKey());
                options.put("root", "{row}");
                out.put("value", displayAsveryplain("{row}." + prefix + fs.getPrimaryKey()));
            } else if (fs instanceof Repeat) {
                options.put("elPath", fs.getPrimaryKey());
                options.put("root", "{row}");
                out.put("value", displayAsveryplain("{row}." + fs.getPrimaryKey()));
            }
        }
    }
    if (!truerepeat) {
        options.put("elPath", "fields." + fs.getPrimaryKey());
        for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
            if (!fs2.getSearchType().equals("false") || !this.spectype.equals("search")) {
                // only hide if this is a search uispec - need to extend to all uispec stuff
                subexpander.put(getSelector(fs2, sub), displayAsveryplainWithoutEnclosure(fs2, sub));
            }
        }
    }
    options.put("elPaths", subexpander);
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) FieldParent(org.collectionspace.chain.csp.schema.FieldParent) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Repeat(org.collectionspace.chain.csp.schema.Repeat)

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