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();
}
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());
}
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);
}
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());
}
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();
}
Aggregations