Search in sources :

Example 6 with EntityModel

use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.

the class ModelContentToEcoreConverterTest method testConvertDatatype.

@Test
public void testConvertDatatype() {
    EntityModel entityModel = EntityModel.Builder(ModelId.fromPrettyFormat("org.eclipse.vorto:Location:1.0.0")).property(ModelProperty.Builder("lng", PrimitiveType.FLOAT).withConstraint(ConstraintType.MIN, "0").build()).property(ModelProperty.Builder("lat", PrimitiveType.STRING).build()).description("Some description").displayname("Location").build();
    ModelContentToEcoreConverter converter = new ModelContentToEcoreConverter();
    Entity model = (Entity) converter.convert(ModelContent.Builder(entityModel).build(), Optional.empty());
    assertEquals(entityModel.getId().getNamespace(), model.getNamespace());
    assertEquals(entityModel.getId().getName(), model.getName());
    assertEquals(entityModel.getId().getVersion(), model.getVersion());
    assertEquals(entityModel.getDescription(), model.getDescription());
    assertEquals(entityModel.getDisplayName(), model.getDisplayname());
    assertEquals(entityModel.getCategory(), model.getCategory());
    assertEquals(2, model.getProperties().size());
    Property property1 = model.getProperties().stream().filter(p -> p.getName().equals("lng")).findAny().get();
    assertNotNull(property1);
    assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.FLOAT, ((PrimitivePropertyType) property1.getType()).getType());
    assertEquals(1, property1.getConstraintRule().getConstraints().size());
    Property property2 = model.getProperties().stream().filter(p -> p.getName().equals("lat")).findAny().get();
    assertNotNull(property2);
    assertEquals(org.eclipse.vorto.core.api.model.datatype.PrimitiveType.STRING, ((PrimitivePropertyType) property2.getType()).getType());
}
Also used : Entity(org.eclipse.vorto.core.api.model.datatype.Entity) EntityModel(org.eclipse.vorto.model.EntityModel) FunctionblockProperty(org.eclipse.vorto.core.api.model.informationmodel.FunctionblockProperty) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelProperty(org.eclipse.vorto.model.ModelProperty) Test(org.junit.Test)

Example 7 with EntityModel

use of org.eclipse.vorto.model.EntityModel 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 EntityModel

use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.

the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatformLatestTag.

@Test
public void testConvertWithoutTargetPlatformLatestTag() throws Exception {
    setupTestDataForLatestTag();
    ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
    ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:latest"), Optional.empty());
    assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.1"), content.getModels().get(content.getRoot()).getId());
    assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
Also used : ModelContent(org.eclipse.vorto.model.ModelContent) EntityModel(org.eclipse.vorto.model.EntityModel) Test(org.junit.Test)

Example 9 with EntityModel

use of org.eclipse.vorto.model.EntityModel in project vorto by eclipse.

the class ModelIdToModelContentConverterTest method testConvertWithoutTargetPlatform.

@Test
public void testConvertWithoutTargetPlatform() throws Exception {
    importModel("Color.type");
    importModel("sample.mapping");
    ModelIdToModelContentConverter converter = new ModelIdToModelContentConverter(this.repositoryFactory);
    ModelContent content = converter.convert(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), Optional.empty());
    assertEquals(ModelId.fromPrettyFormat("org.eclipse.vorto.examples.type:Color:1.0.0"), content.getModels().get(content.getRoot()).getId());
    assertEquals(0, ((EntityModel) content.getModels().get(content.getRoot())).getStereotypes().size());
}
Also used : ModelContent(org.eclipse.vorto.model.ModelContent) EntityModel(org.eclipse.vorto.model.EntityModel) Test(org.junit.Test)

Example 10 with EntityModel

use of org.eclipse.vorto.model.EntityModel 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));
        }
    }
}
Also used : ModelProperty(org.eclipse.vorto.model.ModelProperty) EntityModel(org.eclipse.vorto.model.EntityModel) ModelId(org.eclipse.vorto.model.ModelId)

Aggregations

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