Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 11, 2024
1 parent df8c0df commit b92a04f
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class DansDepositSupportFactoryImpl implements DansDepositSupportFactory
private final DataverseService dataverseService;
private final YamlService yamlService;

// todo: property isMigration

@Override
public Deposit addDansDepositSupportIfEnabled(DataverseIngestDeposit deposit) {
return new DansDepositSupport(deposit, validateDansBagService, dansBagMappingService, dataverseService, yamlService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ private void verifyCreate(Create create, Expect expect, String targetPid) throws
if (StringUtils.isBlank(create.getImportPid())) {
throw new IllegalArgumentException("Cannot import a dataset without a PID.");
}
if (expect != null && expect.getState() != null && !"absent".equals(expect.getState().toLowerCase())) {
if (expect != null && expect.getState() != null && !"absent".equalsIgnoreCase(expect.getState())) {
throw new IllegalArgumentException("Cannot expect a state other than 'absent' when importing a dataset.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
import nl.knaw.dans.dvingest.core.yaml.Init;
import nl.knaw.dans.lib.dataverse.DataverseException;
import nl.knaw.dans.lib.dataverse.model.dataset.Dataset;
import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion;
Expand Down Expand Up @@ -49,6 +50,14 @@ public interface DansBagMappingService {
*/
DansBagDeposit readDansDeposit(Path depositDir) throws InvalidDepositException;

/**
* Determines what preconditions to expect and whether and how to create a new dataset based on the DANS deposit.
*
* @param dansDeposit the DANS deposit
* @return the preconditions to expect and whether and how to create a new dataset
*/
Init getInitFromDansDeposit(DansBagDeposit dansDeposit);

/**
* Maps the metadata from the DANS deposit to the new dataset level metadata for the dataset. For some parts the new metadata depends on the current metadata of the dataset. That is why the
* current metadata is also given as input. If the deposit is to create a new dataset, the current metadata is null.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
import nl.knaw.dans.dvingest.core.dansbag.xml.XmlReader;
import nl.knaw.dans.dvingest.core.dansbag.xml.XmlReaderImpl;
import nl.knaw.dans.dvingest.core.service.DataverseService;
import nl.knaw.dans.dvingest.core.yaml.Create;
import nl.knaw.dans.dvingest.core.yaml.EditFiles;
import nl.knaw.dans.dvingest.core.yaml.EditPermissions;
import nl.knaw.dans.dvingest.core.yaml.Init;
import nl.knaw.dans.lib.dataverse.DataverseException;
import nl.knaw.dans.lib.dataverse.model.RoleAssignment;
import nl.knaw.dans.lib.dataverse.model.dataset.Dataset;
Expand Down Expand Up @@ -119,6 +121,21 @@ else if (depositToDvDatasetMetadataMapper.isMigration()) {
}
}

@Override
public Init getInitFromDansDeposit(DansBagDeposit dansDeposit) {
if (depositToDvDatasetMetadataMapper.isMigration()) {
var init = new Init();
var create = new Create();
if (StringUtils.isBlank(dansDeposit.getDoi())) {
throw new IllegalArgumentException("Migration deposit must have a DOI");
}
create.setImportPid(dansDeposit.getDoi());
init.setCreate(create);
return init;
}
return null;
}

@Override
public Dataset getDatasetMetadataFromDansDeposit(DansBagDeposit dansDeposit, DatasetVersion currentMetadata) {
// TODO: rename to DatasetComposer en push the terms stuff into it as well.
Expand Down Expand Up @@ -178,11 +195,14 @@ public EditPermissions getEditPermissionsFromDansDeposit(DansBagDeposit dansDepo

@Override
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();
if (!depositToDvDatasetMetadataMapper.isMigration()) {
// 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();
}
return null;
}

// todo: move to mapping package
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import nl.knaw.dans.dvingest.core.service.YamlService;
import nl.knaw.dans.dvingest.core.yaml.EditFilesRoot;
import nl.knaw.dans.dvingest.core.yaml.EditPermissionsRoot;
import nl.knaw.dans.dvingest.core.yaml.InitRoot;
import nl.knaw.dans.dvingest.core.yaml.UpdateState;
import nl.knaw.dans.lib.dataverse.model.dataset.DatasetVersion;

Expand All @@ -37,6 +38,9 @@ public void run() throws IOException {
// TODO: pass to getEditFilesFromDansDeposit so that update-deposit can register it as a replaced file
var originalMetadataPath = mappingService.packageOriginalMetadata(dansDeposit);

var init = mappingService.getInitFromDansDeposit(dansDeposit);
yamlService.writeYaml(new InitRoot(init), dansDeposit.getBagDir().resolve("init.yml"));

var dataset = mappingService.getDatasetMetadataFromDansDeposit(dansDeposit, currentMetadata);
yamlService.writeYaml(dataset, dansDeposit.getBagDir().resolve("dataset.yml"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public Path getLocation() {
@Override
public void onSuccess(@NonNull String pid, String message) {
try {
// todo: skip for migration deposit

var bag = ingestDataverseIngestDeposit.getBags().get(0);
var action = bag.getUpdateState().getAction();
if (action.startsWith("publish")) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/nl/knaw/dans/dvingest/core/yaml/InitRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
*/
package nl.knaw.dans.dvingest.core.yaml;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class InitRoot {
private Init init;
}

0 comments on commit b92a04f

Please sign in to comment.