Skip to content

Commit

Permalink
Removed originalFilePathMapping as we are not going to use it in the …
Browse files Browse the repository at this point in the history
…Data Stations
  • Loading branch information
janvanmansum committed Dec 7, 2024
1 parent 4e9d137 commit 62901ae
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@

import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DepositFile;
import nl.knaw.dans.dvingest.core.dansbag.domain.OriginalFilePathMapping;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelperImpl;
import nl.knaw.dans.dvingest.core.dansbag.service.XPathEvaluator;
import org.w3c.dom.Node;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import static nl.knaw.dans.dvingest.core.dansbag.service.XPathConstants.FILES_FILE;
Expand All @@ -37,9 +33,7 @@ public class DepositFileListerImpl implements DepositFileLister {
@Override
public List<DepositFile> getDepositFiles(DansBagDeposit dansBagDeposit) throws IOException {
var bag = dansBagDeposit.getBag();
var bagDir = bag.getRootDir();
var filePathToSha1 = ManifestHelperImpl.getFilePathToSha1(bag);
var originalFilePathMappings = getOriginalFilePathMapping(bagDir);

return XPathEvaluator.nodes(dansBagDeposit.getFilesXml(), FILES_FILE)
.map(node -> {
Expand All @@ -48,38 +42,10 @@ public List<DepositFile> getDepositFiles(DansBagDeposit dansBagDeposit) throws I
.map(Path::of)
.orElseThrow(() -> new IllegalArgumentException("File element without filepath attribute"));

var physicalFile = originalFilePathMappings.getPhysicalPath(filePath);
var sha1 = filePathToSha1.get(physicalFile);
var sha1 = filePathToSha1.get(filePath);

return new DepositFile(filePath, physicalFile, sha1, node);
return new DepositFile(filePath, sha1, node);
})
.collect(Collectors.toList());
}

private OriginalFilePathMapping getOriginalFilePathMapping(Path bagDir) throws IOException {
var originalFilepathsFile = bagDir.resolve("original-filepaths.txt");

if (Files.exists(originalFilepathsFile)) {
var lines = Files.readAllLines(originalFilepathsFile);
var mappings = lines.stream().map(line -> {
var parts = line.split("\\s+", 2);

if (parts.length == 2) {
return new OriginalFilePathMapping.Mapping(
Path.of(parts[0].trim()),
Path.of(parts[1].trim())
);
}

return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toSet());

return new OriginalFilePathMapping(mappings);
}
else {
return new OriginalFilePathMapping(Set.of());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import nl.knaw.dans.dvingest.core.dansbag.service.XPathEvaluator;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

import java.nio.file.Path;
import java.time.Instant;
Expand All @@ -31,7 +30,6 @@

import static nl.knaw.dans.dvingest.core.dansbag.service.XPathConstants.DDM_PROFILE;
import static nl.knaw.dans.dvingest.core.dansbag.service.XPathConstants.FILES_FILE;
import static nl.knaw.dans.dvingest.core.dansbag.service.XmlNamespaces.NAMESPACE_XSI;

@Data
@NoArgsConstructor
Expand Down Expand Up @@ -76,11 +74,6 @@ public VaultMetadata getVaultMetadata() {
return new VaultMetadata(getDataversePid(), getDataverseBagId(), getDataverseNbn(), getDataverseOtherId(), getDataverseSwordToken());
}

private static boolean hasTypeDoi(Node n) {
Node type = n.getAttributes().getNamedItemNS(NAMESPACE_XSI, "type");
return type != null && type.getTextContent().contains("DOI");
}

public String getDataversePid() {
return String.format("%s:%s/%s", dataverseIdProtocol, dataverseIdAuthority, dataverseId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
@AllArgsConstructor
public class DepositFile {
Path path;
Path physicalPath;
String checksum;
Node xmlNode;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO
/*
* Fix for EASY-1306: a tag manifest must not contain an entry for itself, as this is practically
* impossible to calculate. It could in theory contain entries for other tag manifests. However,
* the CreateTagManifestsVistor, once it finds an entry for a tag file in ONE of the tag manifests,
* the CreateTagManifestsVisitor, once it finds an entry for a tag file in ONE of the tag manifests,
* will add an entry in ALL tag manifests.
*
* Therefore, we adopt the strategy NOT to calculate any checksums for the tag manifests themselves.
Expand Down

0 comments on commit 62901ae

Please sign in to comment.