in birt/src/main/java/org/apache/ofbiz/birt/flexible/ReportDesignGenerator.java [114:239]
public void buildReport() throws IOException, GeneralException, BirtException {
DesignConfig config = new DesignConfig();
Platform.startup();
IDesignEngine engine = ((IDesignEngineFactory) Platform.createFactoryObject(
IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY)).createDesignEngine(config);
// creating main design elements
SessionHandle session = engine.newSessionHandle(ULocale.forLocale(locale));
design = session.createDesign();
factory = design.getElementFactory();
DesignElementHandle element = factory.newSimpleMasterPage("Page Master");
design.getMasterPages().add(element);
// create DataSource call
createScriptedDataSource();
// create DataSet call
createScriptedDataset();
// General design parameters
design.setLayoutPreference(DesignChoiceConstants.REPORT_LAYOUT_PREFERENCE_AUTO_LAYOUT);
design.setBidiOrientation(DesignChoiceConstants.BIDI_DIRECTION_LTR);
design.setDefaultUnits(DesignChoiceConstants.UNITS_IN);
design.setCreatedBy(design.getVersion());
design.setImageDPI(96);
// adding filters as parameters to make them available for design
// first adding parameters to the design itself
if (UtilValidate.isNotEmpty(filterMap)) {
// adding filters within reportDesign if generateFilters is set to true
GridHandle grid = null;
int i = 0;
if (generateFilters) {
grid = factory.newGridItem(null, 2, filterMap.size());
design.getBody().add(grid);
grid.setWidth("100%");
}
for (String filter : filterMap.keySet()) {
String birtType = BirtUtil.convertFieldTypeToBirtParameterType(filterMap.get(filter));
if (birtType == null) {
throw new GeneralException(UtilProperties.getMessage(RES_ERROR, "BirtErrorConversionFieldToBirtFailed", locale));
}
// get label
String displayFilterName;
if (UtilValidate.isNotEmpty(filterDisplayLabels)) {
displayFilterName = filterDisplayLabels.get(filter);
} else {
displayFilterName = filter;
}
ScalarParameterHandle scalParam = factory.newScalarParameter(filter);
// scalParam.setDisplayName(displayFilterName); // TODO has no incidence at all right now, is only displayed when using birt's
// report parameter system. Not our case. I leave it here if any idea arise of how to translate these.
scalParam.setPromptText(displayFilterName);
if ("javaObject".equals(birtType)) { //Fields of type='blob' are rejected by Birt: org.eclipse.birt.report.model.api.metadata
// .PropertyValueException: The choice value "javaObject" is not allowed.
throw new GeneralException("Fields of type='blob' are rejected by Birt. Create a view entity, based on the requested entity, "
+ "where you exclude the field of type='blob'");
} else {
scalParam.setDataType(birtType);
}
scalParam.setIsRequired(false);
design.getParameters().add(scalParam);
if (generateFilters) {
RowHandle row = (RowHandle) grid.getRows().get(i);
CellHandle cellLabel = (CellHandle) row.getCells().get(0);
CellHandle cellFilter = (CellHandle) row.getCells().get(1);
LabelHandle label = factory.newLabel(null);
label.setText(displayFilterName);
cellLabel.getContent().add(label);
// 1. create computed column and add it to grid column bindings
ComputedColumn computedCol = StructureFactory.createComputedColumn();
PropertyHandle computedSet = grid.getColumnBindings();
computedCol.setName(displayFilterName);
StringBuffer expression = new StringBuffer("params[\"");
expression.append(filter);
expression.append("\"]");
computedCol.setExpression(expression.toString());
computedSet.addItem(computedCol);
// 2. create data and add computed column to it
DataItemHandle data = factory.newDataItem(null);
data.setResultSetColumn(computedCol.getName());
cellFilter.getContent().add(data);
// add visibility rule on row
HideRule hideRule = StructureFactory.createHideRule();
StringBuffer expressionHide = new StringBuffer(expression);
expressionHide.append(".value == null || ");
expressionHide.append(expression);
expressionHide.append(".value == \"\"");
hideRule.setExpression(expressionHide.toString());
PropertyHandle propVisHandle = row.getPropertyHandle(ReportItem.VISIBILITY_PROP);
propVisHandle.addItem(hideRule);
i++;
}
}
// second adding script within beforeFactory filling the parameters with values from inputFields
createScriptedBeforeFactory();
}
/*//################ CODE HERE IF YOU WANT TO ADD GENERATED DESIGN / MAY BE WORTH USING RPTTEMPLATE AND-OR RPTLIBRARY ###################
GridHandle grid = factory.newGridItem(null, 7, 3);
design.getBody().add(grid);
grid.setWidth("100%");
RowHandle row = (RowHandle) grid.getRows().get(0);
ImageHandle image = factory.newImage(null);
CellHandle cell = (CellHandle) row.getCells().get(0);
cell.getContent().add(image);
image.setURL("https://ofbiz.apache.org/images/ofbiz_logo.png");
LabelHandle label = factory.newLabel(null);
cell = (CellHandle) row.getCells().get(1);
cell.getContent().add(label);
label.setText("Dat is dat test !");
// ################ CODE HERE IF YOU WANT TO ADD GENERATED DESIGN / MAY BE WORTH USING RPTTEMPLATE AND-OR RPTLIBRARY ################### */
design.saveAs(rptDesignName);
design.close();
if (Debug.infoOn()) {
Debug.logInfo("####### Design generated: " + rptDesignName, MODULE);
}
session.closeAll(false);
Platform.shutdown();
}