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