use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class RhinoScriptTestData method getPointValuesBetween.
public static List<PointValueTime> getPointValuesBetween(DataType dataType, int id, long from, long to) {
switch(dataType) {
case ALPHANUMERIC:
case BINARY:
case MULTISTATE:
default:
throw new ShouldNeverHappenException("Unimplemented");
case NUMERIC:
List<PointValueTime> values = new ArrayList<PointValueTime>();
List<PointValueTime> pvts = numericPvts.get(id);
for (PointValueTime pvt : pvts) {
if ((pvt.getTime() > from) || (pvt.getTime() <= to))
values.add(pvt);
}
return values;
}
}
use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class AbstractPointLocatorVO method readDataType.
protected DataType readDataType(JsonObject json) throws JsonException {
String text = json.getString("dataType");
if (text == null) {
throw new TranslatableJsonException("emport.error.missing", "dataType", DataType.formatNames());
}
DataType dataType;
try {
dataType = DataType.valueOf(text);
} catch (IllegalArgumentException e) {
throw new TranslatableJsonException("emport.error.invalid", "dataType", text, DataType.formatNames());
}
return dataType;
}
use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class BaseTextRenderer method getImplementation.
public static List<ImplDefinition> getImplementation(DataType dataType) {
ensureDefinitions();
List<ImplDefinition> impls = new ArrayList<ImplDefinition>(definitions.size());
for (ImplDefinition def : definitions) {
if (def.supports(dataType))
impls.add(def);
}
return impls;
}
use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class PointValueTimeDeserializer method deserialize.
@Override
public PointValueTime deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException {
ObjectCodec codec = jsonParser.getCodec();
JsonNode node = codec.readTree(jsonParser);
JsonNode dataTypeNode = node.get("dataType");
if (dataTypeNode == null) {
throw JsonMappingException.from(jsonParser, "Missing dataType");
}
JsonNode valueNode = node.get("value");
if (valueNode == null) {
throw JsonMappingException.from(jsonParser, "Missing value");
}
JsonNode timestampNode = node.get("timestamp");
if (timestampNode == null) {
throw JsonMappingException.from(jsonParser, "Missing timestamp");
}
long timestamp = timestampNode.asLong();
String dataTypeStr = dataTypeNode.asText();
DataType dataType = DataType.fromName(dataTypeStr);
if (dataType == null) {
throw JsonMappingException.from(jsonParser, "Unknown dataType: " + dataTypeStr);
}
DataValue dataValue;
switch(dataType) {
case ALPHANUMERIC:
dataValue = new AlphanumericValue(valueNode.asText());
break;
case BINARY:
dataValue = new BinaryValue(valueNode.asBoolean());
break;
case MULTISTATE:
dataValue = new MultistateValue(valueNode.asInt());
break;
case NUMERIC:
dataValue = new NumericValue(valueNode.asDouble());
break;
default:
throw JsonMappingException.from(jsonParser, "Unsupported dataType " + dataType);
}
JsonNode annotationNode = node.get("serializedAnnotation");
if (annotationNode != null && !annotationNode.isNull()) {
try {
return new AnnotatedPointValueTime(dataValue, timestamp, TranslatableMessage.deserialize(annotationNode.asText()));
} catch (TranslatableMessageParseException e) {
throw JsonMappingException.from(jsonParser, "Can't deserialize annotation", e);
}
}
return new PointValueTime(dataValue, timestamp);
}
use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class PointValueTimeSerializer method serialize.
@Override
public void serialize(PointValueTime pointValueTime, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
jsonGenerator.writeStartObject();
DataValue value = pointValueTime.getValue();
switch(value.getDataType()) {
case ALPHANUMERIC:
jsonGenerator.writeStringField("dataType", "ALPHANUMERIC");
jsonGenerator.writeStringField("value", value.getStringValue());
break;
case BINARY:
jsonGenerator.writeStringField("dataType", "BINARY");
jsonGenerator.writeBooleanField("value", value.getBooleanValue());
break;
case MULTISTATE:
jsonGenerator.writeStringField("dataType", "MULTISTATE");
jsonGenerator.writeNumberField("value", value.getIntegerValue());
break;
case NUMERIC:
jsonGenerator.writeStringField("dataType", "NUMERIC");
jsonGenerator.writeNumberField("value", value.getDoubleValue());
break;
}
jsonGenerator.writeNumberField("timestamp", pointValueTime.getTime());
if (pointValueTime instanceof IAnnotated) {
jsonGenerator.writeStringField("serializedAnnotation", ((IAnnotated) pointValueTime).getSourceMessage().serialize());
}
jsonGenerator.writeEndObject();
}
Aggregations