Search in sources :

Example 1 with UISpecRunContext

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

the class UISchema method uisearchschema.

/**
 * Create the search uischemas
 * @param storage
 * @param record
 * @return
 * @throws UIException
 */
private JSONObject uisearchschema(Storage storage, Record record) throws UIException {
    UISpecRunContext context = new UISpecRunContext();
    this.storage = storage;
    this.record = record;
    this.tenantname = this.record.getSpec().getAdminData().getTenantName();
    try {
        JSONObject out = new JSONObject();
        JSONObject fields = actualSchemaFields(record, context);
        JSONObject prop = fields.getJSONObject("properties");
        fields.put("properties", prop);
        out.put(record.getWebURL(), fields);
        return out;
    } catch (JSONException e) {
        throw new UIException("Cannot generate UISpec due to JSONException", e);
    }
}
Also used : UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException)

Example 2 with UISpecRunContext

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

the class UISpec method uispec.

/**
 * create the UISpec and return the JSONObject
 * @param storage
 * @return
 * @throws UIException
 */
protected JSONObject uispec(Storage storage) throws UIException {
    this.storage = storage;
    UISpecRunContext context = new UISpecRunContext();
    try {
        JSONObject out = new JSONObject();
        Structure s = record.getStructure(this.structureview);
        if (this.structureview.equals("search")) {
            out = generateUISpecRecordEditor(context, s.showMessageKey());
        } else {
            if (s.showListSection()) {
                /* used in termlist, reports, all */
                out.put(s.getListSectionName(), generateUISpecListSection(s, context));
            }
            if (s.showEditSection()) {
                out.put(s.getEditSectionName(), generateUISpecRecordEditor(context, s.showMessageKey()));
            }
            if (s.showHierarchySection()) {
                out.put(s.getHierarchySectionName(), generateUISpecHierarchySection(context, s.showMessageKey()));
            }
        }
        return out;
    } catch (JSONException e) {
        throw new UIException("Cannot generate UISpec due to JSONException", e);
    }
}
Also used : UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) UIException(org.collectionspace.csp.api.ui.UIException) Structure(org.collectionspace.chain.csp.schema.Structure)

Example 3 with UISpecRunContext

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

the class DataGenerator method makedata.

/**
 * drop into the SchemaStructure calls to get the structure of the data we wish to create
 * @param num
 * @return
 * @throws JSONException
 */
private JSONObject makedata(Integer num) throws JSONException {
    UISpecRunContext context = new UISpecRunContext();
    num = num + this.startvalue;
    this.dataprefix = this.extraprefix + num.toString();
    JSONObject out = generateDataEntrySection(context, this.record, this.spectype);
    return out;
}
Also used : UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) JSONObject(org.json.JSONObject)

Example 4 with UISpecRunContext

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

the class SchemaStructure method makeAGroupField.

/**
 * Do all the magic to make a GroupField
 *
 * @param fs
 * @param context
 * @throws JSONException
 */
protected JSONObject makeAGroupField(FieldSet fs, UISpecRunContext context) throws JSONException {
    JSONObject out = new JSONObject();
    if (fs instanceof Field || fs instanceof Repeat) {
        JSONObject subexpander = new JSONObject();
        JSONObject options = new JSONObject();
        String[] parts = fs.getUIType().split("/");
        Record subitems = fs.getRecord().getSpec().getRecordByServicesUrl(parts[1]);
        UISpecRunContext sub = context.createChild();
        sub.setUIPrefix(fs.getID());
        sub.setPad(false);
        if (isAStructureDate(fs)) {
            makeAStructureDate(fs, out, subexpander, options, subitems, sub, context);
        } else if (fs.isASelfRenderer()) {
            makeASelfRenderer(fs, context, out, subexpander, options, subitems, sub);
        } else {
            makeAOtherGroup(fs, out, subexpander, options, subitems, sub);
        }
    }
    return out;
}
Also used : Field(org.collectionspace.chain.csp.schema.Field) UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) JSONObject(org.json.JSONObject) Repeat(org.collectionspace.chain.csp.schema.Repeat) Record(org.collectionspace.chain.csp.schema.Record)

Example 5 with UISpecRunContext

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

the class SchemaStructure method makeASubRecordEntry.

/**
 * Do all the magic to make a sub record thing first is it nested directly
 * in the data or one level under
 *
 * @param out
 * @param fs
 * @param context
 * @throws JSONException
 */
protected void makeASubRecordEntry(JSONObject out, FieldSet fs, UISpecRunContext context, JSONObject outerlayer) throws JSONException {
    // create group item or field at the same level as parent fields - do not nest
    UISpecRunContext sub = context;
    if (!fs.getUISpecInherit()) {
        // default behaviour do group or field as expected by changing the context (adds more info to the selectors etc)
        sub = context.createChild();
        if (!fs.getSelectorAffix().equals("")) {
            sub.setUIAffix(fs.getSelectorAffix());
        }
        String sp = fs.getUISpecPrefix();
        if (sp != null)
            sub.setUIPrefix(sp);
    }
    Record subrecord = fs.usesRecordId();
    Boolean repeated = false;
    if (fs.getParent() instanceof Repeat || (fs instanceof Repeat && !(fs instanceof Group))) {
        repeated = true;
    }
    if (outerlayer == null) {
        outerlayer = out;
    }
    if (fs instanceof Group) {
        Group gp = (Group) fs;
        if (gp.isGrouped()) {
            sub.setPad(false);
        }
    }
    actualSubRecordField(out, fs, sub, subrecord, repeated, outerlayer);
}
Also used : Group(org.collectionspace.chain.csp.schema.Group) UISpecRunContext(org.collectionspace.chain.csp.schema.UISpecRunContext) Record(org.collectionspace.chain.csp.schema.Record) Repeat(org.collectionspace.chain.csp.schema.Repeat)

Aggregations

UISpecRunContext (org.collectionspace.chain.csp.schema.UISpecRunContext)6 JSONObject (org.json.JSONObject)5 UIException (org.collectionspace.csp.api.ui.UIException)3 JSONException (org.json.JSONException)3 Record (org.collectionspace.chain.csp.schema.Record)2 Repeat (org.collectionspace.chain.csp.schema.Repeat)2 Field (org.collectionspace.chain.csp.schema.Field)1 Group (org.collectionspace.chain.csp.schema.Group)1 Structure (org.collectionspace.chain.csp.schema.Structure)1