Search in sources :

Example 6 with StudyFile

use of com.odysseusinc.arachne.portal.model.StudyFile in project ArachneCentralAPI by OHDSI.

the class BaseStudyServiceImpl method getAllStudyFilesExceptLinks.

@Override
@PreAuthorize("hasPermission(#studyId, 'Study', " + "T(com.odysseusinc.arachne.portal.security.ArachnePermission).ACCESS_STUDY)")
public void getAllStudyFilesExceptLinks(Long studyId, String archiveName, OutputStream os) throws IOException {
    T study = studyRepository.findOne(studyId);
    Path storeFilesPath = fileService.getPath(study);
    List<StudyFile> files = study.getFiles().stream().filter(file -> StringUtils.isEmpty(file.getLink())).collect(Collectors.toList());
    fileService.archiveFiles(os, storeFilesPath, files);
}
Also used : Path(java.nio.file.Path) Arrays(java.util.Arrays) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) UserStudy(com.odysseusinc.arachne.portal.model.UserStudy) Collections.singletonList(java.util.Collections.singletonList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) StudyDataSourceCommentRepository(com.odysseusinc.arachne.portal.repository.StudyDataSourceCommentRepository) BaseDataSourceService(com.odysseusinc.arachne.portal.service.BaseDataSourceService) Map(java.util.Map) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) AddDataSourceStrategy(com.odysseusinc.arachne.portal.service.study.AddDataSourceStrategy) Sort(org.springframework.data.domain.Sort) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) User(com.odysseusinc.arachne.portal.model.User) BaseSolrService(com.odysseusinc.arachne.portal.service.BaseSolrService) ArachneMailSender(com.odysseusinc.arachne.portal.service.mail.ArachneMailSender) Set(java.util.Set) EventListener(org.springframework.context.event.EventListener) PageRequest(org.springframework.data.domain.PageRequest) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) Page(org.springframework.data.domain.Page) IUser(com.odysseusinc.arachne.portal.model.IUser) SimpMessagingTemplate(org.springframework.messaging.simp.SimpMessagingTemplate) StudyFileService(com.odysseusinc.arachne.portal.service.StudyFileService) AntivirusJob(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJob) SuggestSearchRegion(com.odysseusinc.arachne.portal.model.SuggestSearchRegion) CollectionUtils(org.springframework.util.CollectionUtils) UserStudyRepository(com.odysseusinc.arachne.portal.repository.UserStudyRepository) TRUE(java.lang.Boolean.TRUE) AbstractUserStudyListItem(com.odysseusinc.arachne.portal.model.AbstractUserStudyListItem) StudySpecification(com.odysseusinc.arachne.portal.model.search.StudySpecification) UserStudyGroupedRepository(com.odysseusinc.arachne.portal.repository.UserStudyGroupedRepository) PENDING(com.odysseusinc.arachne.portal.model.DataSourceStatus.PENDING) BaseStudyHelper(com.odysseusinc.arachne.portal.util.BaseStudyHelper) ArrayList(java.util.ArrayList) AntivirusJobEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobEvent) DataSource(com.odysseusinc.arachne.portal.model.DataSource) ParticipantRole(com.odysseusinc.arachne.portal.model.ParticipantRole) BaseUserStudyLinkRepository(com.odysseusinc.arachne.portal.repository.BaseUserStudyLinkRepository) DECLINED(com.odysseusinc.arachne.portal.model.DataSourceStatus.DECLINED) UserStudyGrouped(com.odysseusinc.arachne.portal.model.UserStudyGrouped) HttpMethod(org.springframework.http.HttpMethod) IOException(java.io.IOException) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) InvitationCollaboratorMailSender(com.odysseusinc.arachne.portal.service.mail.InvitationCollaboratorMailSender) StudyTypeService(com.odysseusinc.arachne.portal.service.StudyTypeService) HttpStatus(org.springframework.http.HttpStatus) UserStudyExtended(com.odysseusinc.arachne.portal.model.UserStudyExtended) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) ParticipantStatus(com.odysseusinc.arachne.portal.model.ParticipantStatus) URL(java.net.URL) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) StudyStatusService(com.odysseusinc.arachne.portal.service.StudyStatusService) AntivirusStatus(com.odysseusinc.arachne.portal.model.AntivirusStatus) SolrField(com.odysseusinc.arachne.portal.service.impl.solr.SolrField) IDataSource(com.odysseusinc.arachne.portal.model.IDataSource) RestTemplate(org.springframework.web.client.RestTemplate) UserStudyExtendedRepository(com.odysseusinc.arachne.portal.repository.UserStudyExtendedRepository) LEAD_INVESTIGATOR(com.odysseusinc.arachne.portal.model.ParticipantRole.LEAD_INVESTIGATOR) AlreadyExistException(com.odysseusinc.arachne.portal.exception.AlreadyExistException) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) PostAuthorize(org.springframework.security.access.prepost.PostAuthorize) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) SolrCollection(com.odysseusinc.arachne.portal.model.solr.SolrCollection) Objects(java.util.Objects) CommonFileUtils(com.odysseusinc.arachne.commons.utils.CommonFileUtils) List(java.util.List) HttpEntity(org.springframework.http.HttpEntity) StudyDataSourceComment(com.odysseusinc.arachne.portal.model.StudyDataSourceComment) StudyFileRepository(com.odysseusinc.arachne.portal.repository.StudyFileRepository) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) BaseStudyService(com.odysseusinc.arachne.portal.service.BaseStudyService) Authentication(org.springframework.security.core.Authentication) FieldException(com.odysseusinc.arachne.portal.exception.FieldException) FilenameUtils(org.apache.commons.io.FilenameUtils) Study(com.odysseusinc.arachne.portal.model.Study) EntityGraph(com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph) AddDataSourceStrategyFactory(com.odysseusinc.arachne.portal.service.study.AddDataSourceStrategyFactory) NotUniqueException(com.odysseusinc.arachne.portal.exception.NotUniqueException) StudyStateMachine(com.odysseusinc.arachne.portal.model.statemachine.study.StudyStateMachine) StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) AntivirusJobResponse(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobResponse) HashMap(java.util.HashMap) StudyDataSourceLinkRepository(com.odysseusinc.arachne.portal.repository.StudyDataSourceLinkRepository) BaseUserService(com.odysseusinc.arachne.portal.service.BaseUserService) FavouriteStudy(com.odysseusinc.arachne.portal.model.FavouriteStudy) CrudRepository(org.springframework.data.repository.CrudRepository) ResultFileRepository(com.odysseusinc.arachne.portal.repository.ResultFileRepository) ValidationException(com.odysseusinc.arachne.portal.exception.ValidationException) AntivirusJobStudyFileResponseEvent(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobStudyFileResponseEvent) IORuntimeException(com.odysseusinc.arachne.portal.exception.IORuntimeException) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSourceStatus(com.odysseusinc.arachne.portal.model.DataSourceStatus) OutputStream(java.io.OutputStream) APPROVED(com.odysseusinc.arachne.portal.model.DataSourceStatus.APPROVED) Logger(org.slf4j.Logger) AntivirusJobFileType(com.odysseusinc.arachne.portal.service.impl.antivirus.events.AntivirusJobFileType) FavouriteStudyRepository(com.odysseusinc.arachne.portal.repository.FavouriteStudyRepository) BaseStudyRepository(com.odysseusinc.arachne.portal.repository.BaseStudyRepository) BaseDataNodeService(com.odysseusinc.arachne.portal.service.BaseDataNodeService) PermissionDeniedException(com.odysseusinc.arachne.portal.exception.PermissionDeniedException) WebSecurityConfig(com.odysseusinc.arachne.portal.config.WebSecurityConfig) CommonHealthStatus(com.odysseusinc.arachne.commons.api.v1.dto.CommonHealthStatus) NotExistException(com.odysseusinc.arachne.portal.exception.NotExistException) EntityUtils(com.odysseusinc.arachne.portal.util.EntityUtils) DataNode(com.odysseusinc.arachne.portal.model.DataNode) DataNodeUser(com.odysseusinc.arachne.portal.model.DataNodeUser) MultipartFile(org.springframework.web.multipart.MultipartFile) ResponseEntity(org.springframework.http.ResponseEntity) Comparator(java.util.Comparator) Hibernate(org.hibernate.Hibernate) StudySearch(com.odysseusinc.arachne.portal.model.search.StudySearch) Transactional(org.springframework.transaction.annotation.Transactional) StringUtils(org.springframework.util.StringUtils) StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 7 with StudyFile

use of com.odysseusinc.arachne.portal.model.StudyFile in project ArachneCentralAPI by OHDSI.

the class BaseStudyController method getFile.

@ApiOperation("Get file of the study.")
@RequestMapping(value = "/api/v1/study-management/studies/{studyId}/files/{fileUuid}", method = GET)
public FileDTO getFile(@PathVariable("studyId") Long studyId, @PathVariable("fileUuid") String uuid, @RequestParam(defaultValue = "true") Boolean withContent) throws PermissionDeniedException, NotExistException, IOException {
    StudyFile studyFile = studyService.getStudyFile(studyId, uuid);
    FileDTO fileDto = conversionService.convert(studyFile, StudyFileContentDTO.class);
    if (withContent) {
        fileDto = FileDtoContentHandler.getInstance(fileDto, fileService.getPathToFile(studyFile).toFile()).withPdfConverter(toPdfConverter::convert).handle();
    }
    return fileDto;
}
Also used : FileDTO(com.odysseusinc.arachne.portal.api.v1.dto.FileDTO) UploadFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.UploadFileDTO) StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with StudyFile

use of com.odysseusinc.arachne.portal.model.StudyFile in project ArachneCentralAPI by OHDSI.

the class StudyFileServiceImpl method getFileInputStream.

@Override
public InputStream getFileInputStream(AbstractStudyFile studyFile) throws FileNotFoundException {
    Objects.requireNonNull(studyFile, "File must not be null");
    final File file = getPathToFile(studyFile).toFile();
    if (!file.exists()) {
        if (!StringUtils.isEmpty(studyFile.getLink())) {
            InputStream response = getInputStream(studyFile);
            if (response != null) {
                return response;
            }
        }
        throw new FileNotFoundException();
    }
    return new FileInputStream(file);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) AbstractPaperFile(com.odysseusinc.arachne.portal.model.AbstractPaperFile) File(java.io.File) AbstractStudyFile(com.odysseusinc.arachne.portal.model.AbstractStudyFile) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream)

Example 9 with StudyFile

use of com.odysseusinc.arachne.portal.model.StudyFile in project ArachneCentralAPI by OHDSI.

the class BaseStudyToStudyDTOConverter method convert.

@Override
public DTO convert(final S source) {
    final DTO studyDTO = createResultObject();
    studyDTO.setStatus(conversionService.convert(source.getStatus(), StudyStatusDTO.class));
    studyDTO.setTitle(source.getTitle());
    studyDTO.setType(conversionService.convert(source.getType(), StudyTypeDTO.class));
    studyDTO.setEndDate(source.getEndDate());
    studyDTO.setStartDate(source.getStartDate());
    studyDTO.setDescription(source.getDescription());
    if (!CollectionUtils.isEmpty(source.getParticipants())) {
        studyDTO.setParticipants(source.getParticipants().stream().map(link -> conversionService.convert(link, ParticipantDTO.class)).collect(Collectors.toList()));
    }
    final List<StudyDataSourceLink> foundLinks = studyService.getLinksByStudyId(source.getId(), EntityUtils.fromAttributePaths("dataSource.dataNode.dataNodeUsers.user"));
    for (final StudyDataSourceLink studyDataSourceLink : foundLinks) {
        final DataSourceDTO dataSourceDTO = conversionService.convert(studyDataSourceLink, DataSourceDTO.class);
        studyDTO.getDataSources().add(dataSourceDTO);
    }
    List<Analysis> analyses = getAnalyses(source);
    for (final Analysis analysis : analyses) {
        studyDTO.getAnalyses().add(conversionService.convert(analysis, BaseAnalysisDTO.class));
    }
    List<StudyFile> files = studyService.getFilesByStudyId(source.getId(), EntityUtils.fromAttributePaths("author"));
    for (final StudyFile studyFile : files) {
        studyDTO.getFiles().add(conversionService.convert(studyFile, StudyFileDTO.class));
    }
    studyDTO.setCreated(source.getCreated());
    studyDTO.setUpdated(source.getUpdated());
    studyDTO.setId(source.getId());
    studyDTO.setPermissions(conversionService.convert(source, PermissionsDTO.class));
    studyDTO.setPaperId(source.getPaper() == null ? null : source.getPaper().getId());
    studyDTO.setPrivacy(source.getPrivacy());
    proceedAdditionalFields(studyDTO, source);
    return studyDTO;
}
Also used : StudyFile(com.odysseusinc.arachne.portal.model.StudyFile) StudyDataSourceLink(com.odysseusinc.arachne.portal.model.StudyDataSourceLink) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) StudyFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyFileDTO) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) BaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseAnalysisDTO) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) Analysis(com.odysseusinc.arachne.portal.model.Analysis) StudyStatusDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyStatusDTO) BaseAnalysisDTO(com.odysseusinc.arachne.portal.api.v1.dto.BaseAnalysisDTO) ParticipantDTO(com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO) PermissionsDTO(com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO) DataSourceDTO(com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO) StudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.StudyTypeDTO) StudyDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO) StudyFileDTO(com.odysseusinc.arachne.portal.api.v1.dto.StudyFileDTO)

Aggregations

StudyFile (com.odysseusinc.arachne.portal.model.StudyFile)9 IORuntimeException (com.odysseusinc.arachne.portal.exception.IORuntimeException)3 FavouriteStudy (com.odysseusinc.arachne.portal.model.FavouriteStudy)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 Study (com.odysseusinc.arachne.portal.model.Study)2 StudyDataSourceLink (com.odysseusinc.arachne.portal.model.StudyDataSourceLink)2 UserStudy (com.odysseusinc.arachne.portal.model.UserStudy)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 Date (java.util.Date)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 EntityGraph (com.cosium.spring.data.jpa.entity.graph.domain.EntityGraph)1 CommonHealthStatus (com.odysseusinc.arachne.commons.api.v1.dto.CommonHealthStatus)1 CommonFileUtils (com.odysseusinc.arachne.commons.utils.CommonFileUtils)1 BaseAnalysisDTO (com.odysseusinc.arachne.portal.api.v1.dto.BaseAnalysisDTO)1 DataSourceDTO (com.odysseusinc.arachne.portal.api.v1.dto.DataSourceDTO)1 FileDTO (com.odysseusinc.arachne.portal.api.v1.dto.FileDTO)1 ParticipantDTO (com.odysseusinc.arachne.portal.api.v1.dto.ParticipantDTO)1 PermissionsDTO (com.odysseusinc.arachne.portal.api.v1.dto.PermissionsDTO)1 StudyDTO (com.odysseusinc.arachne.portal.api.v1.dto.StudyDTO)1