use of org.collectionspace.chain.csp.schema.Repeat in project application by collectionspace.
the class GenericStorage method refViewRetrieveJSON.
/**
* get data needed for terms Used block of a record
* @param creds
* @param cache
* @param path
* @return
* @throws ExistException
* @throws UnimplementedException
* @throws UnderlyingStorageException
* @throws JSONException
* @throws UnsupportedEncodingException
*/
public JSONObject refViewRetrieveJSON(ContextualisedStorage storage, CSPRequestCredentials creds, CSPRequestCache cache, String path, JSONObject restrictions) throws ExistException, UnimplementedException, UnderlyingStorageException, JSONException, UnsupportedEncodingException {
try {
JSONObject out = new JSONObject();
JSONObject pagination = new JSONObject();
JSONObject listitems = new JSONObject();
// not all the records need a reference, look in cspace-config.xml for which that don't
if (r.hasTermsUsed()) {
path = getRestrictedPath(path, restrictions, "kw", "", false, "");
if (r.hasSoftDeleteMethod()) {
// XXX completely not the right thinsg to do but a good enough hack
path = softpath(path);
}
if (r.hasHierarchyUsed("screen")) {
path = hierarchicalpath(path);
}
ReturnedDocument all = conn.getXMLDocument(RequestMethod.GET, path, null, creds, cache);
if (all.getStatus() != 200)
throw new ConnectionException("Bad request during identifier cache map update: status not 200", all.getStatus(), path);
Document list = all.getDocument();
// assumes consistency in service layer payloads - possible could configure this rather than hard code?
List<Node> nodes = list.selectNodes("authority-ref-list/*");
for (Node node : nodes) {
if (node.getName().equals("authority-ref-item")) {
if (!(node instanceof Element))
continue;
if (((Element) node).hasContent()) {
String key = ((Element) node).selectSingleNode("sourceField").getText();
String refname = ((Element) node).selectSingleNode("refName").getText();
String itemDisplayName = ((Element) node).selectSingleNode("itemDisplayName").getText();
String uri = "";
if (null != ((Element) node).selectSingleNode("uri")) {
// seems to be missing sometimes
uri = ((Element) node).selectSingleNode("uri").getText();
}
String fieldName = key;
if (key.split(":").length > 1) {
fieldName = key.split(":")[1];
}
Field fieldinstance = null;
if (r.getFieldFullList(fieldName) instanceof Repeat) {
Repeat rp = (Repeat) r.getFieldFullList(fieldName);
for (FieldSet a : rp.getChildren("GET")) {
if (a instanceof Field && a.hasAutocompleteInstance()) {
fieldinstance = (Field) a;
}
}
} else {
fieldinstance = (Field) r.getFieldFullList(fieldName);
}
if (fieldinstance != null) {
JSONObject data = new JSONObject();
data.put("sourceField", key);
data.put("itemDisplayName", itemDisplayName);
data.put("refname", refname);
data.put("uri", uri);
// JSONObject data=miniForURI(storage,creds,cache,refname,null,restrictions);
/*
if(!data.has("refid")){//incase of permissions errors try our best
data.put("refid",refname);
if(data.has("displayName")){
String itemDisplayName=((Element)node).selectSingleNode("itemDisplayName").getText();
String temp = data.getString("displayName");
data.remove("displayName");
data.put(temp, itemDisplayName);
}
}
*/
data.put("sourceFieldselector", fieldinstance.getSelector());
data.put("sourceFieldName", fieldName);
data.put("sourceFieldType", r.getID());
if (listitems.has(key)) {
JSONArray temp = listitems.getJSONArray(key).put(data);
listitems.put(key, temp);
} else {
JSONArray temp = new JSONArray();
temp.put(data);
listitems.put(key, temp);
}
}
}
} else {
pagination.put(node.getName(), node.getText());
}
}
}
out.put("pagination", pagination);
out.put("listItems", listitems);
return out;
} catch (ConnectionException e) {
throw new UnderlyingStorageException("Connection problem" + e.getLocalizedMessage(), e.getStatus(), e.getUrl(), e);
}
}
use of org.collectionspace.chain.csp.schema.Repeat in project application by collectionspace.
the class ServiceBindingsGeneration method createAuthRefOrTermRef.
/*
* If we have authRef's or termRef's, then we create an entry in the bindings xml and return 'true'; otherwise, we return 'false'
*/
private boolean createAuthRefOrTermRef(Element auth, Namespace types, Record r, String section, FieldSet in) {
boolean result = false;
// for debugging - remove after
String fieldName = in.getID();
// for debugging - remove after
String sec = in.getSection();
// Ignore passed-in section, in order to create authRefs and termRefs for every section
if (isAuthOrTermRef(in) && in.getSection().equals(section)) {
// Let the caller know we created a referenced term
result = true;
Boolean isEnum = false;
if (in instanceof Field) {
isEnum = (((Field) in).getUIType()).equals("enum");
}
Element tele = auth.addElement(new QName("item", types));
Element tele2 = tele.addElement(new QName("key", types));
Element tele3 = tele.addElement(new QName("value", types));
String refType = AUTH_REF;
if (isEnum == true) {
refType = TERM_REF;
}
tele2.addText(refType);
String name = "";
FieldSet fs = (FieldSet) in;
while (fs.getParent().isTrueRepeatField() == true) {
String xpathStructuredPart = fs.getServicesTag();
if (fs.getParent() instanceof Repeat) {
xpathStructuredPart = getXpathStructuredPart((Repeat) fs.getParent());
}
fs = (FieldSet) fs.getParent();
// Repeatable scalars are separated by the '|' character; otherwise, we use the '/' for xpath expressions
String separator = "|";
if (xpathStructuredPart.endsWith("*")) {
separator = "/";
}
name = xpathStructuredPart + separator + name;
}
name += in.getServicesTag();
tele3.addText(name);
}
return result;
}
use of org.collectionspace.chain.csp.schema.Repeat in project application by collectionspace.
the class ServiceBindingsGeneration method isScalarRepeat.
/*
* Repeatable scalars (multivalued scalars)...
*/
private boolean isScalarRepeat(FieldSet fieldSet) {
boolean result = false;
FieldParent parent = fieldSet.getParent();
if (parent instanceof Repeat) {
Repeat repeat = (Repeat) parent;
if (repeat.isTrueRepeatField() == true) {
String[] parts = repeat.getfullID().split("/");
if (parts.length == 1) {
result = true;
}
}
}
return result;
}
use of org.collectionspace.chain.csp.schema.Repeat in project application by collectionspace.
the class ServiceBindingsGeneration method getFullyQualifiedFieldPath.
/*
* Returns the fully qualified path of a field name
*/
private String getFullyQualifiedFieldPath(FieldSet in) {
String tail = null;
// Start by assuming it's just a plain scalar field, so we would just return the name
String name = in.getServicesTag();
//
// Debug info
//
String[] fullName = in.getIDPath();
boolean isPartOfGroup = in.getParent() instanceof Group;
boolean isGroup = in instanceof Group;
boolean isGroupField = in.isAGroupField();
//
if (in.getParent().isTrueRepeatField() == true) {
name = "";
FieldSet fst = in;
while (fst.getParent().isTrueRepeatField() == true) {
// Fields that are part of a repeatable structured group have a form like this 'titleGroupList/[0]/title'
tail = "/";
if (isScalarRepeat(fst) == true) {
// Scalar-repeats (aka, multi-valued fields) look like 'responsibleDepartments/[0]' and *not* 'responsibleDepartments/[0]/responsibleDepartment'
tail = "";
}
fst = (FieldSet) fst.getParent();
if (fst instanceof Repeat) {
Repeat rt = (Repeat) fst;
if (rt.hasServicesParent()) {
name += rt.getServicesParent()[0];
} else {
name += rt.getServicesTag();
}
} else {
// REM - This 'else' clause is not necessary and should be removed.
Group gp = (Group) fst;
if (gp.hasServicesParent()) {
name += gp.getServicesParent()[0];
} else {
name += gp.getServicesTag();
}
}
name += GROUP_LIST_SUFFIX + tail;
}
if (name.contains(GROUP_LIST_SUFFIX) && name.endsWith("/")) {
name += in.getServicesTag();
}
}
return name;
}
Aggregations