Search in sources :

Example 21 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class SnomedEclRefinementEvaluator method evalMembers.

private Promise<Collection<Property>> evalMembers(BranchContext context, Set<String> focusConceptIds, Collection<String> typeIds, DataTypeComparison comparison) {
    final Object value;
    final DataType type;
    if (comparison instanceof BooleanValueComparison) {
        value = ((BooleanValueComparison) comparison).isValue();
        type = DataType.BOOLEAN;
    } else if (comparison instanceof StringValueComparison) {
        value = ((StringValueComparison) comparison).getValue();
        type = DataType.STRING;
    } else if (comparison instanceof IntegerValueComparison) {
        value = ((IntegerValueComparison) comparison).getValue();
        type = DataType.INTEGER;
    } else if (comparison instanceof DecimalValueComparison) {
        value = ((DecimalValueComparison) comparison).getValue();
        type = DataType.DECIMAL;
    } else {
        return SnomedEclEvaluationRequest.throwUnsupported(comparison);
    }
    final SearchResourceRequest.Operator operator = toSearchOperator(comparison.getOp());
    final Options propFilter = Options.builder().put(SnomedRf2Headers.FIELD_CHARACTERISTIC_TYPE_ID, getCharacteristicTypes(expressionForm)).put(SnomedRf2Headers.FIELD_TYPE_ID, typeIds).put(SnomedRefSetMemberIndexEntry.Fields.DATA_TYPE, type).put(SnomedRf2Headers.FIELD_VALUE, value).put(SearchResourceRequest.operator(SnomedRf2Headers.FIELD_VALUE), operator).build();
    return SnomedRequests.prepareSearchMember().filterByActive(true).filterByRefSetType(SnomedRefSetType.CONCRETE_DATA_TYPE).filterByReferencedComponent(focusConceptIds).filterByProps(propFilter).setEclExpressionForm(expressionForm).setLimit(context.service(RepositoryConfiguration.class).getIndexConfiguration().getResultWindow()).<Property>transformAsync(context, req -> req.build(context.path()), members -> members.stream().map(input -> {
        return new Property(input.getReferencedComponent().getId(), (String) input.getProperties().get(SnomedRf2Headers.FIELD_TYPE_ID), input.getProperties().get(SnomedRf2Headers.FIELD_VALUE), (Integer) input.getProperties().get(SnomedRf2Headers.FIELD_RELATIONSHIP_GROUP));
    }));
}
Also used : PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher) Query(com.b2international.index.query.Query) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) ID(com.b2international.index.revision.Revision.Fields.ID) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) com.b2international.snomed.ecl.ecl(com.b2international.snomed.ecl.ecl) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) CompareUtils(com.b2international.commons.CompareUtils) com.google.common.collect(com.google.common.collect) ResourceURI(com.b2international.snowowl.core.ResourceURI) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Collection(java.util.Collection) SnomedRelationshipSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder) DataType(com.b2international.snowowl.snomed.core.domain.refset.DataType) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) Entry(java.util.Map.Entry) Expression(com.b2international.index.query.Expression) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Fields(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Fields) Expressions(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) Options(com.b2international.commons.options.Options) DataType(com.b2international.snowowl.snomed.core.domain.refset.DataType) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest)

Example 22 with Promise

use of com.b2international.snowowl.core.events.util.Promise in project snow-owl by b2ihealthcare.

the class AsyncRequest method execute.

/**
 * Executes the asynchronous request using the event bus passed in.
 * @param bus
 * @return {@link Promise}
 */
public Promise<R> execute(IEventBus bus) {
    final Promise<R> promise = new Promise<>();
    final Class<R> responseType = request.getReturnType();
    final CompositeClassLoader classLoader = new CompositeClassLoader();
    classLoader.add(request.getClassLoader());
    request.getNestedRequests().stream().map(Request::getClassLoader).forEach(classLoader::add);
    request.getNestedRequests().stream().map(r -> r.getClass().getClassLoader()).forEach(classLoader::add);
    bus.send(Request.ADDRESS, request, Request.TAG, Collections.emptyMap(), new IHandler<IMessage>() {

        @Override
        public void handle(IMessage message) {
            try {
                if (message.isSucceeded()) {
                    promise.resolve(message.body(responseType, classLoader), message.headers());
                } else {
                    promise.reject(message.body(Throwable.class, AsyncRequest.class.getClassLoader()));
                }
            } catch (Throwable e) {
                promise.reject(e);
            }
        }
    });
    return promise;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) ScheduleJobRequestBuilder(com.b2international.snowowl.core.jobs.ScheduleJobRequestBuilder) Promise(com.b2international.snowowl.core.events.util.Promise) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) CompositeClassLoader(com.b2international.commons.CompositeClassLoader) IEventBus(com.b2international.snowowl.eventbus.IEventBus) IMessage(com.b2international.snowowl.eventbus.IMessage) Collections(java.util.Collections) IHandler(com.b2international.snowowl.eventbus.IHandler) Promise(com.b2international.snowowl.core.events.util.Promise) IMessage(com.b2international.snowowl.eventbus.IMessage) CompositeClassLoader(com.b2international.commons.CompositeClassLoader)

Aggregations

Promise (com.b2international.snowowl.core.events.util.Promise)22 ResourceURI (com.b2international.snowowl.core.ResourceURI)10 TimeUnit (java.util.concurrent.TimeUnit)10 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)9 SnomedRequests (com.b2international.snowowl.snomed.datastore.request.SnomedRequests)9 IOException (java.io.IOException)9 List (java.util.List)9 Test (org.junit.Test)9 BranchContext (com.b2international.snowowl.core.domain.BranchContext)8 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)8 Set (java.util.Set)8 Collectors (java.util.stream.Collectors)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)7 IEventBus (com.b2international.snowowl.eventbus.IEventBus)7 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)7 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)7 Trees (com.b2international.snowowl.snomed.core.tree.Trees)7 Function (com.google.common.base.Function)7 Collection (java.util.Collection)7