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;
}
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);
}
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));
}
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;
}
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);
}
Aggregations