Search in sources :

Example 1 with DefaultTime

use of org.opennms.netmgt.config.reporting.DefaultTime 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

Calendar (java.util.Calendar)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ReportDateParm (org.opennms.api.reporting.parameter.ReportDateParm)1 ReportIntParm (org.opennms.api.reporting.parameter.ReportIntParm)1 ReportParameters (org.opennms.api.reporting.parameter.ReportParameters)1 ReportStringParm (org.opennms.api.reporting.parameter.ReportStringParm)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