Search in sources :

Example 11 with TransactionContext

use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.

the class TransactionalRequest method execute.

@Override
public CommitResult execute(BranchContext context) {
    // final Metrics metrics = context.service(Metrics.class);
    // metrics.setExternalValue("preRequest", preRequestPreparationTime);
    TransactionContext tx = null;
    try (final TransactionContext transaction = context.openTransaction(context, author, commitComment, parentLockContext)) {
        tx = transaction;
        transaction.setNotificationEnabled(notify);
        final Object body = executeNext(transaction);
        return commit(transaction, body);
    } catch (ApiException e) {
        if (tx != null) {
            tx.rollback();
        }
        throw e;
    } catch (Exception e) {
        if (tx != null) {
            tx.rollback();
        }
        throw SnowowlRuntimeException.wrap(e);
    }
}
Also used : TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) ApiException(com.b2international.commons.exceptions.ApiException) ApiException(com.b2international.commons.exceptions.ApiException)

Example 12 with TransactionContext

use of com.b2international.snowowl.core.domain.TransactionContext in project snow-owl by b2ihealthcare.

the class SnomedConceptApiTest method testConceptInactivationModuleChanges.

@Test
public void testConceptInactivationModuleChanges() {
    final String conceptId = createNewConcept(branchPath);
    final String moduleConceptId = createNewConcept(branchPath);
    String sourceRelationshipId = createNewRelationship(branchPath, conceptId, Concepts.HAS_DOSE_FORM, Concepts.MODULE_SCT_MODEL_COMPONENT);
    String destinationRelationshipId = createNewRelationship(branchPath, Concepts.MODULE_SCT_MODEL_COMPONENT, Concepts.HAS_DOSE_FORM, conceptId);
    ResourceURI codeSystemURI = SnomedContentRule.SNOMEDCT.withPath(branchPath.getPath().replace(Branch.MAIN_PATH + "/", ""));
    SnomedRelationship sourceRelationship = SnomedRequests.prepareGetRelationship(sourceRelationshipId).build(codeSystemURI).execute(getBus()).getSync();
    SnomedRelationship destinationRelationship = SnomedRequests.prepareGetRelationship(destinationRelationshipId).build(codeSystemURI).execute(getBus()).getSync();
    Request<TransactionContext, Boolean> request = SnomedRequests.prepareUpdateConcept(conceptId).setActive(false).build();
    SnomedRequests.prepareCommit().setDefaultModuleId(moduleConceptId).setBody(request).setCommitComment("commit").build(codeSystemURI).execute(getBus()).getSync();
    SnomedRelationship updatedSourceRelationship = SnomedRequests.prepareGetRelationship(sourceRelationshipId).build(codeSystemURI).execute(getBus()).getSync();
    SnomedRelationship updatedDestinationRelationship = SnomedRequests.prepareGetRelationship(destinationRelationshipId).build(codeSystemURI).execute(getBus()).getSync();
    // Before update
    assertTrue(sourceRelationship.isActive());
    assertTrue(destinationRelationship.isActive());
    assertFalse(moduleConceptId.equals(sourceRelationship.getModuleId()));
    assertFalse(moduleConceptId.equals(destinationRelationship.getModuleId()));
    // After update
    assertFalse(updatedSourceRelationship.isActive());
    assertEquals(moduleConceptId, updatedSourceRelationship.getModuleId());
    assertFalse(updatedDestinationRelationship.isActive());
    assertEquals(moduleConceptId, updatedDestinationRelationship.getModuleId());
}
Also used : ResourceURI(com.b2international.snowowl.core.ResourceURI) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) Test(org.junit.Test)

Aggregations

TransactionContext (com.b2international.snowowl.core.domain.TransactionContext)12 BadRequestException (com.b2international.commons.exceptions.BadRequestException)3 Request (com.b2international.snowowl.core.events.Request)3 BulkRequest (com.b2international.snowowl.core.events.bulk.BulkRequest)3 CommitResult (com.b2international.snowowl.core.request.CommitResult)3 Branch (com.b2international.snowowl.core.branch.Branch)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 BulkRequestBuilder (com.b2international.snowowl.core.events.bulk.BulkRequestBuilder)2 SnomedRf2Headers (com.b2international.snowowl.snomed.common.SnomedRf2Headers)2 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)2 ClassificationTracker (com.b2international.snowowl.snomed.reasoner.classification.ClassificationTracker)2 Strings (com.google.common.base.Strings)2 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 SubMonitor (org.eclipse.core.runtime.SubMonitor)2 Test (org.junit.Test)2 CompareUtils (com.b2international.commons.CompareUtils)1