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

IQSS/10793 Improve Handling of Parallel Edit/Publish errors #10794

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
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 @@ -2888,6 +2889,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 @@ -4002,6 +4006,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 @@ -4011,6 +4019,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 @@ -834,7 +834,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 @@ -995,7 +994,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
Loading