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