use of org.eclipse.vorto.model.EnumModel in project vorto by eclipse.
the class ModelContentToEcoreConverterTest method testConvertEnum.
@Test
public void testConvertEnum() {
EnumModel enumModel = EnumModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Unit:1.0.0")).literal("celcius", null).literal("kg", null).build();
ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
org.eclipse.vorto.core.api.model.datatype.Enum model = (org.eclipse.vorto.core.api.model.datatype.Enum) converter.convert(ModelContent.Builder(enumModel).build(), Optional.empty());
assertEquals(enumModel.getId().getNamespace(), model.getNamespace());
assertEquals(enumModel.getId().getName(), model.getName());
assertEquals(enumModel.getId().getVersion(), model.getVersion());
assertEquals(enumModel.getDescription(), model.getDescription());
assertEquals(enumModel.getDisplayName(), model.getDisplayname());
assertEquals(enumModel.getCategory(), model.getCategory());
assertEquals(2, model.getEnums().size());
}
use of org.eclipse.vorto.model.EnumModel 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.EnumModel in project vorto by eclipse.
the class SpecWithNestedEnum method createModel.
@Override
protected void createModel() {
EnumModel unitEnum = EnumModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Enum:1.0.0")).literal("Celcius", null).literal("Fahrenheit", null).build();
FunctionblockModel temperatureModel = FunctionblockModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Temperature:1.0.0")).statusProperty(ModelProperty.Builder("value", PrimitiveType.FLOAT).withXPathStereotype("/temperature", "iotbutton").build()).statusProperty(ModelProperty.Builder("unit", unitEnum.getId()).withXPathStereotype("'Celcius'", "iotbutton").build()).build();
infomodel.getFunctionblocks().add(ModelProperty.Builder("outdoorTemperature", temperatureModel).build());
}
Aggregations