Search in sources :

Example 56 with FieldSet

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

Example 57 with FieldSet

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

the class ServiceBindingsGeneration method doServiceProperties.

private boolean doServiceProperties(Record record, Element props, Namespace types, boolean isAuthority) {
    boolean result = false;
    Record r = record;
    // 
    if (isAuthority == true) {
        Spec spec = r.getSpec();
        r = spec.getRecord(BASE_AUTHORITY_RECORD);
    }
    FieldSet objNameProp = r.getMiniSummary();
    if (objNameProp != null) {
        String serviceFieldAlias = objNameProp.getServiceFieldAlias();
        if (serviceFieldAlias != null) {
            objNameProp = r.getField(serviceFieldAlias);
        }
        this.addServiceProperty(props, objNameProp, OBJECT_NAME_PROPERTY, types, isAuthority);
        result = true;
    }
    FieldSet objNumberProp = r.getMiniNumber();
    if (objNumberProp != null) {
        this.addServiceProperty(props, objNumberProp, OBJECT_NUMBER_PROPERTY, types, isAuthority);
        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)

Example 58 with FieldSet

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

the class ServiceBindingsGeneration method createInitFieldList.

/*
	 * Returns true if we end up creating service binding entries for field initialization.
	 */
private boolean createInitFieldList(Element paramsElement, Namespace namespace, Record record, Boolean isAuthority) {
    boolean result = false;
    // Loop through each field to see if we need to create a service binding entry
    for (FieldSet f : record.getAllFieldFullList("")) {
        boolean createdEntry = false;
        if (f.isASelfRenderer() == true) {
            // 
            // Self rendered fields are essentially sub-records
            // 
            String fieldSetServicesType = f.getServicesType(NOT_NAMESPACED);
            Spec spec = f.getRecord().getSpec();
            // find a record that corresponds to the fieldset's service type
            Record subRecord = spec.getRecord(fieldSetServicesType);
            // make a recursive call with the subrecord
            createdEntry = createInitFieldList(paramsElement, namespace, subRecord, isAuthority);
        } else {
            // Create a service binding for the field
            createdEntry = createInitFieldEntry(paramsElement, namespace, record, f, isAuthority);
        }
        // 
        if (createdEntry == true) {
            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)

Example 59 with FieldSet

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

the class ServiceBindingsGeneration method doLists.

// defines fields to show in list results
private void doLists(Record record, Element el, Namespace thisns, boolean isAuthority) {
    Record r = record;
    // 
    if (isAuthority == true) {
        Spec recordSpec = r.getSpec();
        r = recordSpec.getRecord(BASE_AUTHORITY_RECORD);
    }
    FieldSet[] allMiniSummaryList = r.getAllMiniSummaryList();
    if (allMiniSummaryList == null) {
        log.error(String.format("Config Generation: '%s' - allMiniSummaryList for record '%s' is null.", getConfigFile().getName(), r.getRecordName()));
    }
    String section;
    for (FieldSet fs : allMiniSummaryList) {
        if ((fs.isInServices() && !fs.excludeFromServicesList()) || fs.isServicesDerived()) {
            String fieldNamePath = this.getFullyQualifiedFieldPath(fs);
            section = fs.getSection();
            // 
            // Add the <ListResultField> element
            // 
            Element lrf = el.addElement(new QName("ListResultField", thisns));
            // the field is from the common part.)
            if (!section.equals(Record.COLLECTIONSPACE_COMMON_PART_NAME)) {
                Element slrf = lrf.addElement(new QName("schema", thisns));
                slrf.addText(r.getServicesSchemaName(fs.getSection()));
            } else {
                log.isDebugEnabled();
            }
            Element elrf = lrf.addElement(new QName("element", thisns));
            elrf.addText(fs.getServicesTag());
            Element xlrf = lrf.addElement(new QName("xpath", thisns));
            xlrf.addText(fieldNamePath);
            String setter = fs.getServicesSetter();
            if (setter != null && setter.trim().isEmpty() == false) {
                Element slrf = lrf.addElement(new QName("setter", thisns));
                slrf.addText(setter);
            }
        }
    }
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) QName(org.dom4j.QName) Element(org.dom4j.Element) Record(org.collectionspace.chain.csp.schema.Record) TenantSpec(org.collectionspace.chain.csp.persistence.services.TenantSpec) Spec(org.collectionspace.chain.csp.schema.Spec)

Example 60 with FieldSet

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

the class ServiceBindingsGeneration method doRefnameDisplayNameField.

/*
	 * Creates the <> element in the Service binding. Is used to generate the 'refName' in service payloads
	 * For example,
	 * 	<service:RefnameDisplayNameField> <!-- The field used as the display name in an object's refname -->
	 *		<service:element>objectNumber</service:element>
	 *		<service:xpath>objectNumber</service:xpath>
	 *	</service:RefnameDisplayNameField>
	 */
private void doRefnameDisplayNameField(Record record, Element ele, Namespace thisns) {
    for (FieldSet fieldSet : record.getAllFieldFullList()) {
        if (fieldSet.isServicesRefnameDisplayName() == true) {
            Element doRefnameDisplayNameEle = ele.addElement(new QName("RefnameDisplayNameField", thisns));
            Element elrf = doRefnameDisplayNameEle.addElement(new QName("element", thisns));
            elrf.addText(fieldSet.getServicesTag());
            Element xlrf = doRefnameDisplayNameEle.addElement(new QName("xpath", thisns));
            String fieldNamePath = this.getFullyQualifiedFieldPath(fieldSet);
            xlrf.addText(fieldNamePath);
            // Allow only a single <RefnameDisplayNameField> element
            break;
        }
    }
}
Also used : FieldSet(org.collectionspace.chain.csp.schema.FieldSet) QName(org.dom4j.QName) Element(org.dom4j.Element)

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