use of org.eclipse.vorto.core.api.model.mapping.StatusSource 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();
}
use of org.eclipse.vorto.core.api.model.mapping.StatusSource in project vorto by eclipse.
the class TestFunctionBlockMappingFactory method createStatusSource.
private static StatusSource createStatusSource() {
StatusSource source = MappingFactory.eINSTANCE.createStatusSource();
source.setProperty(TestEntityFactory.createPrimitiveProperty("statusStringParam", PrimitiveType.STRING));
source.setModel(functionblockModel);
return source;
}
use of org.eclipse.vorto.core.api.model.mapping.StatusSource 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());
}
Aggregations