use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class LdapIdentityProvider method validateSettings.
@Override
public void validateSettings() throws Exception {
InitialLdapContext systemContext = null;
try {
systemContext = createLdapContext();
getAllLdapRoles(systemContext);
} catch (final NamingException e) {
throw new SnowowlRuntimeException("Check LDAP identity provider settings, one or more parameters are invalid.", e);
} finally {
closeLdapContext(systemContext);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class LdapIdentityProvider method auth.
@Override
public User auth(String username, String token) {
InitialLdapContext systemContext = null;
try {
systemContext = createLdapContext();
final String userDN = findUserDN(systemContext, username);
if (!Strings.isNullOrEmpty(userDN) && authenticateUser(userDN, token)) {
return searchUsers(Collections.singleton(username), 1).getSync(1, TimeUnit.MINUTES).first().get();
} else {
return null;
}
} catch (final NamingException e) {
throw new SnowowlRuntimeException("Cannot bind to LDAP server.", e);
} finally {
closeLdapContext(systemContext);
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class VersioningRequest method execute.
@Override
public final Boolean execute(TransactionContext context) {
final Logger log = context.log();
log.info("Versioning components of '{}' resource...", config.getResource());
try {
// capped context to commit versioned components in the configured low watermark bulks
try (CappedTransactionContext versioningContext = new CappedTransactionContext(context, getCommitLimit(context))) {
doVersionComponents(versioningContext);
}
} catch (Exception e) {
if (e instanceof ApiException) {
throw (ApiException) e;
}
throw new SnowowlRuntimeException(e);
}
return Boolean.TRUE;
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class VersionRestService method createVersion.
@Operation(summary = "Create a new resource version", description = "Creates a new resource version. " + "The version tag (represented by an empty branch) is created on the resource's current working branch. " + "Where applicable, effective times are set on the unpublished content as part of this operation.")
@ApiResponses({ @ApiResponse(responseCode = "201", description = "Created"), @ApiResponse(responseCode = "404", description = "Not found"), @ApiResponse(responseCode = "409", description = "Code system version conflicts with existing branch") })
@PostMapping(consumes = { AbstractRestService.JSON_MEDIA_TYPE })
@ResponseStatus(value = HttpStatus.CREATED)
public ResponseEntity<Void> createVersion(@Parameter(description = "Version parameters") @RequestBody final ResourceRequest<VersionRestInput> input) {
final VersionRestInput change = input.getChange();
ApiValidation.checkInput(change);
String newVersionUri = String.join(Branch.SEPARATOR, change.getResource().toString(), change.getVersion());
String jobId = ResourceRequests.prepareNewVersion().setResource(change.getResource()).setVersion(change.getVersion()).setDescription(change.getDescription()).setEffectiveTime(change.getEffectiveTime()).setForce(change.isForce()).setCommitComment(input.getCommitComment()).buildAsync().runAsJobWithRestart(ResourceRequests.versionJobKey(change.getResource()), "Creating version " + newVersionUri).execute(getBus()).getSync(1, TimeUnit.MINUTES);
RemoteJobEntry job = JobRequests.waitForJob(getBus(), jobId, 500);
if (job.isSuccessful()) {
final URI location = MvcUriComponentsBuilder.fromMethodName(VersionRestService.class, "getVersion", newVersionUri).build().toUri();
return ResponseEntity.created(location).build();
} else if (!Strings.isNullOrEmpty(job.getResult())) {
ApiError error = job.getResultAs(ApplicationContext.getServiceForClass(ObjectMapper.class), ApiError.class);
throw new ApiErrorException(error.withMessage(error.getMessage().replace("Branch name", "Version")));
} else {
throw new SnowowlRuntimeException("Version creation failed.");
}
}
use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.
the class DefaultOperationLockManager method lock.
@Override
public void lock(final DatastoreLockContext context, final long timeoutMillis, final Iterable<DatastoreLockTarget> targets) throws LockedException {
final Map<DatastoreLockTarget, DatastoreLockContext> alreadyLockedTargets = Maps.newHashMap();
final long startTimeMillis = getCurrentTimeMillis();
try {
synchronized (syncObject) {
while (true) {
alreadyLockedTargets.clear();
canContextLockTargets(context, targets, alreadyLockedTargets);
if (alreadyLockedTargets.isEmpty()) {
for (final DatastoreLockTarget newTarget : targets) {
final IOperationLock existingLock = getOrCreateLock(context, newTarget);
fireTargetAcquired(existingLock.getTarget(), context);
}
syncObject.notifyAll();
return;
}
if (NO_TIMEOUT == timeoutMillis) {
syncObject.wait();
} else {
final long remainingTimeoutMillis = timeoutMillis - (getCurrentTimeMillis() - startTimeMillis);
if (remainingTimeoutMillis < 1L) {
throwLockedException(ACQUIRE_FAILED_MESSAGE, context, alreadyLockedTargets);
} else {
syncObject.wait(remainingTimeoutMillis);
}
}
}
}
} catch (InterruptedException e) {
throw new SnowowlRuntimeException(e);
}
}
Aggregations