-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2668 from pierrehenri-dauvergne/shanoir-issue#2660
shanoir-issue#2658: delete dataset
- Loading branch information
Showing
9 changed files
with
137 additions
and
38 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
shanoir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetAsyncService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.shanoir.ng.dataset.service; | ||
|
||
import org.shanoir.ng.dataset.model.Dataset; | ||
import org.shanoir.ng.datasetfile.DatasetFile; | ||
import org.shanoir.ng.shared.exception.ShanoirException; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
|
||
import java.util.List; | ||
|
||
public interface DatasetAsyncService { | ||
|
||
|
||
// No PreAuthorize here since it's always called after a security check | ||
void deleteDatasetFilesFromDiskAndPacsAsync(List<DatasetFile> datasetFiles, boolean isDicom, Long datasetId) throws ShanoirException; | ||
} |
82 changes: 82 additions & 0 deletions
82
...oir-ng-datasets/src/main/java/org/shanoir/ng/dataset/service/DatasetAsyncServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package org.shanoir.ng.dataset.service; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.shanoir.ng.dataset.model.Dataset; | ||
import org.shanoir.ng.dataset.model.DatasetExpression; | ||
import org.shanoir.ng.dataset.model.DatasetExpressionFormat; | ||
import org.shanoir.ng.datasetfile.DatasetFile; | ||
import org.shanoir.ng.dicom.web.service.DICOMWebService; | ||
import org.shanoir.ng.shared.event.ShanoirEvent; | ||
import org.shanoir.ng.shared.event.ShanoirEventService; | ||
import org.shanoir.ng.shared.event.ShanoirEventType; | ||
import org.shanoir.ng.shared.exception.AccessDeniedException; | ||
import org.shanoir.ng.shared.exception.ShanoirException; | ||
import org.shanoir.ng.utils.KeycloakUtil; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.util.UriUtils; | ||
|
||
import java.io.File; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
@Service | ||
public class DatasetAsyncServiceImpl implements DatasetAsyncService { | ||
|
||
@Autowired | ||
private DICOMWebService dicomWebService; | ||
@Autowired | ||
ShanoirEventService eventService; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DatasetAsyncService.class); | ||
|
||
public void deleteDatasetFilesFromDiskAndPacs(List<DatasetFile> datasetFiles, boolean isDicom, Long datasetId) throws ShanoirException { | ||
deleteDatasetFilesFromDiskAndPacsAsync(datasetFiles, isDicom, datasetId); | ||
} | ||
|
||
@Override | ||
@Async | ||
public void deleteDatasetFilesFromDiskAndPacsAsync(List<DatasetFile> datasetFiles, boolean isDicom, Long datasetId) throws ShanoirException { | ||
ShanoirEvent event = null; | ||
event = new ShanoirEvent( | ||
ShanoirEventType.DELETE_DATASET_EVENT, | ||
String.valueOf(datasetId), | ||
KeycloakUtil.getTokenUserId(), | ||
"Delete dataset with id :" + datasetId, | ||
ShanoirEvent.IN_PROGRESS, | ||
0f, | ||
null); | ||
|
||
eventService.publishEvent(event); | ||
|
||
for (DatasetFile file : datasetFiles) { | ||
// DICOM | ||
if (isDicom && file.isPacs()) { | ||
dicomWebService.rejectDatasetFromPacs(file.getPath()); | ||
float progress = event.getProgress(); | ||
progress += 1f / datasetFiles.size(); | ||
event.setProgress(progress); | ||
eventService.publishEvent(event); | ||
// NIfTI | ||
} else if (!file.isPacs()) { | ||
try { | ||
URL url = new URL(file.getPath().replaceAll("%20", " ")); | ||
File srcFile = new File(UriUtils.decode(url.getPath(), "UTF-8")); | ||
FileUtils.deleteQuietly(srcFile); | ||
} catch (MalformedURLException e) { | ||
throw new ShanoirException("Error while deleting dataset file.", e); | ||
} | ||
} | ||
} | ||
|
||
event.setMessage("Dataset " + datasetId + " deleted."); | ||
event.setProgress(1f); | ||
event.setStatus(ShanoirEvent.SUCCESS); | ||
eventService.publishEvent(event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters