Search in sources :

Example 1 with ResolveQuery

use of org.eclipse.vorto.repository.web.core.dto.ResolveQuery in project vorto by eclipse.

the class DefaultResolver method doResolve.

@Override
protected ModelId doResolve(String tenantId, ModelInfo mappingModelResource, ResolveQuery query) {
    ModelFileContent content = getRepositoryFactory().getRepository(tenantId).getModelContent(mappingModelResource.getId(), false);
    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 : ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) ResolveQuery(org.eclipse.vorto.repository.web.core.dto.ResolveQuery) Service(org.springframework.stereotype.Service) 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) ModelId(org.eclipse.vorto.model.ModelId) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) ModelInfo(org.eclipse.vorto.repository.core.ModelInfo) ModelFileContent(org.eclipse.vorto.repository.core.ModelFileContent) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) 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

Optional (java.util.Optional)1 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)1 MappingModel (org.eclipse.vorto.core.api.model.mapping.MappingModel)1 MappingRule (org.eclipse.vorto.core.api.model.mapping.MappingRule)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 ModelId (org.eclipse.vorto.model.ModelId)1 ModelFileContent (org.eclipse.vorto.repository.core.ModelFileContent)1 ModelInfo (org.eclipse.vorto.repository.core.ModelInfo)1 ResolveQuery (org.eclipse.vorto.repository.web.core.dto.ResolveQuery)1 Service (org.springframework.stereotype.Service)1