Skip to content

Commit

Permalink
Added embargo for subsequent versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 10, 2024
1 parent d296193 commit dbb35a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ else if (depositToDvDatasetMetadataMapper.isMigration()) {

@Override
public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion currentMetadata) {
// TODO: rename to DatasetComposer en push the terms stuff into it as well.
var dataset = depositToDvDatasetMetadataMapper.toDataverseDataset(
dansDeposit.getDdm(),
dansDeposit.getOtherDoiId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -65,13 +66,8 @@ public EditFiles composeEditFiles() {
editFiles.setAddUnrestrictedFiles(getUnrestrictedFilesToAdd(pathFileInfoMap));
editFiles.setUpdateFileMetas(getUpdatedFileMetas(pathFileInfoMap));

var filePathsToEmbargo = getEmbargoedFiles(pathFileInfoMap, dateAvailable);
if (!filePathsToEmbargo.isEmpty()) {
var addEmbargo = new AddEmbargo();
addEmbargo.setDateAvailable(yyyymmddFormat.format(Date.from(dateAvailable)));
addEmbargo.setFilePaths(filePathsToEmbargo.stream().map(Path::toString).toList());
editFiles.setAddEmbargoes(List.of(addEmbargo));
}
addEmbargo(editFiles, pathFileInfoMap.keySet());

return editFiles;
}

Expand Down Expand Up @@ -123,10 +119,23 @@ private List<FileMeta> getUpdatedFileMetas(Map<Path, FileInfo> files) {
.toList();
}

private List<Path> getEmbargoedFiles(Map<Path, FileInfo> files, Instant dateAvailable) {
var now = Instant.now();
if (dateAvailable.isAfter(now)) {
return files.keySet().stream()
protected void addEmbargo(EditFiles editFiles, Set<Path> candidates) {
if (dateAvailable.isAfter(Instant.now())) {
var filesToEmbargo = candidates.stream()
.filter(f -> !embargoExclusions.contains(f.toString())).toList();

if (!filesToEmbargo.isEmpty()) {
var addEmbargo = new AddEmbargo();
addEmbargo.setDateAvailable(yyyymmddFormat.format(Date.from(dateAvailable)));
addEmbargo.setFilePaths(filesToEmbargo.stream().map(Path::toString).toList());
editFiles.setAddEmbargoes(List.of(addEmbargo));
}
}
}

private List<Path> getEmbargoedFiles(Set<Path> candidates, Instant dateAvailable) {
if (dateAvailable.isAfter(Instant.now())) {
return candidates.stream()
.filter(f -> !embargoExclusions.contains(f.toString())).toList();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import nl.knaw.dans.dvingest.core.bagprocessor.FilesInDatasetCache;
import nl.knaw.dans.dvingest.core.dansbag.deposit.FileInfo;
import nl.knaw.dans.dvingest.core.service.DataverseService;
import nl.knaw.dans.dvingest.core.yaml.AddEmbargo;
import nl.knaw.dans.dvingest.core.yaml.EditFiles;
import nl.knaw.dans.dvingest.core.yaml.FromTo;
import nl.knaw.dans.lib.dataverse.DataverseException;
Expand All @@ -27,6 +28,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -144,11 +146,11 @@ public EditFiles composeEditFiles() {
editFiles.setAddUnrestrictedFiles(pathsToAdd.stream()
.filter(p -> !pathFileInfoMap.get(p).getMetadata().getRestricted()).toList().stream().map(Path::toString).toList());

// todo: embargoes

addEmbargo(editFiles, SetUtils.union(pathsToAdd, filesToReplace));
return editFiles;
}


private Set<Path> getFilesToReplace(Map<Path, FileInfo> pathToFileInfo, Map<Path, FileMeta> fileReplacementCandidates) {

var intersection = SetUtils.intersection(pathToFileInfo.keySet(), fileReplacementCandidates.keySet());
Expand Down

0 comments on commit dbb35a6

Please sign in to comment.