Search in sources :

Example 11 with Repeat

use of org.collectionspace.chain.csp.schema.Repeat 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 12 with Repeat

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

the class UISpec method actualENUMField.

/**
 * output the ENUM markup for the UISpec
 * @param f
 * @param context
 * @param decorators
 * @return
 * @throws JSONException
 */
@Override
protected Object actualENUMField(Field f, UISpecRunContext context, JSONArray decorators) throws JSONException {
    JSONObject out = new JSONObject();
    JSONObject options = new JSONObject();
    if (f.getParent() instanceof Repeat && (isATrueRepeat((Repeat) f.getParent()))) {
        options.put("elPath", f.getID());
        options.put("root", "{row}");
    } else {
        options.put("elPath", displayAsveryplainWithoutEnclosure(f, context));
    }
    options.put("termListType", f.getID());
    JSONObject decorator = getDecorator("fluid", null, "cspace.termList", options, f.isReadOnly());
    if (decorators == null) {
        decorators = new JSONArray();
    }
    decorators.put(decorator);
    out.put(DECORATORS_KEY, decorators);
    return out;
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 13 with Repeat

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

Example 14 with Repeat

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

the class GenericSearch method getSearchSpecifierForField.

/**
 * Returns an NXQL-conformant string that specifies the full (X)path to this field.
 * May recurse to handle nested fields.
 * This should probably live in Field.java, not here.
 *
 * @param fieldname the name of the field
 * @param fieldSet the containing fieldSet
 * @return NXQL conformant specifier.
 */
public static String getSearchSpecifierForField(FieldSet fieldSet, Boolean isOrderNotSearch) {
    // String specifier = fieldname;	// default is just the simple field name
    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] + (isOrderNotSearch ? "/0" : "/*");
        }
    }
    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 {
            // Otherwise, we're dealing with some amount of nesting.
            // First, recurse to get the fully qualified path to the parent.
            String parentID = parentFieldSet.getID();
            log.debug("Recursing for parent: " + parentID);
            specifier = getSearchSpecifierForField(parentFieldSet, isOrderNotSearch);
            // 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 if (isOrderNotSearch) {
                specifier += "/0";
            } 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 15 with Repeat

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

the class XmlJsonConversion method FieldListFROMConfig.

private static List<String> FieldListFROMConfig(FieldSet f, String operation) {
    List<String> children = new ArrayList<String>();
    if (f.getUIType().startsWith("groupfield")) {
        String[] parts = f.getUIType().split("/");
        Record subitems = f.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
        for (FieldSet fs : subitems.getAllFieldTopLevel(operation)) {
            children.add(fs.getID());
        }
    }
    if (f instanceof Repeat) {
        for (FieldSet a : ((Repeat) f).getChildren(operation)) {
            if (a instanceof Repeat && ((Repeat) a).hasServicesParent()) {
                children.add(((Repeat) a).getServicesParent()[0]);
            } else if (a.getUIType().startsWith("groupfield")) {
                // structuredates etc
                String[] parts = a.getUIType().split("/");
                Record subitems = a.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
                if (a instanceof Group) {
                    if (((Group) a).getXxxServicesNoRepeat()) {
                        for (FieldSet fs : subitems.getAllFieldTopLevel(operation)) {
                            if (fs instanceof Repeat && ((Repeat) fs).hasServicesParent()) {
                                children.add(((Repeat) fs).getServicesParent()[0]);
                            } else {
                                children.add(fs.getID());
                            }
                        }
                    } else {
                        children.add(a.getID());
                    }
                }
            } else {
                children.add(a.getID());
            }
        }
    }
    if (f instanceof Group) {
        for (FieldSet ab : ((Group) f).getChildren(operation)) {
            children.add(ab.getID());
        }
    }
    if (f instanceof Field) {
    }
    return children;
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) Field(org.collectionspace.chain.csp.schema.Field) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) ArrayList(java.util.ArrayList) Record(org.collectionspace.chain.csp.schema.Record) 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