diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/bids/service/BIDSServiceImpl.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/bids/service/BIDSServiceImpl.java index 180cc65d2f..a684e3f07d 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/bids/service/BIDSServiceImpl.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/bids/service/BIDSServiceImpl.java @@ -19,14 +19,10 @@ import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; import org.shanoir.ng.dataset.DatasetDescription; import org.shanoir.ng.dataset.controler.DatasetApiController.CoordinatesSystem; -import org.shanoir.ng.dataset.modality.BidsDataset; -import org.shanoir.ng.dataset.modality.EegDataSetDescription; -import org.shanoir.ng.dataset.modality.EegDataset; -import org.shanoir.ng.dataset.modality.MrDataset; -import org.shanoir.ng.dataset.modality.MrDatasetNature; -import org.shanoir.ng.dataset.modality.PetDataset; +import org.shanoir.ng.dataset.modality.*; import org.shanoir.ng.dataset.model.Dataset; import org.shanoir.ng.dataset.model.DatasetExpression; import org.shanoir.ng.dataset.model.DatasetExpressionFormat; @@ -203,7 +199,7 @@ public void deleteBidsFolder(Long studyId, String studyName) { studyName = this.studyRepo.findById(studyId).get().getName(); } // Try to delete the BIDS folder recursively if possible - File bidsDir = new File(bidsStorageDir + File.separator + STUDY_PREFIX + studyId + '_' + studyName); + File bidsDir = new File(bidsStorageDir + File.separator + STUDY_PREFIX + studyId + studyName); if (bidsDir.exists()) { FileUtils.deleteDirectory(bidsDir); } @@ -214,15 +210,14 @@ public void deleteBidsFolder(Long studyId, String studyName) { /** * Returns data from the study formatted as BIDS in a .zip file. - * @param study the study we want to export as BIDS * @return data from the study formatted as BIDS in a .zip file. * @throws IOException */ @Override public File exportAsBids(final Long studyId, String studyName) throws IOException { // Get folder - studyName = studyName.replaceAll("[ _] ", ""); - String tmpFilePath = bidsStorageDir + File.separator + STUDY_PREFIX + studyId + '_' + studyName; + studyName = this.formatLabel(studyName); + String tmpFilePath = bidsStorageDir + File.separator + STUDY_PREFIX + studyId + studyName; File workFolder = new File(tmpFilePath); if (workFolder.exists()) { // If the file already exists, just return it @@ -267,7 +262,6 @@ private List getSubjectsForStudy(final Long studyId) throws JsonParseEx /** * Create the study/BASE BIDS folder. * @param studyName the study name - * @param studyId the study id * @return the base folder newly created */ private File createBaseBidsFolder(File workFolder, String studyName) { @@ -317,11 +311,7 @@ private void exportAsBids(final Subject subject, final String studyName, Long st .append(NEW_LINE); for (Examination examination : examinationList) { - String sessionLabel = "" + examination.getId(); - sessionLabel += (examination.getComment() != null ? "-" + examination.getComment() : ""); - - sessionLabel = sessionLabel.replaceAll(" ", ""); - sessionLabel = sessionLabel.replaceAll("_", ""); + String sessionLabel = this.getSessionLabel(examination); buffer.append(sessionLabel).append(TABULATION) .append(examination.getExaminationDate()).append(TABULATION) @@ -334,7 +324,7 @@ private void exportAsBids(final Subject subject, final String studyName, Long st File examDir = subjDir; for (Examination exam : examinationList) { if (useSessionFolder) { - examDir = createExaminationFolder(exam, subjDir, sessionFile); + examDir = createExaminationFolder(exam, subjDir); } exportAsBids(exam, examDir, studyName, subject.getName()); } @@ -353,10 +343,9 @@ private void exportAsBids(final Subject subject, final String studyName, Long st */ private File createSubjectFolder(String subjectName, final int index, final File baseDir) throws IOException { // Generate another ID here ? - subjectName = subjectName.replaceAll(" ", ""); - subjectName = subjectName.replaceAll("_", ""); + subjectName = this.formatLabel(subjectName); - File subjectFolder = new File(baseDir.getAbsolutePath() + File.separator + SUBJECT_PREFIX + index + "-" + subjectName); + File subjectFolder = new File(baseDir.getAbsolutePath() + File.separator + SUBJECT_PREFIX + index + subjectName); if (!subjectFolder.exists()) { subjectFolder.mkdirs(); } @@ -366,7 +355,6 @@ private File createSubjectFolder(String subjectName, final int index, final File /** * Returns data from the examination formatted as BIDS in a .zip file. * @param examination the examination we want to export as BIDS - * @param subjDir examination BIDS directory where we are working. * @param studyName the study name * @param subjectName the subject name * @return data from the examination formatted as BIDS in a .zip file. @@ -403,16 +391,11 @@ private void exportAsBids(final Examination examination, final File examDir, fin * Create the session/examination BIDS folder * @param examination the examination for which we want to create the folder * @param subjectDir the parent folder - * @param sessionFile the session file to complete * @return the newly created folder * @throws IOException */ - private File createExaminationFolder(final Examination examination, final File subjectDir, File sessionFile) throws IOException { - String sessionLabel = "" + examination.getId(); - sessionLabel += (examination.getComment() != null ? "-" + examination.getComment() : ""); - - sessionLabel = sessionLabel.replaceAll(" ", ""); - sessionLabel = sessionLabel.replaceAll("_", ""); + private File createExaminationFolder(final Examination examination, final File subjectDir) throws IOException { + String sessionLabel = this.getSessionLabel(examination); // Create exam/session folder File examFolder = new File(subjectDir.getAbsolutePath() + File.separator + SESSION_PREFIX + sessionLabel); @@ -422,6 +405,15 @@ private File createExaminationFolder(final Examination examination, final File s return examFolder; } + private String getSessionLabel(Examination examination) { + String label = "" + examination.getId(); + if(!StringUtils.isBlank(examination.getComment())){ + label += examination.getComment(); + } + + return formatLabel(label); + } + /** * Create the list of BIDS files associated to a dataset. * @param dataset the dataset from which we want the specific BIDS files to be created @@ -434,7 +426,7 @@ private File createExaminationFolder(final Examination examination, final File s private void createDatasetBidsFiles(final Dataset dataset, final File workDir, final String studyName, final String subjectName) throws IOException { File dataFolder = null; - String subjectNameUpdated = subjectName.replaceAll("[ _] ", ""); + String subjectNameUpdated = this.formatLabel(subjectName); String datasetFilePrefix = workDir.getName().contains(SESSION_PREFIX) ? workDir.getParentFile().getName() + "_" + workDir.getName() : workDir.getName(); dataFolder = createSpecificDataFolder(dataset, workDir, dataFolder, subjectNameUpdated, studyName); @@ -556,8 +548,7 @@ private void deleteIfExists(String filePath) { private File getScansFile(File parentFile, String subjectName) throws IOException { String fileName = parentFile.getName() + SCANS_FILE_EXTENSION; - subjectName = subjectName.replaceAll(" ", ""); - subjectName = subjectName.replaceAll("_", ""); + subjectName = this.formatLabel(subjectName); if (!parentFile.getName().contains(subjectName)) { fileName = SUBJECT_PREFIX + subjectName + "_" + parentFile.getName() + SCANS_FILE_EXTENSION; } @@ -618,8 +609,6 @@ private void getDatasetFilePathURLs(final Dataset dataset, final List pathU * See https://bids-specification.readthedocs.io/en/latest/04-modality-specific-files/03-electroencephalography.html * for more informations * @param dataset the dataset we want to export in BIDS - * @param workFolder the examination work folder in which we are working - * @param pathURLs list of file URL * @param studyName the name of associated study * @param subjectName the subject name associated * @param sessionId the session ID / examination ID associated @@ -760,8 +749,7 @@ private void participantsSerializer(File parentFolder, List subjs) { for (Subject subject : subjs) { String subjectName = subject.getName(); - subjectName = subjectName.replaceAll(" ", ""); - subjectName = subjectName.replaceAll("_", ""); + subjectName = this.formatLabel(subjectName); // Write in the file the values buffer.append(SUBJECT_PREFIX).append(index++).append("_").append(subjectName).append(CSV_SEPARATOR) .append(subject.getId()).append(CSV_SEPARATOR) @@ -775,4 +763,8 @@ private void participantsSerializer(File parentFolder, List subjs) { } } + private String formatLabel(String label){ + return label.replaceAll("[^a-zA-Z0-9]+", ""); + } + } diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/modality/BidsDataType.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/modality/BidsDataType.java index 648c8595ae..e7e2c4a12e 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/modality/BidsDataType.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/modality/BidsDataType.java @@ -36,7 +36,10 @@ public enum BidsDataType { PET("pet"), /* Microscopy.*/ - MICR("micr"); + MICR("micr"), + + /* Near-Infrared Spectroscopy */ + NIRS("nirs"); private String folderName; diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/model/DatasetModalityType.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/model/DatasetModalityType.java index 97ca2f9bf3..51f5408a53 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/model/DatasetModalityType.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/model/DatasetModalityType.java @@ -50,7 +50,10 @@ public enum DatasetModalityType { MICR_DATASET(9), // Behavioural Dataset - BEH_DATASET(10); + BEH_DATASET(10), + + // Near-Infrared Spectroscopy dataset + NIRS_DATASET(11); private int id; diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/security/DatasetSecurityService.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/security/DatasetSecurityService.java index 5888fa74ae..3c4a35b827 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/security/DatasetSecurityService.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/security/DatasetSecurityService.java @@ -568,36 +568,70 @@ public boolean hasUpdateRightOnDataset(Dataset dataset, String rightStr) throws } } + /** + * Check the connected user has the given right for the given dataset acquisition. + * If the study is updated, check the user has the given right in both former and new studies. + * + * @param datasetAcq the dataset acquisition + * @param rightStr the right + * @return true or false + * @throws EntityNotFoundException + */ + public boolean hasUpdateRightOnDatasetAcquisition(DatasetAcquisition datasetAcq, String rightStr) throws EntityNotFoundException { + if (KeycloakUtil.getTokenRoles().contains("ROLE_ADMIN")) { + return true; + } + if (datasetAcq == null) { + throw new IllegalArgumentException("Dataset acquisition cannot be null here."); + } + if (datasetAcq.getId() == null) { + throw new IllegalArgumentException("Dataset acquisition id cannot be null here."); + } + if (datasetAcq.getExamination() == null || datasetAcq.getExamination().getStudyId() == null) { + return false; + } + DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcq.getId()).orElse(null); + if (dbDatasetAcq == null) { + throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcq.getId()); + } + if (datasetAcq.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed + return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr); + } else { // study has changed : check user has right on both studies + return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr) && + this.hasRightOnStudyCenter(dbDatasetAcq.getExamination().getCenterId(), dbDatasetAcq.getExamination().getStudyId(), rightStr); + } + } + /** - * Check the connected user has the given right for the given dataset acquisition. + * Check the connected user has the given right for the given dataset acquisition DTO. * If the study is updated, check the user has the given right in both former and new studies. * - * @param datasetAcq the dataset acquisition + * @param datasetAcqDto the dataset acquisition dto * @param rightStr the right * @return true or false * @throws EntityNotFoundException */ - public boolean hasUpdateRightOnDatasetAcquisition(DatasetAcquisition datasetAcq, String rightStr) throws EntityNotFoundException { + public boolean hasUpdateRightOnDatasetAcquisitionDTO(DatasetAcquisitionDTO datasetAcqDto, String rightStr) throws EntityNotFoundException { if (KeycloakUtil.getTokenRoles().contains("ROLE_ADMIN")) { return true; } - if (datasetAcq == null) { + if (datasetAcqDto == null) { throw new IllegalArgumentException("Dataset acquisition cannot be null here."); } - if (datasetAcq.getId() == null) { + if (datasetAcqDto.getId() == null) { throw new IllegalArgumentException("Dataset acquisition id cannot be null here."); } - if (datasetAcq.getExamination() == null || datasetAcq.getExamination().getStudyId() == null) { + if (datasetAcqDto.getExamination() == null || datasetAcqDto.getExamination().getStudyId() == null) { return false; } - DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcq.getId()).orElse(null); + DatasetAcquisition dbDatasetAcq = datasetAcquisitionRepository.findById(datasetAcqDto.getId()).orElse(null); if (dbDatasetAcq == null) { - throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcq.getId()); + throw new EntityNotFoundException("Cannot find dataset acquisition with id " + datasetAcqDto.getId()); } - if (datasetAcq.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed - return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr); - } else { // study has changed : check user has right on both studies - return this.hasRightOnStudyCenter(datasetAcq.getExamination().getCenterId(), datasetAcq.getExamination().getStudyId(), rightStr) && + if (datasetAcqDto.getExamination().getStudyId() == dbDatasetAcq.getExamination().getStudyId()) { // study hasn't changed + return this.hasRightOnStudyCenter(datasetAcqDto.getExamination().getCenterId(), datasetAcqDto.getExamination().getStudyId(), rightStr); + } else { // study has changed : check user has right on both studies + return this.hasRightOnStudyCenter(datasetAcqDto.getExamination().getCenterId(), datasetAcqDto.getExamination().getStudyId(), rightStr) && this.hasRightOnStudyCenter(dbDatasetAcq.getExamination().getCenterId(), dbDatasetAcq.getExamination().getStudyId(), rightStr); } } diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetUtils.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetUtils.java index 11a0ea147e..4f098221dc 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetUtils.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetUtils.java @@ -5,21 +5,7 @@ import java.util.Iterator; import java.util.List; -import org.shanoir.ng.dataset.modality.BidsDataset; -import org.shanoir.ng.dataset.modality.CalibrationDataset; -import org.shanoir.ng.dataset.modality.CtDataset; -import org.shanoir.ng.dataset.modality.EegDataset; -import org.shanoir.ng.dataset.modality.GenericDataset; -import org.shanoir.ng.dataset.modality.MegDataset; -import org.shanoir.ng.dataset.modality.MeshDataset; -import org.shanoir.ng.dataset.modality.MrDataset; -import org.shanoir.ng.dataset.modality.ParameterQuantificationDataset; -import org.shanoir.ng.dataset.modality.PetDataset; -import org.shanoir.ng.dataset.modality.RegistrationDataset; -import org.shanoir.ng.dataset.modality.SegmentationDataset; -import org.shanoir.ng.dataset.modality.SpectDataset; -import org.shanoir.ng.dataset.modality.StatisticalDataset; -import org.shanoir.ng.dataset.modality.TemplateDataset; +import org.shanoir.ng.dataset.modality.*; import org.shanoir.ng.dataset.model.Dataset; import org.shanoir.ng.dataset.model.DatasetExpression; import org.shanoir.ng.dataset.model.DatasetExpressionFormat; diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/controler/DatasetAcquisitionApi.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/controler/DatasetAcquisitionApi.java index 03ba83b14c..816827e08f 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/controler/DatasetAcquisitionApi.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/controler/DatasetAcquisitionApi.java @@ -131,7 +131,7 @@ ResponseEntity> findDatasetAcquisitionByData @ApiResponse(responseCode = "500", description = "unexpected error") }) @RequestMapping(value = "/datasetacquisition/{datasetAcquisitionId}", produces = { "application/json" }, consumes = { "application/json" }, method = RequestMethod.PUT) - @PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and #datasetAcquisitionId == #datasetAcquisition.getId() and @datasetSecurityService.hasUpdateRightOnDatasetAcquisition(#datasetAcquisition, 'CAN_ADMINISTRATE')") + @PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and #datasetAcquisitionId == #datasetAcquisition.getId() and @datasetSecurityService.hasRightOnExamination(#datasetAcquisition.examination.id, 'CAN_ADMINISTRATE')") ResponseEntity updateDatasetAcquisition( @Parameter(name = "id of the datasetAcquisition", required = true) @PathVariable("datasetAcquisitionId") Long datasetAcquisitionId, @Parameter(name = "datasetAcquisition to update", required = true) @Valid @RequestBody DatasetAcquisitionDTO datasetAcquisition, BindingResult result) diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionDatasetsMapper.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionDatasetsMapper.java index cbefd571f6..a7037f01f4 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionDatasetsMapper.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionDatasetsMapper.java @@ -28,7 +28,10 @@ import org.shanoir.ng.dataset.service.DatasetUtils; import org.shanoir.ng.datasetacquisition.dto.DatasetAcquisitionDatasetsDTO; import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.GenericDatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.bids.BidsDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.ct.CtDatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.eeg.EegDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.mr.MrDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.pet.PetDatasetAcquisition; import org.shanoir.ng.examination.dto.mapper.ExaminationMapper; @@ -54,8 +57,11 @@ DatasetAcquisitionDatasetsDTO datasetAcquisitionToDatasetAcquisitionDatasetsDTO( default DatasetAcquisition createDatasetAcquisition(DatasetAcquisitionDatasetsDTO dto) { if (dto.getType().equals("Mr")) return new MrDatasetAcquisition(); else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition(); - else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition(); - else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType()); + else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition(); + else if (dto.getType().equals("BIDS")) return new BidsDatasetAcquisition(); + else if (dto.getType().equals("Eeg")) return new EegDatasetAcquisition(); + else if (dto.getType().equals("Generic")) return new GenericDatasetAcquisition(); + else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType()); } @ObjectFactory diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionMapper.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionMapper.java index e8eabf3c0d..4a6204fcc1 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionMapper.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/dto/mapper/DatasetAcquisitionMapper.java @@ -23,7 +23,10 @@ import org.mapstruct.ObjectFactory; import org.shanoir.ng.datasetacquisition.dto.DatasetAcquisitionDTO; import org.shanoir.ng.datasetacquisition.model.DatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.GenericDatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.bids.BidsDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.ct.CtDatasetAcquisition; +import org.shanoir.ng.datasetacquisition.model.eeg.EegDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.mr.MrDatasetAcquisition; import org.shanoir.ng.datasetacquisition.model.pet.PetDatasetAcquisition; import org.shanoir.ng.examination.dto.mapper.ExaminationMapper; @@ -49,9 +52,12 @@ DatasetAcquisitionDTO datasetAcquisitionToDatasetAcquisitionDTO( @ObjectFactory default DatasetAcquisition createDatasetAcquisition(DatasetAcquisitionDTO dto) { - if (dto.getType().equals("Mr")) return new MrDatasetAcquisition(); - else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition(); - else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition(); + if (dto.getType().equals("Mr")) return new MrDatasetAcquisition(); + else if (dto.getType().equals("Pet")) return new PetDatasetAcquisition(); + else if (dto.getType().equals("Ct")) return new CtDatasetAcquisition(); + else if (dto.getType().equals("BIDS")) return new BidsDatasetAcquisition(); + else if (dto.getType().equals("Eeg")) return new EegDatasetAcquisition(); + else if (dto.getType().equals("Generic")) return new GenericDatasetAcquisition(); else throw new IllegalStateException("Cannot map from a dataset acquisition dto that don't provide a valid type. Given type = " + dto.getType()); } diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/service/DatasetAcquisitionService.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/service/DatasetAcquisitionService.java index 1250553bfd..e2adf1eb07 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/service/DatasetAcquisitionService.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/datasetacquisition/service/DatasetAcquisitionService.java @@ -56,7 +56,7 @@ public interface DatasetAcquisitionService { @PreAuthorize("#entity.getId() == null and (hasRole('ADMIN') or (hasAnyRole('EXPERT', 'USER') and @datasetSecurityService.hasRightOnExamination(#entity.getExamination().getId(), 'CAN_IMPORT')))") DatasetAcquisition create(DatasetAcquisition entity); - @PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and @datasetSecurityService.hasUpdateRightOnDatasetAcquisition(#entity, 'CAN_ADMINISTRATE')") + @PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and @datasetSecurityService.hasRightOnExamination(#entity.examination.id, 'CAN_ADMINISTRATE')") DatasetAcquisition update(DatasetAcquisition entity) throws EntityNotFoundException; @PreAuthorize("hasAnyRole('ADMIN', 'EXPERT') and @datasetSecurityService.hasRightOnEveryTrustedDatasetAcquisition(#entities, 'CAN_ADMINISTRATE')") diff --git a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/importer/service/BidsImporterService.java b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/importer/service/BidsImporterService.java index 9f22a61d75..3c15138702 100644 --- a/shanoir-ng-datasets/src/main/java/org/shanoir/ng/importer/service/BidsImporterService.java +++ b/shanoir-ng-datasets/src/main/java/org/shanoir/ng/importer/service/BidsImporterService.java @@ -132,6 +132,9 @@ public void createAllBidsDatasetAcquisition(Message importJobStr) throws AmqpRej case "micr": importDataset(importJob, BidsDataType.MICR, DatasetModalityType.MICR_DATASET, event); break; + case "nirs": + importDataset(importJob, BidsDataType.NIRS, DatasetModalityType.NIRS_DATASET, event); + break; default: if (event != null) { LOG.error("The data type folder is not recognized. Please update your BIDS archive following the rules."); @@ -234,9 +237,15 @@ private void importDataset(ImportJob importJob, BidsDataType bidsDataType, Datas final String subLabel = SUBJECT_PREFIX + importJob.getSubjectName(); final String sesLabel = SESSION_PREFIX + importJob.getExaminationId(); - final File outDir = new File(niftiStorageDir + File.separator + File.separator + subLabel + File.separator + sesLabel + File.separator + bidsDataType.getFolderName()); + final File outDir = new File(niftiStorageDir + File.separator + subLabel + File.separator + sesLabel + File.separator + bidsDataType.getFolderName()); outDir.mkdirs(); - String outPath = outDir.getAbsolutePath() + File.separator + importedFile.getName(); + + // remove old subject and session names from files names + String filename = importedFile.getName() + .replaceFirst("sub-[^_]+_", "") + .replaceFirst("ses-[^_]+_", ""); + + String outPath = outDir.getAbsolutePath() + File.separator + filename; Path importedFileFinalLocation = Files.copy(importedFile.toPath(), Paths.get(outPath), StandardCopyOption.REPLACE_EXISTING); DatasetFile dsFile = new DatasetFile(); @@ -262,6 +271,7 @@ private void importDataset(ImportJob importJob, BidsDataType bidsDataType, Datas datasetAcquisition.setDatasets(new ArrayList<>(datasets)); datasetAcquisition.setAcquisitionEquipmentId(equipmentId); + datasetAcquisition.setCreationDate(LocalDateTime.now().toLocalDate()); datasetAcquisitionRepository.save(datasetAcquisition); eventService.publishEvent(new ShanoirEvent(ShanoirEventType.CREATE_DATASET_ACQUISITION_EVENT, datasetAcquisition.getId().toString(), KeycloakUtil.getTokenUserId(), "", ShanoirEvent.SUCCESS, examination.getStudyId())); diff --git a/shanoir-ng-datasets/src/test/java/org/shanoir/ng/datasetacquisition/DatasetAcquisitionApiSecurityTest.java b/shanoir-ng-datasets/src/test/java/org/shanoir/ng/datasetacquisition/DatasetAcquisitionApiSecurityTest.java index 9284a4864b..fc52a7aa44 100644 --- a/shanoir-ng-datasets/src/test/java/org/shanoir/ng/datasetacquisition/DatasetAcquisitionApiSecurityTest.java +++ b/shanoir-ng-datasets/src/test/java/org/shanoir/ng/datasetacquisition/DatasetAcquisitionApiSecurityTest.java @@ -241,7 +241,8 @@ private void testAll(String role) throws ShanoirException, RestServiceException // findDatasetAcquisitions(Pageable) assertThat(api.findDatasetAcquisitions(PageRequest.of(0, 10)).getBody()).hasSize(1); - + + given(rightsService.hasRightOnStudy(1L, "CAN_ADMINISTRATE")).willReturn(true); // updateDatasetAcquisition(Long, DatasetAcquisitionDTO, BindingResult) if ("ROLE_USER".equals(role)) { assertAccessDenied(api::updateDatasetAcquisition, 1L, mockDsAcqDTO(1L), mockBindingResult); @@ -286,6 +287,8 @@ private DatasetAcquisitionDTO mockDsAcqDTO(Long id) { dto.setId(id); dto.setAcquisitionEquipmentId(1L); dto.setExamination(new ExaminationDTO()); + dto.getExamination().setStudyId(1L); + dto.getExamination().setCenterId(1L); dto.setRank(1); dto.setSoftwareRelease("v1.0.0"); dto.setSortingIndex(1); diff --git a/shanoir-ng-datasets/src/test/java/org/shanoir/ng/exporter/service/BidsServiceTest.java b/shanoir-ng-datasets/src/test/java/org/shanoir/ng/exporter/service/BidsServiceTest.java index 31c9da77f5..cbcceb21c8 100644 --- a/shanoir-ng-datasets/src/test/java/org/shanoir/ng/exporter/service/BidsServiceTest.java +++ b/shanoir-ng-datasets/src/test/java/org/shanoir/ng/exporter/service/BidsServiceTest.java @@ -132,10 +132,10 @@ public void testExportAsBids() throws IOException, InterruptedException { service.exportAsBids(exam.getStudyId(), studyName); // THEN the bids folder is generated with study - subject - exam - data - File studyFile = new File(tempFolderPath + "stud-" + exam.getStudyId() + "_" + studyName); + File studyFile = new File(tempFolderPath + "stud-" + exam.getStudyId() + "" + studyName); assertTrue(studyFile.exists()); - File subjectFile = new File(studyFile.getAbsolutePath() + "/sub-1-" + subject.getName()); + File subjectFile = new File(studyFile.getAbsolutePath() + "/sub-1" + subject.getName()); assertTrue(subjectFile.exists()); File examFile = new File(subjectFile.getAbsolutePath() + "/ses-" + exam.getId()); diff --git a/shanoir-ng-front/src/app/dataset-acquisitions/dataset-acquisition/dataset-acquisition.component.html b/shanoir-ng-front/src/app/dataset-acquisitions/dataset-acquisition/dataset-acquisition.component.html index 86cc2c059b..751fab2ac1 100644 --- a/shanoir-ng-front/src/app/dataset-acquisitions/dataset-acquisition/dataset-acquisition.component.html +++ b/shanoir-ng-front/src/app/dataset-acquisitions/dataset-acquisition/dataset-acquisition.component.html @@ -61,7 +61,7 @@

Create dataset acquisition

- {{datasetAcquisition.examination?.comment}} + {{datasetAcquisition?.examination?.comment ? datasetAcquisition?.examination?.comment : datasetAcquisition?.examination?.examinationDate | date: 'dd/MM/yyyy'}} @@ -90,7 +90,7 @@

Create dataset acquisition

- + {{datasetAcquisition.acquisitionEquipment | acqEqptLabel}} diff --git a/shanoir-ng-front/src/app/dataset-acquisitions/shared/dataset-acquisition.dto.ts b/shanoir-ng-front/src/app/dataset-acquisitions/shared/dataset-acquisition.dto.ts index 16216a48ef..ecdccf3c1d 100644 --- a/shanoir-ng-front/src/app/dataset-acquisitions/shared/dataset-acquisition.dto.ts +++ b/shanoir-ng-front/src/app/dataset-acquisitions/shared/dataset-acquisition.dto.ts @@ -2,12 +2,12 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ @@ -46,13 +46,17 @@ export class DatasetAcquisitionDTOService { * Warning : DO NOT USE THIS IN A LOOP, use toDatasetAcquisitions instead * @param result can be used to get an immediate temporary result without async data */ - public toDatasetAcquisition(dto: DatasetAcquisitionDTO, result?: DatasetAcquisition): Promise { + public toDatasetAcquisition(dto: DatasetAcquisitionDTO, result?: DatasetAcquisition): Promise { if (!result) result = DatasetAcquisitionUtils.getNewDAInstance(dto.type); DatasetAcquisitionDTOService.mapSyncFields(dto, result); - return Promise.all([ - this.acqEqService.get(dto.acquisitionEquipmentId).then(acqEq => result.acquisitionEquipment = acqEq), // TODO dto - this.studyService.get(dto.examination.studyId).then(study => result.examination.study = study) // TODO dto - ]).then(([]) => { + let promises = []; + if(dto.acquisitionEquipmentId > 0){ + promises.push(this.acqEqService.get(dto.acquisitionEquipmentId).then(acqEq => result.acquisitionEquipment = acqEq)); + }else{ + result.acquisitionEquipment = new AcquisitionEquipment(); + } + promises.push( this.studyService.get(dto.examination.studyId).then(study => result.examination.study = study)); + return Promise.all(promises).then(([]) => { return result; }); } @@ -66,10 +70,6 @@ export class DatasetAcquisitionDTOService { for (let dto of dtos ? dtos : []) { let entity = DatasetAcquisitionUtils.getNewDAInstance(dto.type); DatasetAcquisitionDTOService.mapSyncFields(dto, entity); - if (dto.acquisitionEquipmentId) { - entity.acquisitionEquipment = new AcquisitionEquipment(); - entity.acquisitionEquipment.id = dto.acquisitionEquipmentId; - } if ((dto as DatasetAcquisitionDatasetsDTO).datasets) { entity.datasets = (dto as DatasetAcquisitionDatasetsDTO).datasets.map(dsdto => { let simpleDataset: Dataset = DatasetUtils.getDatasetInstance(dsdto.type); @@ -102,6 +102,10 @@ export class DatasetAcquisitionDTOService { entity.sortingIndex = dto.sortingIndex; entity.type = dto.type; entity.creationDate = dto.creationDate; + if (dto.acquisitionEquipmentId) { + entity.acquisitionEquipment = new AcquisitionEquipment(); + entity.acquisitionEquipment.id = dto.acquisitionEquipmentId; + } if (dto.examination) { entity.examination = new Examination(); ExaminationDTOService.mapSyncFields(dto.examination, entity.examination); @@ -136,7 +140,7 @@ export class DatasetAcquisitionDTO { } this.acquisitionEquipmentId = dsAcq.acquisitionEquipment ? dsAcq.acquisitionEquipment.id : null; if (dsAcq.examination) { - this.examination = new ExaminationDTO(); + this.examination = new ExaminationDTO(); this.examination.id = dsAcq.examination.id; } this.rank = dsAcq.rank; diff --git a/shanoir-ng-front/src/app/datasets/dataset/common/dataset.common.component.html b/shanoir-ng-front/src/app/datasets/dataset/common/dataset.common.component.html index 0f3ac4a6aa..a7e8144762 100644 --- a/shanoir-ng-front/src/app/datasets/dataset/common/dataset.common.component.html +++ b/shanoir-ng-front/src/app/datasets/dataset/common/dataset.common.component.html @@ -46,7 +46,7 @@ - {{dataset.datasetAcquisition?.examination?.comment}} + {{dataset.datasetAcquisition?.examination?.comment ? dataset.datasetAcquisition?.examination?.comment : dataset.datasetAcquisition?.examination?.examinationDate | date: 'dd/MM/yyyy'}} diff --git a/shanoir-ng-front/src/app/datasets/shared/dataset-type.model.ts b/shanoir-ng-front/src/app/datasets/shared/dataset-type.model.ts index fa23d73a71..2988d21ade 100644 --- a/shanoir-ng-front/src/app/datasets/shared/dataset-type.model.ts +++ b/shanoir-ng-front/src/app/datasets/shared/dataset-type.model.ts @@ -2,12 +2,12 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ @@ -33,7 +33,7 @@ export enum DatasetType { BIDS = 'BIDS', Measurement = 'Measurement' } export namespace DatasetType { - + export function all(): Array { return allOfEnum(DatasetType); } diff --git a/shanoir-ng-front/src/app/enum/bids-data-type.enum.ts b/shanoir-ng-front/src/app/enum/bids-data-type.enum.ts index 6c15bbceb7..cba578d66b 100644 --- a/shanoir-ng-front/src/app/enum/bids-data-type.enum.ts +++ b/shanoir-ng-front/src/app/enum/bids-data-type.enum.ts @@ -2,12 +2,12 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ @@ -21,10 +21,11 @@ export enum BidsDataType { DWI = 'DWI', FMAP = 'FMAP', ANAT = 'ANAT', - PERF = 'PERF' - + PERF = 'PERF', + NIRS = 'NIRS' + } export namespace BidsDataType { - + export function all(): Array { return allOfEnum(BidsDataType); } @@ -34,4 +35,4 @@ export enum BidsDataType { } export var options: Option[] = all().map(prop => new Option(prop, getLabel(prop))); -} \ No newline at end of file +} diff --git a/shanoir-ng-front/src/app/enum/dataset-modality-type.enum.ts b/shanoir-ng-front/src/app/enum/dataset-modality-type.enum.ts index 658c616cd6..911f64b461 100644 --- a/shanoir-ng-front/src/app/enum/dataset-modality-type.enum.ts +++ b/shanoir-ng-front/src/app/enum/dataset-modality-type.enum.ts @@ -2,12 +2,12 @@ * Shanoir NG - Import, manage and share neuroimaging data * Copyright (C) 2009-2019 Inria - https://www.inria.fr/ * Contact us on https://project.inria.fr/shanoir/ - * + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see https://www.gnu.org/licenses/gpl-3.0.html */ @@ -22,10 +22,12 @@ export enum DatasetModalityType { CT = 'CT_DATASET', // MEG = 'MG', // SPECT = 'SPECT', - EEG = 'EEG_DATASET' + EEG = 'EEG_DATASET', + NIRS = 'NIRS_DATASET' + } export namespace DatasetModalityType { - + export function all(): Array { return allOfEnum(DatasetModalityType); } @@ -35,4 +37,4 @@ export enum DatasetModalityType { } export var options: Option[] = all().map(prop => new Option(prop, getLabel(prop))); -} \ No newline at end of file +} diff --git a/shanoir-ng-front/src/app/import/bids/bids-upload.component.html b/shanoir-ng-front/src/app/import/bids/bids-upload.component.html index 5d8a62c725..529a52a3b0 100644 --- a/shanoir-ng-front/src/app/import/bids/bids-upload.component.html +++ b/shanoir-ng-front/src/app/import/bids/bids-upload.component.html @@ -20,7 +20,7 @@

import.zip
- sub-[SubjectName]
- - ses-[examination-comment]
- - - - [anat/func/dwi/eeg/ieeg/pet/..]
+ - - - [anat/func/dwi/eeg/ieeg/pet/nirs..]
- - - - [list of data files]

1) Subject:
@@ -58,7 +58,7 @@
  • - + - + +