Search in sources :

Example 1 with Repeat

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

the class SchemaStructure method actualSelfRenderer.

/**
 * render the mark up needed by the UISpec for self renderers
 *
 * @param fs
 * @param context
 * @param subexpander
 * @param subitems
 * @param options
 * @throws JSONException
 */
protected void actualSelfRenderer(FieldSet fs, UISpecRunContext context, JSONObject subexpander, Record subitems) throws JSONException {
    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)) {
            truerepeat = true;
            for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
                whatIsThisFieldSet(subexpander, fs2, context);
            }
            makeAllRecordMessageKey(context, subexpander, subitems);
        }
    }
    if (!truerepeat) {
        for (FieldSet fs2 : subitems.getAllFieldTopLevel("")) {
            whatIsThisFieldSet(subexpander, fs2, context);
        }
        makeAllRecordMessageKey(context, subexpander, subitems);
    }
}
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)

Example 2 with Repeat

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

the class UISpec method generateComputedField.

/**
 * Generate the JSON needed by the UI to create a computed field.
 * @param f
 * @param context
 * @return
 * @throws JSONException
 */
protected JSONObject generateComputedField(FieldSet fs, UISpecRunContext context) throws JSONException {
    Field f = (Field) fs;
    JSONObject out = new JSONObject();
    JSONArray decorators = new JSONArray();
    JSONObject options = new JSONObject();
    String type = f.getDataType();
    if (type.equals("")) {
        type = "string";
    }
    options.put("type", type);
    options.put("label", f.getLabel());
    options.put("readOnly", f.isReadOnly());
    if (StringUtils.isNotEmpty(f.getUIFunc())) {
        options.put("func", f.getUIFunc());
    }
    if (StringUtils.isNotEmpty(f.getUIArgs())) {
        options.put("args", f.getUIArgs().split(","));
    }
    String root = "";
    String elPath = "";
    // really needs to be refactored so it doesn't have to be repeated here.
    if (f.getParent().isExpander() || f.isRepeatSubRecord()) {
        root = "{row}";
        String[] paths = f.getIDPath();
        elPath = paths[paths.length - 1];
    } else if (f.getParent() instanceof Repeat) {
        // remove bogus repeats used in search
        Repeat rp = (Repeat) f.getParent();
        if (!rp.getSearchType().equals("repeator") && !this.spectype.equals("search")) {
            root = "{row}";
            String[] paths = f.getIDPath();
            elPath = paths[paths.length - 1];
        } else if (this.spectype.equals("search")) {
            root = "{row}";
            String[] paths = f.getIDPath();
            elPath = paths[paths.length - 1];
        } else {
            elPath = displayAsveryplainWithoutEnclosure(f, context);
        }
    } else {
        elPath = displayAsveryplainWithoutEnclosure(f, context);
    }
    options.put("root", root);
    options.put("elPath", elPath);
    JSONObject decorator = getDecorator("fluid", null, "cspace.computedField", options, f.isReadOnly());
    if (!f.isRefactored()) {
        if (f.hasContainer()) {
            decorator.put("container", getSelector(f, context));
        }
    }
    decorators.put(decorator);
    out.put("decorators", 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) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 3 with Repeat

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

the class MakeXsd method generateDataEntry.

private void generateDataEntry(Element ele, FieldSet fs, Namespace ns, Element root, Boolean unbounded) throws Exception {
    // 
    if (fs.isInServices() == false) {
        sendToDebugLog(String.format("Field set is not part of the Services schema %s:%s", fs.getSection(), fs.getID()));
        return;
    }
    String sectionName = fs.getSection();
    String listName = fs.getServicesTag();
    // to the "GroupField's" structured types -e.g., structuredData and dimension types
    if (fs.isAGroupField() == true) {
        String groupFieldType = generateFieldGroup(fs, ele, ns, root);
        fs.setServicesType(groupFieldType);
    }
    if (fs.isAGroupField() && fs.isAStructureDate() == false) {
        // 
        return;
    }
    if (fs instanceof Field || fs instanceof Group) {
        String servicesTag = fs.getServicesTag();
        if (isOrphaned(fs) == true) {
            // If we have a Repeat with a single child that is a "Group" with a "ui-type=groupfield/foo" attribute.
            servicesTag = fs.getParentID();
            unbounded = true;
        }
        // <xs:element name="csid" type="xs:string"/>
        Element field = ele.addElement(new QName("element", ns));
        if (fs.isAGroupField() && fs.isAStructureDate() == false) {
            servicesTag = fs.getServicesType();
        }
        field.addAttribute("name", servicesTag);
        String servicesType = fs.getServicesType();
        String fieldType = "xs:string";
        if (servicesType != null) {
            fieldType = servicesType;
        }
        field.addAttribute("type", fieldType);
        if (unbounded == true) {
            field.addAttribute("minOccurs", "0");
            field.addAttribute("maxOccurs", "unbounded");
        }
    }
    if (isRepeatType(fs) == true) {
        // Has to be a Repeat class instance and not any descendant (e.g. not a Group instance)
        Element fieldElement = root;
        Repeat rfs = (Repeat) fs;
        if (rfs.hasServicesParent()) {
            // group repeatable
            // <xs:element name="objectNameList" type="ns:objectNameList"/>
            Element newField = ele.addElement(new QName("element", ns));
            newField.addAttribute("name", rfs.getServicesParent()[0]);
            String fieldType = rfs.getServicesParent()[0];
            newField.addAttribute("type", FieldSet.NS + fieldType);
        } else {
            // single repeatable
            // <xs:element name="responsibleDepartments"
            // type="responsibleDepartmentList"/>
            fieldElement = ele.addElement(new QName("element", ns));
            fieldElement.addAttribute("name", rfs.getServicesTag());
            FieldSet[] fieldSetArray = rfs.getChildren("");
            if (fieldSetArray != null && fieldSetArray.length > 0) {
                if (rfs.isServicesAnonymousType() == true) {
                    // Ends up creating an embedded anonymous complex type
                    listName = null;
                } else {
                    listName = rfs.getChildren("")[0].getServicesTag() + "List";
                    fieldElement.addAttribute("type", FieldSet.NS + listName);
                    fieldElement = fieldElement.getParent();
                }
            } else {
                // If there is no children to define the type, there better be an explicit services type declaration
                String servicesType = rfs.getServicesType();
                if (servicesType != null) {
                    fieldElement.addAttribute("type", servicesType);
                } else {
                    sendToErrorLog("Repeat/Group fieldset child array was null or the first element was null. Field attribute name: " + fieldElement.toString());
                }
            }
        }
        generateRepeat(rfs, fieldElement, listName, ns, root);
    }
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) Group(org.collectionspace.chain.csp.schema.Group) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) QName(org.dom4j.QName) Element(org.dom4j.Element) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 4 with Repeat

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

the class ConfiguredVocabStorage method getXPathForField.

/**
 * Returns an XPath-conformant string that specifies the full (X)path to this field.
 * May recurse to handle nested fields. Will choose primary, in lists (i.e, 1st element)
 * This should probably live in Field.java, not here (but needs to be in both Field.java
 * and Repeat.java - do I hear "Base Class"?!?!)
 *
 * @param fieldSet the containing fieldSet
 * @return NXQL conformant specifier.
 */
public static String getXPathForField(FieldSet fieldSet) {
    String specifier = fieldSet.getServicesTag();
    // leaf, and the first part is held in the "services parent"
    if (fieldSet.hasServicesParent()) {
        // Prepend the services parent field, and make the child a wildcard
        String[] svcsParent = fieldSet.getServicesParent();
        if (svcsParent[0] != null && !svcsParent[0].isEmpty()) {
            specifier = svcsParent[0] + "/";
            // Note that we do not handle paths more the 2 in length - makes no sense
            if (svcsParent.length < 2) {
                specifier += XPATH_GENERIC_FIRST_EL;
            } else if (svcsParent[1] == null) {
                // Work around ridiculous hack/nonsense in Repeat init
                specifier += fieldSet.getServicesTag();
            } else {
                specifier += svcsParent[1];
            }
            specifier += XPATH_FIRST_EL;
        }
    }
    FieldParent parent = fieldSet.getParent();
    // Assume we are recursing until we see otherwise
    boolean isRootLevelField = false;
    if (parent instanceof Record) {
        // A simple reference to base field.
        isRootLevelField = true;
        log.debug("Specifier for root-level field: " + specifier + " is: " + specifier);
    } else {
        FieldSet parentFieldSet = (FieldSet) parent;
        // "repeator" marks things for some expansion - not handled here (?)
        if (parentFieldSet.getSearchType().equals("repeator")) {
            isRootLevelField = true;
        } else {
            // First, recurse to get the fully qualified path to the parent.
            if (log.isDebugEnabled()) {
                String parentID = parentFieldSet.getID();
                log.debug("Recursing for parent: " + parentID);
            }
            specifier = getXPathForField(parentFieldSet);
            // Is parent a scalar list or a complex list?
            Repeat rp = (Repeat) parentFieldSet;
            FieldSet[] children = rp.getChildren("");
            int size = children.length;
            // or a complex schema from which only 1 field is used, will break this.
            if (size > 1) {
                // The parent is a complex schema, not just a scalar repeat
                // Append the field name to build an XPath-like specifier.
                specifier += "/" + fieldSet.getServicesTag();
            } else {
            // Leave specifier as is. We just search on the parent name,
            // as the backend is smart about scalar lists.
            }
        }
        log.debug("Specifier for non-leaf field: " + fieldSet.getServicesTag() + " is: " + specifier);
    }
    if (isRootLevelField) {
    // TODO - map leaf names like "titleGroupList/titleGroup" to "titleGroupList/*"
    }
    return specifier;
}
Also used : FieldParent(org.collectionspace.chain.csp.schema.FieldParent) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Record(org.collectionspace.chain.csp.schema.Record) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 5 with Repeat

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

the class ServiceBindingsGeneration method getServiceTableName.

private String getServiceTableName(FieldSet fieldSet, Record record, Boolean isAuthority) {
    String result = record.getServicesSchemaName(fieldSet.getSection());
    if (isAuthority == true) {
        result = record.getAuthoritySchemaName();
    }
    // 
    // If the parent is a Repeat instance then we need to use a different method to
    // get the table name.
    // 
    FieldParent parent = fieldSet.getParent();
    if (parent instanceof Repeat) {
        Repeat fieldParent = (Repeat) parent;
        result = fieldParent.getServicesTag().toLowerCase();
    } else {
    }
    return result;
}
Also used : FieldParent(org.collectionspace.chain.csp.schema.FieldParent) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Aggregations

Repeat (org.collectionspace.chain.csp.schema.Repeat)19 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)11 Field (org.collectionspace.chain.csp.schema.Field)9 Group (org.collectionspace.chain.csp.schema.Group)9 Record (org.collectionspace.chain.csp.schema.Record)7 JSONObject (org.json.JSONObject)7 FieldParent (org.collectionspace.chain.csp.schema.FieldParent)6 JSONArray (org.json.JSONArray)6 Element (org.dom4j.Element)5 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)3 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)3 QName (org.dom4j.QName)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)2 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)2 UISpecRunContext (org.collectionspace.chain.csp.schema.UISpecRunContext)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1