Class DataSourceAttribute

java.lang.Object
org.mapfish.print.attribute.DataSourceAttribute
All Implemented Interfaces:
Attribute, ConfigurationObject

public final class DataSourceAttribute extends 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 Details

    • DataSourceAttribute

      public DataSourceAttribute()
  • Method Details

    • setDefault

      public void setDefault(List<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 Map<String,Attribute> getAttributes()
      Gets the attributes.
      Returns:
      the attributes
    • setAttributes

      public void setAttributes(Map<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(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(List<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
    • parseAttribute

      public DataSourceAttribute.DataSourceAttributeValue parseAttribute(@Nonnull Template template, @Nullable PArray jsonValue) throws org.json.JSONException
      Parameters:
      template - the containing template
      jsonValue - the json
      Throws:
      org.json.JSONException
    • getValueType

      public 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 Object getValue(@Nonnull Template template, @Nonnull 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