Search in sources :

Example 1 with ComponentNotFoundException

use of com.b2international.snowowl.core.exceptions.ComponentNotFoundException in project snow-owl by b2ihealthcare.

the class SnomedRefSetCreateRequest method execute.

@Override
public String execute(TransactionContext context) {
    RefSetSupport.checkType(type, referencedComponentType);
    final SnomedConceptDocument concept;
    if (Strings.isNullOrEmpty(identifierId)) {
        throw new BadRequestException("Reference set identifier ID may not be null or empty.");
    } else {
        try {
            concept = context.lookup(identifierId, SnomedConceptDocument.class);
            if (concept.getRefSetType() != null) {
                throw new BadRequestException("Identifier concept %s has been already registered as refset", identifierId);
            }
        } catch (ComponentNotFoundException e) {
            throw e.toBadRequestException();
        }
    }
    final SnomedConceptDocument.Builder updatedConcept = SnomedConceptDocument.builder(concept);
    final SnomedReferenceSet refSet = new SnomedReferenceSet();
    refSet.setType(type);
    refSet.setReferencedComponentType(referencedComponentType);
    if (SnomedRefSetUtil.isMapping(type)) {
        refSet.setMapTargetComponentType(mapTargetComponentType);
    }
    updatedConcept.refSet(refSet);
    context.update(concept, updatedConcept.build());
    return identifierId;
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 2 with ComponentNotFoundException

use of com.b2international.snowowl.core.exceptions.ComponentNotFoundException in project snow-owl by b2ihealthcare.

the class BundleDeleteRequest method execute.

@Override
public Boolean execute(TransactionContext context) {
    try {
        final ResourceDocument bundleToDelete = context.lookup(resourceId, ResourceDocument.class);
        updateResourceBundles(context, bundleToDelete);
        context.delete(bundleToDelete);
    } catch (ComponentNotFoundException e) {
    // ignore, probably already deleted
    }
    return Boolean.TRUE;
}
Also used : ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) ResourceDocument(com.b2international.snowowl.core.internal.ResourceDocument)

Example 3 with ComponentNotFoundException

use of com.b2international.snowowl.core.exceptions.ComponentNotFoundException 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)

Example 4 with ComponentNotFoundException

use of com.b2international.snowowl.core.exceptions.ComponentNotFoundException in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberCreateRequest method getRequiredComponentIds.

/**
 * @return the set of core component SCTIDs mentioned in any reference set member property
 */
@Override
public Set<String> getRequiredComponentIds(TransactionContext context) {
    try {
        SnomedReferenceSet refSet = getRefSet(context);
        SnomedRefSetMemberCreateDelegate delegate = getDelegate(refSet.getType());
        Builder<String> requiredComponentIds = ImmutableSet.<String>builder().addAll(delegate.getRequiredComponentIds());
        requiredComponentIds.add(referenceSetId);
        if (!Strings.isNullOrEmpty(referencedComponentId)) {
            requiredComponentIds.add(referencedComponentId);
        }
        if (!Strings.isNullOrEmpty(moduleId)) {
            requiredComponentIds.add(moduleId);
        }
        return requiredComponentIds.build();
    } catch (ComponentNotFoundException e) {
        throw e.toBadRequestException();
    }
}
Also used : SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException)

Example 5 with ComponentNotFoundException

use of com.b2international.snowowl.core.exceptions.ComponentNotFoundException in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberCreateRequest method execute.

@Override
public String execute(TransactionContext context) {
    /* 
		 * TODO: Generalize the logic below: any attempts of retrieving a missing component during component creation
		 * should return a 400 response instead of a 404. 
		 */
    try {
        SnomedReferenceSet refSet = getRefSet(context);
        SnomedRefSetMemberCreateDelegate delegate = getDelegate(refSet.getType());
        return delegate.execute(refSet, context);
    } catch (ComponentNotFoundException e) {
        throw e.toBadRequestException();
    }
}
Also used : SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException)

Aggregations

ComponentNotFoundException (com.b2international.snowowl.core.exceptions.ComponentNotFoundException)8 BadRequestException (com.b2international.commons.exceptions.BadRequestException)3 SnomedReferenceSet (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet)3 ConstantIdStrategy (com.b2international.snowowl.snomed.core.domain.ConstantIdStrategy)2 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 ResourceDocument (com.b2international.snowowl.core.internal.ResourceDocument)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 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)1 com.b2international.snowowl.snomed.datastore.index.entry (com.b2international.snowowl.snomed.datastore.index.entry)1 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)1 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)1 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)1 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)1