use of com.b2international.commons.exceptions.LockedException in project snow-owl by b2ihealthcare.
the class ClassificationJobRequest method executeClassification.
private void executeClassification(final BranchContext context, final String classificationId, final ClassificationTracker tracker) {
final RevisionSearcher revisionSearcher = context.service(RevisionSearcher.class);
TerminologyResource resource = context.service(TerminologyResource.class);
@SuppressWarnings("unchecked") final Set<String> reasonerExcludedModuleIds = Collections3.toImmutableSet((Iterable) resource.getSettings().getOrDefault(REASONER_EXCLUDE_MODULE_IDS, Collections.emptySet()));
final SnomedCoreConfiguration configuration = context.service(SnomedCoreConfiguration.class);
final boolean concreteDomainSupported = configuration.isConcreteDomainSupported();
final ReasonerTaxonomy taxonomy;
try (Locks locks = Locks.on(context).lock(DatastoreLockContextDescriptions.CLASSIFY, parentLockContext)) {
taxonomy = buildTaxonomy(revisionSearcher, reasonerExcludedModuleIds, concreteDomainSupported);
} catch (final LockedException e) {
throw new ReasonerApiException("Couldn't acquire exclusive access to terminology store for classification; %s", e.getMessage(), e);
}
final OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
ontologyManager.getOntologyFactories().add(new DelegateOntologyFactory(taxonomy));
// TODO: custom moduleId in ontology IRI?
final IRI ontologyIRI = IRI.create(DelegateOntology.NAMESPACE_SCTM + Concepts.MODULE_SCT_CORE);
try {
final DelegateOntology ontology = (DelegateOntology) ontologyManager.createOntology(ontologyIRI);
final ReasonerTaxonomyInferrer inferrer = new ReasonerTaxonomyInferrer(reasonerId, ontology, context);
final ReasonerTaxonomy inferredTaxonomy = inferrer.addInferences(taxonomy);
final NormalFormGenerator normalFormGenerator = new NormalFormGenerator(inferredTaxonomy);
tracker.classificationCompleted(classificationId, inferredTaxonomy, normalFormGenerator);
} catch (final OWLOntologyCreationException e) {
throw new ReasonerApiException("Exception caught while creating ontology instance.", e);
} catch (final ReasonerInterruptedException | OWLReasonerRuntimeException e) {
throw new ReasonerApiException("Exception caught while classifying the ontology.", e);
}
}
use of com.b2international.commons.exceptions.LockedException in project snow-owl by b2ihealthcare.
the class SaveJobRequest method execute.
@Override
public Boolean execute(final BranchContext context) {
final IProgressMonitor monitor = context.service(IProgressMonitor.class);
final ClassificationTracker tracker = context.service(ClassificationTracker.class);
final String user = !Strings.isNullOrEmpty(userId) ? userId : context.service(User.class).getUsername();
try (Locks locks = Locks.on(context).user(user).lock(DatastoreLockContextDescriptions.SAVE_CLASSIFICATION_RESULTS, parentLockContext)) {
return persistChanges(context, monitor);
} catch (final LockedException e) {
tracker.classificationFailed(classificationId);
throw new ReasonerApiException("Couldn't acquire exclusive access to terminology store for persisting classification changes; %s", e.getMessage(), e);
} catch (final Exception e) {
LOG.error("Unexpected error while persisting classification changes.", e);
tracker.classificationSaveFailed(classificationId);
throw new ReasonerApiException("Error while persisting classification changes on '%s'.", context.path(), e);
} finally {
monitor.done();
}
}
Aggregations