Search in sources :

Example 16 with FunctionblockModel

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());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel)

Example 17 with FunctionblockModel

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;
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Constraint(org.eclipse.vorto.model.Constraint) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 18 with FunctionblockModel

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;
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ModelProperty(org.eclipse.vorto.model.ModelProperty)

Example 19 with FunctionblockModel

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());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EntityModel(org.eclipse.vorto.model.EntityModel)

Example 20 with FunctionblockModel

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);
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) JXPathContext(org.apache.commons.jxpath.JXPathContext) HashMap(java.util.HashMap) Stereotype(org.eclipse.vorto.model.Stereotype) JXPathNotFoundException(org.apache.commons.jxpath.JXPathNotFoundException) JXPathInvalidAccessException(org.apache.commons.jxpath.JXPathInvalidAccessException) MappingException(org.eclipse.vorto.mapping.engine.MappingException) MappingException(org.eclipse.vorto.mapping.engine.MappingException)

Aggregations

FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)61 ModelProperty (org.eclipse.vorto.model.ModelProperty)32 Infomodel (org.eclipse.vorto.model.Infomodel)17 Test (org.junit.Test)17 FunctionblockValue (org.eclipse.vorto.model.runtime.FunctionblockValue)6 EntityModel (org.eclipse.vorto.model.EntityModel)5 EnumModel (org.eclipse.vorto.model.EnumModel)5 ArrayList (java.util.ArrayList)3 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)3 Property (org.eclipse.vorto.core.api.model.datatype.Property)3 DictionaryType (org.eclipse.vorto.model.DictionaryType)3 InfomodelValue (org.eclipse.vorto.model.runtime.InfomodelValue)3 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)2 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)2 InformationModelBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.InformationModelBuilder)2 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)2 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)2 MappingException (org.eclipse.vorto.mapping.engine.MappingException)2 Constraint (org.eclipse.vorto.model.Constraint)2 ModelContent (org.eclipse.vorto.model.ModelContent)2