Search in sources :

Example 31 with FieldSet

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

the class SchemaStructure method makeASubRecord.

/**
 * Do all the real magic to make a sub record thing
 *
 * @param subr
 * @param out
 * @param repeated
 * @param context
 * @param parent
 * @throws JSONException
 */
protected void makeASubRecord(Record subr, JSONObject out, Boolean repeated, UISpecRunContext context, JSONObject parent) throws JSONException {
    for (FieldSet fs2 : subr.getAllFieldTopLevel("")) {
        if (repeated) {
            fs2.setRepeatSubRecord(true);
        }
        whatIsThisFieldSet(out, fs2, context);
        fs2.setRepeatSubRecord(false);
    }
    Structure s = subr.getStructure(this.structureview);
    if (s.showMessageKey()) {
        makeAllRecordMessageKey(context, parent, subr);
    }
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Structure(org.collectionspace.chain.csp.schema.Structure)

Example 32 with FieldSet

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

the class SchemaStructure method makeARepeatNonSiblingEntry.

/**
 * Do all the magic for a Repeat that wants to be rendered like siblings
 *
 * @param out
 * @param r
 * @param context
 * @throws JSONException
 */
protected void makeARepeatNonSiblingEntry(JSONObject out, Repeat r, UISpecRunContext context) throws JSONException {
    if (isExpander(r)) {
        actualRepeatExpanderEntry(out, r, context);
    } else {
        JSONObject preProtoTree = new JSONObject();
        if (isARepeatingSubRecord(r)) {
            makeASubRecordEntry(preProtoTree, r, context, out);
        } else {
            for (FieldSet child : r.getChildren("")) {
                whatIsThisFieldSet(preProtoTree, child, context);
            }
        }
        actualRepeatNonSiblingEntry(out, r, context, preProtoTree);
    }
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject)

Example 33 with FieldSet

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

the class ServicesXsd method serviceschema.

private String serviceschema(Storage s, String path) throws UIException {
    if (path != null) {
        section = path;
    }
    Document doc = DocumentFactory.getInstance().createDocument();
    Namespace ns = new Namespace("xs", "http://www.w3.org/2001/XMLSchema");
    String[] parts = record.getServicesRecordPath(section).split(":", 2);
    String[] rootel = parts[1].split(",");
    Element root = doc.addElement(new QName("schema", new Namespace("xs", "http://www.w3.org/2001/XMLSchema")));
    root.addAttribute("xmlns:ns", rootel[0]);
    root.addAttribute("xmlns", rootel[0]);
    root.addAttribute("targetNamespace", rootel[0]);
    root.addAttribute("version", "0.1");
    for (FieldSet fs : record.getAllFieldTopLevel("")) {
        generateDataEntry(root, fs, ns, root, false);
    }
    generateSearchList(root, ns);
    return doc.asXML();
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) QName(org.dom4j.QName) Element(org.dom4j.Element) Document(org.dom4j.Document) Namespace(org.dom4j.Namespace)

Example 34 with FieldSet

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

the class UISchema method UISchemaRepeatItem.

/**
 * UISchema specific idea of a repeatable item
 * @param out
 * @param r
 * @param context
 * @throws JSONException
 */
private void UISchemaRepeatItem(JSONObject out, Repeat r, UISpecRunContext context) throws JSONException {
    JSONObject items = new JSONObject();
    JSONObject structuredate = new JSONObject();
    String selector = getSelector(r, context);
    JSONObject preProtoTree = new JSONObject();
    if (isARepeatingSubRecord(r)) {
        makeASubRecordEntry(preProtoTree, r, context, out);
        preProtoTree = preProtoTree.getJSONObject(selector).getJSONObject("properties");
    } else {
        Integer numChild = r.getChildren("").length;
        for (FieldSet child : r.getChildren("")) {
            whatIsThisFieldSet(preProtoTree, child, context);
            if (isAStructureDate(child)) {
                Boolean truerepeat = isATrueRepeat(r);
                if (!truerepeat) {
                    structuredate = preProtoTree.getJSONObject(getSelector(child, context)).getJSONObject("properties");
                    preProtoTree.remove(getSelector(child, context));
                    Iterator<?> rit = structuredate.keys();
                    while (rit.hasNext()) {
                        String key = (String) rit.next();
                        preProtoTree.put(key, structuredate.get(key));
                    }
                } else if (numChild != 1 && preProtoTree.has("properties")) {
                    structuredate.put("properties", preProtoTree.getJSONObject("properties"));
                    if (preProtoTree.has("type")) {
                        structuredate.put("type", preProtoTree.getString("type"));
                        preProtoTree.remove("type");
                    } else {
                        structuredate.put("type", "object");
                    }
                    preProtoTree.remove("properties");
                    preProtoTree.put(getSelector(child, context), structuredate);
                }
            }
        }
    }
    // actualRepeatNonSiblingEntry(out, r, context, preProtoTree);//XXX ??? do I need this?
    if (preProtoTree.has("properties")) {
        preProtoTree = preProtoTree.getJSONObject("properties");
    }
    if (r.hasPrimary()) {
        JSONObject output = new JSONObject();
        actualSchemaObject("boolean", true, null, null, output);
        preProtoTree.put("_primary", output);
    }
    actualSchemaObject("object", null, preProtoTree, null, items);
    JSONObject output = new JSONObject();
    actualSchemaObject("array", null, null, items, output);
    out.put(selector, output);
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject)

Example 35 with FieldSet

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

the class UISpec method generateUISpecListSection.

protected JSONObject generateUISpecListSection(Structure s, UISpecRunContext context) throws JSONException {
    JSONObject out = new JSONObject();
    String id = s.getListSectionName();
    if (s.getFieldTopLevel(id) != null) {
        FieldSet fs = s.getFieldTopLevel(id);
        whatIsThisFieldSet(out, fs, context);
    }
    return out;
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) JSONObject(org.json.JSONObject)

Aggregations

FieldSet (org.collectionspace.chain.csp.schema.FieldSet)62 JSONObject (org.json.JSONObject)36 Record (org.collectionspace.chain.csp.schema.Record)23 Field (org.collectionspace.chain.csp.schema.Field)22 JSONArray (org.json.JSONArray)22 Element (org.dom4j.Element)19 Group (org.collectionspace.chain.csp.schema.Group)17 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)17 JSONException (org.json.JSONException)13 Repeat (org.collectionspace.chain.csp.schema.Repeat)11 Document (org.dom4j.Document)11 QName (org.dom4j.QName)11 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)9 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ArrayList (java.util.ArrayList)6 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)6 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)5 Spec (org.collectionspace.chain.csp.schema.Spec)5