Search in sources :

Example 1 with LockedException

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);
    }
}
Also used : ReasonerTaxonomy(com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy) IRI(org.semanticweb.owlapi.model.IRI) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerInterruptedException(org.semanticweb.owlapi.reasoner.ReasonerInterruptedException) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException) DelegateOntologyFactory(com.b2international.snowowl.snomed.reasoner.ontology.DelegateOntologyFactory) Locks(com.b2international.snowowl.core.locks.Locks) NormalFormGenerator(com.b2international.snowowl.snomed.reasoner.normalform.NormalFormGenerator) OWLReasonerRuntimeException(org.semanticweb.owlapi.reasoner.OWLReasonerRuntimeException) DelegateOntology(com.b2international.snowowl.snomed.reasoner.ontology.DelegateOntology) ReasonerTaxonomyInferrer(com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer) OWLOntologyCreationException(org.semanticweb.owlapi.model.OWLOntologyCreationException) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) OWLOntologyManager(org.semanticweb.owlapi.model.OWLOntologyManager) RevisionSearcher(com.b2international.index.revision.RevisionSearcher)

Example 2 with LockedException

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();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException) Locks(com.b2international.snowowl.core.locks.Locks) ClassificationTracker(com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker) BadRequestException(com.b2international.commons.exceptions.BadRequestException) LockedException(com.b2international.commons.exceptions.LockedException) ReasonerApiException(com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)

Aggregations

LockedException (com.b2international.commons.exceptions.LockedException)2 Locks (com.b2international.snowowl.core.locks.Locks)2 ReasonerApiException (com.b2international.snowowl.snomed.reasoner.exceptions.ReasonerApiException)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 SnomedCoreConfiguration (com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration)1 ReasonerTaxonomy (com.b2international.snowowl.snomed.datastore.index.taxonomy.ReasonerTaxonomy)1 ClassificationTracker (com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)1 ReasonerTaxonomyInferrer (com.b2international.snowowl.snomed.reasoner.classification.ReasonerTaxonomyInferrer)1 NormalFormGenerator (com.b2international.snowowl.snomed.reasoner.normalform.NormalFormGenerator)1 DelegateOntology (com.b2international.snowowl.snomed.reasoner.ontology.DelegateOntology)1 DelegateOntologyFactory (com.b2international.snowowl.snomed.reasoner.ontology.DelegateOntologyFactory)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntologyCreationException (org.semanticweb.owlapi.model.OWLOntologyCreationException)1 OWLOntologyManager (org.semanticweb.owlapi.model.OWLOntologyManager)1 OWLReasonerRuntimeException (org.semanticweb.owlapi.reasoner.OWLReasonerRuntimeException)1 ReasonerInterruptedException (org.semanticweb.owlapi.reasoner.ReasonerInterruptedException)1