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);
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations