use of com.b2international.snowowl.core.request.DeleteRequest in project snow-owl by b2ihealthcare.
the class SnomedBulkRequest method execute.
@Override
public R execute(TransactionContext context) {
ImmutableList.Builder<SnomedComponentRequest<?>> requests = ImmutableList.builder();
ImmutableList.Builder<DeleteRequest> deletions = ImmutableList.builder();
collectNestedRequests(next(), requests, deletions);
// Prefetch all component IDs mentioned in reference set member creation requests, abort if any of them can not be found
final Set<String> requiredComponentIds = requests.build().stream().flatMap(request -> request.getRequiredComponentIds(context).stream()).filter(// just in case filter out invalid component IDs
componentId -> SnomedComponent.getTypeSafe(componentId) != null || isMember(componentId)).collect(Collectors.toSet());
final Multimap<Class<? extends SnomedDocument>, String> componentIdsByType = HashMultimap.create();
for (String requiredComponentId : requiredComponentIds) {
if (!Strings.isNullOrEmpty(requiredComponentId)) {
componentIdsByType.put(this.getDocType(requiredComponentId), requiredComponentId);
}
}
// collect all deleted IDs as well
deletions.build().stream().map(DeleteRequest::getComponentId).forEach(componentId -> componentIdsByType.put(getDocType(componentId), componentId));
try {
for (final Entry<Class<? extends SnomedDocument>, Collection<String>> idsForType : componentIdsByType.asMap().entrySet()) {
context.lookup(idsForType.getValue(), idsForType.getKey());
}
} catch (final ComponentNotFoundException e) {
throw e.toBadRequestException();
}
// bind additional caches to the context
TransactionContext newContext = context.inject().bind(SnomedOWLExpressionConverter.class, new SnomedOWLExpressionConverter(context)).build();
return next(newContext);
}
Aggregations