Skip to content
Open
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
27 changes: 13 additions & 14 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -6101,20 +6101,19 @@ public void archiveVersion(Long id) {
AbstractSubmitToArchiveCommand cmd = ArchiverUtil.createSubmitToArchiveCommand(className, dvRequestService.getDataverseRequest(), dv);
if (cmd != null) {
try {
DatasetVersion version = commandEngine.submit(cmd);
if (!version.getArchivalCopyLocationStatus().equals(DatasetVersion.ARCHIVAL_STATUS_FAILURE)) {
logger.info(
"DatasetVersion id=" + version.getId() + " submitted to Archive, status: " + dv.getArchivalCopyLocationStatus());
} else {
logger.severe("Error submitting version " + version.getId() + " due to conflict/error at Archive");
}
if (version.getArchivalCopyLocation() != null) {
setVersionTabList(resetVersionTabList());
this.setVersionTabListForPostLoad(getVersionTabList());
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("datasetversion.archive.success"));
} else {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("datasetversion.archive.failure"));
}

// Set initial pending status
dv.setArchivalCopyLocation(DatasetVersion.ARCHIVAL_STATUS_PENDING);
datasetVersionService.persistArchivalCopyLocation(dv);

commandEngine.submitAsync(cmd);

logger.info(
"DatasetVersion id=" + dv.getId() + " submitted to Archive, status: " + dv.getArchivalCopyLocationStatus());
setVersionTabList(resetVersionTabList());
this.setVersionTabListForPostLoad(getVersionTabList());
JsfHelper.addSuccessMessage(BundleUtil.getStringFromBundle("datasetversion.archive.inprogress"));

} catch (CommandException ex) {
logger.log(Level.SEVERE, "Unexpected Exception calling submit archive command", ex);
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("datasetversion.archive.failure"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import jakarta.json.JsonObjectBuilder;
import jakarta.persistence.EntityManager;
import jakarta.persistence.NoResultException;
import jakarta.persistence.OptimisticLockException;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.Query;
import jakarta.persistence.TypedQuery;
Expand Down Expand Up @@ -1333,4 +1334,28 @@ public Long getDatasetVersionCount(Long datasetId, boolean canViewUnpublishedVer

return em.createQuery(cq).getSingleResult();
}


/**
* Update the archival copy location for a specific version of a dataset. Archiving can be long-running and other parallel updates to the datasetversion have likely occurred so this method will check
* for OptimisticLockExceptions and retry the update with the latest version.
*
* @param dv
* The dataset version whose archival copy location we want to update. Must not be {@code null}.
*/
public void persistArchivalCopyLocation(DatasetVersion dv) {
try {
em.merge(dv);
em.flush(); // Force the update and version check immediately
} catch (OptimisticLockException ole) {
logger.log(Level.INFO, "OptimisticLockException while persisting archival copy location for DatasetVersion id={0}. Retrying on latest version.", dv.getId());
DatasetVersion currentVersion = find(dv.getId());
if (currentVersion != null) {
currentVersion.setArchivalCopyLocation(dv.getArchivalCopyLocation());
em.merge(currentVersion);
} else {
logger.log(Level.SEVERE, "Could not find DatasetVersion with id={0} to retry persisting archival copy location after OptimisticLockException.", dv.getId());
}
}
}
}
26 changes: 26 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/EjbDataverseEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

import java.util.Map;
import java.util.Set;

import jakarta.ejb.AsyncResult;
import jakarta.ejb.Asynchronous;
import jakarta.ejb.EJB;
import jakarta.ejb.Stateless;
import jakarta.inject.Named;
Expand All @@ -45,6 +48,7 @@
import java.util.Arrays;
import java.util.EnumSet;
import java.util.Stack;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import jakarta.annotation.Resource;
Expand Down Expand Up @@ -348,6 +352,28 @@ public <R> R submit(Command<R> aCommand) throws CommandException {
logSvc.log(logRec);
}
}

/**
* Submits a command for asynchronous execution.
* The command will be executed in a separate thread and won't block the caller.
*
* @param <R> The return type of the command
* @param aCommand The command to execute
* @param user The user executing the command
* @return A Future representing the pending result
* @throws CommandException if the command cannot be submitted
*/
@Asynchronous
public <R> Future<R> submitAsync(Command<R> aCommand) throws CommandException {
try {
logger.log(Level.INFO, "Submitting async command: {0}", aCommand.getClass().getSimpleName());
R result = submit(aCommand);
return new AsyncResult<>(result);
} catch (Exception e) {
logger.log(Level.SEVERE, "Async command execution failed: " + aCommand.getClass().getSimpleName(), e);
throw e;
}
}

protected void completeCommand(Command command, Object r, Stack<Command> called) {

Expand Down
1 change: 1 addition & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ public Response publishDataset(@Context ContainerRequestContext crc, @PathParam(
if (archiveCommand != null) {
// Delete the record of any existing copy since it is now out of date/incorrect
updateVersion.setArchivalCopyLocation(null);
datasetVersionSvc.persistArchivalCopyLocation(updateVersion);
/*
* Then try to generate and submit an archival copy. Note that running this
* command within the CuratePublishedDatasetVersionCommand was causing an error:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public DatasetVersion execute(CommandContext ctxt) throws CommandException {
token = ctxt.authentication().generateApiTokenForUser(user);
}
performArchiveSubmission(version, token, requestedSettings);
return ctxt.em().merge(version);
ctxt.datasetVersion().persistArchivalCopyLocation(version);
return version;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,7 @@ dataset.notlinked.msg=There was a problem linking this dataset to yours:
dataset.linking.popop.already.linked.note=Note: This dataset is already linked to the following dataverse(s):
dataset.linking.popup.not.linked.note=Note: This dataset is not linked to any of your accessible dataverses
datasetversion.archive.success=Archival copy of Version successfully submitted
datasetversion.archive.inprogress= Data Project archiving has been started
datasetversion.archive.failure=Error in submitting an archival copy
datasetversion.update.failure=Dataset Version Update failed. Changes are still in the DRAFT version.
datasetversion.update.archive.failure=Dataset Version Update succeeded, but the attempt to update the archival copy failed.
Expand Down