Search in sources :

Example 1 with IUser

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));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) IUser(com.odysseusinc.arachne.portal.model.IUser) CommonUserDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonUserDTO) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with IUser

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;
}
Also used : IUser(com.odysseusinc.arachne.portal.model.IUser) List(java.util.List) LinkedList(java.util.LinkedList) AdminUserDTO(com.odysseusinc.arachne.portal.api.v1.dto.AdminUserDTO) LinkedList(java.util.LinkedList) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with IUser

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;
}
Also used : ArachnePasswordData(com.odysseusinc.arachne.portal.security.passwordvalidator.ArachnePasswordData) PasswordValidationException(com.odysseusinc.arachne.portal.exception.PasswordValidationException) IUser(com.odysseusinc.arachne.portal.model.IUser) ArachnePasswordValidationResult(com.odysseusinc.arachne.portal.security.passwordvalidator.ArachnePasswordValidationResult) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) Password(edu.vt.middleware.password.Password) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with IUser

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);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) DataNode(com.odysseusinc.arachne.portal.model.DataNode) IUser(com.odysseusinc.arachne.portal.model.IUser) DataReference(com.odysseusinc.arachne.portal.model.DataReference) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with IUser

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;
}
Also used : PUT(org.springframework.web.bind.annotation.RequestMethod.PUT) GET(org.springframework.web.bind.annotation.RequestMethod.GET) POST(org.springframework.web.bind.annotation.RequestMethod.POST) ArrayList(java.util.ArrayList) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) IUser(com.odysseusinc.arachne.portal.model.IUser) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) AnalysisFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.AnalysisFileDTO) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IUser (com.odysseusinc.arachne.portal.model.IUser)60 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 ApiOperation (io.swagger.annotations.ApiOperation)37 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)22 GET (org.springframework.web.bind.annotation.RequestMethod.GET)12 POST (org.springframework.web.bind.annotation.RequestMethod.POST)12 PUT (org.springframework.web.bind.annotation.RequestMethod.PUT)12 NotExistException (com.odysseusinc.arachne.portal.exception.NotExistException)11 Study (com.odysseusinc.arachne.portal.model.Study)8 Date (java.util.Date)8 Analysis (com.odysseusinc.arachne.portal.model.Analysis)7 Submission (com.odysseusinc.arachne.portal.model.Submission)7 LinkedList (java.util.LinkedList)7 List (java.util.List)7 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)6 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)6 ArrayList (java.util.ArrayList)6 ValidationException (com.odysseusinc.arachne.portal.exception.ValidationException)5 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)4 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)4