Search in sources :

Example 1 with FieldParent

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

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

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

Example 4 with FieldParent

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

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

Aggregations

FieldParent (org.collectionspace.chain.csp.schema.FieldParent)6 Repeat (org.collectionspace.chain.csp.schema.Repeat)6 FieldSet (org.collectionspace.chain.csp.schema.FieldSet)4 Group (org.collectionspace.chain.csp.schema.Group)2 Record (org.collectionspace.chain.csp.schema.Record)2