Search in sources :

Example 56 with ShouldNeverHappenException

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

the class BaseDwr method addUserComment.

/**
 * Logs a user comment after validation.
 *
 * @param eventId
 * @param comment
 * @return
 */
@DwrPermission(user = true)
public UserCommentVO addUserComment(int typeId, int referenceId, String comment) {
    if (StringUtils.isBlank(comment))
        return null;
    User user = Common.getHttpUser();
    UserCommentVO c = new UserCommentVO();
    c.setXid(UserCommentDao.instance.generateUniqueXid());
    c.setComment(comment);
    c.setTs(Common.timer.currentTimeMillis());
    c.setUserId(user.getId());
    c.setUsername(user.getUsername());
    c.setReferenceId(referenceId);
    if (typeId == UserCommentVO.TYPE_EVENT) {
        c.setCommentType(UserCommentVO.TYPE_EVENT);
        EventDao.instance.insertEventComment(c);
    } else if (typeId == UserCommentVO.TYPE_POINT) {
        c.setCommentType(UserCommentVO.TYPE_POINT);
        UserCommentDao.instance.save(c);
    } else
        throw new ShouldNeverHappenException("Invalid comment type: " + typeId);
    return c;
}
Also used : User(com.serotonin.m2m2.vo.User) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) UserCommentVO(com.serotonin.m2m2.vo.comment.UserCommentVO) DwrPermission(com.serotonin.m2m2.web.dwr.util.DwrPermission)

Example 57 with ShouldNeverHappenException

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

the class DataSourceEditDwr method getPoint.

protected DataPointVO getPoint(int pointId, DataPointDefaulter defaulter) {
    // Added to allow saving point settings from data point edit view
    DataPointVO dp = Common.getUser().getEditPoint();
    DataSourceVO<?> ds = Common.getUser().getEditDataSource();
    if (ds.getId() == Common.NEW_ID)
        throw new ShouldNeverHappenException("Please Save Data Source First.");
    if (pointId == Common.NEW_ID) {
        String deviceName;
        String readPermission = null;
        String setPermission = null;
        if (dp != null) {
            deviceName = dp.getDeviceName();
            readPermission = dp.getReadPermission();
            setPermission = dp.getSetPermission();
        } else {
            deviceName = ds.getName();
        }
        dp = new DataPointVO();
        dp.setXid(DataPointDao.instance.generateUniqueXid());
        dp.setDeviceName(deviceName);
        dp.setId(pointId);
        dp.setDataSourceId(ds.getId());
        dp.setDataSourceTypeName(ds.getDefinition().getDataSourceTypeName());
        dp.setReadPermission(readPermission);
        dp.setSetPermission(setPermission);
        dp.setPointLocator(ds.createPointLocator());
        dp.setEventDetectors(new ArrayList<AbstractPointEventDetectorVO<?>>(0));
        dp.defaultTextRenderer();
    } else {
        // retain in the user's editing point
        if (dp.getId() != pointId)
            dp = DataPointDao.instance.getFull(pointId);
    }
    // Use the defaulter
    if (defaulter != null && dp != null) {
        if (dp.getId() == Common.NEW_ID)
            defaulter.setDefaultValues(dp);
        else
            defaulter.updateDefaultValues(dp);
    }
    // should use for this point.  If not we must fail.
    if (!(dp.getDataSourceTypeName().equals(ds.getDefinition().getDataSourceTypeName())) || (dp.getDataSourceId() != ds.getId())) {
        throw new RuntimeException("Data point type mismatch to data source type, unable to save.  Are you working with multiple tabs open?");
    }
    Common.getUser().setEditPoint(dp);
    return dp;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) AbstractPointEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException)

Example 58 with ShouldNeverHappenException

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

the class PointEventDetectorVO method getConfigurationDescription.

private TranslatableMessage getConfigurationDescription() {
    TranslatableMessage message;
    TranslatableMessage durationDesc = getDurationDescription();
    if (detectorType == TYPE_ANALOG_HIGH_LIMIT) {
        if (binaryState) {
            // Check if Not above
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.highLimitNotHigher", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.highLimitNotHigherPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        } else {
            // Must be above
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.highLimit", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.highLimitPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        }
    } else if (detectorType == TYPE_ANALOG_LOW_LIMIT) {
        if (binaryState) {
            // Not below
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.lowLimitNotLower", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.lowLimitNotLowerPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        } else {
            // Must be below
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.lowLimit", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.lowLimitPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        }
    } else if (detectorType == TYPE_BINARY_STATE) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.state", dataPoint.getTextRenderer().getText(binaryState, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.statePeriod", dataPoint.getTextRenderer().getText(binaryState, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else if (detectorType == TYPE_MULTISTATE_STATE) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.state", dataPoint.getTextRenderer().getText(multistateState, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.statePeriod", dataPoint.getTextRenderer().getText(multistateState, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else if (detectorType == TYPE_POINT_CHANGE)
        message = new TranslatableMessage("event.detectorVo.change");
    else if (detectorType == TYPE_STATE_CHANGE_COUNT)
        message = new TranslatableMessage("event.detectorVo.changeCount", changeCount, durationDesc);
    else if (detectorType == TYPE_NO_CHANGE)
        message = new TranslatableMessage("event.detectorVo.noChange", durationDesc);
    else if (detectorType == TYPE_NO_UPDATE)
        message = new TranslatableMessage("event.detectorVo.noUpdate", durationDesc);
    else if (detectorType == TYPE_ALPHANUMERIC_STATE) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.state", dataPoint.getTextRenderer().getText(alphanumericState, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.statePeriod", dataPoint.getTextRenderer().getText(alphanumericState, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else if (detectorType == TYPE_ALPHANUMERIC_REGEX_STATE)
        message = new TranslatableMessage("pointEdit.detectors.regexState", durationDesc);
    else if (detectorType == TYPE_POSITIVE_CUSUM) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.posCusum", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.posCusumPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else if (detectorType == TYPE_NEGATIVE_CUSUM) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.negCusum", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.negCusumPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else if (detectorType == TYPE_ANALOG_RANGE) {
        // For within range
        if (binaryState) {
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.range", dataPoint.getTextRenderer().getText(weight, TextRenderer.HINT_SPECIFIC), dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.rangePeriod", dataPoint.getTextRenderer().getText(weight, TextRenderer.HINT_SPECIFIC), dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        } else {
            // Outside of range
            if (durationDesc == null)
                message = new TranslatableMessage("event.detectorVo.rangeOutside", dataPoint.getTextRenderer().getText(weight, TextRenderer.HINT_SPECIFIC), dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
            else
                message = new TranslatableMessage("event.detectorVo.rangeOutsidePeriod", dataPoint.getTextRenderer().getText(weight, TextRenderer.HINT_SPECIFIC), dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
        }
    } else if (detectorType == TYPE_SMOOTHNESS) {
        if (durationDesc == null)
            message = new TranslatableMessage("event.detectorVo.smoothness", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC));
        else
            message = new TranslatableMessage("event.detectorVo.smoothnessPeriod", dataPoint.getTextRenderer().getText(limit, TextRenderer.HINT_SPECIFIC), durationDesc);
    } else
        throw new ShouldNeverHappenException("Unknown detector type: " + detectorType);
    return message;
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage)

Example 59 with ShouldNeverHappenException

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

the class DataPointRT method scheduleTimeoutImpl.

public void scheduleTimeoutImpl(long fireTime) {
    synchronized (intervalLoggingLock) {
        DataValue value;
        if (vo.getLoggingType() == DataPointVO.LoggingTypes.INTERVAL) {
            if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.INSTANT)
                value = PointValueTime.getValue(pointValue);
            else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MAXIMUM || vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MINIMUM) {
                value = PointValueTime.getValue(intervalValue);
                intervalValue = pointValue;
            } else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
                // If we don't have enough averaging values then we will bail and wait for more
                if (vo.isOverrideIntervalLoggingSamples() && (averagingValues.size() != vo.getIntervalLoggingSampleWindowSize()))
                    return;
                if (vo.getPointLocator().getDataTypeId() == DataTypes.MULTISTATE) {
                    StartsAndRuntimeList stats = new StartsAndRuntimeList(intervalStartTime, fireTime, intervalValue, averagingValues);
                    double maxProportion = -1;
                    Object valueAtMax = null;
                    for (StartsAndRuntime sar : stats.getData()) {
                        if (sar.getProportion() > maxProportion) {
                            maxProportion = sar.getProportion();
                            valueAtMax = sar.getValue();
                        }
                    }
                    if (valueAtMax != null)
                        value = new MultistateValue(DataValue.objectToValue(valueAtMax).getIntegerValue());
                    else
                        value = null;
                } else {
                    AnalogStatistics stats = new AnalogStatistics(intervalStartTime, fireTime, intervalValue, averagingValues);
                    if (stats.getAverage() == null || (stats.getAverage() == Double.NaN && stats.getCount() == 0))
                        value = null;
                    else if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
                        value = new NumericValue(stats.getAverage());
                    else if (vo.getPointLocator().getDataTypeId() == DataTypes.BINARY)
                        value = new BinaryValue(stats.getAverage() >= 0.5);
                    else
                        throw new ShouldNeverHappenException("Unsupported average interval logging data type.");
                }
                // Compute the center point of our average data, starting by finding where our period started
                long sampleWindowStartTime;
                if (vo.isOverrideIntervalLoggingSamples())
                    sampleWindowStartTime = averagingValues.get(0).getTime();
                else
                    sampleWindowStartTime = intervalStartTime;
                intervalStartTime = fireTime;
                // Fix to simulate center tapped filter (un-shift the average)
                fireTime = sampleWindowStartTime + (fireTime - sampleWindowStartTime) / 2L;
                intervalValue = pointValue;
                if (!vo.isOverrideIntervalLoggingSamples())
                    averagingValues.clear();
            } else
                throw new ShouldNeverHappenException("Unknown interval logging type: " + vo.getIntervalLoggingType());
        } else if (vo.getLoggingType() == DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL) {
            // Okay, no changes rescheduled the timer. Get a value, reschedule
            if (pointValue != null) {
                value = pointValue.getValue();
                if (vo.getPointLocator().getDataTypeId() == DataTypes.NUMERIC)
                    toleranceOrigin = pointValue.getDoubleValue();
            } else
                value = null;
            rescheduleChangeInterval(Common.getMillis(vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod()));
        } else
            value = null;
        if (value != null) {
            PointValueTime newValue = new PointValueTime(value, fireTime);
            valueCache.logPointValueAsync(newValue, null);
            // Fire logged Events
            fireEvents(null, newValue, null, false, false, true, false, false);
        }
    }
}
Also used : StartsAndRuntime(com.infiniteautomation.mango.statistics.StartsAndRuntime) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) StartsAndRuntimeList(com.infiniteautomation.mango.statistics.StartsAndRuntimeList) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnalogStatistics(com.infiniteautomation.mango.statistics.AnalogStatistics) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 60 with ShouldNeverHappenException

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

the class ImageChartUtils method getChartData.

public static byte[] getChartData(PointTimeSeriesCollection pointTimeSeriesCollection, boolean showLegend, int width, int height, long from, long to) {
    try {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        writeChart(pointTimeSeriesCollection, showLegend, out, width, height, from, to);
        return out.toByteArray();
    } catch (IOException e) {
        throw new ShouldNeverHappenException(e);
    }
}
Also used : ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

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