Search in sources :

Example 1 with Attribute

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

the class TestStereoTypeFactory method createStereoTypeTarget.

public static StereoTypeTarget createStereoTypeTarget() {
    StereoTypeTarget stereoType = MappingFactory.eINSTANCE.createStereoTypeTarget();
    Attribute typeAttribute = MappingFactory.eINSTANCE.createAttribute();
    typeAttribute.setName("DummyAttribute");
    typeAttribute.setValue("Dummy Attribute Value");
    stereoType.setName("DummyStereoType");
    stereoType.getAttributes().add(typeAttribute);
    return stereoType;
}
Also used : Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)

Example 2 with Attribute

use of org.eclipse.vorto.core.api.model.mapping.Attribute 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

Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)2 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)2 Optional (java.util.Optional)1 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 ModelId (org.eclipse.vorto.repository.api.ModelId)1 ModelInfo (org.eclipse.vorto.repository.api.ModelInfo)1 ResolveQuery (org.eclipse.vorto.repository.api.resolver.ResolveQuery)1 IModelContent (org.eclipse.vorto.repository.core.IModelContent)1 ContentType (org.eclipse.vorto.repository.core.IModelRepository.ContentType)1 Service (org.springframework.stereotype.Service)1