Search in sources :

Example 6 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class PointValueImportResult method saveValue.

public void saveValue(XidPointValueTimeModel model) {
    if (valid) {
        // Validate the model against our point
        long timestamp = model.getTimestamp();
        if (timestamp == 0)
            timestamp = Common.timer.currentTimeMillis();
        int dataTypeId = DataTypeEnum.convertFrom(model.getType());
        if (dataTypeId != vo.getPointLocator().getDataTypeId()) {
            result.addContextualMessage("dataType", "event.ds.dataType");
            return;
        }
        DataValue value;
        switch(model.getType()) {
            case ALPHANUMERIC:
                value = new AlphanumericValue((String) model.getValue());
                break;
            case BINARY:
                value = new BinaryValue((Boolean) model.getValue());
                break;
            case MULTISTATE:
                if (model.getValue() instanceof String) {
                    try {
                        value = vo.getTextRenderer().parseText((String) model.getValue(), dataTypeId);
                    } catch (Exception e) {
                        // Lots can go wrong here so let the user know
                        result.addContextualMessage("value", "event.valueParse.textParse", e.getMessage());
                        return;
                    }
                } else {
                    value = new MultistateValue(((Number) model.getValue()).intValue());
                }
                break;
            case NUMERIC:
                value = new NumericValue(((Number) model.getValue()).doubleValue());
                break;
            case IMAGE:
            default:
                result.addContextualMessage("dataType", "common.default", model.getType() + " data type not supported yet");
                return;
        }
        PointValueTime pvt;
        if (model.getAnnotation() == null) {
            pvt = new PointValueTime(value, timestamp);
        } else {
            pvt = new AnnotatedPointValueTime(value, timestamp, new TranslatableMessage("common.default", model.getAnnotation()));
        }
        if (rt == null) {
            dao.savePointValueAsync(vo.getId(), pvt, null);
        } else {
            rt.savePointValueDirectToCache(pvt, null, true, true);
        }
        total++;
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 7 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class PointValueTimeJsonStreamCallback method row.

/* (non-Javadoc)
	 * @see com.serotonin.db.MappedRowCallback#row(java.lang.Object, int)
	 */
@Override
public void row(PointValueTime pvt, int index) {
    if (this.limiter.limited())
        return;
    try {
        String annotation = null;
        if (pvt.isAnnotated())
            annotation = ((AnnotatedPointValueTime) pvt).getAnnotation(translations);
        if (useRendered) {
            // Convert to Alphanumeric Value
            String textValue = Functions.getRenderedText(vo, pvt);
            this.writePointValueTime(new AlphanumericValue(textValue), pvt.getTime(), annotation, vo);
        } else if (unitConversion) {
            if (pvt.getValue() instanceof NumericValue)
                this.writePointValueTime(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(pvt.getValue().getDoubleValue()), pvt.getTime(), annotation, vo);
            else
                this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
        } else {
            this.writePointValueTime(pvt.getValue(), pvt.getTime(), annotation, vo);
        }
    } catch (IOException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) IOException(java.io.IOException) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 8 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class PointValueTimeWriter method writeNonNullIntegral.

public void writeNonNullIntegral(Double integral, long time, DataPointVO vo) throws IOException {
    if (useRendered) {
        // Convert to Alphanumeric Value
        if (integral != null) {
            String textValue = Functions.getIntegralText(vo, integral);
            this.writePointValueTime(new AlphanumericValue(textValue), time, null, vo);
        } else {
            this.writePointValueTime(new AlphanumericValue(""), time, null, vo);
        }
    } else {
        // No conversion possible
        if (integral == null)
            this.writePointValueTime(0.0D, time, this.noDataMessage, vo);
        else
            this.writePointValueTime(integral, time, null, vo);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)

Example 9 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class XidPointValueTimeJsonWriter method writeXidTime.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.web.mvc.rest.v1.model.time.XidTimeJsonWriter#writeXidTime(com.fasterxml.jackson.core.JsonGenerator, com.serotonin.m2m2.vo.DataPointVO, com.serotonin.m2m2.rt.dataImage.IdTime)
	 */
@Override
public void writeXidTime(JsonGenerator jgen, DataPointVO vo, IdPointValueTime value) throws IOException {
    if (useRendered) {
        // Convert to Alphanumeric Value
        this.writeXidPointValue(value.getTime(), new AlphanumericValue(Functions.getRenderedText(vo, value)), vo);
    } else if (unitConversion) {
        if (value.getValue() instanceof NumericValue)
            this.writeXidPointValue(value.getTime(), new NumericValue(vo.getUnit().getConverterTo(vo.getRenderedUnit()).convert(value.getValue().getDoubleValue())), vo);
        else
            this.writeXidPointValue(value.getTime(), value.getValue(), vo);
    } else {
        if (vo.getPointLocator().getDataTypeId() == DataTypes.IMAGE)
            this.writeXidPointValue(value.getTime(), new AlphanumericValue(imageServletBuilder.buildAndExpand(value.getTime(), vo.getId()).toUri().toString()), vo);
        else
            this.writeXidPointValue(value.getTime(), value.getValue(), vo);
    }
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 10 with AlphanumericValue

use of com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue in project ma-modules-public by infiniteautomation.

the class ReportPointValueTimeSerializer method getObject.

/* (non-Javadoc)
	 * @see com.serotonin.m2m2.db.dao.nosql.NoSQLDataSerializer#getObject(byte[], long)
	 */
@Override
public ITime getObject(ByteArrayBuilder b, long ts, String seriesId) {
    // Get the data type
    int dataType = b.getShort();
    DataValue dataValue = null;
    // Second put in the data value
    switch(dataType) {
        case DataTypes.ALPHANUMERIC:
            String s = b.getString();
            dataValue = new AlphanumericValue(s);
            break;
        case DataTypes.BINARY:
            boolean bool = b.getBoolean();
            dataValue = new BinaryValue(bool);
            break;
        case DataTypes.IMAGE:
            try {
                dataValue = new ImageValue(b.getString());
            } catch (InvalidArgumentException e1) {
            // Probably no file
            }
            break;
        case DataTypes.MULTISTATE:
            int i = b.getInt();
            dataValue = new MultistateValue(i);
            break;
        case DataTypes.NUMERIC:
            double d = b.getDouble();
            dataValue = new NumericValue(d);
            break;
        default:
            throw new ShouldNeverHappenException("Data type of " + dataType + " is not supported");
    }
    // Get the annotation
    String annotation = b.getString();
    if (annotation != null) {
        try {
            return new AnnotatedPointValueTime(dataValue, ts, TranslatableMessage.deserialize(annotation));
        } catch (Exception e) {
            throw new ShouldNeverHappenException(e);
        }
    } else {
        return new PointValueTime(dataValue, ts);
    }
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue) InvalidArgumentException(com.serotonin.InvalidArgumentException) ImageSaveException(com.serotonin.m2m2.ImageSaveException) IOException(java.io.IOException) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) InvalidArgumentException(com.serotonin.InvalidArgumentException) AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) ShouldNeverHappenException(com.serotonin.ShouldNeverHappenException) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) PointValueTime(com.serotonin.m2m2.rt.dataImage.PointValueTime) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) ImageValue(com.serotonin.m2m2.rt.dataImage.types.ImageValue)

Aggregations

AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)14 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)11 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)7 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)7 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)6 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)5 AnnotatedPointValueTime (com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime)4 ImageValue (com.serotonin.m2m2.rt.dataImage.types.ImageValue)3 IOException (java.io.IOException)3 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)2 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 ExportDataValue (com.serotonin.m2m2.vo.export.ExportDataValue)2 InvalidArgumentException (com.serotonin.InvalidArgumentException)1 ImageSaveException (com.serotonin.m2m2.ImageSaveException)1 EnhancedPointValueDao (com.serotonin.m2m2.db.dao.EnhancedPointValueDao)1 TextRenderer (com.serotonin.m2m2.view.text.TextRenderer)1 ChangeTypeRT (com.serotonin.m2m2.virtual.rt.ChangeTypeRT)1 VirtualPointLocatorRT (com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT)1 DataSourceVO (com.serotonin.m2m2.vo.dataSource.DataSourceVO)1