Search in sources :

Example 96 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResource method getCollectionsByToken.

@GET
@Path("role/{roleName}/paginated")
@Produces("application/json")
@RolesAllowed(RESEARCHER)
public Response getCollectionsByToken(@Auth AuthUser authUser, @QueryParam("token") String token, @PathParam("roleName") String roleName) {
    try {
        User user = userService.findUserByEmail(authUser.getEmail());
        validateUserHasRoleName(user, roleName);
        String json = getDecodedJson(token);
        PaginationToken paginationToken = convertJsonToPaginationToken(json);
        PaginationResponse<DarCollection> paginationResponse = darCollectionService.queryCollectionsByFiltersAndUserRoles(user, paginationToken, roleName);
        return Response.ok().entity(paginationResponse).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) PaginationToken(org.broadinstitute.consent.http.models.PaginationToken) BadRequestException(javax.ws.rs.BadRequestException) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 97 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResource method resubmitDarCollection.

@PUT
@Path("{id}/resubmit")
@Produces("application/json")
@RolesAllowed(RESEARCHER)
public Response resubmitDarCollection(@Auth AuthUser authUser, @PathParam("id") Integer collectionId) {
    try {
        User user = userService.findUserByEmail(authUser.getEmail());
        DarCollection sourceCollection = darCollectionService.getByCollectionId(collectionId);
        isCollectionPresent(sourceCollection);
        validateUserIsCreator(user, sourceCollection);
        validateCollectionIsCanceled(sourceCollection);
        DataAccessRequest draftDar = dataAccessRequestService.createDraftDarFromCanceledCollection(user, sourceCollection);
        return Response.ok().entity(draftDar).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) DataAccessRequest(org.broadinstitute.consent.http.models.DataAccessRequest) BadRequestException(javax.ws.rs.BadRequestException) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 98 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResource method createElectionsForCollection.

@POST
@Path("{collectionId}/election")
@Consumes("application/json")
@RolesAllowed({ ADMIN, CHAIRPERSON })
public Response createElectionsForCollection(@Auth AuthUser authUser, @PathParam("collectionId") Integer collectionId) {
    try {
        DarCollection sourceCollection = darCollectionService.getByCollectionId(collectionId);
        isCollectionPresent(sourceCollection);
        User user = userService.findUserByEmail(authUser.getEmail());
        DarCollection updatedCollection = darCollectionService.createElectionsForDarCollection(user, sourceCollection);
        return Response.ok(updatedCollection).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) BadRequestException(javax.ws.rs.BadRequestException) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 99 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResource method getCollectionsForUserByRole.

@GET
@Path("role/{roleName}")
@Produces("application/json")
@RolesAllowed({ ADMIN, CHAIRPERSON, MEMBER, SIGNINGOFFICIAL })
public Response getCollectionsForUserByRole(@Auth AuthUser authUser, @PathParam("roleName") String roleName) {
    try {
        User user = userService.findUserByEmail(authUser.getEmail());
        validateUserHasRoleName(user, roleName);
        List<DarCollection> collections = darCollectionService.getCollectionsForUserByRoleName(user, roleName);
        return Response.ok().entity(collections).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) BadRequestException(javax.ws.rs.BadRequestException) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 100 with DarCollection

use of org.broadinstitute.consent.http.models.DarCollection in project consent by DataBiosphere.

the class DarCollectionResource method getCollectionById.

@GET
@Path("{collectionId}")
@Produces("application/json")
@PermitAll
public Response getCollectionById(@Auth AuthUser authUser, @PathParam("collectionId") Integer collectionId) {
    try {
        DarCollection collection = darCollectionService.getByCollectionId(collectionId);
        User user = userService.findUserByEmail(authUser.getEmail());
        if (checkAdminPermissions(user) || checkSoPermissions(user, collection) || checkDacPermissions(user, collection)) {
            return Response.ok().entity(collection).build();
        }
        validateUserIsCreator(user, collection);
        return Response.ok().entity(collection).build();
    } catch (Exception e) {
        return createExceptionResponse(e);
    }
}
Also used : AuthUser(org.broadinstitute.consent.http.models.AuthUser) User(org.broadinstitute.consent.http.models.User) BadRequestException(javax.ws.rs.BadRequestException) ForbiddenException(javax.ws.rs.ForbiddenException) NotFoundException(javax.ws.rs.NotFoundException) DarCollection(org.broadinstitute.consent.http.models.DarCollection) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PermitAll(javax.annotation.security.PermitAll)

Aggregations

DarCollection (org.broadinstitute.consent.http.models.DarCollection)127 Test (org.junit.Test)110 User (org.broadinstitute.consent.http.models.User)71 DataAccessRequest (org.broadinstitute.consent.http.models.DataAccessRequest)43 AuthUser (org.broadinstitute.consent.http.models.AuthUser)33 PaginationResponse (org.broadinstitute.consent.http.models.PaginationResponse)33 Response (javax.ws.rs.core.Response)32 UserRole (org.broadinstitute.consent.http.models.UserRole)21 Date (java.util.Date)20 DataAccessRequestData (org.broadinstitute.consent.http.models.DataAccessRequestData)18 DataSet (org.broadinstitute.consent.http.models.DataSet)18 Election (org.broadinstitute.consent.http.models.Election)16 PaginationToken (org.broadinstitute.consent.http.models.PaginationToken)14 NotFoundException (javax.ws.rs.NotFoundException)13 BadRequestException (javax.ws.rs.BadRequestException)11 ForbiddenException (javax.ws.rs.ForbiddenException)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 ArrayList (java.util.ArrayList)8 Path (javax.ws.rs.Path)8 Dac (org.broadinstitute.consent.http.models.Dac)8