Search in sources :

Example 1 with ReportDateParm

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

the class DefaultParameterConversionServiceTest method testModifiedDateConversion.

@Test
public void testModifiedDateConversion() {
    ReportParameters parameters = m_conversionService.convert(m_dao.getParameters(ID));
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.MONTH, -1);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    ReportDateParm dateParm = parameters.getDateParms().get(0);
    dateParm.setCount(1);
    dateParm.setInterval("month");
    dateParm.setHours(0);
    dateParm.setMinutes(0);
    Map<String, Object> parmMap = parameters.getReportParms(ReportMode.SCHEDULED);
    Date storedDate = (Date) parmMap.get("endDate");
    assertEquals(0, storedDate.compareTo(cal.getTime()));
}
Also used : ReportParameters(org.opennms.api.reporting.parameter.ReportParameters) ReportDateParm(org.opennms.api.reporting.parameter.ReportDateParm) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 2 with ReportDateParm

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

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

Aggregations

ReportDateParm (org.opennms.api.reporting.parameter.ReportDateParm)3 Calendar (java.util.Calendar)2 ReportIntParm (org.opennms.api.reporting.parameter.ReportIntParm)2 ReportParameters (org.opennms.api.reporting.parameter.ReportParameters)2 ReportStringParm (org.opennms.api.reporting.parameter.ReportStringParm)2 Date (java.util.Date)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Test (org.junit.Test)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 MessageBuilder (org.springframework.binding.message.MessageBuilder)1 MessageContext (org.springframework.binding.message.MessageContext)1