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