Search in sources :

Example 1 with CycleDetectedException

use of com.b2international.commons.exceptions.CycleDetectedException in project snow-owl by b2ihealthcare.

the class TaxonomyGraph method processElements.

private LongSet processElements(final long conceptId, final BitSet bitSet) {
    if (CompareUtils.isEmpty(bitSet)) {
        return PrimitiveSets.newLongOpenHashSet();
    }
    final int count = bitSet.cardinality();
    final LongSet $ = PrimitiveSets.newLongOpenHashSetWithExpectedSize(count);
    for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
        long convertedId = getNodeId(i);
        if (convertedId == conceptId && checkCycles) {
            throw new CycleDetectedException("Concept " + conceptId + " would introduce a cycle in the ISA graph (loop).");
        }
        $.add(convertedId);
    }
    return $;
}
Also used : LongSet(com.b2international.collections.longs.LongSet) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException)

Example 2 with CycleDetectedException

use of com.b2international.commons.exceptions.CycleDetectedException in project snow-owl by b2ihealthcare.

the class BaseResourceUpdateRequest method getBundleAncestorIds.

private List<String> getBundleAncestorIds(final TransactionContext context, final String resourceId) {
    if (IComponent.ROOT_ID.equals(bundleId)) {
        return List.of(bundleId);
    }
    final Bundles bundles = ResourceRequests.bundles().prepareSearch().filterById(bundleId).one().build().execute(context);
    if (bundles.getTotal() == 0) {
        throw new NotFoundException("Bundle parent", bundleId).toBadRequestException();
    }
    final Bundle parentBundle = bundles.first().get();
    if (parentBundle.getBundleId().equals(resourceId) || parentBundle.getBundleAncestorIds().contains(resourceId)) {
        throw new CycleDetectedException("Setting parent bundle ID to '" + bundleId + "' would create a loop.");
    }
    return parentBundle.getResourcePathSegments();
}
Also used : Bundle(com.b2international.snowowl.core.bundle.Bundle) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Bundles(com.b2international.snowowl.core.bundle.Bundles)

Example 3 with CycleDetectedException

use of com.b2international.commons.exceptions.CycleDetectedException in project snow-owl by b2ihealthcare.

the class RepositoryTransactionContext method commit.

@Override
public Optional<Commit> commit(String author, String commitComment, String parentLockContext) {
    if (!isDirty()) {
        return Optional.empty();
    }
    // fall back to the current lock context or ROOT if none is present
    if (Strings.isNullOrEmpty(parentLockContext)) {
        parentLockContext = optionalService(Locks.class).map(Locks::lockContext).orElse(DatastoreLockContextDescriptions.ROOT);
    }
    final DatastoreLockContext lockContext = createLockContext(service(User.class).getUsername(), parentLockContext);
    final DatastoreLockTarget lockTarget = createLockTarget(info().id(), path());
    IOperationLockManager locks = service(IOperationLockManager.class);
    Commit commit = null;
    try {
        locks.lock(lockContext, 1000L, lockTarget);
        final long timestamp = service(TimestampProvider.class).getTimestamp();
        log().info("Persisting changes to {}@{}", path(), timestamp);
        commit = staging.commit(null, timestamp, author, commitComment);
        log().info("Changes have been successfully persisted to {}@{}.", path(), timestamp);
        return Optional.ofNullable(commit);
    } catch (final IndexException e) {
        Throwable rootCause = Throwables.getRootCause(e);
        if (rootCause instanceof CycleDetectedException) {
            throw (CycleDetectedException) rootCause;
        }
        throw new SnowowlRuntimeException(e.getMessage(), e);
    } finally {
        locks.unlock(lockContext, lockTarget);
        if (commit != null && isNotificationEnabled()) {
            service(RepositoryCommitNotificationSender.class).publish(this, commit);
        }
        clear();
    }
}
Also used : IndexException(com.b2international.index.IndexException) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException) Locks(com.b2international.snowowl.core.locks.Locks) IOperationLockManager(com.b2international.snowowl.core.locks.IOperationLockManager) DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 4 with CycleDetectedException

use of com.b2international.commons.exceptions.CycleDetectedException in project snow-owl by b2ihealthcare.

the class TaxonomyGraph method processElements.

private LongSet processElements(final long conceptId, final int... internalIds) {
    if (CompareUtils.isEmpty(internalIds)) {
        return PrimitiveSets.newLongOpenHashSet();
    }
    final LongSet $ = PrimitiveSets.newLongOpenHashSetWithExpectedSize(internalIds.length);
    for (final int i : internalIds) {
        long convertedId = getNodeId(i);
        if (conceptId == convertedId && checkCycles) {
            throw new CycleDetectedException("Concept " + conceptId + " would introduce a cycle in the ISA graph (loop).");
        }
        $.add(convertedId);
    }
    return $;
}
Also used : LongSet(com.b2international.collections.longs.LongSet) CycleDetectedException(com.b2international.commons.exceptions.CycleDetectedException)

Aggregations

CycleDetectedException (com.b2international.commons.exceptions.CycleDetectedException)4 LongSet (com.b2international.collections.longs.LongSet)2 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 IndexException (com.b2international.index.IndexException)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Bundle (com.b2international.snowowl.core.bundle.Bundle)1 Bundles (com.b2international.snowowl.core.bundle.Bundles)1 DatastoreLockContext (com.b2international.snowowl.core.internal.locks.DatastoreLockContext)1 DatastoreLockTarget (com.b2international.snowowl.core.internal.locks.DatastoreLockTarget)1 IOperationLockManager (com.b2international.snowowl.core.locks.IOperationLockManager)1 Locks (com.b2international.snowowl.core.locks.Locks)1