Search in sources :

Example 6 with ReportParameters

use of org.opennms.api.reporting.parameter.ReportParameters in project opennms by OpenNMS.

the class JasperReportServiceTest method testDescriptions.

@Test
public void testDescriptions() throws ReportException {
    ReportParameters reportParameters = m_reportService.getParameters(REPORTID);
    ReportStringParm stringParm1 = reportParameters.getStringParms().get(0);
    Assert.assertEquals("a string parameter", stringParm1.getDisplayName());
    ReportStringParm stringParm2 = reportParameters.getStringParms().get(1);
    Assert.assertEquals("stringParameter2", stringParm2.getDisplayName());
    Assert.assertEquals(3, reportParameters.getDateParms().size());
}
Also used : ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) Test(org.junit.Test)

Example 7 with ReportParameters

use of org.opennms.api.reporting.parameter.ReportParameters in project opennms by OpenNMS.

the class JasperReportServiceTest method testGetParmeters.

@Test
public void testGetParmeters() throws ReportException {
    ReportParameters reportParameters = m_reportService.getParameters(REPORTID);
    assertNotNull(reportParameters);
    assertEquals(1, reportParameters.getIntParms().size());
    assertEquals(1, reportParameters.getFloatParms().size());
    assertEquals(1, reportParameters.getDoubleParms().size());
    assertEquals(2, reportParameters.getStringParms().size());
    assertEquals(3, reportParameters.getDateParms().size());
}
Also used : ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) Test(org.junit.Test)

Example 8 with ReportParameters

use of org.opennms.api.reporting.parameter.ReportParameters in project opennms by OpenNMS.

the class JasperReportServiceGetParametersTest method readPropertiesOfTrivialTestReportFromRESTRepoTest.

@Test
public void readPropertiesOfTrivialTestReportFromRESTRepoTest() throws ReportException {
    String id = "REMOTE_trivialJasperReport";
    assertNotNull(service.getParameters(id));
    ReportParameters params = service.getParameters(id);
    assertEquals(0, params.getReportParms().size());
}
Also used : ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) Test(org.junit.Test)

Example 9 with ReportParameters

use of org.opennms.api.reporting.parameter.ReportParameters in project opennms by OpenNMS.

the class DefaultParameterConversionService method convert.

/**
 * {@inheritDoc}
 */
@Override
public ReportParameters convert(Parameters configParameters) {
    ReportParameters reportParameters = new ReportParameters();
    if (configParameters == null) {
        return reportParameters;
    }
    // add date parms to criteria
    final List<ReportDateParm> dateParms = configParameters.getDateParms().stream().map(dp -> {
        final ReportDateParm dateParm = new ReportDateParm();
        dateParm.setUseAbsoluteDate(dp.getUseAbsoluteDate().orElse(null));
        dateParm.setDisplayName(dp.getDisplayName());
        dateParm.setName(dp.getName());
        dateParm.setCount(new Integer((int) dp.getDefaultCount()));
        dateParm.setInterval(dp.getDefaultInterval());
        Calendar cal = Calendar.getInstance();
        if (dp.getDefaultTime().isPresent()) {
            final DefaultTime defaultTime = dp.getDefaultTime().get();
            dateParm.setHours(defaultTime.getHours());
            cal.set(Calendar.HOUR_OF_DAY, dateParm.getHours());
            dateParm.setMinutes(defaultTime.getMinutes());
            cal.set(Calendar.MINUTE, dateParm.getMinutes());
        } else {
            cal.set(Calendar.HOUR_OF_DAY, 0);
            cal.set(Calendar.MINUTE, 0);
        }
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        int amount = 0 - dp.getDefaultCount();
        if (dp.getDefaultInterval().equals("year")) {
            cal.add(Calendar.YEAR, amount);
        } else {
            if (dp.getDefaultInterval().equals("month")) {
                cal.add(Calendar.MONTH, amount);
            } else {
                cal.add(Calendar.DATE, amount);
            }
        }
        dateParm.setDate(cal.getTime());
        return dateParm;
    }).collect(Collectors.toList());
    reportParameters.setDateParms(dateParms);
    // add string parms to criteria
    final List<ReportStringParm> stringParms = configParameters.getStringParms().stream().map(sp -> {
        final ReportStringParm stringParm = new ReportStringParm();
        stringParm.setDisplayName(sp.getDisplayName());
        stringParm.setName(sp.getName());
        stringParm.setInputType(sp.getInputType());
        stringParm.setValue(sp.getDefault());
        return stringParm;
    }).collect(Collectors.toList());
    reportParameters.setStringParms(stringParms);
    // add int parms to criteria
    final List<ReportIntParm> intParms = configParameters.getIntParms().stream().map(ip -> {
        final ReportIntParm intParm = new ReportIntParm();
        intParm.setDisplayName(ip.getDisplayName());
        intParm.setName(ip.getName());
        intParm.setInputType(ip.getInputType());
        intParm.setValue(ip.getDefault());
        return intParm;
    }).collect(Collectors.toList());
    reportParameters.setIntParms(intParms);
    return reportParameters;
}
Also used : List(java.util.List) Calendar(java.util.Calendar) ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm) ParameterConversionService(org.opennms.reporting.core.svclayer.ParameterConversionService) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) Collectors(java.util.stream.Collectors) Parameters(org.opennms.netmgt.config.reporting.Parameters) DefaultTime(org.opennms.netmgt.config.reporting.DefaultTime) DefaultTime(org.opennms.netmgt.config.reporting.DefaultTime) ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) Calendar(java.util.Calendar) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm)

Example 10 with ReportParameters

use of org.opennms.api.reporting.parameter.ReportParameters in project opennms by OpenNMS.

the class JasperReportServiceTest method testDefaults.

/**
 * Using a test date of -112426200000L ( Thu, 09 Jun 1966 18:30:00)
 */
@Test
public void testDefaults() throws ReportException {
    ReportParameters reportParameters = m_reportService.getParameters(REPORTID);
    ReportStringParm stringParm1 = reportParameters.getStringParms().get(0);
    Assert.assertEquals("Hosts", stringParm1.getValue());
    ReportStringParm stringParm2 = reportParameters.getStringParms().get(1);
    Assert.assertEquals("Routers", stringParm2.getValue());
    ReportFloatParm floatParm = reportParameters.getFloatParms().get(0);
    Assert.assertEquals(Float.valueOf("99.99"), floatParm.getValue());
    ReportIntParm intParm = reportParameters.getIntParms().get(0);
    Assert.assertEquals(100, intParm.getValue());
    ReportDoubleParm doubleParm = reportParameters.getDoubleParms().get(0);
    Assert.assertEquals(Double.valueOf("99.99"), doubleParm.getValue());
}
Also used : ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) ReportDoubleParm(org.opennms.api.reporting.parameter.ReportDoubleParm) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) ReportFloatParm(org.opennms.api.reporting.parameter.ReportFloatParm) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm) Test(org.junit.Test)

Aggregations

ReportParameters (org.opennms.api.reporting.parameter.ReportParameters)14 Test (org.junit.Test)12 ReportStringParm (org.opennms.api.reporting.parameter.ReportStringParm)4 Calendar (java.util.Calendar)3 Date (java.util.Date)2 ReportDateParm (org.opennms.api.reporting.parameter.ReportDateParm)2 ReportIntParm (org.opennms.api.reporting.parameter.ReportIntParm)2 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 BeforeClass (org.junit.BeforeClass)1 ReportDoubleParm (org.opennms.api.reporting.parameter.ReportDoubleParm)1 ReportFloatParm (org.opennms.api.reporting.parameter.ReportFloatParm)1 DefaultTime (org.opennms.netmgt.config.reporting.DefaultTime)1 Parameters (org.opennms.netmgt.config.reporting.Parameters)1 ParameterConversionService (org.opennms.reporting.core.svclayer.ParameterConversionService)1