use of org.eclipse.vorto.model.ModelProperty 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.model.ModelProperty in project vorto by eclipse.
the class SpecWithSameFunctionblock method createModel.
@Override
protected void createModel() {
FunctionblockModel buttonModel = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0"));
ModelProperty digitalInputStateProperty = new ModelProperty();
digitalInputStateProperty.setMandatory(true);
digitalInputStateProperty.setName("sensor_value");
digitalInputStateProperty.setType(PrimitiveType.FLOAT);
digitalInputStateProperty.setTargetPlatformKey("iotbutton");
digitalInputStateProperty.addStereotype(Stereotype.createWithXpath("/@btnvalue1"));
buttonModel.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty }));
infomodel.getFunctionblocks().add(ModelProperty.Builder("btn1", buttonModel).build());
FunctionblockModel buttonModel2 = new FunctionblockModel(ModelId.fromPrettyFormat("demo.fb:PushButton:1.0.0"));
ModelProperty digitalInputStateProperty2 = new ModelProperty();
digitalInputStateProperty2.setMandatory(true);
digitalInputStateProperty2.setName("sensor_value");
digitalInputStateProperty2.setType(PrimitiveType.FLOAT);
digitalInputStateProperty2.setTargetPlatformKey("iotbutton");
digitalInputStateProperty2.addStereotype(Stereotype.createWithXpath("/@btnvalue2"));
buttonModel2.setStatusProperties(Arrays.asList(new ModelProperty[] { digitalInputStateProperty2 }));
infomodel.getFunctionblocks().add(ModelProperty.Builder("btn2", buttonModel2).build());
}
use of org.eclipse.vorto.model.ModelProperty 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.ModelProperty 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();
}
use of org.eclipse.vorto.model.ModelProperty in project vorto by eclipse.
the class MappingSpecificationSerializer method addSerializerRecursive.
private void addSerializerRecursive(ModelId parentId, IModel container, List<ModelProperty> properties, List<IMappingSerializer> serializers) {
for (ModelProperty property : properties) {
if (isEntityProperty(property)) {
EntityModel entityModel = (EntityModel) property.getType();
ModelId mappingId = MappingIdUtils.getIdForProperty(parentId, property);
addSerializerRecursive(mappingId, entityModel, entityModel.getProperties(), serializers);
serializers.add(new EntityMappingSerializer(specification, mappingId, targetPlatform, property.getName(), entityModel));
}
}
}
Aggregations