Search in sources :

Example 6 with DataType

use of org.osate.aadl2.DataType in project ma-core-public by MangoAutomation.

the class DataPointDao method createValueConverterMap.

@Override
protected Map<String, Function<Object, Object>> createValueConverterMap() {
    Map<String, Function<Object, Object>> converters = super.createValueConverterMap();
    Map<String, Function<Object, Object>> myConverters = new HashMap<>();
    myConverters.put("dataTypeId", value -> {
        if (value instanceof String) {
            DataType type = DataType.fromName((String) value);
            return type == null ? null : type.getId();
        }
        return value;
    });
    return combine(converters, myConverters);
}
Also used : Function(java.util.function.Function) HashMap(java.util.HashMap) DataType(com.serotonin.m2m2.DataType)

Example 7 with DataType

use of org.osate.aadl2.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;
}
Also used : TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException) DataType(com.serotonin.m2m2.DataType)

Example 8 with DataType

use of org.osate.aadl2.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);
}
Also used : DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) BinaryValue(com.serotonin.m2m2.rt.dataImage.types.BinaryValue) JsonNode(com.fasterxml.jackson.databind.JsonNode) TranslatableMessageParseException(com.serotonin.m2m2.i18n.TranslatableMessageParseException) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) 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) DataType(com.serotonin.m2m2.DataType) AnnotatedPointValueTime(com.serotonin.m2m2.rt.dataImage.AnnotatedPointValueTime) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue)

Example 9 with DataType

use of org.osate.aadl2.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<>());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) ScriptError(com.serotonin.m2m2.rt.script.ScriptError) ArrayList(java.util.ArrayList) DataType(com.serotonin.m2m2.DataType) MangoJavaScriptService(com.infiniteautomation.mango.spring.service.MangoJavaScriptService)

Example 10 with DataType

use of org.osate.aadl2.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;
}
Also used : DataImplementationImpl(org.osate.aadl2.impl.DataImplementationImpl) SLPort(com.ge.research.osate.verdict.dsl.verdict.SLPort) LPort(com.ge.research.osate.verdict.dsl.verdict.LPort) EventPort(org.osate.aadl2.EventPort) DataPort(org.osate.aadl2.DataPort) Port(verdict.vdm.vdm_model.Port) EventDataPort(org.osate.aadl2.EventDataPort) DataImplementation(org.osate.aadl2.DataImplementation) Port(verdict.vdm.vdm_model.Port) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) DataTypeImpl(org.osate.aadl2.impl.DataTypeImpl) DataType(org.osate.aadl2.DataType) DataType(org.osate.aadl2.DataType)

Aggregations

DataType (com.serotonin.m2m2.DataType)14 DataImplementation (org.osate.aadl2.DataImplementation)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)8 DataType (net.opengis.swe.v20.DataType)8 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)6 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6 IOException (java.io.IOException)6 File (java.io.File)5 DataSubcomponentType (org.osate.aadl2.DataSubcomponentType)5 PropertyAssociation (org.osate.aadl2.PropertyAssociation)5 BinaryComponentImpl (org.vast.data.BinaryComponentImpl)5 DataPort (org.osate.aadl2.DataPort)4 EventDataPort (org.osate.aadl2.EventDataPort)4 EventPort (org.osate.aadl2.EventPort)4 DataTypeImpl (org.osate.aadl2.impl.DataTypeImpl)4 Array (ucar.ma2.Array)4