Class DataSourceProcessor
- All Implemented Interfaces:
ConfigurationObject
,CustomDependencies
,Processor<DataSourceProcessor.Input,
,DataSourceProcessor.Output> RequireAttributes
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]]
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Contains the datasource input.static final class
Contains the datasource output.Nested classes/interfaces inherited from class org.mapfish.print.processor.AbstractProcessor
AbstractProcessor.Context
Nested classes/interfaces inherited from interface org.mapfish.print.processor.Processor
Processor.ExecutionContext
-
Field Summary
Fields inherited from interface org.mapfish.print.processor.Processor
MDC_APPLICATION_ID_KEY, MDC_JOB_ID_KEY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns a new/clean instance of a parameter object.execute
(DataSourceProcessor.Input input, Processor.ExecutionContext context) Perform the process on the input attributes.protected void
extraValidation
(List<Throwable> validationErrors, Configuration configuration) Perform any extra validation a subclass may need to perform.Get what we dynamically depends on, for the "values" input.void
setAttribute
(String name, Attribute attribute) All the sub-level attributes.void
setAttributes
(Map<String, Attribute> attributes) All the attributes needed either by the processors for each datasource row or by the jasper template.void
setCopyAttributes
(List<String> copyAttributes) The attributes that will be copied from the previous level.void
setProcessors
(List<Processor> processors) All the processors that will executed for each value retrieved from theValues
object with the datasource name.void
setReportKey
(String reportKey) The key/name to use when putting the path to the compiled subreport in each row of the datasource.void
setReportTemplate
(String reportTemplate) The path to the report template used to render each row of the data.void
toString
(StringBuilder builder, int indent, String parent) Create a string representing this processor.Methods inherited from class org.mapfish.print.processor.AbstractProcessor
getInputMapperBiMap, getInputPrefix, getOutputMapperBiMap, getOutputPrefix, getOutputType, setInputMapper, setInputPrefix, setOutputMapper, setOutputPrefix, setPrefix, toString, validate
-
Constructor Details
-
DataSourceProcessor
public DataSourceProcessor()Constructor.
-
-
Method Details
-
setReportTemplate
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
The key/name to use when putting the path to the compiled subreport in each row of the datasource. This is required ifreportTemplate
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
All the processors that will executed for each value retrieved from theValues
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
All the attributes needed either by the processors for each datasource row or by the jasper template.- Parameters:
attributes
- the attributes.
-
setCopyAttributes
The attributes that will be copied from the previous level.- Parameters:
copyAttributes
- the attributes name
-
getDependencies
Description copied from interface:CustomDependencies
Get what we dynamically depends on, for the "values" input.- Specified by:
getDependencies
in interfaceCustomDependencies
-
setAttribute
All the sub-level attributes.- Specified by:
setAttribute
in interfaceRequireAttributes
- Parameters:
name
- the attribute name.attribute
- the attribute.
-
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 theValues
object.The way the properties will be looked up is to
- take the bean property name
- 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)
- Look up the property value in the
Values
object using the mapped property name - 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.
It is important to realize that super classes will also be analyzed, so care must be had with inheritance.
- Specified by:
createInputParameter
in interfaceProcessor<DataSourceProcessor.Input,
DataSourceProcessor.Output>
-
execute
@Nullable public DataSourceProcessor.Output execute(DataSourceProcessor.Input input, Processor.ExecutionContext context) throws Exception Description copied from interface:Processor
Perform the process on the input attributes.- Specified by:
execute
in interfaceProcessor<DataSourceProcessor.Input,
DataSourceProcessor.Output> - Parameters:
input
- A Java object whose public fields are populated from theValues
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 theValues
object is the name of the field or if there is a mapping in theProcessor.getOutputMapperBiMap()
map, the mapped name. The key is determined in a similar way as for the input object. - Throws:
Exception
-
toString
Description copied from interface:Processor
Create a string representing this processor.- Specified by:
toString
in interfaceProcessor<DataSourceProcessor.Input,
DataSourceProcessor.Output> - Overrides:
toString
in classAbstractProcessor<DataSourceProcessor.Input,
DataSourceProcessor.Output> - Parameters:
builder
- the builder to add the string to.indent
- the number of steps of indent for this nodeparent
- the parent node's name
-
extraValidation
Description copied from class:AbstractProcessor
Perform any extra validation a subclass may need to perform.- Specified by:
extraValidation
in classAbstractProcessor<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
-