Search in sources :

Example 1 with ReportDoubleParm

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

the class ReportParametersValidator method validateReportParameters.

/**
 * <p>validateReportParameters</p>
 *
 * @param reportCriteria a {@link org.opennms.api.reporting.parameter.ReportParameters} object.
 * @param context a {@link org.springframework.binding.validation.ValidationContext} object.
 */
public void validateReportParameters(ReportParameters reportCriteria, ValidationContext context) {
    MessageContext messages = context.getMessageContext();
    List<ReportDateParm> dateParms = reportCriteria.getDateParms();
    for (Iterator<ReportDateParm> dateParmIter = dateParms.iterator(); dateParmIter.hasNext(); ) {
        ReportDateParm dateParm = dateParmIter.next();
        if (dateParm.getDate() == null) {
            messages.addMessage(new MessageBuilder().error().source("date parms").defaultText("cannot have null date field" + dateParm.getDisplayName()).build());
        }
    }
    List<ReportStringParm> stringParms = reportCriteria.getStringParms();
    for (Iterator<ReportStringParm> stringParmIter = stringParms.iterator(); stringParmIter.hasNext(); ) {
        ReportStringParm stringParm = stringParmIter.next();
        if (stringParm.getValue() == "") {
            messages.addMessage(new MessageBuilder().error().source("string parms").defaultText("cannot have empty string field" + stringParm.getDisplayName()).build());
        }
    }
    List<ReportIntParm> intParms = reportCriteria.getIntParms();
    for (Iterator<ReportIntParm> intParmIter = intParms.iterator(); intParmIter.hasNext(); ) {
        ReportIntParm intParm = intParmIter.next();
        // TODO add a more sensible check here - I think we probably can have zero int parm
        if (intParm.getValue() == 0) {
            messages.addMessage(new MessageBuilder().error().source("int parms").defaultText("cannot have zero integer field" + intParm.getDisplayName()).build());
        }
    }
    List<ReportFloatParm> floatParms = reportCriteria.getFloatParms();
    for (Iterator<ReportFloatParm> floatParmIter = floatParms.iterator(); floatParmIter.hasNext(); ) {
        ReportFloatParm floatParm = floatParmIter.next();
        if (floatParm.getValue() == null) {
            messages.addMessage(new MessageBuilder().error().source("float parms").defaultText("cannot have null float field" + floatParm.getDisplayName()).build());
        }
    }
    List<ReportDoubleParm> doubleParms = reportCriteria.getDoubleParms();
    for (Iterator<ReportDoubleParm> doubleParmIter = doubleParms.iterator(); doubleParmIter.hasNext(); ) {
        ReportDoubleParm doubleParm = doubleParmIter.next();
        if (doubleParm.getValue() == null) {
            messages.addMessage(new MessageBuilder().error().source("double parms").defaultText("cannot have null double field" + doubleParm.getDisplayName()).build());
        }
    }
}
Also used : ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) ReportDoubleParm(org.opennms.api.reporting.parameter.ReportDoubleParm) ReportFloatParm(org.opennms.api.reporting.parameter.ReportFloatParm) MessageBuilder(org.springframework.binding.message.MessageBuilder) ReportStringParm(org.opennms.api.reporting.parameter.ReportStringParm) MessageContext(org.springframework.binding.message.MessageContext) ReportIntParm(org.opennms.api.reporting.parameter.ReportIntParm)

Example 2 with ReportDoubleParm

use of org.opennms.api.reporting.parameter.ReportDoubleParm 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

ReportDoubleParm (org.opennms.api.reporting.parameter.ReportDoubleParm)2 ReportFloatParm (org.opennms.api.reporting.parameter.ReportFloatParm)2 ReportIntParm (org.opennms.api.reporting.parameter.ReportIntParm)2 ReportStringParm (org.opennms.api.reporting.parameter.ReportStringParm)2 Test (org.junit.Test)1 ReportDateParm (org.opennms.api.reporting.parameter.ReportDateParm)1 ReportParameters (org.opennms.api.reporting.parameter.ReportParameters)1 MessageBuilder (org.springframework.binding.message.MessageBuilder)1 MessageContext (org.springframework.binding.message.MessageContext)1