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());
}
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());
}
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;
}
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());
}
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;
}
Aggregations