public final class DataSourceProcessor extends AbstractProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output> implements RequireAttributes, CustomDependencies
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 which 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]]| Modifier and Type | Class and Description |
|---|---|
static class |
DataSourceProcessor.Input
Contains the datasource input.
|
static class |
DataSourceProcessor.Output
Contains the datasource output.
|
AbstractProcessor.ContextProcessor.ExecutionContext| Constructor and Description |
|---|
DataSourceProcessor()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
DataSourceProcessor.Input |
createInputParameter()
Returns a new/clean instance of a parameter object.
|
DataSourceProcessor.Output |
execute(DataSourceProcessor.Input input,
Processor.ExecutionContext context)
Perform the process on the input attributes.
|
protected void |
extraValidation(java.util.List<java.lang.Throwable> validationErrors,
Configuration configuration)
Perform any extra validation a subclass may need to perform.
|
java.util.Collection<java.lang.String> |
getDependencies()
Get what we dynamically depends on, for the "values" input.
|
void |
setAttribute(java.lang.String name,
Attribute attribute)
All the sub-level attributes.
|
void |
setAttributes(java.util.Map<java.lang.String,Attribute> attributes)
All the attributes needed either by the processors for each datasource row or by the jasper template.
|
void |
setCopyAttributes(java.util.List<java.lang.String> copyAttributes)
The attributes that will be copied from the previous level.
|
void |
setProcessors(java.util.List<Processor> processors)
All the processors that will executed for each value retrieved from the
Values object with the datasource name. |
void |
setReportKey(java.lang.String reportKey)
The key/name to use when putting the path to the compiled subreport in each row of the datasource.
|
void |
setReportTemplate(java.lang.String reportTemplate)
The path to the report template used to render each row of the data.
|
void |
toString(java.lang.StringBuilder builder,
int indent,
java.lang.String parent)
Create a string representing this processor.
|
checkCancelState, getInputMapperBiMap, getInputPrefix, getOutputMapperBiMap, getOutputPrefix, getOutputType, setInputMapper, setInputPrefix, setOutputMapper, setOutputPrefix, setPrefix, toString, validatepublic void setReportTemplate(java.lang.String reportTemplate)
The path should be relative to the configuration directory
reportTemplate - the path to the report template.public void setReportKey(java.lang.String reportKey)
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.reportKey - the key/name to use when putting the path to the compiled subreport in each
row of the datasource.public void setProcessors(java.util.List<Processor> processors)
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.
processors - the processors which will be ran to create the datasourcepublic void setAttributes(java.util.Map<java.lang.String,Attribute> attributes)
attributes - the attributes.public void setCopyAttributes(java.util.List<java.lang.String> copyAttributes)
copyAttributes - the attributes name@Nonnull public java.util.Collection<java.lang.String> getDependencies()
CustomDependenciesgetDependencies in interface CustomDependenciespublic void setAttribute(java.lang.String name,
Attribute attribute)
setAttribute in interface RequireAttributesname - the attribute name.attribute - the attribute.@Nullable public DataSourceProcessor.Input createInputParameter()
ProcessorValues object.
The way the properties will be looked up is to
Values object using the mapped
property name
HasDefaultValue annotation is on the field for
the property.
createInputParameter in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>@Nullable public DataSourceProcessor.Output execute(DataSourceProcessor.Input input, Processor.ExecutionContext context) throws java.lang.Exception
Processorexecute in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>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.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.java.lang.Exceptionpublic void toString(@Nonnull
java.lang.StringBuilder builder,
int indent,
java.lang.String parent)
ProcessortoString in interface Processor<DataSourceProcessor.Input,DataSourceProcessor.Output>toString in class AbstractProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output>builder - the builder to add the string to.indent - the number of steps of indent for this nodeparent - the parent node's nameprotected void extraValidation(java.util.List<java.lang.Throwable> validationErrors,
Configuration configuration)
AbstractProcessorextraValidation in class AbstractProcessor<DataSourceProcessor.Input,DataSourceProcessor.Output>validationErrors - a list to add errors to so that all validation errors are reported as
one.configuration - the containing configuration