Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BXC-4787 - Consolidate deposit directory logic and add alt text path getter #1858

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public PreconstructedDepositJob(String uuid, String depositUUID) {
@Override
public void runJob() {
try {
DepositDirectoryManager dirManager = new DepositDirectoryManager(
depositPID, getDepositsDirectory().toPath(), true);
Map<String, String> depositStatus = getDepositStatus();
// Determine if we are importing an external deposit dir, or starting from one already in place
String sourceUriProp = depositStatus.get(DepositField.sourceUri.name());
Expand All @@ -53,7 +51,7 @@ public void runJob() {
}
}
// Check to see if there is a model file to import
Path modelPath = dirManager.getModelPath();
Path modelPath = depositDirectoryManager.getModelPath();
if (Files.exists(modelPath)) {
log.info("Importing preconstructed model file included in deposit directory");
Model importModel = RDFModelUtil.createModel(Files.newInputStream(modelPath), "N3");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
package edu.unc.lib.boxc.deposit.work;

import static edu.unc.lib.boxc.deposit.api.DepositConstants.ALT_TEXT_DIR;
import static edu.unc.lib.boxc.deposit.api.DepositConstants.DESCRIPTION_DIR;
import static edu.unc.lib.boxc.deposit.api.DepositConstants.HISTORY_DIR;
import static edu.unc.lib.boxc.deposit.api.DepositConstants.TECHMD_DIR;
import static edu.unc.lib.boxc.model.api.ids.PIDConstants.DEPOSITS_QUALIFIER;
import static edu.unc.lib.boxc.model.api.ids.RepositoryPathConstants.HASHED_PATH_DEPTH;
import static edu.unc.lib.boxc.model.api.ids.RepositoryPathConstants.HASHED_PATH_SIZE;
import static edu.unc.lib.boxc.model.fcrepo.ids.RepositoryPaths.idToPath;

import java.io.File;
import java.io.IOException;
Expand All @@ -25,6 +18,8 @@

import javax.annotation.PostConstruct;

import edu.unc.lib.boxc.deposit.impl.model.DepositDirectoryManager;
import edu.unc.lib.boxc.model.api.DatastreamType;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.jena.rdf.model.Bag;
import org.apache.jena.rdf.model.Model;
Expand Down Expand Up @@ -105,24 +100,13 @@ public abstract class AbstractDepositJob implements Runnable {
@Autowired
private File depositsDirectory;

// Directory for this deposit
private File depositDirectory;

// Directory for local data files
private File dataDirectory;

// Directory containing PREMIS event files for individual objects in this
// deposit
private File eventsDirectory;

private File techmdDir;

private String depositJobId;

protected boolean rollbackDatasetOnFailure = true;

@Autowired
protected DepositModelManager depositModelManager;
protected DepositDirectoryManager depositDirectoryManager;

public AbstractDepositJob() {
}
Expand All @@ -136,13 +120,7 @@ public AbstractDepositJob(String uuid, String depositUUID) {

@PostConstruct
public void init() {
this.depositDirectory = new File(depositsDirectory, depositUUID);
this.dataDirectory = new File(depositDirectory,
DepositConstants.DATA_DIR);
this.eventsDirectory = new File(depositDirectory,
DepositConstants.EVENTS_DIR);

this.techmdDir = new File(depositDirectory, TECHMD_DIR);
this.depositDirectoryManager = new DepositDirectoryManager(depositPID, depositsDirectory.toPath(), true);
}

@Override
Expand Down Expand Up @@ -241,15 +219,15 @@ public String getDepositField(DepositField field) {
}

public File getAltTextDir() {
return new File(getDepositDirectory(), ALT_TEXT_DIR);
return depositDirectoryManager.getAltTextDir().toFile();
}

public File getDescriptionDir() {
return new File(getDepositDirectory(), DESCRIPTION_DIR);
return depositDirectoryManager.getDescriptionDir().toFile();
}

public File getDescriptionHistoryDir() {
return new File(getDepositDirectory(), HISTORY_DIR);
return depositDirectoryManager.getHistoryDir().toFile();
}

/**
Expand All @@ -270,7 +248,7 @@ public Path getModsPath(PID pid) {
* @return path for mods
*/
public Path getModsPath(PID pid, boolean createDirs) {
return getMetadataPath(getDescriptionDir(), pid, ".xml", createDirs);
return depositDirectoryManager.getModsPath(pid, createDirs);
}

/**
Expand All @@ -280,7 +258,7 @@ public Path getModsPath(PID pid, boolean createDirs) {
* @return Path for the alt text
*/
public Path getAltTextPath(PID pid, boolean createDirs) {
return getMetadataPath(getAltTextDir(), pid, ".txt", createDirs);
return depositDirectoryManager.getAltTextPath(pid, createDirs);
}

/**
Expand All @@ -290,31 +268,27 @@ public Path getAltTextPath(PID pid, boolean createDirs) {
* @return
*/
public Path getModsHistoryPath(PID pid) {
return getMetadataPath(getDescriptionHistoryDir(), pid, ".xml", false);
return depositDirectoryManager.getHistoryFile(pid, DatastreamType.MD_DESCRIPTIVE, false);
}

public File getDepositsDirectory() {
return depositsDirectory;
}

public File getDepositDirectory() {
return depositDirectory;
return depositDirectoryManager.getDepositDir().toFile();
}

public File getTechMdDirectory() {
return techmdDir;
}

public void setDepositDirectory(File depositDirectory) {
this.depositDirectory = depositDirectory;
return depositDirectoryManager.getTechMdDir().toFile();
}

public File getDataDirectory() {
return dataDirectory;
return depositDirectoryManager.getDataDir().toFile();
}

public File getEventsDirectory() {
return eventsDirectory;
return depositDirectoryManager.getEventsDir().toFile();
}

public PremisLoggerFactory getPremisLoggerFactory() {
Expand Down Expand Up @@ -384,27 +358,11 @@ protected void markObjectCompleted(PID objectPid) {
}

public File getPremisFile(PID pid) {
return getMetadataPath(eventsDirectory, pid, ".nt", true).toFile();
return depositDirectoryManager.getPremisPath(pid, true).toFile();
}

public Path getTechMdPath(PID pid, boolean createDirs) {
return getMetadataPath(getTechMdDirectory(), pid, ".xml", createDirs);
}

private Path getMetadataPath(File baseDir, PID pid, String extension, boolean createDirs) {
Path mdBasePath = baseDir.toPath();

String hashing = idToPath(pid.getId(), HASHED_PATH_DEPTH, HASHED_PATH_SIZE);
Path hashedPath = mdBasePath.resolve(hashing);
if (createDirs) {
try {
Files.createDirectories(hashedPath);
} catch (IOException e) {
failJob(e, "Unable to create metadata path {0}", hashedPath);
}
}

return hashedPath.resolve(pid.getId() + extension);
return depositDirectoryManager.getTechMdPath(pid, createDirs);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ private void constructJob() {
job = new IngestContentObjectsJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
job.setPremisLoggerFactory(premisLoggerFactory);
setField(job, "pidMinter", pidMinter);
setField(job, "aclService", aclService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ public void init() throws Exception {
job = new IngestContentObjectsJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "premisLoggerFactory", mockPremisLoggerFactory);
setField(job, "aclService", aclService);
setField(job, "depositModelManager", depositModelManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public void init() throws Exception {
job = new IngestDepositRecordJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
job.setPremisLoggerFactory(premisLoggerFactory);
setField(job, "pidMinter", pidMinter);
setField(job, "depositModelManager", depositModelManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void setup() throws Exception {

job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositStatusFactory", depositStatusFactory);
setField(job, "jobStatusFactory", jobStatusFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public void setup() throws Exception {
private void initJob(String uuid) {
job = new BagIt2N3BagJob();
job.setDepositUUID(uuid);
job.setDepositDirectory(depositDir);
job.setExecutorService(executorService);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositsDirectory", depositsDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void setup() throws Exception {

job = new CDRMETS2N3BagJob(jobUUID, depositUUID);
setField(job, "depositModelManager", depositModelManager);
job.setDepositDirectory(depositDir);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "depositStatusFactory", depositStatusFactory);
setField(job, "metsSipSchema", metsSipSchema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ public void setup() throws Exception {

job = new DirectoryToBagJob();
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
job.setPremisLoggerFactory(premisLoggerFactory);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositsDirectory", depositDirectory);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "depositStatusFactory", depositStatusFactory);

job.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public class NormalizeFileObjectsJobTest extends AbstractDepositJobTest {
public void init() {
job = new NormalizeFileObjectsJob();
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
job.setDepositStatusFactory(depositStatusFactory);
setField(job, "depositModelManager", depositModelManager);
setField(job, "premisLoggerFactory", mockPremisLoggerFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ public void setup() throws Exception {

job = new PreconstructedDepositJob();
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "depositStatusFactory", depositStatusFactory);
job.init();
}

@Test
Expand All @@ -69,7 +69,7 @@ public void withExternalSourceNoModelFile() throws Exception {
Files.createDirectory(externalBasePath);
DepositDirectoryManager extDirManager = new DepositDirectoryManager(depositPid, externalBasePath, true);
status.put(DepositField.sourceUri.name(), extDirManager.getDepositDir().toUri().toString());
Files.createFile(extDirManager.getPremisPath(depositPid));
Files.createFile(extDirManager.getPremisPath(depositPid, true));

job.run();

Expand All @@ -87,7 +87,7 @@ public void withInternalSourceNoModelFile() throws Exception {
DepositDirectoryManager preDirManager = new DepositDirectoryManager(
depositPid, depositsDirectory.toPath(), true);
status.put(DepositField.sourceUri.name(), preDirManager.getDepositDir().toUri().toString());
Files.createFile(preDirManager.getPremisPath(depositPid));
Files.createFile(preDirManager.getPremisPath(depositPid, true));

job.run();

Expand Down Expand Up @@ -130,7 +130,7 @@ public void withSourceWithModelFile() throws Exception {
importModel.write(writer, "N3");

status.put(DepositField.sourceUri.name(), extDirManager.getDepositDir().toUri().toString());
Files.createFile(extDirManager.getPremisPath(depositPid));
Files.createFile(extDirManager.getPremisPath(depositPid, true));

job.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void setup() throws Exception {

job = new Simple2N3BagJob();
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
job.setPremisLoggerFactory(premisLoggerFactory);
setField(job, "depositModelManager", depositModelManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public class VocabularyEnforcementJobTest extends AbstractNormalizationJobTest {
public void setup() throws Exception {
job = new VocabularyEnforcementJob();
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
setField(job, "depositsDirectory", depositsDirectory);
setField(job, "jobStatusFactory", jobStatusFactory);
setField(job, "depositStatusFactory", depositStatusFactory);
setField(job, "vocabManager", vocabManager);
setField(job, "depositModelManager", depositModelManager);
job.init();

PID depositPid = pidMinter.mintContentPid();
depositStatus = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public void init() throws Exception {
fitsCommand = new File(fitsHome, "fits.sh").toPath();

job = new ExtractTechnicalMetadataJob(jobUUID, depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
job.setHttpClient(httpClient);
job.setFitsHomePath(fitsHome.getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void init() throws Exception {
job.setAclValidator(aclValidator);
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "depositsDirectory", depositsDirectory);
job.setDepositStatusFactory(depositStatusFactory);
job.setRepositoryObjectLoader(repoObjectLoader);
setField(job, "pidMinter", pidMinter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public void init() {
job = new ValidateDescriptionJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
setField(job, "depositModelManager", depositModelManager);
setField(job, "depositsDirectory", depositsDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public void init() throws Exception {
job = new ValidateFileAvailabilityJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
setField(job, "pidMinter", pidMinter);
job.setIngestSourceManager(sourceManager);
setField(job, "depositModelManager", depositModelManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private void initializeJob() {
job = new VirusScanJob();
job.setJobUUID(jobUUID);
job.setDepositUUID(depositUUID);
job.setDepositDirectory(depositDir);
job.setMaxStreamSize(300l);
setField(job, "pidMinter", pidMinter);
job.setClamClient(clamClient);
Expand Down
Loading
Loading