Search in sources :

Example 11 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class MappingModelSyntaxTest method parseMappingWithEnumAttribute.

@Test
public void parseMappingWithEnumAttribute() throws IOException {
    MappingModel mappingModel = createMappingModel("type/Enum_Attribute.mapping");
    EList<MappingRule> rules = mappingModel.getRules();
    assertEquals(3, rules.size());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 12 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class MappingModelSyntaxTest method parseMappingWithEntityProperty.

@Test
public void parseMappingWithEntityProperty() throws IOException {
    MappingModel mappingModel = createMappingModel("type/Entity_Property.mapping");
    EList<MappingRule> rules = mappingModel.getRules();
    assertEquals(1, rules.size());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 13 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class MappingModelSyntaxTest method createMappingModel.

private MappingModel createMappingModel(String mappingFileName) throws IOException {
    ResourceSet rset = new ResourceSetImpl();
    rset.getPackageRegistry().put(MappingPackage.eNS_URI, MappingPackage.eINSTANCE);
    rset.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
    String exampleSmarthomeMappingFile = EXAMPLES_DIRECTORY + mappingFileName;
    Resource resource = rset.getResource(URI.createFileURI(exampleSmarthomeMappingFile), true);
    resource.load(null);
    MappingModel mappingModel = (MappingModel) resource.getContents().get(0);
    return mappingModel;
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Example 14 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class MappingModelSyntaxTest method parseMappingWithInfoModelAttribute.

@Test
public void parseMappingWithInfoModelAttribute() throws IOException {
    MappingModel mappingModel = createMappingModel("Infomodel_Attribute.mapping");
    EList<MappingRule> rules = mappingModel.getRules();
    assertEquals(6, rules.size());
}
Also used : MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Test(org.junit.Test)

Example 15 with MappingModel

use of org.eclipse.vorto.core.api.model.mapping.MappingModel in project vorto by eclipse.

the class DefaultResolver method doResolve.

@Override
protected ModelId doResolve(ModelInfo mappingModelResource, ResolveQuery query) {
    IModelContent content = this.repository.getModelContent(mappingModelResource.getId(), ContentType.DSL);
    MappingModel mappingModel = (MappingModel) content.getModel();
    Optional<MappingRule> objectRule = mappingModel.getRules().stream().filter(rule -> rule.getTarget() instanceof StereoTypeTarget && ((StereoTypeTarget) rule.getTarget()).getName().equals(query.getStereoType())).findFirst();
    if (objectRule.isPresent()) {
        Optional<Attribute> objectIdAttribute = ((StereoTypeTarget) objectRule.get().getTarget()).getAttributes().stream().filter(attribute -> attribute.getName().equals(query.getAttributeId())).findFirst();
        if (objectIdAttribute.isPresent() && objectIdAttribute.get().getValue().equals(query.getAttributeValue())) {
            return ModelId.fromReference(mappingModel.getReferences().get(0).getImportedNamespace(), mappingModel.getReferences().get(0).getVersion());
        }
    }
    return null;
}
Also used : IModelContent(org.eclipse.vorto.repository.core.IModelContent) Service(org.springframework.stereotype.Service) ContentType(org.eclipse.vorto.repository.core.IModelRepository.ContentType) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel) Optional(java.util.Optional) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) ResolveQuery(org.eclipse.vorto.repository.api.resolver.ResolveQuery) ModelId(org.eclipse.vorto.repository.api.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.api.ModelInfo) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) IModelContent(org.eclipse.vorto.repository.core.IModelContent) MappingRule(org.eclipse.vorto.core.api.model.mapping.MappingRule) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) MappingModel(org.eclipse.vorto.core.api.model.mapping.MappingModel)

Aggregations

MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)27 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)18 Test (org.junit.Test)15 ZipInputStream (java.util.zip.ZipInputStream)6 ModelId (org.eclipse.vorto.repository.api.ModelId)6 IModelWorkspace (org.eclipse.vorto.server.commons.reader.IModelWorkspace)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 InvocationContext (org.eclipse.vorto.codegen.api.InvocationContext)4 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)4 InformationModel (org.eclipse.vorto.core.api.model.informationmodel.InformationModel)4 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)4 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 ZipEntry (java.util.zip.ZipEntry)3 ZipOutputStream (java.util.zip.ZipOutputStream)3 IOUtils (org.apache.commons.io.IOUtils)3