Search in sources :

Example 41 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class IdPointValueStatisticsQuantizerCsvCallback method closePeriod.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.statistics.ParentStatisticsQuantizerCallback#closePeriod(java.util.Map, long)
	 */
@Override
public void closePeriod(Map<Integer, StatisticsGenerator> periodStatsMap, long periodStartTime) {
    try {
        if (!wroteHeaders) {
            this.writer.writeNext(headers);
            this.wroteHeaders = true;
        }
        // Write out the period start time
        if (dateFormatter == null)
            this.rowData[1] = Long.toString(periodStartTime);
        else
            this.rowData[1] = dateFormatter.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(periodStartTime), TimeZone.getDefault().toZoneId()));
        Iterator<Integer> it = periodStatsMap.keySet().iterator();
        while (it.hasNext()) {
            Integer id = it.next();
            StatisticsGenerator stats = periodStatsMap.get(id);
            DataPointVO vo = this.voMap.get(id);
            if (stats instanceof ValueChangeCounter) {
                ValueChangeCounter statisticsGenerator = (ValueChangeCounter) stats;
                switch(rollup) {
                    case FIRST:
                        if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
                            this.writeImageValue(statisticsGenerator.getFirstValue(), statisticsGenerator.getFirstTime(), periodStartTime, vo);
                        else
                            this.writeDataValue(periodStartTime, statisticsGenerator.getFirstValue(), vo);
                        break;
                    case LAST:
                        if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
                            this.writeImageValue(statisticsGenerator.getLastValue(), statisticsGenerator.getLastTime(), periodStartTime, vo);
                        else
                            this.writeDataValue(periodStartTime, statisticsGenerator.getLastValue(), vo);
                        break;
                    case COUNT:
                        this.rowData[this.columnMap.get(vo.getId())] = Integer.toString(statisticsGenerator.getCount());
                        break;
                    default:
                        // Default to first
                        this.writeDataValue(periodStartTime, statisticsGenerator.getFirstValue(), vo);
                }
            } else if (stats instanceof AnalogStatistics) {
                AnalogStatistics statisticsGenerator = (AnalogStatistics) stats;
                switch(rollup) {
                    case AVERAGE:
                        this.writeDouble(statisticsGenerator.getAverage(), vo);
                        break;
                    case DELTA:
                        this.writeDouble(statisticsGenerator.getDelta(), vo);
                        break;
                    case MINIMUM:
                        this.writeDouble(statisticsGenerator.getMinimumValue(), vo);
                        break;
                    case MAXIMUM:
                        this.writeDouble(statisticsGenerator.getMaximumValue(), vo);
                        break;
                    // TODO This should be removed after discussion with Jared
                    case ACCUMULATOR:
                        Double accumulatorValue = statisticsGenerator.getLastValue();
                        if (accumulatorValue == null) {
                            accumulatorValue = statisticsGenerator.getMaximumValue();
                        }
                        this.writeDouble(accumulatorValue, vo);
                        break;
                    case SUM:
                        this.writeDouble(statisticsGenerator.getSum(), vo);
                        break;
                    case START:
                        this.writeDouble(statisticsGenerator.getStartValue(), vo);
                        break;
                    case FIRST:
                        this.writeDouble(statisticsGenerator.getFirstValue(), vo);
                        break;
                    case LAST:
                        this.writeDouble(statisticsGenerator.getLastValue(), vo);
                        break;
                    case COUNT:
                        this.rowData[this.columnMap.get(vo.getId())] = Integer.toString(statisticsGenerator.getCount());
                        break;
                    case INTEGRAL:
                        this.writeIntegral(statisticsGenerator.getIntegral(), vo);
                        break;
                    default:
                        // Default to first
                        this.writeDouble(statisticsGenerator.getFirstValue(), vo);
                }
            } else {
                throw new ShouldNeverHappenException("Unsuported statistics type: " + stats.getClass().getName());
            }
        }
        this.writer.writeNext(this.rowData);
        // Clear out the row data
        for (int i = 1; i < this.rowData.length; i++) this.rowData[i] = null;
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) StatisticsGenerator(com.serotonin.m2m2.view.stats.StatisticsGenerator) ValueChangeCounter(com.serotonin.m2m2.view.stats.ValueChangeCounter) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnalogStatistics(com.serotonin.m2m2.view.stats.AnalogStatistics) IOException(java.io.IOException)

Example 42 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class MaintenanceEventRT method createTrigger.

public TimerTrigger createTrigger(boolean activeTrigger) {
    if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MANUAL)
        return null;
    if (vo.getScheduleType() == MaintenanceEventVO.TYPE_CRON) {
        try {
            if (activeTrigger)
                return new CronTimerTrigger(vo.getActiveCron());
            return new CronTimerTrigger(vo.getInactiveCron());
        } catch (ParseException e) {
            // Should never happen, so wrap and rethrow
            throw new ShouldNeverHappenException(e);
        }
    }
    if (vo.getScheduleType() == MaintenanceEventVO.TYPE_ONCE) {
        DateTime dt;
        if (activeTrigger)
            dt = new DateTime(vo.getActiveYear(), vo.getActiveMonth(), vo.getActiveDay(), vo.getActiveHour(), vo.getActiveMinute(), vo.getActiveSecond(), 0);
        else
            dt = new DateTime(vo.getInactiveYear(), vo.getInactiveMonth(), vo.getInactiveDay(), vo.getInactiveHour(), vo.getInactiveMinute(), vo.getInactiveSecond(), 0);
        return new OneTimeTrigger(new Date(dt.getMillis()));
    }
    int month = vo.getActiveMonth();
    int day = vo.getActiveDay();
    int hour = vo.getActiveHour();
    int minute = vo.getActiveMinute();
    int second = vo.getActiveSecond();
    if (!activeTrigger) {
        month = vo.getInactiveMonth();
        day = vo.getInactiveDay();
        hour = vo.getInactiveHour();
        minute = vo.getInactiveMinute();
        second = vo.getInactiveSecond();
    }
    StringBuilder expression = new StringBuilder();
    expression.append(second).append(' ');
    expression.append(minute).append(' ');
    if (vo.getScheduleType() == MaintenanceEventVO.TYPE_HOURLY)
        expression.append("* * * ?");
    else {
        expression.append(hour).append(' ');
        if (vo.getScheduleType() == MaintenanceEventVO.TYPE_DAILY)
            expression.append("* * ?");
        else if (vo.getScheduleType() == MaintenanceEventVO.TYPE_WEEKLY)
            expression.append("? * ").append(weekdays[day]);
        else {
            if (day > 0)
                expression.append(day);
            else if (day == -1)
                expression.append('L');
            else
                expression.append(-day).append('L');
            if (vo.getScheduleType() == MaintenanceEventVO.TYPE_MONTHLY)
                expression.append(" * ?");
            else
                expression.append(' ').append(month).append(" ?");
        }
    }
    CronTimerTrigger cronTrigger;
    try {
        cronTrigger = new CronTimerTrigger(expression.toString());
    } catch (ParseException e) {
        // Should never happen, so wrap and rethrow
        throw new ShouldNeverHappenException(e);
    }
    return cronTrigger;
}
Also used : OneTimeTrigger(com.serotonin.timer.OneTimeTrigger) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) CronTimerTrigger(com.serotonin.timer.CronTimerTrigger) ParseException(java.text.ParseException) DateTime(org.joda.time.DateTime) Date(java.util.Date)

Example 43 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class InternalDataSourceRT method defaultNewPointToDataSource.

private void defaultNewPointToDataSource(DataPointVO dpvo, String dsXid) {
    DataSourceVO<?> dsvo = DataSourceDao.instance.getDataSource(dsXid);
    if (dsvo == null)
        throw new ShouldNeverHappenException("Error creating point, unknown data source: " + dsXid);
    dpvo.setDeviceName(dsvo.getName());
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 44 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class PointValueTimeCsvWriter method writeMultiplePointStatsAtSameTime.

@Override
public void writeMultiplePointStatsAtSameTime(List<DataPointStatisticsGenerator> periodStats, long timestamp) throws IOException {
    this.jgen.writeStartObject();
    boolean first = true;
    for (DataPointStatisticsGenerator gen : periodStats) {
        if (info.isMultiplePointsPerArray()) {
            writeEntry(gen, true, first);
        } else {
            throw new ShouldNeverHappenException("Implement me?");
        }
        first = false;
    }
    this.jgen.writeEndObject();
}
Also used : DataPointStatisticsGenerator(com.infiniteautomation.mango.rest.v2.model.pointValue.quantize.DataPointStatisticsGenerator) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 45 with ShouldNeverHappenException

use of com.serotonin.ShouldNeverHappenException in project ma-modules-public by infiniteautomation.

the class PointValueTimeJsonWriter method writeMultiplePointStatsAtSameTime.

/* (non-Javadoc)
     * @see com.infiniteautomation.mango.rest.v2.model.pointValue.query.PointValueTimeWriter#writeMultipleStatsAsObject(java.util.List)
     */
@Override
public void writeMultiplePointStatsAtSameTime(List<DataPointStatisticsGenerator> periodStats, long timestamp) throws IOException {
    this.jgen.writeStartObject();
    if (info.fieldsContains(PointValueField.TIMESTAMP))
        writeTimestamp(timestamp);
    for (DataPointStatisticsGenerator gen : periodStats) {
        if (info.isMultiplePointsPerArray()) {
            DataPointVO vo = gen.getVo();
            this.jgen.writeObjectFieldStart(vo.getXid());
            writeEntry(gen, false, false);
            this.jgen.writeEndObject();
        } else {
            throw new ShouldNeverHappenException("Implement me?");
        }
    }
    this.jgen.writeEndObject();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointStatisticsGenerator(com.infiniteautomation.mango.rest.v2.model.pointValue.quantize.DataPointStatisticsGenerator) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Aggregations

ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)83 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)10 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)9 SQLException (java.sql.SQLException)9 ParseException (java.text.ParseException)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)6 FileNotFoundException (java.io.FileNotFoundException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ResultSet (java.sql.ResultSet)5 Statement (java.sql.Statement)5 JsonException (com.serotonin.json.JsonException)4 JsonWriter (com.serotonin.json.JsonWriter)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)4 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)4 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 StringWriter (java.io.StringWriter)4 HashMap (java.util.HashMap)4