Search in sources :

Example 21 with SnowowlRuntimeException

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);
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingException(javax.naming.NamingException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 22 with SnowowlRuntimeException

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);
    }
}
Also used : InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingException(javax.naming.NamingException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 23 with SnowowlRuntimeException

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;
}
Also used : CappedTransactionContext(com.b2international.snowowl.core.domain.CappedTransactionContext) Logger(org.slf4j.Logger) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) ApiException(com.b2international.commons.exceptions.ApiException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) ApiException(com.b2international.commons.exceptions.ApiException)

Example 24 with SnowowlRuntimeException

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.");
    }
}
Also used : ApiError(com.b2international.commons.exceptions.ApiError) URI(java.net.URI) ApiErrorException(com.b2international.commons.exceptions.ApiErrorException) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 25 with SnowowlRuntimeException

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);
    }
}
Also used : DatastoreLockTarget(com.b2international.snowowl.core.internal.locks.DatastoreLockTarget) DatastoreLockContext(com.b2international.snowowl.core.internal.locks.DatastoreLockContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Aggregations

SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)39 IOException (java.io.IOException)27 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)7 Collection (java.util.Collection)7 HttpPost (org.apache.http.client.methods.HttpPost)6 BadRequestException (com.b2international.commons.exceptions.BadRequestException)5 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)4 Promise (com.b2international.snowowl.core.events.util.Promise)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 File (java.io.File)3 Path (java.nio.file.Path)3 NamingException (javax.naming.NamingException)3 InitialLdapContext (javax.naming.ldap.InitialLdapContext)3 HttpGet (org.apache.http.client.methods.HttpGet)3 Logger (org.slf4j.Logger)3 JwkException (com.auth0.jwk.JwkException)2 JwkProvider (com.auth0.jwk.JwkProvider)2 JwkProviderBuilder (com.auth0.jwk.JwkProviderBuilder)2