use of com.ibm.j9ddr.vm29.j9.DataType in project ma-core-public by infiniteautomation.
the class PointValueDaoSQL method savePointValueImpl.
private long savePointValueImpl(final DataPointVO vo, final PointValueTime pointValue, boolean async) {
DataValue value = pointValue.getValue();
final DataType dataType = value.getDataType();
double dvalue = 0;
String svalue = null;
if (value.hasDoubleRepresentation())
dvalue = value.getDoubleValue();
else
svalue = value.getStringValue();
// Check if we need to create an annotation.
long id;
try {
id = savePointValue(vo, dataType, dvalue, pointValue.getTime(), svalue, getAnnotation(pointValue), async);
} catch (ConcurrencyFailureException e) {
// Still failed to insert after all of the retries. Store the data
unsavedPointValues.add(new UnsavedPointValue(vo, pointValue));
return -1;
}
writeUnsavedPointValues();
return id;
}
use of com.ibm.j9ddr.vm29.j9.DataType in project AMASE by loonwerks.
the class SafetyScopeProvider method getNamedElements.
private Set<NamedElement> getNamedElements(EObject ctx) {
Set<NamedElement> components = new HashSet<>();
if (ctx instanceof AadlPackage) {
PublicPackageSection pubSec = ((AadlPackage) ctx).getPublicSection();
for (Element el : pubSec.getOwnedElements()) {
if (el instanceof DataImplementation || el instanceof DataType) {
components.add((NamedElement) el);
}
}
for (AnnexLibrary annex : AnnexUtil.getAllActualAnnexLibraries(((AadlPackage) ctx), AgreePackage.eINSTANCE.getAgreeContractLibrary())) {
AgreeContract contract = (AgreeContract) ((AgreeContractLibrary) annex).getContract();
components.addAll(getNamedElementsFromSpecs(contract.getSpecs()));
}
components.add((AadlPackage) ctx);
} else {
components.addAll(getNamedElementsFromClassifier((Classifier) ctx, false));
}
return components;
}
use of com.ibm.j9ddr.vm29.j9.DataType in project ma-core-public by MangoAutomation.
the class SetPointHandlerRT method eventRaised.
@Override
public void eventRaised(EventInstance evt) {
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE)
return;
// Validate that the target point is available.
DataPointRT targetPoint = Common.runtimeManager.getDataPoint(vo.getTargetPointId());
if (targetPoint == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.targetPointMissing"), evt.getEventType());
return;
}
if (!targetPoint.getPointLocator().isSettable()) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.targetNotSettable"), evt.getEventType());
return;
}
DataType targetDataType = targetPoint.getVO().getPointLocator().getDataType();
DataValue value = null;
if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
// Get the source data point.
DataPointRT sourcePoint = Common.runtimeManager.getDataPoint(vo.getActivePointId());
if (sourcePoint == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.activePointMissing"), evt.getEventType());
return;
}
PointValueTime valueTime = sourcePoint.getPointValue();
if (valueTime == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.activePointValue"), evt.getEventType());
return;
}
if (valueTime.getValue().getDataType() != targetDataType) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.activePointDataType"), evt.getEventType());
return;
}
value = valueTime.getValue();
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE) {
value = DataValue.stringToValue(vo.getActiveValueToSet(), targetDataType);
} else if (vo.getActiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
ArrayList<JsonImportExclusion> importExclusions = new ArrayList<JsonImportExclusion>();
importExclusions.add(new JsonImportExclusion("xid", vo.getXid()) {
@Override
public String getImporterType() {
return ConfigurationExportData.EVENT_HANDLERS;
}
});
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
context.put(SetPointEventHandlerVO.TARGET_CONTEXT_KEY, targetPoint);
Map<String, Object> additionalContext = new HashMap<String, Object>();
additionalContext.put(EventInstance.CONTEXT_KEY, evt);
additionalContext.put(EventInstanceWrapper.CONTEXT_KEY, new EventInstanceWrapper(evt));
try (ScriptLog scriptLog = new ScriptLog("setPointHandler-" + evt.getId())) {
for (IntStringPair cxt : vo.getAdditionalContext()) {
DataPointRT dprt = Common.runtimeManager.getDataPoint(cxt.getKey());
if (dprt != null)
context.put(cxt.getValue(), dprt);
}
CompiledMangoJavaScript activeScript = new CompiledMangoJavaScript(new SetCallback(vo.getScriptRoles()), scriptLog, additionalContext, null, importExclusions, false, service, vo.getScriptRoles());
activeScript.compile(vo.getActiveScript(), true);
activeScript.initialize(context);
MangoJavaScriptResult result = activeScript.execute(Common.timer.currentTimeMillis(), evt.getActiveTimestamp(), targetPoint.getDataType());
PointValueTime pvt = (PointValueTime) result.getResult();
if (pvt != null)
value = pvt.getValue();
} catch (ScriptPermissionsException e) {
raiseFailureEvent(e.getTranslatableMessage(), evt.getEventType());
return;
} catch (ScriptError e) {
raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidActiveScriptError", e.getTranslatableMessage()), evt.getEventType());
return;
} catch (ResultTypeException e) {
raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidActiveScriptError", e.getMessage()), evt.getEventType());
return;
}
} else
throw new ShouldNeverHappenException("Unknown active action: " + vo.getActiveAction());
// Queue a work item to perform the set point.
if (MangoJavaScriptService.UNCHANGED != value)
Common.backgroundProcessing.addWorkItem(new SetPointWorkItem(vo.getTargetPointId(), new PointValueTime(value, evt.getActiveTimestamp()), this));
}
use of com.ibm.j9ddr.vm29.j9.DataType in project ma-core-public by MangoAutomation.
the class SetPointHandlerRT method eventInactive.
@Override
public void eventInactive(EventInstance evt) {
if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_NONE)
return;
// Validate that the target point is available.
DataPointRT targetPoint = Common.runtimeManager.getDataPoint(vo.getTargetPointId());
if (targetPoint == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.targetPointMissing"), evt.getEventType());
return;
}
if (!targetPoint.getPointLocator().isSettable()) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.targetNotSettable"), evt.getEventType());
return;
}
DataType targetDataType = targetPoint.getVO().getPointLocator().getDataType();
DataValue value = null;
if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_POINT_VALUE) {
// Get the source data point.
DataPointRT sourcePoint = Common.runtimeManager.getDataPoint(vo.getInactivePointId());
if (sourcePoint == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointMissing"), evt.getEventType());
return;
}
PointValueTime valueTime = sourcePoint.getPointValue();
if (valueTime == null) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointValue"), evt.getEventType());
return;
}
if (valueTime.getValue().getDataType() != targetDataType) {
raiseFailureEvent(new TranslatableMessage("event.setPoint.inactivePointDataType"), evt.getEventType());
return;
}
value = valueTime.getValue();
} else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_STATIC_VALUE)
value = DataValue.stringToValue(vo.getInactiveValueToSet(), targetDataType);
else if (vo.getInactiveAction() == SetPointEventHandlerVO.SET_ACTION_SCRIPT_VALUE) {
ArrayList<JsonImportExclusion> importExclusions = new ArrayList<JsonImportExclusion>();
importExclusions.add(new JsonImportExclusion("xid", vo.getXid()) {
@Override
public String getImporterType() {
return ConfigurationExportData.EVENT_HANDLERS;
}
});
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
context.put("target", targetPoint);
Map<String, Object> additionalContext = new HashMap<String, Object>();
additionalContext.put(EventInstance.CONTEXT_KEY, evt);
additionalContext.put(EventInstanceWrapper.CONTEXT_KEY, new EventInstanceWrapper(evt));
try (ScriptLog scriptLog = new ScriptLog("setPointHandler-" + evt.getId())) {
for (IntStringPair cxt : vo.getAdditionalContext()) {
DataPointRT dprt = Common.runtimeManager.getDataPoint(cxt.getKey());
if (dprt != null)
context.put(cxt.getValue(), dprt);
}
CompiledMangoJavaScript inactiveScript = new CompiledMangoJavaScript(new SetCallback(vo.getScriptRoles()), scriptLog, additionalContext, null, importExclusions, false, service, vo.getScriptRoles());
inactiveScript.compile(vo.getInactiveScript(), true);
inactiveScript.initialize(context);
MangoJavaScriptResult result = inactiveScript.execute(Common.timer.currentTimeMillis(), evt.getRtnTimestamp(), targetPoint.getDataType());
PointValueTime pvt = (PointValueTime) result.getResult();
if (pvt != null)
value = pvt.getValue();
} catch (ScriptPermissionsException e) {
raiseFailureEvent(e.getTranslatableMessage(), evt.getEventType());
return;
} catch (ScriptError e) {
raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidInactiveScriptError", e.getTranslatableMessage()), evt.getEventType());
return;
} catch (ResultTypeException e) {
raiseFailureEvent(new TranslatableMessage("eventHandlers.invalidInactiveScriptError", e.getMessage()), evt.getEventType());
return;
}
} else
throw new ShouldNeverHappenException("Unknown active action: " + vo.getInactiveAction());
if (MangoJavaScriptService.UNCHANGED != value)
Common.backgroundProcessing.addWorkItem(new SetPointWorkItem(vo.getTargetPointId(), new PointValueTime(value, evt.getRtnTimestamp()), this));
}
use of com.ibm.j9ddr.vm29.j9.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 dataport
* @return vdm port
*/
private Port createVdmPort(DataPort 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_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.");
}
verdict.vdm.vdm_model.Port newPort = new verdict.vdm.vdm_model.Port();
newPort.setProbe(false);
if (dataPort.getOwnedPropertyAssociations().size() != 0) {
EList<PropertyAssociation> propertyAssocs = dataPort.getOwnedPropertyAssociations();
for (PropertyAssociation propertyAssoc : propertyAssocs) {
if (propertyAssoc.getProperty().getName().equalsIgnoreCase("probe")) {
EList<ModalPropertyValue> propVals = propertyAssoc.getOwnedValues();
if (propVals.size() == 0 || propVals.size() > 1) {
throw new RuntimeException("Unexpected number for values for probe property of port.");
}
if (propVals.get(0).getOwnedValue() instanceof BooleanLiteral) {
BooleanLiteral probeVal = (BooleanLiteral) propVals.get(0).getOwnedValue();
newPort.setProbe(probeVal.getValue());
} else {
throw new RuntimeException("Unexpected type of value for probe property of port.");
}
}
}
}
newPort.setId(dataPort.getQualifiedName());
newPort.setName(dataPort.getName());
newPort.setMode(convertToVdmPortMode(modeString));
newPort.setType(dtype);
return newPort;
}
Aggregations