use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class DefaultPayloadMappingService method addReferencesRecursive.
/**
* Adds reference types of the given properties to the mapping Specification (needed for lookup)
*
* @param model to traverse properties
*/
private void addReferencesRecursive(IModel model, String targetPlatformKey) {
if (model instanceof Infomodel) {
Infomodel infomodel = (Infomodel) model;
for (ModelProperty property : infomodel.getFunctionblocks()) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
property.setType((FunctionblockModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
}
} else if (model instanceof EntityModel) {
EntityModel entityModel = (EntityModel) model;
for (ModelProperty property : entityModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
} else if (model instanceof FunctionblockModel) {
FunctionblockModel fbModel = (FunctionblockModel) model;
for (ModelProperty property : fbModel.getProperties()) {
initStereotypeIfMissing(property);
if (property.getType() instanceof ModelId) {
ModelId referenceModelId = (ModelId) property.getType();
ModelId mappingId = property.getMappingReference();
IModel referenceModel = null;
if (mappingId != null) {
referenceModel = getModelContentByModelAndMappingId(referenceModelId.getPrettyFormat(), mappingId.getPrettyFormat());
} else {
ModelContent modelContent = getModelContent(referenceModelId, targetPlatformKey);
referenceModel = modelContent.getModels().get(modelContent.getRoot());
}
if (referenceModel instanceof EntityModel) {
property.setType((EntityModel) referenceModel);
addReferencesRecursive(referenceModel, targetPlatformKey);
} else {
property.setType((EnumModel) referenceModel);
}
}
}
}
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class ModelIdToModelContentConverterTest method testConvertFbWithMultipleProperty.
@Test
public void testConvertFbWithMultipleProperty() {
importModel("FbWithMultipleProperty.fbmodel");
ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto:TestFb:1.0.0"), Optional.empty());
FunctionblockModel fbm = (FunctionblockModel) content.getModels().get(content.getRoot());
assertTrue(fbm.getStatusProperty("foos").get().isMultiple());
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleMultipleFbProperties.
@Test
public void testCreateRequestSingleMultipleFbProperties() {
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("indoorTemperature", fbm).build()).withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()).build();
FunctionblockValue indoorTemperature = new FunctionblockValue(fbm);
indoorTemperature.withStatusProperty("value", 20.2);
FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm);
outdoorTemperature.withStatusProperty("value", 9.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature);
infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature);
System.out.println(gson.toJson(TwinPayloadFactory.toShadowUpdateRequest(infomodelValue)));
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleMultipleFbProperties.
@Test
public void testCreateRequestSingleMultipleFbProperties() {
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("indoorTemperature", fbm).build()).withProperty(ModelProperty.Builder("outdoorTemperature", fbm).build()).build();
FunctionblockValue indoorTemperature = new FunctionblockValue(fbm);
indoorTemperature.withStatusProperty("value", 20.2);
FunctionblockValue outdoorTemperature = new FunctionblockValue(fbm);
outdoorTemperature.withStatusProperty("value", 9.2);
InfomodelValue infomodelValue = new InfomodelValue(infomodel);
infomodelValue.withFunctionblock("indoorTemperature", indoorTemperature);
infomodelValue.withFunctionblock("outdoorTemperature", outdoorTemperature);
System.out.println(gson.toJson(TwinPayloadFactory.toDittoProtocol(infomodelValue, "com.acme:Sensor-1")));
}
use of org.eclipse.vorto.model.FunctionblockModel in project vorto by eclipse.
the class TwinPayloadFactoryTest method testCreateRequestSingleFbPropertyforEntireInfomodel.
@Test
public void testCreateRequestSingleFbPropertyforEntireInfomodel() {
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.toDittoProtocol(infomodelValue, "com.acme:Sensor-1")));
}
Aggregations