Skip to content

Commit

Permalink
Renamed Deposit in legacy code to DansBagDeposit
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 7, 2024
1 parent dfc30c0 commit 4e9d137
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package nl.knaw.dans.dvingest.core.dansbag;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;
import nl.knaw.dans.dvingest.core.yaml.EditFiles;
import nl.knaw.dans.dvingest.core.yaml.EditPermissions;
Expand All @@ -28,13 +28,13 @@
public interface DansBagMappingService {
String getUpdatesDataset(Path depositDir) throws IOException, DataverseException;

Deposit readDansDeposit(Path depositDir) throws InvalidDepositException;
DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException;

Dataset getDatasetMetadataFromDansDeposit(Deposit dansDeposit);
Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit);

EditFiles getEditFilesFromDansDeposit(Deposit dansDeposit);
EditFiles getEditFilesFromDansDeposit(DansBagDeposit dansDeposit);

EditPermissions getEditPermissionsFromDansDeposit(Deposit dansDeposit);
EditPermissions getEditPermissionsFromDansDeposit(DansBagDeposit dansDeposit);

String packageOriginalMetadata(Deposit dansDeposit) throws IOException;
String packageOriginalMetadata(DansBagDeposit dansDeposit) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositFileListerImpl;
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositReader;
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositReaderImpl;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
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.mapper.DepositToDvDatasetMetadataMapper;
import nl.knaw.dans.dvingest.core.dansbag.service.BagDataManager;
import nl.knaw.dans.dvingest.core.dansbag.service.BagDataManagerImpl;
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 @@ -120,7 +120,7 @@ else if (depositToDvDatasetMetadataMapper.isMigration()) {
}

@Override
public Dataset getDatasetMetadataFromDansDeposit(Deposit dansDeposit) {
public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit) {
var dataset = depositToDvDatasetMetadataMapper.toDataverseDataset(
dansDeposit.getDdm(),
dansDeposit.getOtherDoiId(),
Expand All @@ -143,12 +143,12 @@ public Dataset getDatasetMetadataFromDansDeposit(Deposit dansDeposit) {
}

@Override
public EditFiles getEditFilesFromDansDeposit(Deposit dansDeposit) {
public EditFiles getEditFilesFromDansDeposit(DansBagDeposit dansDeposit) {
return new EditFilesComposer(dansDeposit, fileExclusionPattern, embargoExclusions).composeEditFiles();
}

@Override
public EditPermissions getEditPermissionsFromDansDeposit(Deposit dansDeposit) {
public EditPermissions getEditPermissionsFromDansDeposit(DansBagDeposit dansDeposit) {
var userId = dansDeposit.getDepositorUserId();
var editPermissions = new EditPermissions();
var roleAssignment = new RoleAssignment();
Expand All @@ -159,15 +159,15 @@ public EditPermissions getEditPermissionsFromDansDeposit(Deposit dansDeposit) {
}

@Override
public String packageOriginalMetadata(Deposit dansDeposit) throws IOException {
public String packageOriginalMetadata(DansBagDeposit dansDeposit) throws IOException {
// Zip the contents of the metadata directory of the bag
var metadataDir = dansDeposit.getBagDir().resolve("metadata");
var zipFile = dansDeposit.getBagDir().resolve("data/original-metadata.zip");
ZipUtil.zipDirectory(metadataDir, zipFile, false);
return zipFile.toString();
}

Optional<String> getDateOfDeposit(Deposit dansDeposit) {
Optional<String> getDateOfDeposit(DansBagDeposit dansDeposit) {
if (dansDeposit.isUpdate()) {
return Optional.empty(); // See for implementation CIT025B in DatasetUpdater
}
Expand All @@ -176,15 +176,15 @@ Optional<String> getDateOfDeposit(Deposit dansDeposit) {
}
}

Optional<AuthenticatedUser> getDatasetContact(Deposit dansDeposit) {
Optional<AuthenticatedUser> getDatasetContact(DansBagDeposit dansDeposit) {
return Optional.ofNullable(dansDeposit.getDepositorUserId())
.filter(StringUtils::isNotBlank)
.map(userId -> dataverseService.getUserById(userId)
.orElseThrow(() -> new RuntimeException("Unable to fetch user with id " + userId)));
}

@Override
public Deposit readDansDeposit(Path depositDir) throws InvalidDepositException {
public DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException {
return depositReader.readDeposit(depositDir);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package nl.knaw.dans.dvingest.core.dansbag;

import lombok.AllArgsConstructor;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.service.YamlService;
import nl.knaw.dans.dvingest.core.yaml.EditFilesRoot;
import nl.knaw.dans.dvingest.core.yaml.EditPermissionsRoot;
Expand All @@ -26,7 +26,7 @@

@AllArgsConstructor
public class DansDepositConverter {
private final Deposit dansDeposit;
private final DansBagDeposit dansDeposit;
private final DansBagMappingService mappingService;
private final YamlService yamlService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import nl.knaw.dans.dvingest.core.DataverseIngestBag;
import nl.knaw.dans.dvingest.core.DataverseIngestDeposit;
import nl.knaw.dans.dvingest.core.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;
import nl.knaw.dans.dvingest.core.dansbag.exception.RejectedDepositException;
import nl.knaw.dans.dvingest.core.service.YamlService;
Expand All @@ -44,7 +45,7 @@ public class DansDepositSupport implements Deposit {
private final DataverseIngestDeposit ingestDataverseIngestDeposit;
private final boolean isDansDeposit;

private nl.knaw.dans.dvingest.core.dansbag.domain.Deposit dansDeposit;
private DansBagDeposit dansDeposit;

public DansDepositSupport(DataverseIngestDeposit dataverseIngestDeposit, ValidateDansBagService validateDansBagService, DansBagMappingService dansBagMappingService, YamlService yamlService) {
this.validateDansBagService = validateDansBagService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import nl.knaw.dans.dvingest.core.bagprocessor.DataversePath;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.FileInfo;
import nl.knaw.dans.dvingest.core.dansbag.mapper.mapping.FileElement;
import nl.knaw.dans.dvingest.core.dansbag.service.XPathEvaluator;
Expand Down Expand Up @@ -48,7 +48,7 @@
@Slf4j
@AllArgsConstructor
public class EditFilesComposer {
private final Deposit dansDeposit;
private final DansBagDeposit dansDeposit;
private final Pattern fileExclusionPattern;
private final List<String> embargoExclusions;
private static final SimpleDateFormat yyyymmddFormat = new SimpleDateFormat("yyyy-MM-dd");
Expand Down Expand Up @@ -158,7 +158,7 @@ private List<Path> getEmbargoedFiles(Map<Path, FileInfo> files, Instant dateAvai
}
}

private Map<Path, FileInfo> getFileInfo(Deposit dansDeposit) {
private Map<Path, FileInfo> getFileInfo(DansBagDeposit dansDeposit) {
var files = FileElement.pathToFileInfo(dansDeposit, false); // TODO: handle migration case

return files.entrySet().stream()
Expand Down Expand Up @@ -198,8 +198,8 @@ protected Map<String, String> getAutoRenameMap(Map<Path, FileInfo> files) {
}

// TODO: move to mapping package
private Instant getDateAvailable(Deposit deposit) {
return XPathEvaluator.strings(deposit.getDdm(), "/ddm:DDM/ddm:profile/ddm:available")
private Instant getDateAvailable(DansBagDeposit dansBagDeposit) {
return XPathEvaluator.strings(dansBagDeposit.getDdm(), "/ddm:DDM/ddm:profile/ddm:available")
.map(EditFilesComposer::parseDate)
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Deposit without a ddm:available element"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import lombok.extern.slf4j.Slf4j;
import nl.knaw.dans.dvingest.core.bagprocessor.FilesInDatasetCache;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.FileInfo;
import nl.knaw.dans.dvingest.core.service.DataverseService;
import nl.knaw.dans.dvingest.core.yaml.FromTo;
Expand All @@ -41,7 +41,7 @@ public class EditFilesComposerForUpdate extends EditFilesComposer {
// TODO: this should be a read-only variant the cache
private FilesInDatasetCache filesInDatasetCache;

public EditFilesComposerForUpdate(Deposit dansDeposit, String updatesDatasetPid, Pattern fileExclusionPattern, List<String> embargoExclusions, DataverseService dataverseService) {
public EditFilesComposerForUpdate(DansBagDeposit dansDeposit, String updatesDatasetPid, Pattern fileExclusionPattern, List<String> embargoExclusions, DataverseService dataverseService) {
super(dansDeposit, fileExclusionPattern, embargoExclusions);
this.updatesDatasetPid = updatesDatasetPid;
this.dataverseService = dataverseService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package nl.knaw.dans.dvingest.core.dansbag;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.exception.RejectedDepositException;
import nl.knaw.dans.dvingest.core.dansbag.mapper.mapping.LicenseElem;
import nl.knaw.dans.dvingest.core.dansbag.service.XPathEvaluator;
Expand Down Expand Up @@ -46,7 +46,7 @@ public SupportedLicenses(DataverseService dataverseService) throws IOException,
}


public License getLicenseFromDansDeposit(Deposit dansDeposit) {
public License getLicenseFromDansDeposit(DansBagDeposit dansDeposit) {
var optLicenseUri = XPathEvaluator.nodes(dansDeposit.getDdm(), DDM_DCMI_METADATA + "/dcterms:license")
.filter(LicenseElem::isLicenseUri)
.findFirst()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package nl.knaw.dans.dvingest.core.dansbag.deposit;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DepositFile;

import java.io.IOException;
import java.util.List;

public interface DepositFileLister {
List<DepositFile> getDepositFiles(Deposit deposit) throws IOException;
List<DepositFile> getDepositFiles(DansBagDeposit dansBagDeposit) throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package nl.knaw.dans.dvingest.core.dansbag.deposit;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
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;
Expand All @@ -35,13 +35,13 @@

public class DepositFileListerImpl implements DepositFileLister {
@Override
public List<DepositFile> getDepositFiles(Deposit deposit) throws IOException {
var bag = deposit.getBag();
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(deposit.getFilesXml(), FILES_FILE)
return XPathEvaluator.nodes(dansBagDeposit.getFilesXml(), FILES_FILE)
.map(node -> {
var filePath = Optional.ofNullable(node.getAttributes().getNamedItem("filepath"))
.map(Node::getTextContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package nl.knaw.dans.dvingest.core.dansbag.deposit;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.exception.InvalidDepositException;

import java.nio.file.Path;

public interface DepositReader {

Deposit readDeposit(Path depositDir) throws InvalidDepositException;
DansBagDeposit readDeposit(Path depositDir) throws InvalidDepositException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
package nl.knaw.dans.dvingest.core.dansbag.deposit;

import gov.loc.repository.bagit.domain.Bag;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
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.service.BagDataManager;
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 Down Expand Up @@ -51,7 +51,7 @@ public DepositReaderImpl(XmlReader xmlReader, BagDirResolver bagDirResolver, Bag
}

@Override
public Deposit readDeposit(Path depositDir) throws InvalidDepositException {
public DansBagDeposit readDeposit(Path depositDir) throws InvalidDepositException {
try {
var bagDir = bagDirResolver.getBagDir(depositDir);

Expand Down Expand Up @@ -83,8 +83,8 @@ Document readOptionalXmlFile(Path path) throws ParserConfigurationException, IOE
return null;
}

Deposit mapToDeposit(Path path, Path bagDir, Configuration config, Bag bag) {
var deposit = new Deposit();
DansBagDeposit mapToDeposit(Path path, Path bagDir, Configuration config, Bag bag) {
var deposit = new DansBagDeposit();
deposit.setBagDir(bagDir);
deposit.setDir(path);
deposit.setDoi(config.getString("identifier.doi", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Deposit {
public class DansBagDeposit {

private Path dir;
private Path bagDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package nl.knaw.dans.dvingest.core.dansbag.exception;

import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;

public class RejectedDepositException extends RuntimeException {
public RejectedDepositException(Deposit deposit, String message) {
super(String.format("Rejected %s: %s", deposit.getDir(), message));
public RejectedDepositException(DansBagDeposit dansBagDeposit, String message) {
super(String.format("Rejected %s: %s", dansBagDeposit.getDir(), message));
}

public RejectedDepositException(nl.knaw.dans.dvingest.core.Deposit deposit, String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import nl.knaw.dans.dvingest.core.dansbag.domain.Deposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.DansBagDeposit;
import nl.knaw.dans.dvingest.core.dansbag.domain.FileInfo;
import nl.knaw.dans.dvingest.core.dansbag.service.XPathEvaluator;
import nl.knaw.dans.lib.dataverse.model.file.FileMeta;
Expand Down Expand Up @@ -212,17 +212,17 @@ private static String replaceForbiddenCharactersInFilename(String filename) {
return filenameForbidden.matcher(filename).replaceAll("_");
}

public static Map<Path, FileInfo> pathToFileInfo(Deposit deposit, boolean isMigration) {
public static Map<Path, FileInfo> pathToFileInfo(DansBagDeposit dansBagDeposit, boolean isMigration) {
// FIL006
var defaultRestrict = XPathEvaluator.nodes(deposit.getDdm(), "/ddm:DDM/ddm:profile/ddm:accessRights")
var defaultRestrict = XPathEvaluator.nodes(dansBagDeposit.getDdm(), "/ddm:DDM/ddm:profile/ddm:accessRights")
.map(AccessRights::toDefaultRestrict)
.findFirst()
.orElse(true);

var result = new HashMap<Path, FileInfo>();
var bagDir = deposit.getBagDir();
var bagDir = dansBagDeposit.getBagDir();

deposit.getFiles().forEach(depositFile -> {
dansBagDeposit.getFiles().forEach(depositFile -> {
var fileMetaResult = toFileMeta(depositFile.getXmlNode(), defaultRestrict, isMigration);
result.put(depositFile.getPath(), new FileInfo(
bagDir.resolve(depositFile.getPath()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.dvingest.core.dansbag.io;
package nl.knaw.dans.dvingest.core.dansbag.service;

import gov.loc.repository.bagit.domain.Bag;
import gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nl.knaw.dans.dvingest.core.dansbag.io;
package nl.knaw.dans.dvingest.core.dansbag.service;

import gov.loc.repository.bagit.domain.Bag;
import gov.loc.repository.bagit.exceptions.InvalidBagitFileFormatException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositFileListerImpl;
import nl.knaw.dans.dvingest.core.dansbag.deposit.DepositReader;
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.service.BagDataManager;
import nl.knaw.dans.dvingest.core.dansbag.service.BagDataManagerImpl;
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

0 comments on commit 4e9d137

Please sign in to comment.