Search in sources :

Example 56 with ConcordApplicationException

use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.

the class ProjectProcessResource method list.

@GET
@ApiOperation("List processes for the specified project")
@Path("/{orgName}/project/{projectName}/process")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
@Deprecated
public List<ProcessEntry> list(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("projectName") @ConcordKey String projectName, @ApiParam @QueryParam("status") ProcessStatus processStatus, @ApiParam @QueryParam("afterCreatedAt") OffsetDateTimeParam afterCreatedAt, @ApiParam @QueryParam("beforeCreatedAt") OffsetDateTimeParam beforeCreatedAt, @ApiParam @QueryParam("limit") @DefaultValue(DEFAULT_LIST_LIMIT) int limit, @ApiParam @QueryParam("offset") @DefaultValue("0") int offset) {
    OrganizationEntry org = orgManager.assertAccess(orgName, false);
    UUID projectId = projectDao.getId(org.getId(), projectName);
    if (projectId == null) {
        throw new ConcordApplicationException("Project not found: " + projectName, Response.Status.NOT_FOUND);
    }
    ProcessFilter filter = ProcessFilter.builder().projectId(projectId).status(processStatus).afterCreatedAt(unwrap(afterCreatedAt)).beforeCreatedAt(unwrap(beforeCreatedAt)).limit(limit).offset(offset).build();
    return queueDao.list(filter);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) ProcessFilter(com.walmartlabs.concord.server.process.queue.ProcessFilter) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Example 57 with ConcordApplicationException

use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.

the class ConsoleService method isRepositoryExists.

@GET
@Path("/org/{orgName}/project/{projectName}/repo/{repoName}/exists")
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean isRepositoryExists(@PathParam("orgName") @ConcordKey String orgName, @PathParam("projectName") @ConcordKey String projectName, @PathParam("repoName") String repoName) {
    try {
        OrganizationEntry org = orgManager.assertAccess(orgName, true);
        UUID projectId = projectDao.getId(org.getId(), projectName);
        if (projectId == null) {
            throw new ConcordApplicationException("Project not found: " + projectName, Status.BAD_REQUEST);
        }
        return repositoryDao.getId(projectId, repoName) != null;
    } catch (UnauthorizedException e) {
        return false;
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Example 58 with ConcordApplicationException

use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.

the class UserManager method disable.

public void disable(UUID userId) {
    if (userDao.isDisabled(userId).orElseThrow(() -> new ConcordApplicationException("User not found: " + userId))) {
        // the account is already disabled, nothing to do
        return;
    }
    userDao.disable(userId);
    auditLog.add(AuditObject.USER, AuditAction.UPDATE).field("userId", userId).changes(describeStatusChange(false), describeStatusChange(true)).log();
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException)

Example 59 with ConcordApplicationException

use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.

the class UserResource method updateUserRoles.

@POST
@ApiOperation("Update the list of roles for the existing user")
@Path("/{username}/roles")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public GenericOperationResult updateUserRoles(@ApiParam @PathParam("username") @Size(max = UserEntry.MAX_USERNAME_LENGTH) String username, @ApiParam @Valid UpdateUserRolesRequest req) {
    assertAdmin();
    // TODO: type from request
    UserType type = UserPrincipal.assertCurrent().getType();
    // TODO: userDomain from request
    String userDomain = null;
    UUID id = userManager.getId(username, userDomain, type).orElseThrow(() -> new ConcordApplicationException("User not found: " + username, Status.NOT_FOUND));
    userDao.updateRoles(id, req.getRoles());
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate) ApiOperation(io.swagger.annotations.ApiOperation)

Example 60 with ConcordApplicationException

use of com.walmartlabs.concord.server.sdk.ConcordApplicationException in project concord by walmartlabs.

the class UserResource method findByUsername.

/**
 * Finds an existing user by username.
 *
 * @param username
 * @return
 */
@GET
@ApiOperation("Find a user")
@Path("/{username}")
@Produces(MediaType.APPLICATION_JSON)
@Validate
public UserEntry findByUsername(@PathParam("username") @Size(max = UserEntry.MAX_USERNAME_LENGTH) @NotNull String username) {
    assertAdmin();
    UUID id = userManager.getId(username, null, null).orElseThrow(() -> new ConcordApplicationException("User not found: " + username, Status.NOT_FOUND));
    return userDao.get(id);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)70 ApiOperation (io.swagger.annotations.ApiOperation)28 UUID (java.util.UUID)22 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)21 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)18 IOException (java.io.IOException)14 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)12 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)11 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)11 Validate (org.sonatype.siesta.Validate)11 Path (java.nio.file.Path)10 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)9 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)6 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 UserEntry (com.walmartlabs.concord.server.user.UserEntry)5 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Form (com.walmartlabs.concord.forms.Form)3