Search in sources :

Example 46 with FunctionblockModel

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

the class ModelContentToEcoreConverter method convertInformationModel.

private InformationModel convertInformationModel(Infomodel model, ModelContent context) {
    InformationModelBuilder builder = BuilderUtils.newInformationModel(new ModelId(ModelType.InformationModel, model.getId().getName(), model.getId().getNamespace(), model.getId().getVersion()));
    builder.withCategory(model.getCategory());
    builder.withDescription(model.getDescription());
    builder.withDisplayName(model.getDisplayName());
    builder.withVortolang(model.getVortolang());
    for (ModelProperty property : model.getFunctionblocks()) {
        FunctionblockModel fbModel = (FunctionblockModel) context.getModels().get((org.eclipse.vorto.model.ModelId) property.getType());
        org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel convertedFb = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) convertFunctionblock(fbModel, context);
        builder.withReference(ModelIdFactory.newInstance(convertedFb));
        builder.withFunctionBlock(convertedFb, property.getName(), property.getDescription(), property.isMandatory());
    }
    return builder.build();
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ModelProperty(org.eclipse.vorto.model.ModelProperty) InformationModelBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.InformationModelBuilder) Infomodel(org.eclipse.vorto.model.Infomodel) ModelId(org.eclipse.vorto.core.api.model.model.ModelId)

Example 47 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertFunctionblockWithPropertyMappings.

@Test
public void testConvertFunctionblockWithPropertyMappings() {
    final String targetPlatform = "testPlatform";
    FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).withStereotype("OBJECT", Collections.emptyMap(), targetPlatform).build()).configurationProperty(ModelProperty.Builder("enable", PrimitiveType.BOOLEAN).build()).withTargetPlatform(targetPlatform).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    MappingModel model = (MappingModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.of(targetPlatform));
    assertEquals(targetPlatform, model.getTargetPlatform());
    assertEquals(1, model.getRules().size());
    assertEquals("OBJECT", ((StereoTypeTarget) model.getRules().get(0).getTarget()).getName());
    assertTrue(model.getRules().get(0).getSources().get(0) instanceof StatusSource);
    assertNotNull(((StatusSource) model.getRules().get(0).getSources().get(0)).getModel());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) StatusSource(org.eclipse.vorto.core.api.model.mapping.StatusSource) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 48 with FunctionblockModel

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

the class ModelContentToEcoreConverterTest method testConvertInformationModel.

@Test
public void testConvertInformationModel() throws Exception {
    FunctionblockModel fbModel1 = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).build();
    FunctionblockModel fbModel2 = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).build();
    Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:TestDevice:1.0.0")).withProperty(ModelProperty.Builder("sensor", fbModel1.getId()).build()).withProperty(ModelProperty.Builder("temperature", fbModel2.getId()).build()).build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    org.eclipse.vorto.core.api.model.informationmodel.InformationModel model = (org.eclipse.vorto.core.api.model.informationmodel.InformationModel) converter.convert(ModelContent.Builder(infomodel).withDependency(fbModel1).withDependency(fbModel2).build(), Optional.empty());
    assertEquals(infomodel.getId().getNamespace(), model.getNamespace());
    assertEquals(infomodel.getId().getName(), model.getName());
    assertEquals(infomodel.getId().getVersion(), model.getVersion());
    assertEquals(infomodel.getDescription(), model.getDescription());
    assertEquals(infomodel.getDisplayName(), model.getDisplayname());
    assertEquals(infomodel.getCategory(), model.getCategory());
    assertEquals(2, model.getReferences().size());
    FunctionblockProperty property = model.getProperties().stream().filter(p -> p.getName().equals("sensor")).findAny().get();
    org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel fb = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) property.getType();
    assertEquals(fbModel1.getId().getName(), fb.getName());
    assertEquals(fbModel1.getId().getNamespace(), fb.getNamespace());
    assertEquals(fbModel1.getId().getVersion(), fb.getVersion());
    assertTrue(property.eContainer() instanceof InformationModel);
}
Also used : InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) Infomodel(org.eclipse.vorto.model.Infomodel) InformationModel(org.eclipse.vorto.core.api.model.informationmodel.InformationModel) FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Infomodel(org.eclipse.vorto.model.Infomodel) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Test(org.junit.Test)

Example 49 with FunctionblockModel

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

the class SpecWithOperationRule method createModel.

@Override
protected void createModel() {
    FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0"));
    Operation operation = new Operation("press");
    operation.setTargetPlatformKey("iotbutton");
    operation.addStereotype(Stereotype.createOperationTarget("data/key", "Pressed"));
    buttonModel.setOperations(Arrays.asList(new Operation[] { operation }));
    infomodel.getFunctionblocks().add(ModelProperty.Builder("button", buttonModel).build());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) Operation(org.eclipse.vorto.model.Operation)

Example 50 with FunctionblockModel

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

the class MappingSpecificationSerializer method iterator.

public Iterator<IMappingSerializer> iterator() {
    ModelId rootMappingId = MappingIdUtils.getIdForInfoModel(specification.getInfoModel());
    List<IMappingSerializer> serializers = new ArrayList<IMappingSerializer>();
    for (ModelProperty fbProperty : specification.getInfoModel().getFunctionblocks()) {
        FunctionblockModel fbm = specification.getFunctionBlock(fbProperty.getName());
        ModelId mappingId = MappingIdUtils.getIdForProperty(rootMappingId, fbProperty);
        addSerializerRecursive(mappingId, fbm, fbm.getProperties(), serializers);
        serializers.add(new FunctionblockMappingSerializer(specification, mappingId, targetPlatform, fbProperty.getName()));
    }
    serializers.add(new InformationModelMappingSerializer(specification, rootMappingId, targetPlatform));
    return serializers.iterator();
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ArrayList(java.util.ArrayList) ModelProperty(org.eclipse.vorto.model.ModelProperty) ModelId(org.eclipse.vorto.model.ModelId)

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