use of org.collectionspace.chain.csp.schema.Record 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.Record in project application by collectionspace.
the class RecordTraverser method subTraverser.
private JSONObject subTraverser(Storage storage, UIRequest request, String key, Integer numInstances, String base, String instance, JSONObject restriction) throws JSONException, UIException, ExistException, UnimplementedException, UnderlyingStorageException {
JSONObject results = new JSONObject();
Record myr = this.spec.getRecord(base);
if (myr.isType("record") || myr.isType("searchall")) {
this.searcher = new RecordSearchList(myr, RecordSearchList.MODE_SEARCH);
// Need to set up maps for recordtype.
this.searcher.configure(this.spec);
results = this.searcher.getJSON(storage, restriction, key, base);
} else if (myr.isType("authority")) {
if (myr.hasInstance(instance)) {
Instance myn = myr.getInstance(instance);
this.avsearcher = new AuthoritiesVocabulariesSearchList(myn, true);
} else {
this.avsearcher = new AuthoritiesVocabulariesSearchList(myr, true);
}
if (this.avsearcher != null) {
results = this.avsearcher.getJSON(storage, restriction, key);
}
}
// cache for record traverser
if (results.has("pagination") && results.getJSONObject("pagination").has("separatelists")) {
GenericSearch.createTraverser(request, base, instance, results, restriction, key, numInstances);
}
return results;
}
use of org.collectionspace.chain.csp.schema.Record 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;
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class XmlJsonConversion method addSubRecordToXml.
private static void addSubRecordToXml(Element root, Field field, JSONObject in, String operation) throws JSONException, UnderlyingStorageException {
String[] parts = field.getUIType().split("/");
Record subitems = field.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
// hard coding the section here can not be a good thing....
if (subitems.getAllServiceFieldTopLevel(operation, "common").length > 0) {
for (FieldSet f : subitems.getAllServiceFieldTopLevel(operation, "common")) {
addFieldSetToXml(root, f, in, "common", operation);
}
// log.debug(root.asXML());
// return doc;
}
}
use of org.collectionspace.chain.csp.schema.Record in project application by collectionspace.
the class XmlJsonConversion method addGroupToJson.
private static void addGroupToJson(JSONObject out, Element root, Group f, String operation, JSONObject tempSon, String csid, String ims_url) throws JSONException {
String nodeName = f.getServicesTag();
if (f.hasServicesParent()) {
nodeName = f.getfullID();
// XXX hack because of weird repeats in accountroles permroles etc
if (f.getServicesParent().length == 0) {
nodeName = f.getID();
}
}
if (!f.isGrouped()) {
Element el = root;
if (f.getUIType().startsWith("groupfield") && f.getUIType().contains("selfrenderer")) {
String[] parts = f.getUIType().split("/");
Record subitems = f.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
JSONObject temp = new JSONObject();
for (FieldSet fs : subitems.getAllServiceFieldTopLevel(operation, "common")) {
addFieldSetToJson(temp, el, fs, operation, tempSon, csid, ims_url);
}
out.put(f.getID(), temp);
return;
}
if (f.getUIType().startsWith("groupfield")) {
String[] parts = f.getUIType().split("/");
Record subitems = f.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
JSONObject temp = new JSONObject();
for (FieldSet fs : subitems.getAllServiceFieldTopLevel(operation, "common")) {
addFieldSetToJson(temp, el, fs, operation, tempSon, csid, ims_url);
}
out.put(f.getID(), temp);
}
} else {
List<?> nodes = root.selectNodes(nodeName);
if (nodes.size() == 0)
return;
// Only first element is important in group container
for (Object repeatcontainer : nodes) {
Element container = (Element) repeatcontainer;
JSONArray repeatitem = addRepeatedNodeToJson(container, f, operation, tempSon);
JSONObject repeated = repeatitem.getJSONObject(0);
out.put(f.getID(), repeated);
}
}
}
Aggregations