Search in sources :

Example 1 with ValidationRuntimeException

use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException 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 {
    if (!analysisModificationLock.add(analysisId)) {
        throw new ValidationRuntimeException("Analysis import rejected", Collections.singletonMap(entityReference.getEntityGuid(), Collections.singletonList("Another import into this analysis is in progress")));
    }
    try {
        LOGGER.debug("Started import into analysis {}", analysisId);
        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);
        String description = doAddCommonEntityToAnalysis(analysis, dataReference, user, analysisType, entityFiles);
        return new JsonResult(NO_ERROR, description);
    } finally {
        analysisModificationLock.remove(analysisId);
        LOGGER.debug("Completed import into analysis {}", analysisId);
    }
}
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) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) 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 2 with ValidationRuntimeException

use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException in project ArachneCentralAPI by OHDSI.

the class AnalysisFilesSavingServiceImpl method saveFiles.

@Override
@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
public List<AnalysisFile> saveFiles(List<UploadFileDTO> files, IUser user, A analysis) throws IOException {
    List<String> errorFileMessages = new ArrayList<>();
    List<AnalysisFile> savedFiles = new ArrayList<>();
    for (UploadFileDTO f : files) {
        try {
            if (StringUtils.isNotBlank(f.getLink())) {
                savedFiles.add(saveFileByLink(f.getLink(), user, analysis, f.getLabel(), f.getExecutable()));
            } else if (f.getFile() != null) {
                savedFiles.add(saveFile(f.getFile(), user, analysis, f.getLabel(), f.getExecutable(), null));
            } else {
                errorFileMessages.add(String.format("Invalid file: \"%s\"", f.getLabel()));
            }
        } catch (AlreadyExistException e) {
            errorFileMessages.add(e.getMessage());
        }
    }
    if (!errorFileMessages.isEmpty()) {
        throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of("file", errorFileMessages));
    }
    return savedFiles;
}
Also used : UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) ArrayList(java.util.ArrayList) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ValidationRuntimeException

use of com.odysseusinc.arachne.portal.exception.ValidationRuntimeException in project ArachneCentralAPI by OHDSI.

the class AnalysisFilesSavingServiceImpl method saveFiles.

@PreAuthorize("hasPermission(#analysis, " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).UPLOAD_ANALYSIS_FILES)")
protected List<AnalysisFile> saveFiles(List<MultipartFile> multipartFiles, IUser user, A analysis, DataReference dataReference, BiPredicate<String, CommonAnalysisType> checkFileExecutabilityPredicate) {
    List<MultipartFile> filteredFiles = multipartFiles.stream().filter(file -> !(CommonAnalysisType.COHORT.equals(analysis.getType()) && file.getName().endsWith(OHDSI_JSON_EXT))).filter(file -> !file.getName().startsWith(ANALYSIS_INFO_FILE_DESCRIPTION)).collect(Collectors.toList());
    List<AnalysisFile> savedFiles = new ArrayList<>();
    List<String> errorFileMessages = new ArrayList<>();
    for (MultipartFile file : filteredFiles) {
        try {
            final boolean isExecutable = checkFileExecutabilityPredicate.test(file.getOriginalFilename(), analysis.getType());
            savedFiles.add(saveFile(file, user, analysis, file.getName(), isExecutable, dataReference));
        } catch (AlreadyExistException e) {
            errorFileMessages.add(e.getMessage());
        }
    }
    if (!errorFileMessages.isEmpty()) {
        throw new ValidationRuntimeException("Failed to save files", ImmutableMap.of(dataReference.getGuid(), errorFileMessages));
    }
    return savedFiles;
}
Also used : AnalysisHelper(com.odysseusinc.arachne.portal.util.AnalysisHelper) AnalysisArchiveUtils(com.odysseusinc.arachne.commons.utils.AnalysisArchiveUtils) URL(java.net.URL) Date(java.util.Date) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) LoggerFactory(org.slf4j.LoggerFactory) SqlTranslate(org.ohdsi.sql.SqlTranslate) StringUtils(org.apache.commons.lang3.StringUtils) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) OHDSI_SQL_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT) ByteArrayInputStream(java.io.ByteArrayInputStream) Analysis(com.odysseusinc.arachne.portal.model.Analysis) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) Path(java.nio.file.Path) RestTemplate(org.springframework.web.client.RestTemplate) ImmutableMap(com.google.common.collect.ImmutableMap) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) HttpHeaders(org.springframework.http.HttpHeaders) Collection(java.util.Collection) MediaType(org.springframework.http.MediaType) SqlRender(org.ohdsi.sql.SqlRender) CommonAnalysisType(com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) IUser(com.odysseusinc.arachne.portal.model.IUser) IOUtils(org.apache.commons.io.IOUtils) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) AnalysisFilesSavingService(com.odysseusinc.arachne.portal.service.analysis.AnalysisFilesSavingService) NotNull(org.jetbrains.annotations.NotNull) FilenameUtils(org.apache.commons.io.FilenameUtils) ZipOutputStream(java.util.zip.ZipOutputStream) ANALYSIS_INFO_FILE_DESCRIPTION(com.odysseusinc.arachne.commons.utils.CommonFileUtils.ANALYSIS_INFO_FILE_DESCRIPTION) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OHDSI_JSON_EXT(com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT) DataReference(com.odysseusinc.arachne.portal.model.DataReference) ArachneSystemRuntimeException(com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException) ArrayList(java.util.ArrayList) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) BiPredicate(java.util.function.BiPredicate) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) ZipUtil(com.odysseusinc.arachne.portal.util.ZipUtil) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Service(org.springframework.stereotype.Service) AnalysisFileRepository(com.odysseusinc.arachne.portal.repository.AnalysisFileRepository) AnalysisPreprocessorService(com.odysseusinc.arachne.portal.service.impl.AnalysisPreprocessorService) AnalysisUtils.throwAccessDeniedExceptionIfLocked(com.odysseusinc.arachne.portal.service.analysis.impl.AnalysisUtils.throwAccessDeniedExceptionIfLocked) REPLACE_EXISTING(java.nio.file.StandardCopyOption.REPLACE_EXISTING) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) Logger(org.slf4j.Logger) DBMSType(com.odysseusinc.arachne.commons.types.DBMSType) Files(java.nio.file.Files) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) HttpStatus(org.springframework.http.HttpStatus) Paths(java.nio.file.Paths) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) AnalysisFile(com.odysseusinc.arachne.portal.model.AnalysisFile) ArrayList(java.util.ArrayList) ValidationRuntimeException(com.odysseusinc.arachne.portal.exception.ValidationRuntimeException) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ValidationRuntimeException (com.odysseusinc.arachne.portal.exception.ValidationRuntimeException)3 UploadFileDTO (com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO)2 AlreadyExistException (com.odysseusinc.arachne.portal.exception.AlreadyExistException)2 AnalysisFile (com.odysseusinc.arachne.portal.model.AnalysisFile)2 DataReference (com.odysseusinc.arachne.portal.model.DataReference)2 IUser (com.odysseusinc.arachne.portal.model.IUser)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 CommonAnalysisType (com.odysseusinc.arachne.commons.api.v1.dto.CommonAnalysisType)1 JsonResult (com.odysseusinc.arachne.commons.api.v1.dto.util.JsonResult)1 DBMSType (com.odysseusinc.arachne.commons.types.DBMSType)1 AnalysisArchiveUtils (com.odysseusinc.arachne.commons.utils.AnalysisArchiveUtils)1 CommonFileUtils (com.odysseusinc.arachne.commons.utils.CommonFileUtils)1 ANALYSIS_INFO_FILE_DESCRIPTION (com.odysseusinc.arachne.commons.utils.CommonFileUtils.ANALYSIS_INFO_FILE_DESCRIPTION)1 OHDSI_JSON_EXT (com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_JSON_EXT)1 OHDSI_SQL_EXT (com.odysseusinc.arachne.commons.utils.CommonFileUtils.OHDSI_SQL_EXT)1 ArachneSystemRuntimeException (com.odysseusinc.arachne.portal.exception.ArachneSystemRuntimeException)1 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)1 Analysis (com.odysseusinc.arachne.portal.model.Analysis)1 DataNode (com.odysseusinc.arachne.portal.model.DataNode)1