Search in sources :

Example 6 with EnumModel

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());
}
Also used : Enum(org.eclipse.vorto.core.api.model.datatype.Enum) EnumModel(org.eclipse.vorto.model.EnumModel) Infomodel(org.eclipse.vorto.model.Infomodel) Enum(org.eclipse.vorto.core.api.model.datatype.Enum) Test(org.junit.Test)

Example 7 with EnumModel

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);
                }
            }
        }
    }
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) IModel(org.eclipse.vorto.model.IModel) Infomodel(org.eclipse.vorto.model.Infomodel) EnumModel(org.eclipse.vorto.model.EnumModel) ModelContent(org.eclipse.vorto.model.ModelContent) ModelProperty(org.eclipse.vorto.model.ModelProperty) EntityModel(org.eclipse.vorto.model.EntityModel) ModelId(org.eclipse.vorto.model.ModelId)

Example 8 with EnumModel

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());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) EnumModel(org.eclipse.vorto.model.EnumModel)

Aggregations

EnumModel (org.eclipse.vorto.model.EnumModel)8 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)4 Infomodel (org.eclipse.vorto.model.Infomodel)4 Test (org.junit.Test)4 Enum (org.eclipse.vorto.core.api.model.datatype.Enum)3 EntityModel (org.eclipse.vorto.model.EntityModel)3 ModelProperty (org.eclipse.vorto.model.ModelProperty)3 IModel (org.eclipse.vorto.model.IModel)2 ModelId (org.eclipse.vorto.model.ModelId)2 JXPathInvalidAccessException (org.apache.commons.jxpath.JXPathInvalidAccessException)1 JXPathNotFoundException (org.apache.commons.jxpath.JXPathNotFoundException)1 Entity (org.eclipse.vorto.core.api.model.datatype.Entity)1 ObjectPropertyType (org.eclipse.vorto.core.api.model.datatype.ObjectPropertyType)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 RefParam (org.eclipse.vorto.core.api.model.functionblock.RefParam)1 ReturnObjectType (org.eclipse.vorto.core.api.model.functionblock.ReturnObjectType)1 FunctionblockProperty (org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 MappingException (org.eclipse.vorto.mapping.engine.MappingException)1