Search in sources :

Example 6 with ModelContent

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

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

the class DefaultPayloadMappingService method getOrCreateSpecification.

@Override
public IMappingSpecification getOrCreateSpecification(ModelId modelId) {
    ModelContent modelContent = getModelContent(modelId, createTargetPlatformKey(modelId));
    Infomodel infomodel = (Infomodel) modelContent.getModels().get(modelContent.getRoot());
    MappingSpecification specification = new MappingSpecification();
    specification.setInfoModel(infomodel);
    addReferencesRecursive(infomodel, infomodel.getTargetPlatformKey());
    return specification;
}
Also used : MappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.MappingSpecification) IMappingSpecification(org.eclipse.vorto.mapping.engine.model.spec.IMappingSpecification) Infomodel(org.eclipse.vorto.model.Infomodel) ModelContent(org.eclipse.vorto.model.ModelContent)

Example 8 with ModelContent

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

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

use of org.eclipse.vorto.model.ModelContent 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());
}
Also used : FunctionblockModel(org.eclipse.vorto.model.FunctionblockModel) ModelContent(org.eclipse.vorto.model.ModelContent) Test(org.junit.Test)

Aggregations

ModelContent (org.eclipse.vorto.model.ModelContent)12 Test (org.junit.Test)6 EntityModel (org.eclipse.vorto.model.EntityModel)3 ModelContentToEcoreConverter (org.eclipse.vorto.model.conversion.ModelContentToEcoreConverter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Optional (java.util.Optional)2 DictionaryPropertyType (org.eclipse.vorto.core.api.model.datatype.DictionaryPropertyType)2 PrimitivePropertyType (org.eclipse.vorto.core.api.model.datatype.PrimitivePropertyType)2 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)2 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)2 Model (org.eclipse.vorto.core.api.model.model.Model)2 FunctionblockModel (org.eclipse.vorto.model.FunctionblockModel)2 Infomodel (org.eclipse.vorto.model.Infomodel)2 ModelId (org.eclipse.vorto.model.ModelId)2 ClassPathResource (org.springframework.core.io.ClassPathResource)2 Context (com.amazonaws.services.lambda.runtime.Context)1 RequestStreamHandler (com.amazonaws.services.lambda.runtime.RequestStreamHandler)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1