Class DataSourceAttribute

  • All Implemented Interfaces:
    Attribute, ConfigurationObject

    public final class DataSourceAttribute
    extends java.lang.Object
    implements Attribute
    This attribute represents a collection of attributes which can be used as the data source of a Jasper report's table/detail section.

    For example consider the case where the report should contain multiple tables or charts but the number of reports may change depending on the request. In this case the client will post a datasource attribute json object containing an array of all the table attribute objects. The DataSourceProcessor will process the datasource attribute and create a Jasper datasource that contains all the tables.

    This datasource must be used in tandem with the DataSourceProcessor processor (see !createDataSource processor).

    The json data of this attribute is special since it represents an array of attributes, each element in the array must contain all of the attributes required to satisfy the processors in the DataSourceProcessor.

    Example configuration:

    
     datasource: !datasource
       table: !table
       map: !map
         width: 200
         height: 100
     

    Example request data:

    
     datasource: [
       {
           table: {
               ... // normal table attribute data
           },
           map: {
               ... // normal map attribute data
           }
       }, {
           table: {
               ... // normal table attribute data
           },
           map: {
               ... // normal map attribute data
           }
       }
     ]
     
    [[examples=verboseExample,datasource_dynamic_tables,datasource_many_dynamictables_legend, datasource_multiple_maps,customDynamicReport,report]]
    • Constructor Detail

      • DataSourceAttribute

        public DataSourceAttribute()
    • Method Detail

      • setDefault

        public void setDefault​(java.util.List<java.lang.Object> defaultData)
        Default values for this attribute. Example:
        
             attributes:
               datasource: !datasource
                 attributes:
                   name: !string {}
                   count: !integer {}
                 default:
                   - name: "name"
                   - count: 3
        Parameters:
        defaultData - The default values.
      • getAttributes

        public java.util.Map<java.lang.String,​Attribute> getAttributes()
        Gets the attributes.
        Returns:
        the attributes
      • setAttributes

        public void setAttributes​(java.util.Map<java.lang.String,​Attribute> attributes)
        The attributes that are acceptable by this dataSource. The format is the same as the template attributes section.
        Parameters:
        attributes - the attributes
      • printClientConfig

        public void printClientConfig​(org.json.JSONWriter json,
                                      Template template)
                               throws org.json.JSONException
        Description copied from interface: Attribute
        Write this attribute out the the json writer so that clients can know what attributes are expected.
        Specified by:
        printClientConfig in interface Attribute
        Parameters:
        json - the json writer to write to
        template - the template that this attribute is part of
        Throws:
        org.json.JSONException
      • setConfigName

        public void setConfigName​(java.lang.String name)
        Description copied from interface: Attribute
        Set the name of the attribute as set in the configuration file.
        Specified by:
        setConfigName in interface Attribute
        Parameters:
        name - the name of the attribute
      • validate

        public void validate​(java.util.List<java.lang.Throwable> validationErrors,
                             Configuration configuration)
        Description copied from interface: ConfigurationObject
        validate that the configuration was correct.
        Specified by:
        validate in interface ConfigurationObject
        Parameters:
        validationErrors - a list to add any detected errors to.
        configuration - the containing configuration
      • getValueType

        public java.lang.Class getValueType()
        Description copied from interface: Attribute
        Get the class of the value.
        Specified by:
        getValueType in interface Attribute
        Returns:
        the value class
      • getValue

        public java.lang.Object getValue​(@Nonnull
                                         Template template,
                                         @Nonnull
                                         java.lang.String attributeName,
                                         @Nonnull
                                         PObject requestJsonAttributes)
        Description copied from interface: Attribute
        Get the attribute value.
        Specified by:
        getValue in interface Attribute
        Parameters:
        template - the template of the current request.
        attributeName - the name of the attribute
        requestJsonAttributes - the json data for populating the attribute values
        Returns:
        the value