Class DataSourceProcessor

All Implemented Interfaces:
ConfigurationObject, CustomDependencies, Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>, RequireAttributes

A processor that will process a DataSourceAttribute.DataSourceAttributeValue and construct a single Jasper DataSource from the input values in the DataSourceAttribute.DataSourceAttributeValue input object.

The DataSourceAttribute.DataSourceAttributeValue has an array of maps, each map in the array equates to a row in the Jasper DataSource.

The DataSourceProcessor can be configured with processors that will be used to transform each map in the input array before constructing the final DataSource row.

For example, each map in the array could be MapAttribute.MapAttributeValues and the DataSourceProcessor could be configured with !createMap processor. In this scenario each element in the array would be transformed by the !createMap processor and thus each row of the resulting DataSource will contain the map subreport created by the !createMap processor.

An additional point to remember is that (as with the normal execution) in addition to the output of the processors, the attributes in the input map will also be columns in the row. This means that the jasper report that makes use of the resulting DataSource will have access to both the results of the processor as well as the input values (unless overwritten by the processor output).

If the reportKey is defined (and reportTemplate) then a the reportTemplate jrxml file will be compiled (as required by all jrxml files) and an additional column will be added to each row [reportKey] : [compiled reportTemplate File]

If reportKey is defined the reportTemplate must also be defined (and vice-versa).

See also: !datasource attribute [[examples=verboseExample,datasource_dynamic_tables,datasource_many_dynamictables_legend, datasource_multiple_maps,customDynamicReport,report]]

  • Constructor Details

    • DataSourceProcessor

      public DataSourceProcessor()
      Constructor.
  • Method Details

    • setReportTemplate

      public void setReportTemplate(String reportTemplate)
      The path to the report template used to render each row of the data. This is only required if a subreport needs to be compiled and is referenced in the containing report's detail section.

      The path should be relative to the configuration directory

      Parameters:
      reportTemplate - the path to the report template.
    • setReportKey

      public void setReportKey(String reportKey)
      The key/name to use when putting the path to the compiled subreport in each row of the datasource. This is required if reportTemplate has been set. The path to the compiled subreport will be added to each row in the datasource with this value as the key. This allows the containing report to reference the subreport in each row.
      Parameters:
      reportKey - the key/name to use when putting the path to the compiled subreport in each row of the datasource.
    • setProcessors

      public void setProcessors(List<Processor> processors)
      All the processors that will executed for each value retrieved from the Values object with the datasource name. All output values from the processor graph will be the datasource values.

      Each value retrieved from values with the datasource name will be the input of the processor graph and all the output values for that execution will be the values of a single row in the datasource. The Jasper template can use any of the values in its detail band.

      Parameters:
      processors - the processors which will be ran to create the datasource
    • setAttributes

      public void setAttributes(Map<String,Attribute> attributes)
      All the attributes needed either by the processors for each datasource row or by the jasper template.
      Parameters:
      attributes - the attributes.
    • setCopyAttributes

      public void setCopyAttributes(List<String> copyAttributes)
      The attributes that will be copied from the previous level.
      Parameters:
      copyAttributes - the attributes name
    • getDependencies

      @Nonnull public Collection<String> getDependencies()
      Description copied from interface: CustomDependencies
      Get what we dynamically depends on, for the "values" input.
      Specified by:
      getDependencies in interface CustomDependencies
    • setAttribute

      public void setAttribute(String name, Attribute attribute)
      All the sub-level attributes.
      Specified by:
      setAttribute in interface RequireAttributes
      Parameters:
      name - the attribute name.
      attribute - the attribute.
    • createInputParameter

      @Nullable public DataSourceProcessor.Input createInputParameter()
      Description copied from interface: Processor
      Returns a new/clean instance of a parameter object. This instance's will be inspected using reflection to find its public fields and the properties will be set from the Values object.

      The way the properties will be looked up is to

      1. take the bean property name
      2. map it using the input mapper, (if the input mapper does not have a mapping for the property then the unmapped property name is used)
      3. Look up the property value in the Values object using the mapped property name
      4. set the value on the instance created by this method. If the value is null an exception will be thrown UNLESS the HasDefaultValue annotation is on the field for the property.
      The populated instance will be passed to the execute method. It is imperative that a new instance is created each time because they will be used in a multi-threaded environment and thus the same processor instance may be ran in multiple threads with different instances of the parameter object.

      It is important to realize that super classes will also be analyzed, so care must be had with inheritance.

      Specified by:
      createInputParameter in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>
    • execute

      Description copied from interface: Processor
      Perform the process on the input attributes.
      Specified by:
      execute in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>
      Parameters:
      input - A Java object whose public fields are populated from the Values object (which is used for transferring properties between processors).
      context - The execution context for a print task.
      Returns:
      A Java object whose public fields will be put into the Values object. The key in the Values object is the name of the field or if there is a mapping in the Processor.getOutputMapperBiMap() map, the mapped name. The key is determined in a similar way as for the input object.
      Throws:
      Exception
    • toString

      public void toString(@Nonnull StringBuilder builder, int indent, String parent)
      Description copied from interface: Processor
      Create a string representing this processor.
      Specified by:
      toString in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>
      Overrides:
      toString in class AbstractProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output>
      Parameters:
      builder - the builder to add the string to.
      indent - the number of steps of indent for this node
      parent - the parent node's name
    • extraValidation

      protected void extraValidation(List<Throwable> validationErrors, Configuration configuration)
      Description copied from class: AbstractProcessor
      Perform any extra validation a subclass may need to perform.
      Specified by:
      extraValidation in class AbstractProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output>
      Parameters:
      validationErrors - a list to add errors to so that all validation errors are reported as one.
      configuration - the containing configuration