Skip to content

Commit

Permalink
Merge pull request #10794 from GlobalDataverseCommunityConsortium/IQS…
Browse files Browse the repository at this point in the history
…S/10793-handle_optimisticlockexceptions

IQSS/10793 Improve Handling of Parallel Edit/Publish errors
  • Loading branch information
ofahimIQSS authored Nov 22, 2024
2 parents a3a11a4 + 8a3fe73 commit e32cfd8
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/release-notes/10793-optimisticlockexception handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Improvements have been made in handling the errors when a dataset has been edited in one window and an attempt is made to
edit/publish it in another.
17 changes: 17 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.persistence.OptimisticLockException;

import org.apache.commons.lang3.StringUtils;
import org.primefaces.event.FileUploadEvent;
Expand Down Expand Up @@ -2897,6 +2898,9 @@ private String releaseDataset(boolean minor) {
// the lock info system.
JsfHelper.addErrorMessage(ex.getLocalizedMessage());
}
if(ex.getCause()!=null && ex.getCause() instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelPublishError"));
}
logger.severe(ex.getMessage());
}

Expand Down Expand Up @@ -4011,6 +4015,10 @@ public String save() {
Throwable cause = ex;
while (cause.getCause()!= null) {
cause = cause.getCause();
if (cause != null && cause instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelUpdateError"));
return null;
}
error.append(cause).append(" ");
error.append(cause.getMessage()).append(" ");
}
Expand All @@ -4020,6 +4028,15 @@ public String save() {
} catch (CommandException ex) {
//FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Dataset Save Failed", " - " + ex.toString()));
logger.log(Level.SEVERE, "CommandException, when attempting to update the dataset: " + ex.getMessage(), ex);
Throwable cause = ex;
while (cause.getCause()!= null) {
cause = cause.getCause();
logger.info("Cause is: " + cause.getClass().getName() + ", Message: " + cause.getMessage());
if (cause != null && cause instanceof OptimisticLockException) {
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataset.message.parallelUpdateError"));
return null;
}
}
populateDatasetUpdateFailureMessage();
return returnToDraftVersion();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException;
import edu.harvard.iq.dataverse.workflow.Workflow;
import edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType;

import jakarta.persistence.OptimisticLockException;

import java.util.Optional;
import java.util.logging.Logger;
import static java.util.stream.Collectors.joining;
Expand Down Expand Up @@ -105,10 +108,15 @@ public PublishDatasetResult execute(CommandContext ctxt) throws CommandException
Optional<Workflow> prePubWf = ctxt.workflows().getDefaultWorkflow(TriggerType.PrePublishDataset);
if ( prePubWf.isPresent() ) {
// We start a workflow
theDataset = ctxt.em().merge(theDataset);
ctxt.em().flush();
ctxt.workflows().start(prePubWf.get(), buildContext(theDataset, TriggerType.PrePublishDataset, datasetExternallyReleased), true);
return new PublishDatasetResult(theDataset, Status.Workflow);
try {
theDataset = ctxt.em().merge(theDataset);
ctxt.em().flush();
ctxt.workflows().start(prePubWf.get(),
buildContext(theDataset, TriggerType.PrePublishDataset, datasetExternallyReleased), true);
return new PublishDatasetResult(theDataset, Status.Workflow);
} catch (OptimisticLockException e) {
throw new CommandException(e.getMessage(), e, this);
}

} else{
// We will skip trying to register the global identifiers for datafiles
Expand Down Expand Up @@ -157,7 +165,12 @@ public PublishDatasetResult execute(CommandContext ctxt) throws CommandException
lock.setInfo(info);
ctxt.datasets().addDatasetLock(theDataset, lock);
}
theDataset = ctxt.em().merge(theDataset);
try {
theDataset = ctxt.em().merge(theDataset);
} catch (OptimisticLockException e) {
ctxt.datasets().removeDatasetLocks(theDataset, DatasetLock.Reason.finalizePublication);
throw new CommandException(e.getMessage(), e, this);
}
// The call to FinalizePublicationCommand has been moved to the new @onSuccess()
// method:
//ctxt.datasets().callFinalizePublishCommandAsynchronously(theDataset.getId(), ctxt, request, datasetExternallyReleased);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/propertyFiles/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,8 @@ dataset.message.createFailure=The dataset could not be created.
dataset.message.termsFailure=The dataset terms could not be updated.
dataset.message.label.fileAccess=Publicly-accessible storage
dataset.message.publicInstall=Files in this dataset may be readable outside Dataverse, restricted and embargoed access are disabled
dataset.message.parallelUpdateError=Changes cannot be saved. This dataset has been edited since this page was opened. To continue, copy your changes, refresh the page to see the recent updates, and re-enter any changes you want to save.
dataset.message.parallelPublishError=Publishing is blocked. This dataset has been edited since this page was opened. To publish it, refresh the page to see the recent updates, and publish again.
dataset.metadata.publicationDate=Publication Date
dataset.metadata.publicationDate.tip=The publication date of a Dataset.
dataset.metadata.citationDate=Citation Date
Expand Down
2 changes: 0 additions & 2 deletions src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,6 @@
/>
<p:commandButton id="saveTopTOA" styleClass="btn btn-default" value="#{bundle.saveChanges}" rendered="#{DatasetPage.editMode == 'LICENSE'}"
onclick="testTOADatasetPage();"
update=":datasetForm,:messagePanel"
oncomplete="$(document).scrollTop(0);"
/>
<p:commandButton id="cancelTop" styleClass="btn btn-link" value="#{bundle.cancel}" action="#{DatasetPage.cancel}" process="@this" update="@form">
Expand Down Expand Up @@ -996,7 +995,6 @@
<p:commandButton id="saveBottomTerms" styleClass="btn btn-default" rendered="#{DatasetPage.editMode == 'LICENSE'}"
value="#{DatasetPage.editMode == 'CREATE' ? bundle['file.addBtn'] : bundle.saveChanges}"
onclick="testTOADatasetPage();"
update=":datasetForm,:messagePanel"
oncomplete="$(document).scrollTop(0);"/>
<p:commandButton id="saveBottom" styleClass="btn btn-default" value="#{DatasetPage.editMode == 'CREATE' ? bundle['file.addBtn'] : bundle.saveChanges}" rendered="#{DatasetPage.editMode == 'CREATE' or DatasetPage.editMode == 'METADATA'}"
onclick="PF('blockDatasetForm').show();"
Expand Down

0 comments on commit e32cfd8

Please sign in to comment.