Search in sources :

Example 21 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.

the class BaseUserController method changePassword.

@ApiOperation("Change user password")
@RequestMapping(value = "/api/v1/user-management/users/changepassword", method = POST)
public JsonResult changePassword(@RequestBody @Valid ChangePasswordDTO changePasswordDTO, Principal principal) throws ValidationException, PasswordValidationException {
    JsonResult result;
    U loggedUser = userService.getByEmail(principal.getName());
    try {
        userService.updatePassword(loggedUser, changePasswordDTO.getOldPassword(), changePasswordDTO.getNewPassword());
        result = new JsonResult<>(NO_ERROR);
    } catch (ValidationException ex) {
        result = new JsonResult<>(VALIDATION_ERROR);
        result.setErrorMessage(ex.getMessage());
    }
    return result;
}
Also used : PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.

the class BaseUserController method unlinkUserToDataNode.

@ApiOperation("Unlink User to DataNode")
@RequestMapping(value = "/api/v1/user-management/datanodes/{datanodeId}/users", method = RequestMethod.DELETE)
public JsonResult unlinkUserToDataNode(@PathVariable("datanodeId") Long datanodeId, @RequestBody CommonLinkUserToDataNodeDTO linkUserToDataNode) throws NotExistException {
    final DN datanode = Optional.ofNullable(baseDataNodeService.getById(datanodeId)).orElseThrow(() -> new NotExistException(String.format(DATA_NODE_NOT_FOUND_EXCEPTION, datanodeId), DataNode.class));
    final U user = userService.getByUsernameInAnyTenant(linkUserToDataNode.getUserName());
    baseDataNodeService.unlinkUserToDataNode(datanode, user);
    return new JsonResult(NO_ERROR);
}
Also used : DataNode(com.odysseusinc.arachne.portal.model.DataNode) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.

the class BaseUserController method invitationAccept.

private JsonResult<UserProfileDTO> invitationAccept(InvitationActionDTO invitationActionDTO, U user) throws NotExistException, AlreadyExistException, IOException {
    checkIfUserExists(user);
    final Boolean invitationAccepted = invitationActionDTO.getAccepted();
    final Long invitationId = invitationActionDTO.getId();
    switch(invitationActionDTO.getType()) {
        case InvitationType.COLLABORATOR:
            {
                userService.processInvitation(user, invitationId, invitationAccepted, invitationActionDTO.getComment());
                break;
            }
        case InvitationType.DATA_OWNER:
            {
                studyService.processDataSourceInvitation(user, invitationId, invitationAccepted, invitationActionDTO.getComment());
                break;
            }
        case InvitationType.UNLOCK_ANALYSIS:
            {
                analysisService.processAnalysisUnlockRequest(user, invitationId, invitationAccepted);
                break;
            }
        case InvitationType.APPROVE_EXECUTE_SUBMISSION:
            submissionService.approveSubmission(invitationId, invitationAccepted, invitationActionDTO.getComment(), user);
            break;
        case InvitationType.APPROVE_PUBLISH_SUBMISSION:
            ApproveDTO dto = new ApproveDTO(invitationId, invitationAccepted, Boolean.TRUE, invitationActionDTO.getComment());
            submissionService.approveSubmissionResult(invitationId, dto, user);
            break;
        default:
            {
                throw new IllegalArgumentException();
            }
    }
    return new JsonResult<>(NO_ERROR, conversionService.convert(userService.getByIdInAnyTenantAndInitializeCollections(user.getId()), UserProfileDTO.class));
}
Also used : UserProfileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserProfileDTO) ApproveDTO(com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)

Example 24 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.

the class BaseUserController method findUserStatus.

@ApiOperation("Get status of registered user")
@RequestMapping(value = "/api/v1/auth/status/{userUuid}", method = GET)
public JsonResult<CommonArachneUserStatusDTO> findUserStatus(@PathVariable("userUuid") String uuid) throws UserNotFoundException {
    JsonResult<CommonArachneUserStatusDTO> result;
    IUser user = userService.getByUuid(uuid);
    if (user == null) {
        throw new UserNotFoundException("userUuid", "user not found");
    } else {
        result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
        result.setResult(user.getEnabled() ? CommonArachneUserStatusDTO.APPROVED : CommonArachneUserStatusDTO.PENDING);
    }
    return result;
}
Also used : UserNotFoundException(com.odysseusinc.arachne.portal.exception.UserNotFoundException) CommonArachneUserStatusDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonArachneUserStatusDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with JsonResult

use of com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult in project ArachneCentralAPI by OHDSI.

the class BaseUserController method invitationAcceptViaMail.

@ApiOperation("Accept invitations via mail.")
@RequestMapping(value = "/api/v1/user-management/users/invitations/mail", method = GET)
public JsonResult<UserProfileDTO> invitationAcceptViaMail(@RequestParam("id") Long id, @RequestParam("accepted") Boolean accepted, @RequestParam("type") String type, @RequestParam("token") String token, @RequestParam(value = "userId", required = false) Long userId, HttpServletResponse response) throws NotExistException, AlreadyExistException, IOException {
    InvitationActionWithTokenDTO dto = new InvitationActionWithTokenDTO(id, type, accepted, token);
    String redirectLink;
    U user;
    try {
        user = getUserFromInvitationDto(dto, userId);
        redirectLink = getRedirectLinkFromInvitationDto(dto, id, token);
    } catch (NotExistException ex) {
        JsonResult result = new JsonResult<>(VALIDATION_ERROR);
        result.setErrorMessage(ex.getMessage());
        response.sendRedirect(INVITATION_HOME_PAGE);
        return result;
    }
    response.sendRedirect(redirectLink);
    return invitationAccept(dto, user);
}
Also used : InvitationActionWithTokenDTO(com.odysseusinc.arachne.portal.api.v1.dto.InvitationActionWithTokenDTO) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)71 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)58 ApiOperation (io.swagger.annotations.ApiOperation)55 IUser (com.odysseusinc.arachne.portal.model.IUser)22 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)17 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)17 ResponseEntity (org.springframework.http.ResponseEntity)16 GET (org.springframework.web.bind.annotation.RequestMethod.GET)10 POST (org.springframework.web.bind.annotation.RequestMethod.POST)10 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)10 NotUniqueException (com.odysseusinc.arachne.portal.exception.NotUniqueException)6 FieldError (org.springframework.validation.FieldError)6 PermissionDeniedException (com.odysseusinc.arachne.portal.exception.PermissionDeniedException)5 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)5 DataNode (com.odysseusinc.arachne.portal.model.DataNode)5 IOException (java.io.IOException)5 ApproveDTO (com.odysseusinc.arachne.portal.api.v1.dto.ApproveDTO)4 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 SubmissionFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.SubmissionFileDTO)4