Search in sources :

Example 96 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method getUploads.

@GetMapping("/v3/participants/{userId}/uploads")
public ForwardCursorPagedResourceList<UploadView> getUploads(@PathVariable String userId, @RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) Integer pageSize, @RequestParam(required = false) String offsetKey) {
    UserSession session = getAdministrativeSession();
    CAN_EDIT_PARTICIPANTS.checkAndThrow(USER_ID, userId);
    App app = appService.getApp(session.getAppId());
    DateTime startTimeDate = getDateTimeOrDefault(startTime, null);
    DateTime endTimeDate = getDateTimeOrDefault(endTime, null);
    return participantService.getUploads(app, userId, startTimeDate, endTimeDate, pageSize, offsetKey);
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) DateTime(org.joda.time.DateTime) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 97 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method signOut.

@PostMapping("/v3/participants/{userId}/signOut")
public StatusMessage signOut(@PathVariable String userId, @RequestParam(required = false) boolean deleteReauthToken) {
    UserSession session = getAdministrativeSession();
    CAN_EDIT_PARTICIPANTS.checkAndThrow(USER_ID, userId);
    App app = appService.getApp(session.getAppId());
    participantService.signUserOut(app, userId, deleteReauthToken);
    return new StatusMessage("User signed out.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 98 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method updateParticipant.

@PostMapping("/v3/participants/{userId}")
public StatusMessage updateParticipant(@PathVariable String userId) {
    UserSession session = getAdministrativeSession();
    CAN_EDIT_PARTICIPANTS.checkAndThrow(USER_ID, userId);
    App app = appService.getApp(session.getAppId());
    StudyParticipant participant = parseJson(StudyParticipant.class);
    // Force userId of the URL
    participant = new StudyParticipant.Builder().copyOf(participant).withId(userId).build();
    participantService.updateParticipant(app, participant);
    return new StatusMessage("Participant updated.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 99 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method getEnrollments.

@GetMapping("/v3/participants/{userId}/enrollments")
public PagedResourceList<EnrollmentDetail> getEnrollments(@PathVariable String userId) {
    UserSession session = getAdministrativeSession();
    CAN_EDIT_PARTICIPANTS.checkAndThrow(USER_ID, userId);
    // A limitation of Swagger as we use it is that we don't want different collection
    // containers for the same kind of entity. Since some APIs can page enrollments,
    // this API returns a paged enrollment, despite the fact that there will probably
    // never be more than one page of results returned from this API.
    List<EnrollmentDetail> details = enrollmentService.getEnrollmentsForUser(session.getAppId(), null, userId);
    return new PagedResourceList<>(details, details.size(), true);
}
Also used : EnrollmentDetail(org.sagebionetworks.bridge.models.studies.EnrollmentDetail) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) PagedResourceList(org.sagebionetworks.bridge.models.PagedResourceList) ForwardCursorPagedResourceList(org.sagebionetworks.bridge.models.ForwardCursorPagedResourceList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 100 with UserSession

use of org.sagebionetworks.bridge.models.accounts.UserSession in project BridgeServer2 by Sage-Bionetworks.

the class ParticipantController method createCustomActivityEvent.

@PostMapping(path = { "/v3/participants/{userId}/activityEvents", "/v3/participants/{userId}/activityevents" })
@ResponseStatus(HttpStatus.CREATED)
public StatusMessage createCustomActivityEvent(@PathVariable String userId) {
    UserSession session = getAuthenticatedSession(DEVELOPER, RESEARCHER);
    App app = appService.getApp(session.getAppId());
    CustomActivityEventRequest activityEvent = parseJson(CustomActivityEventRequest.class);
    participantService.createCustomActivityEvent(app, userId, activityEvent);
    return new StatusMessage("Event recorded.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) CustomActivityEventRequest(org.sagebionetworks.bridge.models.activities.CustomActivityEventRequest) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus)

Aggregations

UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)483 PostMapping (org.springframework.web.bind.annotation.PostMapping)149 GetMapping (org.springframework.web.bind.annotation.GetMapping)114 App (org.sagebionetworks.bridge.models.apps.App)104 Test (org.testng.annotations.Test)102 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)89 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)65 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)60 Account (org.sagebionetworks.bridge.models.accounts.Account)56 BeforeMethod (org.testng.annotations.BeforeMethod)47 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)45 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)43 UnauthorizedException (org.sagebionetworks.bridge.exceptions.UnauthorizedException)38 CriteriaContext (org.sagebionetworks.bridge.models.CriteriaContext)31 DateTime (org.joda.time.DateTime)27 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)21 ResourceList (org.sagebionetworks.bridge.models.ResourceList)21 SubpopulationGuid (org.sagebionetworks.bridge.models.subpopulations.SubpopulationGuid)21 BadRequestException (org.sagebionetworks.bridge.exceptions.BadRequestException)18