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();
}
use of com.serotonin.m2m2.DataType in project ma-core-public by MangoAutomation.
the class SetPointEventHandlerDefinition method commonValidation.
private void commonValidation(ProcessResult response, SetPointEventHandlerVO vo) {
DataPointVO dp = DataPointDao.getInstance().get(vo.getTargetPointId());
DataType dataType = null;
if (dp == null)
response.addContextualMessage("targetPointId", "eventHandlers.noTargetPoint");
else {
dataType = dp.getPointLocator().getDataType();
if (!dp.getPointLocator().isSettable())
response.addContextualMessage("targetPointId", "event.setPoint.targetNotSettable");
}
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE && vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE) {
response.addContextualMessage("activeAction", "eventHandlers.noSetPointAction");
response.addContextualMessage("inactiveAction", "eventHandlers.noSetPointAction");
}
MangoJavaScriptService javaScriptService = Common.getBean(MangoJavaScriptService.class);
// Active
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.MULTISTATE) {
try {
Integer.parseInt(vo.getActiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("activeValueToSet", "eventHandlers.invalidActiveValue");
}
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.NUMERIC) {
try {
Double.parseDouble(vo.getActiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("activeValueToSet", "eventHandlers.invalidActiveValue");
}
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
DataPointVO dpActive = DataPointDao.getInstance().get(vo.getActivePointId());
if (dpActive == null)
response.addContextualMessage("activePointId", "eventHandlers.invalidActiveSource");
else if (dataType != dpActive.getPointLocator().getDataType())
response.addContextualMessage("activeDataPointId", "eventHandlers.invalidActiveSourceType");
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
if (StringUtils.isEmpty(vo.getActiveScript())) {
response.addContextualMessage("activeScript", "eventHandlers.invalidActiveScript");
} else {
try {
javaScriptService.compile(vo.getActiveScript(), true);
} catch (ScriptError e) {
response.addContextualMessage("activeScript", "eventHandlers.invalidActiveScriptError", e.getTranslatableMessage());
}
}
}
// Inactive
if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.MULTISTATE) {
try {
Integer.parseInt(vo.getInactiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("inactiveValueToSet", "eventHandlers.invalidInactiveValue");
}
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE && dataType == DataType.NUMERIC) {
try {
Double.parseDouble(vo.getInactiveValueToSet());
} catch (NumberFormatException e) {
response.addContextualMessage("inactiveValueToSet", "eventHandlers.invalidInactiveValue");
}
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
DataPointVO dpInactive = DataPointDao.getInstance().get(vo.getInactivePointId());
if (dpInactive == null)
response.addContextualMessage("inactivePointId", "eventHandlers.invalidInactiveSource");
else if (dataType != dpInactive.getPointLocator().getDataType())
response.addContextualMessage("inactivePointId", "eventHandlers.invalidInactiveSourceType");
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
if (StringUtils.isEmpty(vo.getInactiveScript())) {
response.addContextualMessage("inactiveScript", "eventHandlers.invalidInactiveScript");
} else {
try {
javaScriptService.compile(vo.getInactiveScript(), true);
} catch (ScriptError e) {
response.addContextualMessage("inactiveScript", "eventHandlers.invalidActiveScriptError", e.getTranslatableMessage());
}
}
}
if (vo.getAdditionalContext() != null)
validateScriptContext(vo.getAdditionalContext(), response);
else
vo.setAdditionalContext(new ArrayList<>());
}
use of com.serotonin.m2m2.DataType in project VERDICT by ge-high-assurance.
the class Aadl2Vdm method createVdmPort.
/**
* @author Vidhya Tekken Valapil
* Creates a new Vdm Port object and returns
* Populates "name", "mode" and "type"
* @param eventdataport
* @return vdm port
*/
private Port createVdmPort(EventDataPort dataPort, Model model, HashSet<String> dataTypeDecl) {
String modeString = "in";
if (dataPort.isIn()) {
modeString = "in";
} else if (dataPort.isOut()) {
modeString = "out";
}
// fetching data type information
DataSubcomponentType dSubCompType = dataPort.getDataFeatureClassifier();
verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
if (dSubCompType != null) {
verdict.vdm.vdm_data.DataType dtype = new verdict.vdm.vdm_data.DataType();
if (dSubCompType instanceof DataTypeImpl) {
org.osate.aadl2.DataType aadlDType = (org.osate.aadl2.DataType) dSubCompType;
dtype = resolveAADLDataType(aadlDType, model, dataTypeDecl);
} else if (dSubCompType instanceof DataImplementationImpl) {
org.osate.aadl2.DataImplementation aadlDImpl = (org.osate.aadl2.DataImplementation) dSubCompType;
dtype = resolveAADLDataImplementationType(aadlDImpl, model, dataTypeDecl);
} else {
System.out.println("Unresolved/unexpected Named Element.");
}
newPort.setType(dtype);
}
newPort.setProbe(false);
newPort.setId(dataPort.getQualifiedName());
newPort.setName(dataPort.getName());
newPort.setMode(convertToVdmPortMode(modeString));
newPort.setEvent(true);
return newPort;
}
Aggregations