Search in sources :

Example 1 with FunctionblockModel

use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.

the class TwinPayloadFactoryTest method testCreateRequestSingleFbProperty.

@Test
public void testCreateRequestSingleFbProperty() {
    FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
    Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("temperature", fbm).build()).build();
    FunctionblockValue fbValue = new FunctionblockValue(fbm);
    fbValue.withStatusProperty("value", 20.2);
    InfomodelValue infomodelValue = new InfomodelValue(infomodel);
    infomodelValue.withFunctionblock("temperature", fbValue);
    System.out.println(gson.toJson(TwinPayloadFactory.toShadowUpdateRequest(infomodelValue)));
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Infomodel(org.eclipse.vorto.model.Infomodel) InfomodelValue(org.eclipse.vorto.model.runtime.InfomodelValue) Test(org.junit.Test)

Example 2 with FunctionblockModel

use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.

the class TwinPayloadFactoryTest method testCreateRequestSingleFbPropertyForFeature.

@Test
public void testCreateRequestSingleFbPropertyForFeature() {
    FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
    FunctionblockValue fbValue = new FunctionblockValue(fbm);
    fbValue.withStatusProperty("value", 20.2);
    System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(fbValue, "temperature", "com.acme:Sensor-1")));
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) FunctionblockValue(org.eclipse.vorto.model.runtime.FunctionblockValue) Test(org.junit.Test)

Example 3 with FunctionblockModel

use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.

the class ModelContentToEcoreConverter method convertFunctionblockMapping.

private Model convertFunctionblockMapping(FunctionblockModel model, ModelContent context, String platformKey) {
    MappingBuilder builder = BuilderUtils.newMapping(new ModelId(ModelType.InformationModel, model.getId().getName() + "Mapping", model.getId().getNamespace() + ".mapping." + platformKey, model.getId().getVersion()), platformKey);
    builder.withVortolang("1.0");
    builder.withDescription("Mapping that contains " + platformKey + " specific meta data");
    builder.withReference(ModelIdFactory.newInstance(ModelType.Functionblock, model.getId().getNamespace(), model.getId().getVersion(), model.getId().getVersion()));
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel eFbm = convertFunctionblock(model, context);
    for (Stereotype stereotype : model.getStereotypes()) {
        MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
        ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
        FunctionBlockSource source = MappingFactory.eINSTANCE.createFunctionBlockSource();
        source.setModel(eFbm);
        ruleBuilder.withSource(source);
        builder.addRule(ruleBuilder.build());
    }
    for (ModelProperty statusProperty : model.getStatusProperties()) {
        for (Stereotype stereotype : statusProperty.getStereotypes()) {
            MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
            ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
            StatusSource source = MappingFactory.eINSTANCE.createStatusSource();
            source.setModel(eFbm);
            source.setProperty(eFbm.getFunctionblock().getStatus().getProperties().stream().filter(property -> property.getName().equals(statusProperty.getName())).findAny().get());
            ruleBuilder.withSource(source);
            builder.addRule(ruleBuilder.build());
        }
    }
    for (ModelProperty configProperty : model.getConfigurationProperties()) {
        for (Stereotype stereotype : configProperty.getStereotypes()) {
            MappingRuleBuilder ruleBuilder = new MappingRuleBuilder();
            ruleBuilder.withStereotypeTarget(stereotype.getName(), stereotype.getAttributes());
            ConfigurationSource source = MappingFactory.eINSTANCE.createConfigurationSource();
            source.setModel(eFbm);
            source.setProperty(eFbm.getFunctionblock().getConfiguration().getProperties().stream().filter(property -> property.getName().equals(configProperty.getName())).findAny().get());
            ruleBuilder.withSource(source);
            builder.addRule(ruleBuilder.build());
        }
    }
    return builder.build();
}
Also used : EntityBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EntityBuilder) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) ReturnPrimitiveType(org.eclipse.vorto.core.api.model.functionblock.ReturnPrimitiveType) ModelIdFactory(org.eclipse.vorto.core.api.model.model.ModelIdFactory) MappingPackageImpl(org.eclipse.vorto.core.api.model.mapping.impl.MappingPackageImpl) Entity(org.eclipse.vorto.core.api.model.datatype.Entity) DictionaryPropertyType(org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType) PrimitivePropertyType(org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType) FunctionblockBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.FunctionblockBuilder) RefParam(org.eclipse.vorto.core.api.model.functionblock.RefParam) MappingBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder) MappingRuleBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingRuleBuilder) ReturnObjectType(org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType) Operation(org.eclipse.vorto.model.Operation) Type(org.eclipse.vorto.core.api.model.datatype.Type) IModel(org.eclipse.vorto.model.IModel) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) ReturnDictonaryType(org.eclipse.vorto.core.api.model.functionblock.ReturnDictonaryType) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) ModelBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.ModelBuilder) Collectors(java.util.stream.Collectors) FunctionblockPackageImpl(org.eclipse.vorto.core.api.model.functionblock.impl.FunctionblockPackageImpl) InformationModelPackageImpl(org.eclipse.vorto.core.api.model.informationmodel.impl.InformationModelPackageImpl) List(java.util.List) DictionaryType(org.eclipse.vorto.model.DictionaryType) ModelEvent(org.eclipse.vorto.model.ModelEvent) PrimitiveType(org.eclipse.vorto.model.PrimitiveType) Optional(java.util.Optional) Constraint(org.eclipse.vorto.model.Constraint) Infomodel(org.eclipse.vorto.model.Infomodel) DatatypePackageImpl(org.eclipse.vorto.core.api.model.datatype.impl.DatatypePackageImpl) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) ArrayList(java.util.ArrayList) EnumBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EnumBuilder) Model(org.eclipse.vorto.core.api.model.model.Model) ConstraintIntervalType(org.eclipse.vorto.core.api.model.datatype.ConstraintIntervalType) IReferenceType(org.eclipse.vorto.model.IReferenceType) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionblockFactory(org.eclipse.vorto.core.api.model.functionblock.FunctionblockFactory) MappingFactory(org.eclipse.vorto.core.api.model.mapping.MappingFactory) DatatypeFactory(org.eclipse.vorto.core.api.model.datatype.DatatypeFactory) PrimitiveParam(org.eclipse.vorto.core.api.model.functionblock.PrimitiveParam) EntityModel(org.eclipse.vorto.model.EntityModel) Presence(org.eclipse.vorto.core.api.model.datatype.Presence) ModelProperty(org.eclipse.vorto.model.ModelProperty) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) InformationModelBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.InformationModelBuilder) Param(org.eclipse.vorto.core.api.model.functionblock.Param) BuilderUtils(org.eclipse.vorto.core.api.model.BuilderUtils) FunctionBlockSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockSource) EventBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.EventBuilder) DictonaryParam(org.eclipse.vorto.core.api.model.functionblock.DictonaryParam) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Stereotype(org.eclipse.vorto.model.Stereotype) ModelContent(org.eclipse.vorto.model.ModelContent) ModelType(org.eclipse.vorto.core.api.model.model.ModelType) EnumModel(org.eclipse.vorto.model.EnumModel) ObjectPropertyType(org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType) ConfigurationSource(org.eclipse.vorto.core.api.model.mapping.ConfigurationSource) FunctionBlockSource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockSource) Stereotype(org.eclipse.vorto.model.Stereotype) MappingBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) MappingRuleBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingRuleBuilder)

Example 4 with FunctionblockModel

use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.

the class ModelContentToEcoreConverterTest method testConvertFunctionblockConfigStatusProperties.

@Test
public void testConvertFunctionblockConfigStatusProperties() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).build()).configurationProperty(ModelProperty.Builder("enable", PrimitiveType.BOOLEAN).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    assertEquals(1, model.getFunctionblock().getStatus().getProperties().size());
    assertEquals(1, model.getFunctionblock().getConfiguration().getProperties().size());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) Test(org.junit.Test)

Example 5 with FunctionblockModel

use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.

the class ModelContentToEcoreConverterTest method testConvertFunctionblockStatusPropertiesWithMultiple.

/*
   * Check whether the multiple keyword is deserialized when present
   */
@Test
public void testConvertFunctionblockStatusPropertiesWithMultiple() {
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).multiple().build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
    List<Property> propertyList = model.getFunctionblock().getStatus().getProperties();
    boolean isMultiple = false;
    for (Property prop : propertyList) {
        isMultiple = prop.isMultiplicity();
    }
    assertEquals(true, isMultiple);
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) Test(org.junit.Test)

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