Search in sources :

Example 61 with FieldSet

use of org.collectionspace.chain.csp.schema.FieldSet 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;
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Example 62 with FieldSet

use of org.collectionspace.chain.csp.schema.FieldSet in project application by collectionspace.

the class ServiceBindingsGeneration method doAuthRefsAndTermRefs.

/*
	 * Creates a set of Service binding authRefs and termRefs similar in form to these examples:
	 *  <types:item>
	 *      <types:key>authRef</types:key>
	 *      <types:value>currentOwner</types:value>
	 *  </types:item>
         *  <types:item>
	 *      <types:key>termRef</types:key>
	 *      <types:value>termLanguage</types:value>
	 *  </types:item>
	 *  
	 *  If we don't create any entries then we'll return 'false' to the caller;
	 */
private boolean doAuthRefsAndTermRefs(Element auth, Namespace types, Record r, String section) {
    boolean result = false;
    for (FieldSet in : r.getAllFieldFullList("")) {
        // for debugging only
        String fieldName = in.getID() + ":" + in.getLabel();
        if (in.isASelfRenderer() == true) {
            if (in.getSection().equals(section)) {
                String fieldSetServicesType = in.getServicesType(false);
                Spec recordSpec = in.getRecord().getSpec();
                // find a record that corresponds to the fieldset's service type
                Record subRecord = recordSpec.getRecord(fieldSetServicesType);
                // the fields in an included subrecord should always be in the "common" section
                String subSection = "common";
                // 
                // Iterate through each field of the subrecord
                // 
                // Recursive call
                boolean createdAuths = doAuthRefsAndTermRefs(auth, types, subRecord, subSection);
                if (createdAuths == true) {
                    // Let the caller know we created at least one auth/term reference
                    result = true;
                }
            }
        } else {
            boolean createdAuths = createAuthRefOrTermRef(auth, types, r, section, in);
            if (createdAuths == true) {
                // Let the caller know we created at least one auth/term reference
                result = true;
            }
        }
    }
    return result;
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) Record(org.collectionspace.chain.csp.schema.Record) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec)

Aggregations

FieldSet (org.collectionspace.chain.csp.schema.FieldSet)62 JSONObject (org.json.JSONObject)36 Record (org.collectionspace.chain.csp.schema.Record)23 Field (org.collectionspace.chain.csp.schema.Field)22 JSONArray (org.json.JSONArray)22 Element (org.dom4j.Element)19 Group (org.collectionspace.chain.csp.schema.Group)17 UnderlyingStorageException (org.collectionspace.csp.api.persistence.UnderlyingStorageException)17 JSONException (org.json.JSONException)13 Repeat (org.collectionspace.chain.csp.schema.Repeat)11 Document (org.dom4j.Document)11 QName (org.dom4j.QName)11 ConnectionException (org.collectionspace.chain.csp.persistence.services.connection.ConnectionException)10 ReturnedDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedDocument)9 ReturnedMultipartDocument (org.collectionspace.chain.csp.persistence.services.connection.ReturnedMultipartDocument)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ArrayList (java.util.ArrayList)6 UnimplementedException (org.collectionspace.csp.api.persistence.UnimplementedException)6 TenantSpec (org.collectionspace.chain.csp.persistence.services.TenantSpec)5 Spec (org.collectionspace.chain.csp.schema.Spec)5