Search in sources :

Example 1 with JRField

use of net.sf.jasperreports.engine.JRField in project midpoint by Evolveum.

the class JasperReportDto method initFileds.

private void initFileds(boolean onlyForPromptingParams) {
    if (jasperReportXml == null) {
        return;
    }
    try {
        design = ReportTypeUtil.loadJasperDesign(jasperReportXml);
        query = design.getQuery().getText();
        fields = new ArrayList<JasperReportFieldDto>();
        for (JRField field : design.getFieldsList()) {
            fields.add(new JasperReportFieldDto(field.getName(), field.getValueClass(), field.getValueClassName()));
        }
        for (JasperReportFieldDto field : fields) {
            design.removeField(field.getName());
        }
        parameters = new ArrayList<JasperReportParameterDto>();
        for (JRParameter parameter : design.getParametersList()) {
            if (parameter.isSystemDefined()) {
                continue;
            }
            if (onlyForPromptingParams && !parameter.isForPrompting()) {
                continue;
            }
            JasperReportParameterDto p = new JasperReportParameterDto(parameter);
            parameters.add(p);
        }
        for (JasperReportParameterDto param : parameters) {
            design.removeParameter(param.getName());
        }
        detail = new String(Base64.decodeBase64(jasperReportXml));
    } catch (SchemaException e) {
        // TODO Auto-generated catch block
        throw new IllegalArgumentException(e);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) JRParameter(net.sf.jasperreports.engine.JRParameter) JRField(net.sf.jasperreports.engine.JRField)

Example 2 with JRField

use of net.sf.jasperreports.engine.JRField in project opennms by OpenNMS.

the class JRobinFieldsProvider method getFields.

public JRField[] getFields(IReportConnection irConn, JRDataset reportDataset, Map parameters) throws JRException, UnsupportedOperationException {
    String query = "";
    if (reportDataset.getQuery() == null || reportDataset.getQuery().getText() == null || reportDataset.getQuery().getText().length() == 0) {
        return new JRField[0];
    }
    List<JRField> fields = new ArrayList<JRField>();
    //Add timestamp field
    addTimestampField(fields);
    query = reportDataset.getQuery().getText();
    if (query.contains("--step")) {
        addStepField(fields);
    }
    Matcher matcher = m_pattern.matcher(query);
    boolean matchFound = matcher.find();
    int i = 0;
    while (matchFound) {
        JRDesignField field = new JRDesignField();
        String fieldName = matcher.group();
        if (fieldName.contains(":")) {
            String[] split = fieldName.split(":");
            fieldName = split[split.length - 1];
        }
        field.setName(fieldName);
        field.setValueClass(Double.class);
        field.setDescription(fieldName);
        fields.add(field);
        matchFound = matcher.find();
        i++;
    }
    System.out.println("match count: " + matcher.groupCount());
    return fields.toArray(new JRField[fields.size()]);
}
Also used : JRField(net.sf.jasperreports.engine.JRField) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) JRDesignField(net.sf.jasperreports.engine.design.JRDesignField)

Example 3 with JRField

use of net.sf.jasperreports.engine.JRField in project opennms by OpenNMS.

the class MeasurementDataSourceTest method testMeasurementDataSource.

@Test
public void testMeasurementDataSource() {
    MeasurementDataSource ds = new MeasurementDataSource(getClass().getResourceAsStream("/responses/response1.xml"));
    List<JRField> fields = ds.getFields();
    Assert.assertEquals(6, fields.size());
    Assert.assertEquals(-1, ds.getCurrentRow());
    Assert.assertEquals(6, ds.getRowCount());
    final Double[][] expectedValues = new Double[][] { { Double.NaN, Double.NaN }, { Double.NaN, Double.NaN }, { 1.3, 2.3 }, { 1.4, 2.4 }, { 1.5, 2.5 }, { 1.6, 2.6 } };
    final Long[] expectedTimestamps = new Long[] { 1439544100000L, 1439544200000L, 1439544300000L, 1439544400000L, 1439544500000L, 1439544600000L };
    // to verify that moveFirst() is correctly implemented, we execute the test twice
    int runCount = 2;
    do {
        while (ds.next()) {
            // verify constant fields
            verifyField(ds, "step", Long.class, 1234567L);
            verifyField(ds, "start", Long.class, 1439539163433L);
            verifyField(ds, "end", Long.class, 1439557163433L);
            verifyField(ds, "timestamp", Date.class, new Date(expectedTimestamps[ds.getCurrentRow()]));
            // verify constant fields
            verifyField(ds, "IfHCInOctets", Double.class, expectedValues[ds.getCurrentRow()][0]);
            verifyField(ds, "IfHCOutOctets", Double.class, expectedValues[ds.getCurrentRow()][1]);
        }
        Assert.assertEquals(ds.getRowCount(), ds.getCurrentRow());
        ds.moveFirst();
    } while (--runCount > 0);
}
Also used : JRField(net.sf.jasperreports.engine.JRField) Date(java.util.Date) Test(org.junit.Test)

Example 4 with JRField

use of net.sf.jasperreports.engine.JRField in project opennms by OpenNMS.

the class ResourceQueryFieldsProvider method getFields.

public JRField[] getFields(IReportConnection irConn, JRDataset reportDataset, Map parameters) throws JRException, UnsupportedOperationException {
    String query = "";
    if (reportDataset.getQuery() == null || reportDataset.getQuery().getText() == null || reportDataset.getQuery().getText().length() == 0) {
        return new JRField[0];
    }
    List<JRField> fields = new ArrayList<JRField>();
    query = reportDataset.getQuery().getText();
    addPathColumn(fields);
    if (query.contains("--dsName")) {
        String[] splitDsNames = query.split("--dsName");
        String dsNames = splitDsNames[splitDsNames.length - 1];
        String[] dsNameList = checkForCommandsAndTrim(dsNames).split(",");
        for (String ds : dsNameList) {
            JRDesignField field = new JRDesignField();
            field.setName(ds.trim());
            field.setDescription(ds.trim());
            field.setValueClass(String.class);
            fields.add(field);
        }
    }
    if (query.contains("--string")) {
        String[] splitStrProps = query.split("--string");
        String strProp = splitStrProps[splitStrProps.length - 1];
        String[] strPropList = checkForCommandsAndTrim(strProp).split(",");
        for (String prop : strPropList) {
            JRDesignField field = new JRDesignField();
            field.setName(prop.trim());
            field.setDescription(prop.trim());
            field.setValueClass(String.class);
            fields.add(field);
        }
    }
    return fields.toArray(new JRField[fields.size()]);
}
Also used : JRField(net.sf.jasperreports.engine.JRField) ArrayList(java.util.ArrayList) JRDesignField(net.sf.jasperreports.engine.design.JRDesignField)

Aggregations

JRField (net.sf.jasperreports.engine.JRField)4 ArrayList (java.util.ArrayList)2 JRDesignField (net.sf.jasperreports.engine.design.JRDesignField)2 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 JRParameter (net.sf.jasperreports.engine.JRParameter)1 Test (org.junit.Test)1