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/9555 update list curation states api call #9556

19 changes: 19 additions & 0 deletions doc/sphinx-guides/source/api/curation-labels.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,22 @@ To get the list of allowed curation labels allowed for a given Dataset
curl -H X-Dataverse-key:$API_TOKEN "$SERVER_URL/api/datasets/:persistentId/allowedCurationLabels?persistentId=$DATASET_PID"

You should expect a 200 ("OK") response with a comma-separated list of allowed labels contained in a JSON 'data' object.


Get a Report on the Curation Status of all Datasets
pdurbin marked this conversation as resolved.
Show resolved Hide resolved
---------------------------------------------------

To get a CSV file listing the curation label assigned to each Dataset with a draft version, along with the creation and last modification dates, and list of those with permissions to publish the version.

This API call is restricted to superusers.

.. code-block:: bash

export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
export SERVER_URL=https://demo.dataverse.org

Example: Get the report

curl -H X-Dataverse-key:$API_TOKEN "$SERVER_URL/api/datasets/listCurationStates"

You should expect a 200 ("OK") response with a 'datasets.status.csv' file download.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse;

import edu.harvard.iq.dataverse.DatasetVersion.VersionState;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.authorization.Permission;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
Expand Down Expand Up @@ -232,8 +233,10 @@ public List<Long> findAllUnindexed() {
}

//Used in datasets listcurationstatus API
public List<Dataset> findAllUnpublished() {
return em.createQuery("SELECT object(o) FROM Dataset o, DvObject d WHERE d.id=o.id and d.publicationDate IS null ORDER BY o.id ASC", Dataset.class).getResultList();
public List<Dataset> findAllWithDraftVersion() {
TypedQuery<Dataset> query = em.createQuery("SELECT object(d) FROM Dataset d, DatasetVersion v WHERE d.id=v.dataset.id and v.versionState=:state ORDER BY d.id ASC", Dataset.class);
query.setParameter("state", VersionState.DRAFT);
return query.getResultList();
}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -3630,7 +3630,7 @@ public Response getCurationStates(@Context ContainerRequestContext crc) throws W
BundleUtil.getStringFromBundle("datasets.api.modificationdate"),
BundleUtil.getStringFromBundle("datasets.api.curationstatus"),
String.join(",", assignees.keySet())));
for (Dataset dataset : datasetSvc.findAllUnpublished()) {
for (Dataset dataset : datasetSvc.findAllWithDraftVersion()) {
List<RoleAssignment> ras = permissionService.assignmentsOn(dataset);
curationRoles.forEach(r -> {
assignees.put(r.getAlias(), new HashSet<String>());
Expand All @@ -3640,11 +3640,12 @@ public Response getCurationStates(@Context ContainerRequestContext crc) throws W
assignees.get(ra.getRole().getAlias()).add(ra.getAssigneeIdentifier());
}
}
DatasetVersion dsv = dataset.getLatestVersion();
String name = "\"" + dataset.getCurrentName().replace("\"", "\"\"") + "\"";
String status = dataset.getLatestVersion().getExternalStatusLabel();
String status = dsv.getExternalStatusLabel();
String url = systemConfig.getDataverseSiteUrl() + dataset.getTargetUrl() + dataset.getGlobalId().asString();
String date = new SimpleDateFormat("yyyy-MM-dd").format(dataset.getCreateDate());
String modDate = new SimpleDateFormat("yyyy-MM-dd").format(dataset.getModificationTime());
String date = new SimpleDateFormat("yyyy-MM-dd").format(dsv.getCreateTime());
String modDate = new SimpleDateFormat("yyyy-MM-dd").format(dsv.getLastUpdateTime());
String hyperlink = "\"=HYPERLINK(\"\"" + url + "\"\",\"\"" + name + "\"\")\"";
List<String> sList = new ArrayList<String>();
assignees.entrySet().forEach(e -> sList.add(e.getValue().size() == 0 ? "" : String.join(";", e.getValue())));
Expand Down