use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleFbProperty.
@Test
public void testCreateRequestSingleFbProperty() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
Infomodel infomodel = Infomodel.Builder(ModelId.fromPrettyFormat("com.acme:TemperatureSensor:1.0.0")).withProperty(ModelProperty.Builder("temperature", fbm).build()).build();
FunctionblockValue fbValue = new FunctionblockValue(fbm);
fbValue.withStatusProperty("value", 20.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("temperature", fbValue);
System.out.println(gson.toJson(TwinPayloadFactory.toShadowUpdateRequest(infomodelValue)));
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleFbPropertyForFeature.
@Test
public void testCreateRequestSingleFbPropertyForFeature() {
FunctionblockModel fbm = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.createPrimitiveProperty("value", true, PrimitiveType.FLOAT)).build();
FunctionblockValue fbValue = new FunctionblockValue(fbm);
fbValue.withStatusProperty("value", 20.2);
System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(fbValue, "temperature", "com.acme:Sensor-1")));
}
use of org.eclipse.vorto.model.FunctionblockModel 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.FunctionblockModel in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockConfigStatusProperties.
@Test
public void testConvertFunctionblockConfigStatusProperties() {
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).build()).configurationProperty(ModelProperty.Builder("enable", PrimitiveType.BOOLEAN).build()).build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
assertEquals(1, model.getFunctionblock().getStatus().getProperties().size());
assertEquals(1, model.getFunctionblock().getConfiguration().getProperties().size());
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertFunctionblockStatusPropertiesWithMultiple.
/*
* Check whether the multiple keyword is deserialized when present
*/
@Test
public void testConvertFunctionblockStatusPropertiesWithMultiple() {
FunctionblockModel fbModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Sensor:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).multiple().build()).build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel model = (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) converter.convert(ModelContent.Builder(fbModel).build(), Optional.empty());
List<Property> propertyList = model.getFunctionblock().getStatus().getProperties();
boolean isMultiple = false;
for (Property prop : propertyList) {
isMultiple = prop.isMultiplicity();
}
assertEquals(true, isMultiple);
}
Aggregations