Search in sources :

Example 11 with JsonResult

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

the class BaseDataNodeController method createDataSource.

@ApiOperation("Create new data source of datanode.")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}/data-sources", method = RequestMethod.POST)
public JsonResult createDataSource(@PathVariable("dataNodeId") Long id, @RequestBody C_DS_DTO commonDataSourceDTO) throws FieldException, NotExistException, ValidationException, IOException, SolrServerException, NoSuchFieldException, IllegalAccessException, BindException {
    // we validate only two fields, because we don't want to validate another fields, because they always are null
    validate(commonDataSourceDTO);
    JsonResult<CommonDataSourceDTO> result;
    DataNode dataNode = baseDataNodeService.getById(id);
    if (dataNode == null) {
        throw new IllegalArgumentException("Unable to find datanode by ID " + id);
    }
    DS dataSource = convertCommonDataSourceDtoToDataSource(commonDataSourceDTO);
    dataSource.setDataNode(dataNode);
    dataSource = dataSourceService.createOrRestoreDataSource(dataSource);
    result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(genericConversionService.convert(dataSource, CommonDataSourceDTO.class));
    return result;
}
Also used : CommonDataSourceDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataSourceDTO) DataNode(com.odysseusinc.arachne.portal.model.DataNode) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with JsonResult

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

the class BaseDataNodeController method createDataNode.

@ApiOperation("Create new data node.")
@RequestMapping(value = "/api/v1/data-nodes", method = RequestMethod.POST)
public JsonResult<CommonDataNodeCreationResponseDTO> createDataNode(Principal principal) throws PermissionDeniedException, AlreadyExistException {
    final IUser user = getUser(principal);
    final DN dataNode = buildEmptyDN();
    CommonDataNodeCreationResponseDTO responseDTO = createDataNode(dataNode, principal);
    final JsonResult<CommonDataNodeCreationResponseDTO> result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(responseDTO);
    return result;
}
Also used : CommonDataNodeCreationResponseDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataNodeCreationResponseDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with JsonResult

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

the class BaseDataNodeController method updateDataNode.

@ApiOperation("Update data node info")
@RequestMapping(value = "/api/v1/data-nodes/{dataNodeId}", method = RequestMethod.PUT)
public JsonResult<CommonDataNodeDTO> updateDataNode(@PathVariable("dataNodeId") Long dataNodeId, @RequestBody @Valid CommonDataNodeRegisterDTO commonDataNodeRegisterDTO, Principal principal) throws PermissionDeniedException, NotExistException {
    final IUser user = getUser(principal);
    final DN dataNode = conversionService.convert(commonDataNodeRegisterDTO, getDataNodeDNClass());
    dataNode.setId(dataNodeId);
    final DN updatedDataNode = baseDataNodeService.update(dataNode);
    final CommonDataNodeDTO dataNodeRegisterResponseDTO = conversionService.convert(updatedDataNode, CommonDataNodeDTO.class);
    final JsonResult<CommonDataNodeDTO> result = new JsonResult<>(JsonResult.ErrorCode.NO_ERROR);
    result.setResult(dataNodeRegisterResponseDTO);
    return result;
}
Also used : CommonDataNodeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonDataNodeDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with JsonResult

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

the class BaseDataSourceController method updateDataSource.

private JsonResult<DTO> updateDataSource(Principal principal, Long dataSourceId, DTO commonDataSourceDTO, BindingResult bindingResult) throws PermissionDeniedException, IllegalAccessException, IOException, NoSuchFieldException, SolrServerException, ValidationException {
    JsonResult result;
    if (bindingResult.hasErrors()) {
        result = setValidationErrors(bindingResult);
    } else {
        IUser user = getUser(principal);
        final DS exist = dataSourceService.getNotDeletedByIdInAnyTenant(dataSourceId);
        DS dataSource = convertDTOToDataSource(commonDataSourceDTO);
        dataSource.setId(dataSourceId);
        dataSource.setDataNode(exist.getDataNode());
        dataSource.setPublished(true);
        dataSource = dataSourceService.updateInAnyTenant(dataSource);
        result = new JsonResult<>(NO_ERROR);
        result.setResult(convertDataSourceToDTO(dataSource));
    }
    return result;
}
Also used : IUser(com.odysseusinc.arachne.portal.model.IUser) JsonResult(com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)

Example 15 with JsonResult

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

the class BaseStudyController method addParticipant.

@ApiOperation("Add participant to the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/participants", method = POST)
public JsonResult<Boolean> addParticipant(Principal principal, @PathVariable("studyId") Long studyId, @RequestBody @Valid AddStudyParticipantDTO addParticipantDTO, BindingResult binding) throws PermissionDeniedException, NotExistException, AlreadyExistException {
    JsonResult<Boolean> result;
    if (binding.hasErrors()) {
        return setValidationErrors(binding);
    }
    final IUser createdBy = getUser(principal);
    IUser participant = Optional.ofNullable(userService.getByUuid(addParticipantDTO.getUserId())).orElseThrow(() -> new NotExistException(EX_USER_NOT_EXISTS, User.class));
    UserStudy userStudy = studyService.addParticipant(createdBy, studyId, participant.getId(), addParticipantDTO.getRole());
    wsTemplate.convertAndSendToUser(userStudy.getUser().getUsername(), "/topic/invitations", new UpdateNotificationDTO());
    return new JsonResult<>(NO_ERROR, Boolean.TRUE);
}
Also used : User(com.odysseusinc.arachne.portal.model.User) IUser(com.odysseusinc.arachne.portal.model.IUser) UpdateNotificationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UpdateNotificationDTO) IUser(com.odysseusinc.arachne.portal.model.IUser) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) 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