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++;
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations