-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactorings, renamed some classes and separated out code into packages.
- Loading branch information
1 parent
e636bb9
commit 64b2aa1
Showing
18 changed files
with
224 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/main/java/nl/knaw/dans/dvingest/core/CreateNewDatasetTask.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
src/main/java/nl/knaw/dans/dvingest/core/UpdateDatasetTask.java
This file was deleted.
Oops, something went wrong.
77 changes: 77 additions & 0 deletions
77
src/main/java/nl/knaw/dans/dvingest/core/datasetversiontask/AbstractDatasetVersionTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core.datasetversiontask; | ||
|
||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import nl.knaw.dans.dvingest.core.service.DataverseService; | ||
import nl.knaw.dans.dvingest.core.Deposit; | ||
import nl.knaw.dans.dvingest.core.service.UtilityServices; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Task that results in a new dataset (version) in Dataverse. | ||
*/ | ||
@Slf4j | ||
public abstract class AbstractDatasetVersionTask implements Runnable { | ||
public enum Status { | ||
TODO, | ||
SUCCESS, | ||
REJECTED, | ||
FAILED | ||
} | ||
|
||
protected final Deposit deposit; | ||
protected final DataverseService dataverseService; | ||
protected final UtilityServices utilityServices; | ||
protected final Path outputDir; | ||
|
||
@Getter | ||
protected Status status = Status.TODO; | ||
|
||
public AbstractDatasetVersionTask(Deposit deposit, DataverseService dataverseService, UtilityServices utilityServices, Path outputDir) { | ||
this.deposit = deposit; | ||
this.dataverseService = dataverseService; | ||
this.utilityServices = utilityServices; | ||
this.outputDir = outputDir; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
var pid = performAndReturnPid(); | ||
status = Status.SUCCESS; | ||
dataverseService.publishDataset(pid); | ||
dataverseService.waitForState(pid, "RELEASED"); | ||
deposit.moveTo(outputDir.resolve("processed")); | ||
status = Status.SUCCESS; | ||
} | ||
catch (Exception e) { | ||
try { | ||
log.error("Failed to ingest deposit", e); | ||
deposit.moveTo(outputDir.resolve("failed")); | ||
status = Status.FAILED; | ||
} | ||
catch (IOException ioException) { | ||
log.error("Failed to move deposit to failed directory", ioException); | ||
} | ||
} | ||
} | ||
|
||
public abstract String performAndReturnPid() throws Exception; | ||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/nl/knaw/dans/dvingest/core/datasetversiontask/CreateNewDataset.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected]) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package nl.knaw.dans.dvingest.core.datasetversiontask; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import nl.knaw.dans.dvingest.core.service.DataverseService; | ||
import nl.knaw.dans.dvingest.core.Deposit; | ||
import nl.knaw.dans.dvingest.core.service.PathIterator; | ||
import nl.knaw.dans.dvingest.core.service.UtilityServices; | ||
import nl.knaw.dans.lib.dataverse.model.file.FileMeta; | ||
import org.apache.commons.io.FileUtils; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
/** | ||
* Creates the first version of a new dataset in Dataverse. | ||
*/ | ||
@Slf4j | ||
public class CreateNewDataset extends AbstractDatasetVersionTask { | ||
public CreateNewDataset(Deposit deposit, DataverseService dataverseService, UtilityServices utilityServices, Path outputDir) { | ||
super(deposit, dataverseService, utilityServices, outputDir); | ||
} | ||
|
||
@Override | ||
public String performAndReturnPid() throws Exception { | ||
var result = dataverseService.createDataset(deposit.getDatasetMetadata()); | ||
var pid = result.getData().getPersistentId(); | ||
log.debug(result.getEnvelopeAsString()); | ||
var iterator = new PathIterator(FileUtils.iterateFiles(deposit.getFilesDir().toFile(), null, true)); | ||
while (iterator.hasNext()) { | ||
var tempZipFile = utilityServices.createTempZipFile(); | ||
try { | ||
var zipFile = utilityServices.createPathIteratorZipperBuilder() | ||
.rootDir(deposit.getFilesDir()) | ||
.sourceIterator(iterator) | ||
.targetZipFile(tempZipFile) | ||
.build() | ||
.zip(); | ||
dataverseService.addFile(pid, zipFile, new FileMeta()); | ||
log.debug("Uploaded {} files (cumulative)", iterator.getIteratedCount()); | ||
} | ||
finally { | ||
Files.deleteIfExists(tempZipFile); | ||
} | ||
|
||
} | ||
return pid; | ||
} | ||
} |
Oops, something went wrong.