Search in sources :

Example 31 with Field

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

the class SchemaStructure method makeAGroupField.

/**
 * Do all the magic to make a GroupField
 *
 * @param fs
 * @param context
 * @throws JSONException
 */
protected JSONObject makeAGroupField(FieldSet fs, UISpecRunContext context) throws JSONException {
    JSONObject out = new JSONObject();
    if (fs instanceof Field || fs instanceof Repeat) {
        JSONObject subexpander = new JSONObject();
        JSONObject options = new JSONObject();
        String[] parts = fs.getUIType().split("/");
        Record subitems = fs.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
        UISpecRunContext sub = context.createChild();
        sub.setUIPrefix(fs.getID());
        sub.setPad(false);
        if (isAStructureDate(fs)) {
            makeAStructureDate(fs, out, subexpander, options, subitems, sub, context);
        } else if (fs.isASelfRenderer()) {
            makeASelfRenderer(fs, context, out, subexpander, options, subitems, sub);
        } else {
            makeAOtherGroup(fs, out, subexpander, options, subitems, sub);
        }
    }
    return out;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) JSONObject(org.json.JSONObject) Repeat(org.collectionspace.chain.csp.schema.Repeat) Record(org.collectionspace.chain.csp.schema.Record)

Example 32 with Field

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

the class ServicesXsd method generateDataEntry.

private void generateDataEntry(Element ele, FieldSet fs, Namespace ns, Element root, Boolean isRepeat) {
    if (fs instanceof Field) {
        // <xs:element name="csid" type="xs:string"/>
        Element field = ele.addElement(new QName("element", ns));
        field.addAttribute("name", fs.getServicesTag());
        field.addAttribute("type", "xs:string");
        if (isRepeat) {
            field.addAttribute("minOccurs", "0");
            field.addAttribute("maxOccurs", "unbounded");
        }
    }
    if (fs instanceof Repeat) {
        Repeat rfs = (Repeat) fs;
        String listName = rfs.getServicesTag();
        if (rfs.hasServicesParent()) {
            // group repeatable
            // <xs:element name="objectNameList" type="ns:objectNameList"/>
            Element field = ele.addElement(new QName("element", ns));
            field.addAttribute("name", rfs.getServicesParent()[0]);
            Namespace groupns = new Namespace("ns", "");
            field.addAttribute("type", "ns:" + rfs.getServicesParent()[0]);
        } else {
            // single repeatable
            // <xs:element name="responsibleDepartments"
            // type="responsibleDepartmentList"/>
            Element field = ele.addElement(new QName("element", ns));
            field.addAttribute("name", rfs.getServicesTag());
            listName = rfs.getChildren("")[0].getServicesTag() + "List";
            field.addAttribute("type", listName);
        }
        generateRepeat(rfs, root, ns, listName);
    }
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) QName(org.dom4j.QName) Element(org.dom4j.Element) Repeat(org.collectionspace.chain.csp.schema.Repeat) Namespace(org.dom4j.Namespace)

Example 33 with Field

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

the class UISpec method actualRichText.

/**
 * Generate UISpec JSON needed by the UI to show a rich text editor
 * @param f
 * @param context
 * @return
 * @throws JSONException
 */
private JSONObject actualRichText(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
    JSONObject out = new JSONObject();
    Field f = (Field) fs;
    JSONObject decorator = getDecorator("fluid", null, "cspace.richTextEditor", null, f.isReadOnly());
    if (!f.isRefactored()) {
        if (f.hasContainer()) {
            decorator.put("container", getSelector(f, context));
        }
    }
    if (decorators == null) {
        decorators = new JSONArray();
    }
    decorators.put(decorator);
    out.put(DECORATORS_KEY, decorators);
    out.put("value", actualFieldEntry(f, context));
    return out;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 34 with Field

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

the class UISpec method actualDate.

/**
 * This is a bit of JSON needed by the UI so they display dates in the UIspec
 * @param f
 * @param context
 * @return
 * @throws JSONException
 */
private JSONObject actualDate(FieldSet fs, UISpecRunContext context, JSONArray decorators) throws JSONException {
    JSONObject out = new JSONObject();
    Field f = (Field) fs;
    JSONObject decorator = getDecorator("fluid", null, "cspace.datePicker", null, f.isReadOnly());
    if (!f.isRefactored()) {
        if (f.hasContainer()) {
            decorator.put("container", getSelector(f, context));
        }
    }
    if (decorators == null) {
        decorators = new JSONArray();
    }
    decorators.put(decorator);
    out.put(DECORATORS_KEY, decorators);
    out.put("value", actualFieldEntry(f, context));
    return out;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 35 with Field

use of org.collectionspace.chain.csp.schema.Field 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)

Aggregations

Field (org.collectionspace.chain.csp.schema.Field)45 JSONObject (org.json.JSONObject)37 JSONArray (org.json.JSONArray)26 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)22 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)14 Group (org.collectionspace.chain.csp.schema.Group)12 Record (org.collectionspace.chain.csp.schema.Record)12 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)9 Repeat (org.collectionspace.chain.csp.schema.Repeat)9 JSONException (org.json.JSONException)9 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)7 Document (org.dom4j.Document)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)6 Element (org.dom4j.Element)6 ArrayList (java.util.ArrayList)5 Instance (org.collectionspace.chain.csp.schema.Instance)5 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)5 HashMap (java.util.HashMap)4 Option (org.collectionspace.chain.csp.schema.Option)4