Skip to content

Commit

Permalink
More pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 7, 2024
1 parent 7e0ade9 commit 795ba5f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;
import nl.knaw.dans.dvingest.core.dansbag.io.BagDataManager;
import nl.knaw.dans.dvingest.core.dansbag.io.BagDataManagerImpl;
import nl.knaw.dans.dvingest.core.dansbag.io.FileService;
import nl.knaw.dans.dvingest.core.dansbag.io.FileServiceImpl;
import nl.knaw.dans.dvingest.core.dansbag.mapper.DepositToDvDatasetMetadataMapper;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelper;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelperImpl;
Expand Down Expand Up @@ -76,10 +74,9 @@ public DansBagMappingServiceImpl(DepositToDvDatasetMetadataMapper depositToDvDat
DepositFileLister depositFileLister = new DepositFileListerImpl();
BagDataManager bagDataManager = new BagDataManagerImpl(bagReader);
XmlReader xmlReader = new XmlReaderImpl();
FileService fileService = new FileServiceImpl();
BagDirResolver bagDirResolver = new BagDirResolverImpl(fileService);
BagDirResolver bagDirResolver = new BagDirResolverImpl();

depositReader = new DepositReaderImpl(xmlReader, bagDirResolver, fileService, bagDataManager, depositFileLister, manifestHelper);
depositReader = new DepositReaderImpl(xmlReader, bagDirResolver, bagDataManager, depositFileLister, manifestHelper);
this.supportedLicenses = supportedLicenses;
this.fileExclusionPattern = fileExclusionPattern;
this.embargoExclusions = embargoExclusions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,21 @@
package nl.knaw.dans.dvingest.core.dansbag.deposit;

import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;
import nl.knaw.dans.dvingest.core.dansbag.io.FileService;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Collectors;

public class BagDirResolverImpl implements BagDirResolver {
private final FileService fileService;

public BagDirResolverImpl(FileService fileService) {
this.fileService = fileService;
}

@Override
public Path getBagDir(Path depositDir) throws InvalidDepositException, IOException {
if (!fileService.isDirectory(depositDir)) {
if (!Files.isDirectory(depositDir)) {
throw new InvalidDepositException(String.format("%s is not a directory", depositDir));
}

try (var substream = fileService.listDirectories(depositDir)) {
var directories = substream.collect(Collectors.toList());
try (var substream = Files.list(depositDir).filter(Files::isDirectory)) {
var directories = substream.toList();

// only 1 directory allowed, not 0 or more than 1
if (directories.size() != 1) {
Expand All @@ -46,15 +40,15 @@ public Path getBagDir(Path depositDir) throws InvalidDepositException, IOExcepti
}

// check for the presence of deposit.properties and bagit.txt
if (!fileService.fileExists(depositDir.resolve("deposit.properties"))) {
if (!Files.exists(depositDir.resolve("deposit.properties"))) {
throw new InvalidDepositException(String.format(
"%s does not contain a deposit.properties file", depositDir
));
}

var bagDir = directories.get(0);

if (!fileService.fileExists(bagDir.resolve("bagit.txt"))) {
if (!Files.exists(bagDir.resolve("bagit.txt"))) {
throw new InvalidDepositException(String.format(
"%s does not contain a bag", depositDir
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;
import nl.knaw.dans.dvingest.core.dansbag.io.BagDataManager;
import nl.knaw.dans.dvingest.core.dansbag.io.FileService;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelper;
import nl.knaw.dans.dvingest.core.dansbag.service.XmlReader;
import org.apache.commons.configuration2.Configuration;
Expand All @@ -29,6 +28,7 @@

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.OffsetDateTime;
import java.util.List;
Expand All @@ -37,16 +37,14 @@
public class DepositReaderImpl implements DepositReader {
private final XmlReader xmlReader;
private final BagDirResolver bagDirResolver;
private final FileService fileService;
private final BagDataManager bagDataManager;
private final DepositFileLister depositFileLister;

private final ManifestHelper manifestHelper;

public DepositReaderImpl(XmlReader xmlReader, BagDirResolver bagDirResolver, FileService fileService, BagDataManager bagDataManager, DepositFileLister depositFileLister, ManifestHelper manifestHelper) {
public DepositReaderImpl(XmlReader xmlReader, BagDirResolver bagDirResolver, BagDataManager bagDataManager, DepositFileLister depositFileLister, ManifestHelper manifestHelper) {
this.xmlReader = xmlReader;
this.bagDirResolver = bagDirResolver;
this.fileService = fileService;
this.bagDataManager = bagDataManager;
this.depositFileLister = depositFileLister;
this.manifestHelper = manifestHelper;
Expand Down Expand Up @@ -78,7 +76,7 @@ public Deposit readDeposit(Path depositDir) throws InvalidDepositException {
}

Document readOptionalXmlFile(Path path) throws ParserConfigurationException, IOException, SAXException {
if (fileService.fileExists(path)) {
if (Files.exists(path)) {
return xmlReader.readXmlFile(path);
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositReaderImpl;
import nl.knaw.dans.dvingest.core.dansbag.io.BagDataManager;
import nl.knaw.dans.dvingest.core.dansbag.io.BagDataManagerImpl;
import nl.knaw.dans.dvingest.core.dansbag.io.FileService;
import nl.knaw.dans.dvingest.core.dansbag.io.FileServiceImpl;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelper;
import nl.knaw.dans.dvingest.core.dansbag.service.ManifestHelperImpl;
import nl.knaw.dans.dvingest.core.dansbag.service.XmlReader;
Expand Down Expand Up @@ -62,10 +60,9 @@ public void setUp() throws Exception {
DepositFileLister depositFileLister = new DepositFileListerImpl();
BagDataManager bagDataManager = new BagDataManagerImpl(bagReader);
XmlReader xmlReader = new XmlReaderImpl();
FileService fileService = new FileServiceImpl();
BagDirResolver bagDirResolver = new BagDirResolverImpl(fileService);
BagDirResolver bagDirResolver = new BagDirResolverImpl();

depositReader = new DepositReaderImpl(xmlReader, bagDirResolver, fileService, bagDataManager, depositFileLister, manifestHelper);
depositReader = new DepositReaderImpl(xmlReader, bagDirResolver, bagDataManager, depositFileLister, manifestHelper);
var defaultConfigDir = Paths.get("src/main/assembly/dist/cfg");
var mapper = new DepositToDvDatasetMetadataMapper(
false,
Expand Down

0 comments on commit 795ba5f

Please sign in to comment.