Search in sources :

Example 11 with IPropertyRuleIntrospector

use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.

the class FinderMetaDataHelper method determinePropertyMetaData.

/**
 * Returns meta data for the input field.
 */
private static Map<String, String> determinePropertyMetaData(Class outputClass, Class domainClass, GraphMapping graphMapping, String fieldName) throws Exception {
    IPropertyRuleIntrospector i = RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(outputClass, fieldName);
    // Apply an optional wrapper that also takes the FieldMetaData into account
    try {
        FieldMetaData fieldMetaData = PersistentHelper.getFieldMetaData(domainClass.getName(), graphMapping != null ? graphMapping.getDomainFieldName(fieldName) : fieldName);
        i = new PropertyRuleIntrospectorUsingFieldMetaData(i, fieldMetaData);
    } catch (Exception ignore) {
    }
    // A Map to hold the various attributes of the field
    Map<String, String> m = new LinkedHashMap<String, String>();
    // determine type
    String type = toJsType(i.getPropertyType());
    if (type == null) {
        // A foreign-key on a Graph will typically be modelled as another Graph, in which case obtain the datatype for that field from the domainClass
        type = toJsType(RulesEngineFactory.getRulesEngine().getPropertyRuleIntrospector(domainClass, fieldName).getPropertyType());
    }
    // Ignore field having unsupported propertyType
    if (type == null)
        return null;
    m.put("type", '\'' + type + '\'');
    // determine label
    String label = i.getLabel();
    if (label == null) {
        label = StringHelper.getSpace(StringHelper.getUpper1(fieldName));
    } else {
        String tmp = label.substring(1);
        tmp = tmp.substring(0, tmp.length() - 1);
        m.put("labelToken", '\'' + tmp + '\'');
        label = StringHelper.escapeJavascript(MessageHelper.replaceTokens(label));
    }
    m.put("label", '\'' + label + '\'');
    // determine maxLength
    Integer maxLength = i.getMaxLength();
    if (maxLength != null)
        m.put("maxLength", maxLength.toString());
    // sortable
    m.put("sortable", "true");
    // determine hidden
    Boolean hidden = i.isHidden();
    if (hidden) {
        m.put("hidden", "true");
        m.put("alwaysHidden", "true");
    }
    // determine caseType
    String caseType = i.getCaseType();
    if (caseType != null && caseType.toLowerCase().startsWith("upper"))
        caseType = "UpperCase";
    else if (caseType != null && caseType.toLowerCase().startsWith("lower"))
        caseType = "LowerCase";
    else
        caseType = null;
    if (caseType != null)
        m.put("caseType", '\'' + caseType + '\'');
    return m;
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) FieldMetaData(org.jaffa.metadata.FieldMetaData) PropertyRuleIntrospectorUsingFieldMetaData(org.jaffa.metadata.PropertyRuleIntrospectorUsingFieldMetaData) PropertyRuleIntrospectorUsingFieldMetaData(org.jaffa.metadata.PropertyRuleIntrospectorUsingFieldMetaData) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with IPropertyRuleIntrospector

use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.

the class FoldingSectionTag method lookupPropertyTag.

/**
 * Checks for the nearest outer PropertyTag.
 * Will set the 'key' on this tag, if not specified, with the value from the rules engine.
 * If not specifed, it will use the values from the outer PropertyTag to determine the FieldMetaData object to obtain the key
 */
private void lookupPropertyTag() {
    PropertyTag propertyTag = (PropertyTag) findCustomTagAncestorWithClass(this, PropertyTag.class);
    if (propertyTag != null) {
        IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
        if (getKey() == null && getLabel() == null) {
            try {
                String domainClassName = propertyTag.getPropertyClass();
                String fieldName = propertyTag.getPropertyName();
                setKey(TagHelper.getFieldMetaData(domainClassName, fieldName).getLabelToken());
            } catch (Exception e) {
            // do nothing
            }
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspException(javax.servlet.jsp.JspException) IOException(java.io.IOException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)

Example 13 with IPropertyRuleIntrospector

use of org.jaffa.rules.IPropertyRuleIntrospector in project jaffa-framework by jaffa-projects.

the class LabelTag method lookupPropertyTag.

/**
 * Checks for the nearest outer PropertyTag.
 * Will set the 'key' on this tag, if not specified, with the value from the rules engine.
 * Will set the 'domain' and field' on this tag, if not specifed, with the values from the outer PropertyTag.
 * @return the IPropertyRuleIntrospector from the outer PropertyTag.
 */
private IPropertyRuleIntrospector lookupPropertyTag() {
    // Cannnot use findCustomTagAncestorWithClass, since LabelTag doesn't implement IFormTag, and hence does not have a ParentTag stamped on it
    PropertyTag propertyTag = (PropertyTag) findAncestorWithClass(this, PropertyTag.class);
    if (propertyTag != null) {
        if (log.isDebugEnabled())
            log.debug("Found Property Tag for Label. Field=" + propertyTag.getField());
        IPropertyRuleIntrospector propertyRuleIntrospector = propertyTag.getPropertyRuleIntrospector();
        if (getKey() == null && getDomain() == null && getField() == null) {
            if (propertyRuleIntrospector != null) {
                setKey(propertyRuleIntrospector.getLabel());
                if (log.isDebugEnabled())
                    log.debug("Found Label via Rules (Field=" + propertyTag.getField() + ") = " + getKey());
            }
            setDomain(propertyTag.getPropertyClass());
            setField(propertyTag.getPropertyName());
        }
        return propertyRuleIntrospector;
    } else
        return null;
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector)

Aggregations

IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)13 IOException (java.io.IOException)8 JspException (javax.servlet.jsp.JspException)7 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)7 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)6 JspWriter (javax.servlet.jsp.JspWriter)5 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)5 FieldMetaData (org.jaffa.metadata.FieldMetaData)4 PropertyRuleIntrospectorUsingFieldMetaData (org.jaffa.metadata.PropertyRuleIntrospectorUsingFieldMetaData)4 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)4 LinkedHashMap (java.util.LinkedHashMap)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 FormBase (org.jaffa.presentation.portlet.FormBase)1 OuterGridTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterGridTagMissingRuntimeException)1 OuterLayoutTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterLayoutTagMissingRuntimeException)1 IRulesEngine (org.jaffa.rules.IRulesEngine)1