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-4760 update current version #5541

Merged
5 changes: 5 additions & 0 deletions doc/sphinx-guides/source/admin/dataverses-datasets.rst
Expand Up @@ -72,3 +72,8 @@ Send Dataset metadata to PID provider
Forces update to metadata provided to the PID provider of a published dataset. Only accessible to superusers. ::

curl -H "X-Dataverse-key: $API_TOKEN" -X POST http://$SERVER/api/datasets/$dataset-id/modifyRegistrationMetadata

Make Metadata Updates Without Changing Dataset Version
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As a superuser, click "Update Current Version" when publishing. (This option is only available when a 'Minor' update would be allowed.)
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/api/native-api.rst
Expand Up @@ -372,7 +372,7 @@ For these deletes your JSON file must include an exact match of those dataset fi
Publish a Dataset
~~~~~~~~~~~~~~~~~

Publishes the dataset whose id is passed. If this is the first version of the dataset, its version number will be set to ``1.0``. Otherwise, the new dataset version number is determined by the most recent version number and the ``type`` parameter. Passing ``type=minor`` increases the minor version number (2.3 is updated to 2.4). Passing ``type=major`` increases the major version number (2.3 is updated to 3.0). ::
Publishes the dataset whose id is passed. If this is the first version of the dataset, its version number will be set to ``1.0``. Otherwise, the new dataset version number is determined by the most recent version number and the ``type`` parameter. Passing ``type=minor`` increases the minor version number (2.3 is updated to 2.4). Passing ``type=major`` increases the major version number (2.3 is updated to 3.0). Superusers can pass ``type=updatecurrent`` to update metadata without changing the version number::

POST http://$SERVER/api/datasets/$id/actions/:publish?type=$type&key=$apiKey

Expand Down
5 changes: 5 additions & 0 deletions src/main/java/Bundle.properties
Expand Up @@ -1205,6 +1205,7 @@ dataset.publishBoth.tip=Once you publish this dataset it must remain published.
dataset.unregistered.tip= This dataset is unregistered. We will attempt to register it before publishing.
dataset.republish.tip=Are you sure you want to republish this dataset?
dataset.selectVersionNumber=Select if this is a minor or major version update.
dataset.updateRelease=Update Current Version (will permanently overwrite the latest published version)
dataset.majorRelease=Major Release
dataset.minorRelease=Minor Release
dataset.majorRelease.tip=Due to the nature of changes to the current draft this will be a major release ({0})
Expand Down Expand Up @@ -2022,6 +2023,10 @@ dataset.notlinked=DatasetNotLinked
dataset.notlinked.msg=There was a problem linking this dataset to yours:
datasetversion.archive.success=Archival copy of Version successfully submitted
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.
datasetversion.update.success=The published version of your Dataset has been updated.
datasetversion.update.archive.success=The published version of your Dataset, and its archival copy, have been updated.

#ThemeWidgetFragment.java
theme.validateTagline=Tagline must be at most 140 characters.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/DataFile.java
Expand Up @@ -434,7 +434,7 @@ public FileMetadata getFileMetadata() {
return getLatestFileMetadata();
}

private FileMetadata getLatestFileMetadata() {
public FileMetadata getLatestFileMetadata() {
FileMetadata fmd = null;

// for newly added or harvested, just return the one fmd
Expand Down
63 changes: 62 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Expand Up @@ -19,6 +19,7 @@
import edu.harvard.iq.dataverse.engine.command.Command;
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand;
import edu.harvard.iq.dataverse.engine.command.impl.CuratePublishedDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeaccessionDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeletePrivateUrlCommand;
Expand Down Expand Up @@ -1790,8 +1791,12 @@ public void edit(EditMode editMode) {
public String releaseDraft() {
if (releaseRadio == 1) {
return releaseDataset(true);
} else {
} else if(releaseRadio ==2) {
return releaseDataset(false);
} else if(releaseRadio ==3) {
return updateCurrentVersion();
} else {
return "Invalid Choice";
}
}

Expand Down Expand Up @@ -1976,6 +1981,7 @@ private String releaseDataset(boolean minor) {
return returnToDatasetOnly();
}

@Deprecated
public String registerDataset() {
try {
UpdateDatasetVersionCommand cmd = new UpdateDatasetVersionCommand(dataset, dvRequestService.getDataverseRequest());
Expand All @@ -1989,6 +1995,61 @@ public String registerDataset() {
FacesContext.getCurrentInstance().addMessage(null, message);
return returnToDatasetOnly();
}

public String updateCurrentVersion() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qqmyers can you add comments here and in the api that this code is duplicated so that we know thatif a change occurs we would need to update in multiple places (until we move to an onSuccess)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added comments and brought the PR back up to date with dev...

/*
* Note: The code here mirrors that in the
* edu.harvard.iq.dataverse.api.Datasets:publishDataset method (case
* "updatecurrent"). Any changes to the core logic (i.e. beyond updating the
* messaging about results) should be applied to the code there as well.
*/
String errorMsg = null;
String successMsg = BundleUtil.getStringFromBundle("datasetversion.update.success");
try {
CuratePublishedDatasetVersionCommand cmd = new CuratePublishedDatasetVersionCommand(dataset, dvRequestService.getDataverseRequest());
dataset = commandEngine.submit(cmd);
// If configured, and currently published version is archived, try to update archive copy as well
DatasetVersion updateVersion = dataset.getLatestVersion();
if (updateVersion.getArchivalCopyLocation() != null) {
String className = settingsService.get(SettingsServiceBean.Key.ArchiverClassName.toString());
AbstractSubmitToArchiveCommand archiveCommand = ArchiverUtil.createSubmitToArchiveCommand(className, dvRequestService.getDataverseRequest(), updateVersion);
if (archiveCommand != null) {
// Delete the record of any existing copy since it is now out of date/incorrect
updateVersion.setArchivalCopyLocation(null);
/*
* Then try to generate and submit an archival copy. Note that running this
* command within the CuratePublishedDatasetVersionCommand was causing an error:
* "The attribute [id] of class
* [edu.harvard.iq.dataverse.DatasetFieldCompoundValue] is mapped to a primary
* key column in the database. Updates are not allowed." To avoid that, and to
* simplify reporting back to the GUI whether this optional step succeeded, I've
* pulled this out as a separate submit().
*/
try {
updateVersion = commandEngine.submit(archiveCommand);
if (updateVersion.getArchivalCopyLocation() != null) {
successMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.success");
} else {
errorMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.failure");
}
} catch (CommandException ex) {
errorMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.failure") + " - " + ex.toString();
logger.severe(ex.getMessage());
}
}
}
} catch (CommandException ex) {
errorMsg = BundleUtil.getStringFromBundle("datasetversion.update.failure") + " - " + ex.toString();
logger.severe(ex.getMessage());
}
if (errorMsg != null) {
JsfHelper.addErrorMessage(errorMsg);
} else {
JsfHelper.addSuccessMessage(successMsg);
}
return returnToDatasetOnly();
}


public void refresh(ActionEvent e) {
refresh();
Expand Down
83 changes: 77 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Expand Up @@ -38,10 +38,12 @@
import edu.harvard.iq.dataverse.datasetutility.OptionalFileParams;
import edu.harvard.iq.dataverse.engine.command.Command;
import edu.harvard.iq.dataverse.engine.command.DataverseRequest;
import edu.harvard.iq.dataverse.engine.command.impl.AbstractSubmitToArchiveCommand;
import edu.harvard.iq.dataverse.engine.command.impl.AddLockCommand;
import edu.harvard.iq.dataverse.engine.command.impl.AssignRoleCommand;
import edu.harvard.iq.dataverse.engine.command.impl.CreateDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.CreatePrivateUrlCommand;
import edu.harvard.iq.dataverse.engine.command.impl.CuratePublishedDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetVersionCommand;
import edu.harvard.iq.dataverse.engine.command.impl.DeleteDatasetLinkingDataverseCommand;
Expand Down Expand Up @@ -76,6 +78,7 @@
import edu.harvard.iq.dataverse.engine.command.exception.CommandException;
import edu.harvard.iq.dataverse.engine.command.impl.UpdateDvObjectPIDMetadataCommand;
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
import edu.harvard.iq.dataverse.util.ArchiverUtil;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.EjbUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
Expand Down Expand Up @@ -167,6 +170,9 @@ public class Datasets extends AbstractApiBean {
@EJB
S3PackageImporter s3PackageImporter;

@EJB
SettingsServiceBean settingsService;

/**
* Used to consolidate the way we parse and handle dataset versions.
* @param <T>
Expand Down Expand Up @@ -775,28 +781,93 @@ public Response publishDataseUsingGetDeprecated( @PathParam("id") String id, @Qu
public Response publishDataset(@PathParam("id") String id, @QueryParam("type") String type) {
try {
if (type == null) {
return error(Response.Status.BAD_REQUEST, "Missing 'type' parameter (either 'major' or 'minor').");
return error(Response.Status.BAD_REQUEST, "Missing 'type' parameter (either 'major','minor', or 'updatecurrent').");
}

boolean updateCurrent=false;
AuthenticatedUser user = findAuthenticatedUserOrDie();
type = type.toLowerCase();
boolean isMinor;
boolean isMinor=false;
switch (type) {
case "minor":
isMinor = true;
break;
case "major":
isMinor = false;
break;
case "updatecurrent":
if(user.isSuperuser()) {
updateCurrent=true;
} else {
return error(Response.Status.FORBIDDEN, "Only superusers can update the current version");
}
break;
default:
return error(Response.Status.BAD_REQUEST, "Illegal 'type' parameter value '" + type + "'. It needs to be either 'major' or 'minor'.");
return error(Response.Status.BAD_REQUEST, "Illegal 'type' parameter value '" + type + "'. It needs to be either 'major', 'minor', or 'updatecurrent'.");
}

Dataset ds = findDatasetOrDie(id);
if (updateCurrent) {
/*
* Note: The code here mirrors that in the
* edu.harvard.iq.dataverse.DatasetPage:updateCurrentVersion method. Any changes
* to the core logic (i.e. beyond updating the messaging about results) should
* be applied to the code there as well.
*/
String errorMsg = null;
String successMsg = null;
try {
CuratePublishedDatasetVersionCommand cmd = new CuratePublishedDatasetVersionCommand(ds, createDataverseRequest(user));
ds = commandEngine.submit(cmd);
successMsg = BundleUtil.getStringFromBundle("datasetversion.update.success");

// If configured, update archive copy as well
String className = settingsService.get(SettingsServiceBean.Key.ArchiverClassName.toString());
DatasetVersion updateVersion = ds.getLatestVersion();
AbstractSubmitToArchiveCommand archiveCommand = ArchiverUtil.createSubmitToArchiveCommand(className, createDataverseRequest(user), updateVersion);
if (archiveCommand != null) {
// Delete the record of any existing copy since it is now out of date/incorrect
updateVersion.setArchivalCopyLocation(null);
/*
* Then try to generate and submit an archival copy. Note that running this
* command within the CuratePublishedDatasetVersionCommand was causing an error:
* "The attribute [id] of class
* [edu.harvard.iq.dataverse.DatasetFieldCompoundValue] is mapped to a primary
* key column in the database. Updates are not allowed." To avoid that, and to
* simplify reporting back to the GUI whether this optional step succeeded, I've
* pulled this out as a separate submit().
*/
try {
updateVersion = commandEngine.submit(archiveCommand);
if (updateVersion.getArchivalCopyLocation() != null) {
successMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.success");
} else {
successMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.failure");
}
} catch (CommandException ex) {
successMsg = BundleUtil.getStringFromBundle("datasetversion.update.archive.failure") + " - " + ex.toString();
logger.severe(ex.getMessage());
}
}
} catch (CommandException ex) {
errorMsg = BundleUtil.getStringFromBundle("datasetversion.update.failure") + " - " + ex.toString();
logger.severe(ex.getMessage());
}
if (errorMsg != null) {
return error(Response.Status.INTERNAL_SERVER_ERROR, errorMsg);
} else {
return Response.ok(Json.createObjectBuilder()
.add("status", STATUS_OK)
.add("status_details", successMsg)
.add("data", json(ds)).build())
.type(MediaType.APPLICATION_JSON)
.build();
}
} else {
PublishDatasetResult res = execCommand(new PublishDatasetCommand(ds,
createDataverseRequest(findAuthenticatedUserOrDie()),
createDataverseRequest(user),
isMinor));
return res.isCompleted() ? ok(json(res.getDataset())) : accepted(json(res.getDataset()));

}
} catch (WrappedResponse ex) {
return ex.getResponse();
}
Expand Down