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
Datasets API extension for the SPA #9592
Changes from all commits
2ef9297
4a622a0
15a47b1
cedba0e
60fde0c
d89f301
16ab0e8
6e1ab82
9d9d74e
c198730
47fab3c
53edae5
6784770
f561e39
514dac6
f5653e3
c3a1cad
3ff1f19
e59043f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The following APIs have been added: | ||
|
||
- /api/datasets/summaryFieldNames | ||
- /api/datasets/privateUrlDatasetVersion/{privateUrlToken} | ||
- /api/datasets/privateUrlDatasetVersion/{privateUrlToken}/citation | ||
- /api/datasets/{datasetId}/versions/{version}/citation |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import edu.harvard.iq.dataverse.authorization.RoleAssignee; | ||
import edu.harvard.iq.dataverse.authorization.users.ApiToken; | ||
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | ||
import edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser; | ||
import edu.harvard.iq.dataverse.authorization.users.User; | ||
import edu.harvard.iq.dataverse.batch.jobs.importer.ImportMode; | ||
import edu.harvard.iq.dataverse.datacapturemodule.DataCaptureModuleUtil; | ||
|
@@ -82,6 +83,7 @@ | |
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountLoggingServiceBean.MakeDataCountEntry; | ||
import edu.harvard.iq.dataverse.metrics.MetricsUtil; | ||
import edu.harvard.iq.dataverse.makedatacount.MakeDataCountUtil; | ||
import edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean; | ||
import edu.harvard.iq.dataverse.settings.SettingsServiceBean; | ||
import edu.harvard.iq.dataverse.settings.SettingsServiceBean.Key; | ||
import edu.harvard.iq.dataverse.util.ArchiverUtil; | ||
|
@@ -236,6 +238,9 @@ public class Datasets extends AbstractApiBean { | |
@EJB | ||
DatasetVersionServiceBean datasetversionService; | ||
|
||
@Inject | ||
PrivateUrlServiceBean privateUrlService; | ||
|
||
/** | ||
* Used to consolidate the way we parse and handle dataset versions. | ||
* @param <T> | ||
|
@@ -3849,4 +3854,62 @@ public Response getExternalToolDVParams(@Context ContainerRequestContext crc, | |
return wr.getResponse(); | ||
} | ||
} | ||
|
||
@GET | ||
@Path("summaryFieldNames") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started a thread in Slack about being consistent in how we expose database settings: https://iqss.slack.com/archives/C010LA04BCG/p1686603802872139 This might be fine but we should make an active decision because we'll be doing this a lot for the SPA. It needs to know how the backend is configured. |
||
public Response getDatasetSummaryFieldNames() { | ||
String customFieldNames = settingsService.getValueForKey(SettingsServiceBean.Key.CustomDatasetSummaryFields); | ||
String[] fieldNames = DatasetUtil.getDatasetSummaryFieldNames(customFieldNames); | ||
JsonArrayBuilder fieldNamesArrayBuilder = Json.createArrayBuilder(); | ||
for (String fieldName : fieldNames) { | ||
fieldNamesArrayBuilder.add(fieldName); | ||
} | ||
return ok(fieldNamesArrayBuilder); | ||
} | ||
|
||
@GET | ||
@Path("privateUrlDatasetVersion/{privateUrlToken}") | ||
public Response getPrivateUrlDatasetVersion(@PathParam("privateUrlToken") String privateUrlToken) { | ||
PrivateUrlUser privateUrlUser = privateUrlService.getPrivateUrlUserFromToken(privateUrlToken); | ||
if (privateUrlUser == null) { | ||
return notFound("Private URL user not found"); | ||
} | ||
boolean isAnonymizedAccess = privateUrlUser.hasAnonymizedAccess(); | ||
String anonymizedFieldTypeNames = settingsSvc.getValueForKey(SettingsServiceBean.Key.AnonymizedFieldTypeNames); | ||
if(isAnonymizedAccess && anonymizedFieldTypeNames == null) { | ||
throw new NotAcceptableException("Anonymized Access not enabled"); | ||
} | ||
DatasetVersion dsv = privateUrlService.getDraftDatasetVersionFromToken(privateUrlToken); | ||
if (dsv == null || dsv.getId() == null) { | ||
return notFound("Dataset version not found"); | ||
} | ||
JsonObjectBuilder responseJson; | ||
if (isAnonymizedAccess) { | ||
List<String> anonymizedFieldTypeNamesList = new ArrayList<>(Arrays.asList(anonymizedFieldTypeNames.split(",\\s"))); | ||
responseJson = json(dsv, anonymizedFieldTypeNamesList); | ||
} else { | ||
responseJson = json(dsv); | ||
} | ||
return ok(responseJson); | ||
} | ||
|
||
@GET | ||
@Path("privateUrlDatasetVersion/{privateUrlToken}/citation") | ||
public Response getPrivateUrlDatasetVersionCitation(@PathParam("privateUrlToken") String privateUrlToken) { | ||
PrivateUrlUser privateUrlUser = privateUrlService.getPrivateUrlUserFromToken(privateUrlToken); | ||
if (privateUrlUser == null) { | ||
return notFound("Private URL user not found"); | ||
} | ||
DatasetVersion dsv = privateUrlService.getDraftDatasetVersionFromToken(privateUrlToken); | ||
return (dsv == null || dsv.getId() == null) ? notFound("Dataset version not found") | ||
: ok(dsv.getCitation(true, privateUrlUser.hasAnonymizedAccess())); | ||
} | ||
|
||
@GET | ||
@AuthRequired | ||
@Path("{id}/versions/{versionId}/citation") | ||
public Response getDatasetVersionCitation(@Context ContainerRequestContext crc, @PathParam("id") String datasetId, @PathParam("versionId") String versionId, @Context UriInfo uriInfo, @Context HttpHeaders headers) { | ||
return response(req -> ok( | ||
getDatasetVersionOrDie(req, versionId, findDatasetOrDie(datasetId), uriInfo, headers).getCitation(true, false)), getRequestUser(crc)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just putting this here the top but this PR needs: