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 classContains the datasource input.static final recordContains the datasource output.Nested classes/interfaces inherited from class org.mapfish.print.processor.AbstractProcessor
AbstractProcessor.ContextNested 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 voidextraValidation(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.voidsetAttribute(String name, Attribute attribute) All the sub-level attributes.voidsetAttributes(Map<String, Attribute> attributes) All the attributes needed either by the processors for each datasource row or by the jasper template.voidsetCopyAttributes(List<String> copyAttributes) The attributes that will be copied from the previous level.voidsetProcessors(List<Processor> processors) All the processors that will executed for each value retrieved from theValuesobject with the datasource name.voidsetReportKey(String reportKey) The key/name to use when putting the path to the compiled subreport in each row of the datasource.voidsetReportTemplate(String reportTemplate) The path to the report template used to render each row of the data.voidtoString(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 ifreportTemplatehas 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 theValuesobject 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:CustomDependenciesGet what we dynamically depends on, for the "values" input.- Specified by:
getDependenciesin interfaceCustomDependencies
-
setAttribute
All the sub-level attributes.- Specified by:
setAttributein interfaceRequireAttributes- Parameters:
name- the attribute name.attribute- the attribute.
-
createInputParameter
Description copied from interface:ProcessorReturns 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 theValuesobject.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
Valuesobject 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
HasDefaultValueannotation 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:
createInputParameterin interfaceProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output>
-
execute
@Nullable public DataSourceProcessor.Output execute(DataSourceProcessor.Input input, Processor.ExecutionContext context) throws Exception Description copied from interface:ProcessorPerform the process on the input attributes.- Specified by:
executein interfaceProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output> - Parameters:
input- A Java object whose public fields are populated from theValuesobject (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
Valuesobject. The key in theValuesobject 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:ProcessorCreate a string representing this processor.- Specified by:
toStringin interfaceProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output> - Overrides:
toStringin 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:AbstractProcessorPerform any extra validation a subclass may need to perform.- Specified by:
extraValidationin 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
-