use of org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder 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.BuilderUtils.MappingBuilder in project vorto by eclipse.
the class HelloWorldGeneratorTest method getMappedElementEntity.
/*
* Test case for checking the attribute mapping and corresponding property value for an entity
*
*
*/
@Test
public void getMappedElementEntity() throws Exception {
MappingBuilder mapping = BuilderUtils.newMapping(new ModelId(ModelType.Mapping, "", "", ""), "helloworld");
EntityMappingRule entityMappingRule = MappingFactory.eINSTANCE.createEntityMappingRule();
EntityAttributeSource entityAttributeSource = MappingFactory.eINSTANCE.createEntityAttributeSource();
entityAttributeSource.setModel(_entity);
entityMappingRule.getSources().add(entityAttributeSource);
StereoTypeTarget stereotypeTarget = MappingFactory.eINSTANCE.createStereoTypeTarget();
stereotypeTarget.setName("OBJECT_ID");
Attribute objectIDattribute = MappingFactory.eINSTANCE.createAttribute();
objectIDattribute.setName("ID");
objectIDattribute.setValue("entityAttributID");
stereotypeTarget.getAttributes().add(objectIDattribute);
entityMappingRule.setTarget(stereotypeTarget);
mapping.addRule(entityMappingRule);
InvocationContext ctx = new InvocationContext(createMappingList(mapping.build()), Collections.emptyMap());
Property prop = functionBlock.getFunctionblock().getStatus().getProperties().get(0);
assertNotNull(ctx.getMappedElement(prop, "OBJECT_ID"));
assertEquals("entityAttributID", ctx.getMappedElement(prop, "OBJECT_ID").getAttributeValue("ID", "entityAttributID"));
}
use of org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder in project vorto by eclipse.
the class HelloWorldGeneratorTest method getMappedElementFunctionbLock.
/*
* Test case for checking the attribute mapping and corresponding property value for a function block
*
*
*/
@Test
public void getMappedElementFunctionbLock() throws Exception {
MappingBuilder mapping = BuilderUtils.newMapping(new ModelId(ModelType.Mapping, "", "", ""), "helloworld");
FunctionBlockMappingRule rule = MappingFactory.eINSTANCE.createFunctionBlockMappingRule();
FunctionBlockPropertySource statusValueSource = MappingFactory.eINSTANCE.createFunctionBlockPropertySource();
statusValueSource.setModel(functionBlock);
rule.getSources().add(statusValueSource);
StereoTypeTarget stereotypeTarget = MappingFactory.eINSTANCE.createStereoTypeTarget();
stereotypeTarget.setName("OBJECT_ID");
Attribute objectIDattribute = MappingFactory.eINSTANCE.createAttribute();
objectIDattribute.setName("ID");
objectIDattribute.setValue("functionBlockAttributID");
stereotypeTarget.getAttributes().add(objectIDattribute);
rule.setTarget(stereotypeTarget);
mapping.addRule(rule);
InvocationContext ctx = new InvocationContext(createMappingList(mapping.build()), Collections.emptyMap());
Property prop = functionBlock.getFunctionblock().getStatus().getProperties().get(0);
assertNotNull(ctx.getMappedElement(prop, "OBJECT_ID"));
assertEquals("functionBlockAttributID", ctx.getMappedElement(prop, "OBJECT_ID").getAttributeValue("ID", "functionBlockAttributID"));
}
Aggregations