Search in sources :

Example 1 with DeleteRequest

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);
}
Also used : BadRequestException(com.b2international.commons.exceptions.BadRequestException) SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Collection(java.util.Collection) Request(com.b2international.snowowl.core.events.Request) Set(java.util.Set) UUID(java.util.UUID) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) DeleteRequest(com.b2international.snowowl.core.request.DeleteRequest) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) Strings(com.google.common.base.Strings) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) HashMultimap(com.google.common.collect.HashMultimap) ImmutableList(com.google.common.collect.ImmutableList) Entry(java.util.Map.Entry) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) com.b2international.snowowl.snomed.datastore.index.entry(com.b2international.snowowl.snomed.datastore.index.entry) DelegatingRequest(com.b2international.snowowl.core.events.DelegatingRequest) SnomedComponent(com.b2international.snowowl.snomed.core.domain.SnomedComponent) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) ImmutableList(com.google.common.collect.ImmutableList) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) Collection(java.util.Collection) DeleteRequest(com.b2international.snowowl.core.request.DeleteRequest)

Aggregations

BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)1 DelegatingRequest (com.b2international.snowowl.core.events.DelegatingRequest)1 Request (com.b2international.snowowl.core.events.Request)1 BulkRequest (com.b2international.snowowl.core.events.bulk.BulkRequest)1 ComponentNotFoundException (com.b2international.snowowl.core.exceptions.ComponentNotFoundException)1 DeleteRequest (com.b2international.snowowl.core.request.DeleteRequest)1 SnomedComponent (com.b2international.snowowl.snomed.core.domain.SnomedComponent)1 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)1 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)1 SnomedRelationship (com.b2international.snowowl.snomed.core.domain.SnomedRelationship)1 com.b2international.snowowl.snomed.datastore.index.entry (com.b2international.snowowl.snomed.datastore.index.entry)1 Strings (com.google.common.base.Strings)1 HashMultimap (com.google.common.collect.HashMultimap)1 ImmutableList (com.google.common.collect.ImmutableList)1 Multimap (com.google.common.collect.Multimap)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 UUID (java.util.UUID)1