use of com.odysseusinc.arachne.portal.model.IUser in project ArachneCentralAPI by OHDSI.
the class BaseAdminController method getAll.
@ApiOperation(value = "Get all users.", hidden = true)
@RequestMapping(value = "/api/v1/admin/users", method = RequestMethod.GET)
public Page<CommonUserDTO> getAll(@PageableDefault(page = 1) @SortDefault.SortDefaults({ @SortDefault(sort = "name", direction = Sort.Direction.ASC) }) Pageable pageable, UserSearch userSearch) throws PermissionDeniedException, UserNotFoundException {
Pageable search = new PageRequest(pageable.getPageNumber() - 1, pageable.getPageSize(), pageable.getSort());
Iterator<Sort.Order> pageIt = pageable.getSort().iterator();
Stream<Sort.Order> pageStream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(pageIt, Spliterator.ORDERED), false);
if (pageStream.anyMatch(order -> order.getProperty().equals("name"))) {
search = new PageRequest(pageable.getPageNumber() - 1, pageable.getPageSize(), pageable.getSort().getOrderFor("name").getDirection(), "firstname", "middlename", "lastname");
}
Page<IUser> users = userService.getAll(search, userSearch);
return users.map(user -> conversionService.convert(user, CommonUserDTO.class));
}
use of com.odysseusinc.arachne.portal.model.IUser in project ArachneCentralAPI by OHDSI.
the class BaseAdminController method suggestUsers.
@ApiOperation("Suggests user according to query to add admin role.")
@RequestMapping(value = "/api/v1/admin/admins/suggest", method = RequestMethod.GET)
public JsonResult<List<AdminUserDTO>> suggestUsers(@RequestParam("query") String query, @RequestParam(value = "limit", required = false) Integer limit) {
JsonResult<List<AdminUserDTO>> result;
List<IUser> users = userService.suggestNotAdmin(query, limit == null ? 10 : limit);
List<AdminUserDTO> userDTOs = new LinkedList<>();
for (IUser user : users) {
userDTOs.add(conversionService.convert(user, AdminUserDTO.class));
}
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
result.setResult(userDTOs);
return result;
}
use of com.odysseusinc.arachne.portal.model.IUser in project ArachneCentralAPI by OHDSI.
the class BaseAuthenticationController method resetPassword.
@ApiOperation("Reset password for specified e-mail.")
@RequestMapping(value = "/api/v1/auth/reset-password", method = RequestMethod.POST)
public JsonResult resetPassword(Principal principal, HttpServletRequest request, @RequestBody @Valid ResetPasswordDTO resetPasswordDTO, BindingResult binding) throws PasswordValidationException, UserNotFoundException, NotExistException, NoSuchFieldException, IOException, SolrServerException, IllegalAccessException {
if (principal != null) {
String token = request.getHeader(tokenHeader);
tokenUtils.addInvalidateToken(token);
}
JsonResult result;
if (binding.hasErrors()) {
result = super.setValidationErrors(binding);
} else {
String email = resetPasswordDTO.getEmail();
String token = resetPasswordDTO.getToken();
String newPassword = resetPasswordDTO.getPassword();
final ArachnePasswordData passwordData = new ArachnePasswordData(new Password(newPassword));
final ArachnePasswordValidationResult validationResult = passwordValidator.validate(passwordData);
if (!validationResult.isValid()) {
throw new PasswordValidationException(passwordValidator.getMessages(validationResult));
}
if (passwordResetService.canReset(email, token)) {
IUser user = userService.getByUnverifiedEmailInAnyTenant(email);
user.setPassword(newPassword);
userService.resetPassword(user);
result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
} else {
result = new JsonResult<>(JsonResult.ErrorCode.VALIDATION_ERROR);
result.setErrorMessage("Token expired. Please, request new reset password link.");
}
}
return result;
}
use of com.odysseusinc.arachne.portal.model.IUser in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method addCommonEntityToAnalysis.
@ApiOperation("Add common entity to analysis")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/entities", method = POST)
public JsonResult addCommonEntityToAnalysis(@PathVariable("analysisId") Long analysisId, @RequestBody @Valid DataReferenceDTO entityReference, @RequestParam(value = "type", required = false, defaultValue = "COHORT") CommonAnalysisType analysisType, Principal principal) throws NotExistException, JMSException, IOException, PermissionDeniedException, URISyntaxException {
final IUser user = getUser(principal);
final DataNode dataNode = dataNodeService.getById(entityReference.getDataNodeId());
final T analysis = analysisService.getById(analysisId);
final DataReference dataReference = dataReferenceService.addOrUpdate(entityReference.getEntityGuid(), dataNode);
final List<MultipartFile> entityFiles = getEntityFiles(entityReference, dataNode, analysisType);
doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
return new JsonResult(NO_ERROR);
}
use of com.odysseusinc.arachne.portal.model.IUser in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method uploadFile.
@ApiOperation("Upload file to attach to analysis.")
@RequestMapping(value = "/api/v1/analysis-management/analyses/{analysisId}/upload", method = POST)
public JsonResult<List<AnalysisFileDTO>> uploadFile(Principal principal, @Valid UploadFileDTO uploadFileDTO, @PathVariable("analysisId") Long id) throws PermissionDeniedException, NotExistException, IOException {
IUser user = getUser(principal);
T analysis = analysisService.getById(id);
JsonResult<List<AnalysisFileDTO>> result = new JsonResult<>(NO_ERROR);
List<AnalysisFileDTO> createdFiles = new ArrayList<>();
if (uploadFileDTO.getFile() != null) {
AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getFile(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable(), null);
createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
} else {
if (StringUtils.hasText(uploadFileDTO.getLink())) {
AnalysisFile createdFile = analysisService.saveFile(uploadFileDTO.getLink(), user, analysis, uploadFileDTO.getLabel(), uploadFileDTO.getExecutable());
createdFiles.add(conversionService.convert(createdFile, AnalysisFileDTO.class));
} else {
result.setErrorCode(VALIDATION_ERROR.getCode());
}
}
result.setResult(createdFiles);
return result;
}
Aggregations