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