Search in sources :

Example 6 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-core-public by infiniteautomation.

the class DataPointVO method createIntegralRenderer.

public TextRenderer createIntegralRenderer() {
    AnalogRenderer renderer = new AnalogRenderer();
    renderer.setUnit(defaultIntegralUnit());
    if (useIntegralUnit)
        renderer.setRenderedUnit(integralUnit);
    else
        renderer.setRenderedUnit(defaultIntegralUnit());
    renderer.setUseUnitAsSuffix(true);
    renderer.setFormat("0.0");
    return renderer;
}
Also used : AnalogRenderer(com.serotonin.m2m2.view.text.AnalogRenderer)

Example 7 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-core-public by infiniteautomation.

the class DataPointVO method validate.

@Override
public void validate(ProcessResult response) {
    super.validate(response);
    // xid,name in superclass
    if (StringValidation.isLengthGreaterThan(deviceName, 255))
        response.addMessage("deviceName", new TranslatableMessage("validate.notLongerThan", 255));
    if (pointLocator != null) {
        if (pointLocator.getDataTypeId() == DataTypes.NUMERIC && (loggingType == DataPointVO.LoggingTypes.ON_CHANGE || loggingType == DataPointVO.LoggingTypes.ON_CHANGE_INTERVAL)) {
            if (tolerance < 0)
                response.addContextualMessage("tolerance", "validate.cannotBeNegative");
        }
    } else {
        response.addContextualMessage("pointLocator", "validate.required");
        return;
    }
    if (!LOGGING_TYPE_CODES.isValidId(loggingType))
        response.addContextualMessage("loggingType", "validate.invalidValue");
    if (!Common.TIME_PERIOD_CODES.isValidId(intervalLoggingPeriodType))
        response.addContextualMessage("intervalLoggingPeriodType", "validate.invalidValue");
    if (intervalLoggingPeriod <= 0)
        response.addContextualMessage("intervalLoggingPeriod", "validate.greaterThanZero");
    if (!INTERVAL_LOGGING_TYPE_CODES.isValidId(intervalLoggingType))
        response.addContextualMessage("intervalLoggingType", "validate.invalidValue");
    if (pointLocator.getDataTypeId() == DataTypes.IMAGE || pointLocator.getDataTypeId() == DataTypes.ALPHANUMERIC) {
        if (loggingType == LoggingTypes.INTERVAL && intervalLoggingType != IntervalLoggingTypes.INSTANT)
            response.addContextualMessage("intervalLoggingType", "validate.intervalType.incompatible", INTERVAL_LOGGING_TYPE_CODES.getCode(intervalLoggingType), DataTypes.CODES.getCode(pointLocator.getDataTypeId()));
    }
    if (!Common.TIME_PERIOD_CODES.isValidId(purgeType, TimePeriods.MILLISECONDS, TimePeriods.SECONDS, TimePeriods.MINUTES, TimePeriods.HOURS))
        response.addContextualMessage("purgeType", "validate.invalidValue");
    if (purgePeriod <= 0)
        response.addContextualMessage("purgePeriod", "validate.greaterThanZero");
    if (textRenderer == null)
        response.addContextualMessage("textRenderer", "validate.required");
    if (defaultCacheSize < 0)
        response.addContextualMessage("defaultCacheSize", "validate.cannotBeNegative");
    if (discardExtremeValues && discardHighLimit <= discardLowLimit)
        response.addContextualMessage("discardHighLimit", "validate.greaterThanDiscardLow");
    if (pointLocator.getDataTypeId() != DataTypes.NUMERIC && pointLocator.getDataTypeId() != DataTypes.MULTISTATE)
        preventSetExtremeValues = false;
    if (preventSetExtremeValues && setExtremeHighLimit <= setExtremeLowLimit)
        response.addContextualMessage("setExtremeHighLimit", "validate.greaterThanSetExtremeLow");
    if (!StringUtils.isBlank(chartColour)) {
        try {
            ColorUtils.toColor(chartColour);
        } catch (InvalidArgumentException e) {
            response.addContextualMessage("chartColour", "validate.invalidValue");
        }
    } else if (chartColour == null) {
        response.addContextualMessage("chartColour", "validate.invalidValue");
    }
    if (!Common.ROLLUP_CODES.isValidId(rollup))
        response.addContextualMessage("rollup", "validate.invalidValue");
    else if (!validateRollup())
        response.addContextualMessage("rollup", "validate.rollup.incompatible", rollup);
    pointLocator.validate(response, this);
    // Check text renderer type
    if (textRenderer != null && !textRenderer.getDef().supports(pointLocator.getDataTypeId()))
        response.addGenericMessage("validate.text.incompatible");
    // Check chart renderer type
    if (chartRenderer != null && !chartRenderer.getDef().supports(pointLocator.getDataTypeId()))
        response.addGenericMessage("validate.chart.incompatible");
    // Check the plot type
    if (!PLOT_TYPE_CODES.isValidId(plotType))
        response.addContextualMessage("plotType", "validate.invalidValue");
    if (plotType != PlotTypes.STEP && pointLocator.getDataTypeId() != DataTypes.NUMERIC)
        response.addContextualMessage("plotType", "validate.invalidValue");
    if (!SIMPLIFY_TYPE_CODES.isValidId(simplifyType))
        response.addContextualMessage("simplifyType", "validate.invalidValue");
    else if (simplifyType == SimplifyTypes.TARGET && simplifyTarget < 10)
        response.addContextualMessage("simplifyTarget", "validate.greaterThan", 10);
    else if (simplifyType != DataPointVO.SimplifyTypes.NONE && (pointLocator.getDataTypeId() == DataTypes.ALPHANUMERIC || pointLocator.getDataTypeId() == DataTypes.IMAGE))
        response.addContextualMessage("simplifyType", "validate.cannotSimplifyType", DataTypes.getDataTypeMessage(pointLocator.getDataTypeId()));
    // Validate the unit
    try {
        if (unit == null) {
            // We know the unit is invalid and will try the unitString as a likely invalid source (From DWR only)
            // So the other units validate ok
            unit = defaultUnit();
            UnitUtil.parseLocal(this.unitString);
            // Guarantee we fail
            throw new Exception("No Unit");
        }
    } catch (Exception e) {
        response.addContextualMessage("unit", "validate.unitInvalid", e.getMessage());
    }
    try {
        if (!validateIntegralUnit()) {
            response.addContextualMessage("integralUnit", "validate.unitNotCompatible");
        }
    } catch (Exception e) {
        if (e instanceof IllegalArgumentException) {
            response.addContextualMessage("integralUnit", "validate.unitInvalid", ((IllegalArgumentException) e).getCause().getMessage());
        } else {
            response.addContextualMessage("integralUnit", "validate.unitInvalid", e.getMessage());
        }
    }
    try {
        if (!validateRenderedUnit()) {
            response.addContextualMessage("renderedUnit", "validate.unitNotCompatible");
        }
    } catch (Exception e) {
        response.addContextualMessage("renderedUnit", "validate.unitInvalid", e.getMessage());
    }
    if (overrideIntervalLoggingSamples) {
        if (intervalLoggingSampleWindowSize <= 0) {
            response.addContextualMessage("intervalLoggingSampleWindowSize", "validate.greaterThanZero");
        }
    }
    if ((templateId != null) && (templateId > 0)) {
        DataPointPropertiesTemplateVO template = (DataPointPropertiesTemplateVO) TemplateDao.instance.get(templateId);
        if (template == null) {
            response.addContextualMessage("template", "pointEdit.template.validate.templateNotFound", templateId);
        } else if (template.getDataTypeId() != this.pointLocator.getDataTypeId()) {
            response.addContextualMessage("template", "pointEdit.template.validate.templateDataTypeNotCompatible");
        }
    }
    Map<String, String> tags = this.tags;
    if (tags != null) {
        for (Entry<String, String> entry : tags.entrySet()) {
            String tagKey = entry.getKey();
            if (tagKey == null || entry.getValue() == null) {
                response.addContextualMessage("tags", "validate.tagCantBeNull");
                break;
            }
            if (DataPointTagsDao.NAME_TAG_KEY.equals(tagKey) || DataPointTagsDao.DEVICE_TAG_KEY.equals(tagKey)) {
                response.addContextualMessage("tags", "validate.invalidTagKey");
                break;
            }
        }
    }
}
Also used : InvalidArgumentException(com.serotonin.InvalidArgumentException) DataPointPropertiesTemplateVO(com.serotonin.m2m2.vo.template.DataPointPropertiesTemplateVO) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) InvalidArgumentException(com.serotonin.InvalidArgumentException) JsonException(com.serotonin.json.JsonException) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) IOException(java.io.IOException)

Example 8 with TextRenderer

use of com.serotonin.m2m2.view.text.TextRenderer in project ma-core-public by infiniteautomation.

the class DataPointVO method setUnitsOnTextRenderer.

private void setUnitsOnTextRenderer() {
    if (textRenderer instanceof ConvertingRenderer) {
        ConvertingRenderer cr = (ConvertingRenderer) textRenderer;
        cr.setUnit(unit);
        if (useRenderedUnit) {
            cr.setRenderedUnit(renderedUnit);
        } else {
            cr.setRenderedUnit(unit);
        }
    }
}
Also used : ConvertingRenderer(com.serotonin.m2m2.view.text.ConvertingRenderer)

Aggregations

TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)4 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)2 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)2 AnalogRenderer (com.serotonin.m2m2.view.text.AnalogRenderer)2 ConvertingRenderer (com.serotonin.m2m2.view.text.ConvertingRenderer)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 ExportPointInfo (com.serotonin.m2m2.vo.export.ExportPointInfo)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 JsonException (com.serotonin.json.JsonException)1 NoSQLDao (com.serotonin.m2m2.db.dao.nosql.NoSQLDao)1 NoSQLQueryCallback (com.serotonin.m2m2.db.dao.nosql.NoSQLQueryCallback)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)1 IdPointValueTime (com.serotonin.m2m2.rt.dataImage.IdPointValueTime)1 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)1