use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class SpecWithConstraintConfigMapping method createModel.
@Override
protected void createModel() {
FunctionblockModel buttonModel = createButtonFb();
infomodel.getFunctionblocks().add(ModelProperty.Builder("button", buttonModel).build());
FunctionblockModel voltageModel = createVoltageFb();
infomodel.getFunctionblocks().add(ModelProperty.Builder("voltage", voltageModel).build());
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class SpecWithConstraintConfigMapping method createVoltageFb.
private FunctionblockModel createVoltageFb() {
FunctionblockModel voltageModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:Voltage:1.0.0"));
ModelProperty sensorValueProperty = new ModelProperty();
sensorValueProperty.setMandatory(true);
sensorValueProperty.setName("sensor_value");
sensorValueProperty.setType(PrimitiveType.FLOAT);
Constraint constraint = new Constraint(ConstraintType.MAX, "5000");
sensorValueProperty.setConstraints(Arrays.asList(constraint));
sensorValueProperty.setTargetPlatformKey("iotbutton");
sensorValueProperty.addStereotype(Stereotype.createWithXpath("number:toFloat(string:substring(batteryVoltage,0,string:length(batteryVoltage)-2))"));
ModelProperty sensorUnitsProperty = new ModelProperty();
sensorUnitsProperty.setMandatory(false);
sensorUnitsProperty.setName("sensor_units");
sensorUnitsProperty.setType(PrimitiveType.STRING);
sensorUnitsProperty.setTargetPlatformKey("iotbutton");
sensorUnitsProperty.addStereotype(Stereotype.createWithXpath("string:substring(batteryVoltage,string:length(batteryVoltage)-2)"));
voltageModel.setConfigurationProperties(Arrays.asList(new ModelProperty[] { sensorValueProperty, sensorUnitsProperty }));
return voltageModel;
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class SpecWithMaliciousFunction method createButtonFb.
private FunctionblockModel createButtonFb() {
FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0"));
ModelProperty digitalInputCount = new ModelProperty();
digitalInputCount.setMandatory(true);
digitalInputCount.setName("digital_input_count");
digitalInputCount.setType(PrimitiveType.INT);
digitalInputCount.setTargetPlatformKey("iotbutton");
digitalInputCount.addStereotype(Stereotype.createWithXpath("button:convert(clickType)"));
buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputCount }));
return buttonModel;
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class SpecWithNestedEntityAndCustomFunction method createModel.
@Override
protected void createModel() {
EntityModel countEntity = EntityModel.Builder(ModelId.fromPrettyFormat("demo:Count:1.0.0")).property(ModelProperty.Builder("value", PrimitiveType.INT).withXPathStereotype("button:convertClickType(clickType)", "iotbutton").build()).build();
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0")).statusProperty(ModelProperty.Builder("count", countEntity).build()).build();
infomodel.getFunctionblocks().add(ModelProperty.Builder("button", fbm).build());
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class DataMapperJxpath method mapTarget.
@Override
public Object mapTarget(PropertyValue newValue, Optional<PropertyValue> oldValue, String infomodelProperty) {
FunctionblockModel fbm = this.specification.getFunctionBlock(infomodelProperty);
if (fbm == null) {
throw new IllegalArgumentException("No property with the given name could be found in Information Model");
}
Optional<Stereotype> targetStereotype = newValue.getMeta().getStereotype(STEREOTYPE_TARGET);
if (!targetStereotype.isPresent()) {
throw new MappingException("No mapping rule defined for property");
}
Map<String, Object> jxpathContext = new HashMap<String, Object>();
Map<String, Object> param = new HashMap<String, Object>();
param.put("newValue", newValue.getValue());
param.put("oldValue", oldValue.isPresent() ? oldValue.get().getValue() : null);
jxpathContext.put("ctx", param);
final String functionName = "convert" + newValue.getMeta().getName().substring(0, 1).toUpperCase() + newValue.getMeta().getName().substring(1);
final String xpath = infomodelProperty.toLowerCase() + ":" + functionName + "(ctx)";
JXPathContext context = jxpathHelper.newContext(jxpathContext);
try {
return context.getValue(xpath);
} catch (Exception ex) {
throw new MappingException("Problem occurred during mapping", ex);
}
}
Aggregations