Skip to content

Commit

Permalink
rearranged/cleaned up handling of OAI delete in harvesting. (#8372)
Browse files Browse the repository at this point in the history
  • Loading branch information
landreev committed Jun 6, 2022
1 parent bf413e7 commit 171f2f4
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ private List<Long> harvestOAI(DataverseRequest dataverseRequest, HarvestingClien
Date dateStamp = Date.from(h.getDatestamp());

hdLogger.info("processing identifier: " + identifier + ", date: " + dateStamp);

if (h.isDeleted()) {
hdLogger.info("Deleting harvesting dataset for " + identifier + ", per ListIdentifiers.");

deleteHarvestedDatasetIfExists(identifier, oaiHandler.getHarvestingClient().getDataverse(), dataverseRequest, deletedIdentifiers, hdLogger);
continue;
}

MutableBoolean getRecordErrorOccurred = new MutableBoolean(false);

Expand Down Expand Up @@ -301,19 +308,9 @@ private Long processRecord(DataverseRequest dataverseRequest, Logger hdLogger, P
hdLogger.log(Level.SEVERE, "Error calling GetRecord - " + errMessage);

} else if (deleted) {
hdLogger.info("Deleting harvesting dataset for "+identifier+", per the OAI server's instructions.");
hdLogger.info("Deleting harvesting dataset for "+identifier+", per GetRecord.");

Dataset dataset = datasetService.getDatasetByHarvestInfo(oaiHandler.getHarvestingClient().getDataverse(), identifier);
if (dataset != null) {
hdLogger.info("Deleting dataset " + dataset.getGlobalIdString());
datasetService.deleteHarvestedDataset(dataset, dataverseRequest, hdLogger);
// TODO:
// check the status of that Delete - see if it actually succeeded
deletedIdentifiers.add(identifier);
} else {
hdLogger.info("No dataset found for "+identifier+", skipping delete. ");
}

deleteHarvestedDatasetIfExists(identifier, oaiHandler.getHarvestingClient().getDataverse(), dataverseRequest, deletedIdentifiers, hdLogger);
} else {
hdLogger.info("Successfully retrieved GetRecord response.");

Expand Down Expand Up @@ -396,6 +393,18 @@ File retrieveProprietaryDataverseMetadata (String remoteApiUrl) throws IOExcepti

}

private void deleteHarvestedDatasetIfExists(String persistentIdentifier, Dataverse harvestingDataverse, DataverseRequest dataverseRequest, List<String> deletedIdentifiers, Logger hdLogger) {
Dataset dataset = datasetService.getDatasetByHarvestInfo(harvestingDataverse, persistentIdentifier);
if (dataset != null) {
datasetService.deleteHarvestedDataset(dataset, dataverseRequest, hdLogger);
// TODO:
// check the status of that Delete - see if it actually succeeded
deletedIdentifiers.add(persistentIdentifier);
return;
}
hdLogger.info("No dataset found for " + persistentIdentifier + ", skipping delete. ");
}

private static String getProprietaryDataverseMetadataURL(String baseURL, String identifier) {

baseURL = baseURL.replaceAll("/oai", "");
Expand Down

0 comments on commit 171f2f4

Please sign in to comment.