Skip to content

Commit

Permalink
quick preliminary fixes/work in progress #3437
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jan 5, 2024
1 parent 871f373 commit 2001f52
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,8 @@ public class OAIRecordServiceBean implements java.io.Serializable {
EntityManager em;

private static final Logger logger = Logger.getLogger("edu.harvard.iq.dataverse.harvest.server.OAIRecordServiceBean");

public void updateOaiRecords(String setName, List<Long> datasetIds, Date updateTime, boolean doExport) {
updateOaiRecords(setName, datasetIds, updateTime, doExport, logger);
}

public void updateOaiRecords(String setName, List<Long> datasetIds, Date updateTime, boolean doExport, Logger setUpdateLogger) {


public void updateOaiRecords(String setName, List<Long> datasetIds, Date updateTime, boolean doExport, boolean confirmed, Logger setUpdateLogger) {
// create Map of OaiRecords
List<OAIRecord> oaiRecords = findOaiRecordsBySetName(setName);
Map<String, OAIRecord> recordMap = new HashMap<>();
Expand Down Expand Up @@ -101,9 +96,6 @@ public void updateOaiRecords(String setName, List<Long> datasetIds, Date updateT
DatasetVersion releasedVersion = dataset.getReleasedVersion();
Date publicationDate = releasedVersion == null ? null : releasedVersion.getReleaseTime();

//if (dataset.getPublicationDate() != null
// && (dataset.getLastExportTime() == null
// || dataset.getLastExportTime().before(dataset.getPublicationDate()))) {
if (publicationDate != null
&& (dataset.getLastExportTime() == null
|| dataset.getLastExportTime().before(publicationDate))) {
Expand All @@ -125,7 +117,9 @@ public void updateOaiRecords(String setName, List<Long> datasetIds, Date updateT
}

// anything left in the map should be marked as removed!
markOaiRecordsAsRemoved( recordMap.values(), updateTime, setUpdateLogger);
markOaiRecordsAsRemoved(recordMap.values(), updateTime, confirmed, setUpdateLogger);



}

Expand Down Expand Up @@ -162,7 +156,7 @@ record = new OAIRecord(setName, dataset.getGlobalId().asString(), new Date());
}
}

/*
// Updates any existing OAI records for this dataset
// Should be called whenever there's a change in the release status of the Dataset
// (i.e., when it's published or deaccessioned), so that the timestamps and
Expand Down Expand Up @@ -201,13 +195,31 @@ public void updateOaiRecordsForDataset(Dataset dataset) {
logger.fine("Null returned - no records found.");
}
}
*/

public void markOaiRecordsAsRemoved(Collection<OAIRecord> records, Date updateTime, Logger setUpdateLogger) {
public void markOaiRecordsAsRemoved(Collection<OAIRecord> records, Date updateTime, boolean confirmed, Logger setUpdateLogger) {
for (OAIRecord oaiRecord : records) {
if ( !oaiRecord.isRemoved() ) {
setUpdateLogger.fine("marking OAI record "+oaiRecord.getGlobalId()+" as removed");
oaiRecord.setRemoved(true);
oaiRecord.setLastUpdateTime(updateTime);
boolean confirmedRemoved = confirmed;
if (!confirmedRemoved) {
Dataset lookedUp = datasetService.findByGlobalId(oaiRecord.getGlobalId());
if (lookedUp == null) {
confirmedRemoved = true;
} else if (lookedUp.getLastExportTime() == null) {
confirmedRemoved = true;
} else {
boolean isReleased = lookedUp.getReleasedVersion() != null;
if (!isReleased) {
confirmedRemoved = true;
}
}
}

if (confirmedRemoved) {
setUpdateLogger.fine("marking OAI record "+oaiRecord.getGlobalId()+" as removed");
oaiRecord.setRemoved(true);
oaiRecord.setLastUpdateTime(updateTime);
}
} else {
setUpdateLogger.fine("OAI record "+oaiRecord.getGlobalId()+" is already marked as removed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public void exportOaiSet(OAISet oaiSet, Logger exportLogger) {
String query = managedSet.getDefinition();

List<Long> datasetIds;
boolean databaseLookup = false; // As opposed to a search engine lookup

try {
if (!oaiSet.isDefaultSet()) {
datasetIds = expandSetQuery(query);
Expand All @@ -161,6 +163,7 @@ public void exportOaiSet(OAISet oaiSet, Logger exportLogger) {
// including the unpublished drafts and deaccessioned ones.
// Those will be filtered out further down the line.
datasetIds = datasetService.findAllLocalDatasetIds();
databaseLookup = true;
}
} catch (OaiSetException ose) {
datasetIds = null;
Expand All @@ -171,7 +174,7 @@ public void exportOaiSet(OAISet oaiSet, Logger exportLogger) {
// they will be properly marked as "deleted"! -- L.A. 4.5
//if (datasetIds != null && !datasetIds.isEmpty()) {
exportLogger.info("Calling OAI Record Service to re-export " + datasetIds.size() + " datasets.");
oaiRecordService.updateOaiRecords(managedSet.getSpec(), datasetIds, new Date(), true, exportLogger);
oaiRecordService.updateOaiRecords(managedSet.getSpec(), datasetIds, new Date(), true, databaseLookup, exportLogger);
//}
managedSet.setUpdateInProgress(false);

Expand Down

0 comments on commit 2001f52

Please sign in to comment.