Skip to content

Commit 67e9971

Browse files
committed
Merge branch 'develop' into 10517-dataset-types #10517
2 parents 19e3e51 + 7d4d534 commit 67e9971

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+297
-148
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Search API (/api/search) response will now include publicationStatuses in the Json response as long as the list is not empty
2+
3+
Example:
4+
```javascript
5+
"items": [
6+
{
7+
"name": "Darwin's Finches",
8+
...
9+
"publicationStatuses": [
10+
"Unpublished",
11+
"Draft"
12+
],
13+
(etc, etc)
14+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
New API endpoint "dataverses/{identifier}/userPermissions" for obtaining the user permissions on a dataverse.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Rust API client library
2+
3+
An API client library for the Rust programming language is now available at https://github.com/gdcc/rust-dataverse and has been added to the [list of client libraries](https://dataverse-guide--10758.org.readthedocs.build/en/10758/api/client-libraries.html) in the API Guide. See also #10758.

doc/sphinx-guides/source/api/client-libraries.rst

+7
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,10 @@ Ruby
7878
https://github.com/libis/dataverse_api is a Ruby gem for Dataverse APIs. It is registered as a library on Rubygems (https://rubygems.org/search?query=dataverse).
7979

8080
The gem is created and maintained by the LIBIS team (https://www.libis.be) at the University of Leuven (https://www.kuleuven.be).
81+
82+
Rust
83+
----
84+
85+
https://github.com/gdcc/rust-dataverse
86+
87+
The Rust Dataverse client is a comprehensive crate designed for seamless interaction with the Dataverse API. It facilitates essential operations such as collection, dataset, and file management. Additionally, the crate includes a user-friendly command-line interface (CLI) that brings the full functionality of the library to the command line. This project is actively maintained by `Jan Range <https://github.com/jr-1991>`_.

doc/sphinx-guides/source/api/native-api.rst

+23
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,29 @@ The fully expanded example above (without environment variables) looks like this
678678
679679
Note: You must have "Edit Dataverse" permission in the given Dataverse to invoke this endpoint.
680680

681+
Get User Permissions on a Dataverse
682+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
683+
684+
This API call returns the permissions that the calling user has on a particular dataverse.
685+
686+
In particular, the user permissions that this API call checks, returned as booleans, are the following:
687+
688+
* Can add a dataverse
689+
* Can add a dataset
690+
* Can view the unpublished dataverse
691+
* Can edit the dataverse
692+
* Can manage the dataverse permissions
693+
* Can publish the dataverse
694+
* Can delete the dataverse
695+
696+
.. code-block:: bash
697+
698+
export API_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
699+
export SERVER_URL=https://demo.dataverse.org
700+
export ID=root
701+
702+
curl -H "X-Dataverse-key: $API_TOKEN" -X GET "$SERVER_URL/api/dataverses/$ID/userPermissions"
703+
681704
.. _create-dataset-command:
682705

683706
Create a Dataset in a Dataverse Collection

doc/sphinx-guides/source/api/search.rst

+16
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ https://demo.dataverse.org/api/search?q=trees
114114
"identifier_of_dataverse":"dvbe69f5e1",
115115
"name_of_dataverse":"dvbe69f5e1",
116116
"citation":"Finch, Fiona; Spruce, Sabrina; Poe, Edgar Allen; Mulligan, Hercules, 2019, \"Darwin's Finches\", https://doi.org/10.70122/FK2/MB5VGR, Root, V3",
117+
"publicationStatuses": [
118+
"Published"
119+
],
117120
"storageIdentifier":"file://10.70122/FK2/MB5VGR",
118121
"subjects":[
119122
"Astronomy and Astrophysics",
@@ -207,6 +210,9 @@ In this example, ``show_relevance=true`` matches per field are shown. Available
207210
"published_at":"2016-05-10T12:57:45Z",
208211
"citationHtml":"Finch, Fiona, 2016, \"Darwin's Finches\", <a href=\"http://dx.doi.org/10.5072/FK2/G2VPE7\" target=\"_blank\">http://dx.doi.org/10.5072/FK2/G2VPE7</a>, Root Dataverse, V1",
209212
"citation":"Finch, Fiona, 2016, \"Darwin's Finches\", http://dx.doi.org/10.5072/FK2/G2VPE7, Root Dataverse, V1",
213+
"publicationStatuses": [
214+
"Published"
215+
],
210216
"matches":[
211217
{
212218
"authorName":{
@@ -297,6 +303,9 @@ The above example ``fq=publicationStatus:Published`` retrieves only "RELEASED" v
297303
"identifier_of_dataverse": "rahman",
298304
"name_of_dataverse": "mdmizanur rahman Dataverse collection",
299305
"citation": "Finch, Fiona, 2019, \"Darwin's Finches\", https://doi.org/10.70122/FK2/GUAS41, Demo Dataverse, V1",
306+
"publicationStatuses": [
307+
"Published"
308+
],
300309
"storageIdentifier": "file://10.70122/FK2/GUAS41",
301310
"subjects": [
302311
"Medicine, Health and Life Sciences"
@@ -330,6 +339,9 @@ The above example ``fq=publicationStatus:Published`` retrieves only "RELEASED" v
330339
"identifier_of_dataverse": "demo",
331340
"name_of_dataverse": "Demo Dataverse",
332341
"citation": "Finch, Fiona, 2020, \"Darwin's Finches\", https://doi.org/10.70122/FK2/7ZXYRH, Demo Dataverse, V1",
342+
"publicationStatuses": [
343+
"Published"
344+
],
333345
"storageIdentifier": "file://10.70122/FK2/7ZXYRH",
334346
"subjects": [
335347
"Medicine, Health and Life Sciences"
@@ -386,6 +398,10 @@ The above example ``metadata_fields=citation:*`` returns under "metadataBlocks"
386398
"identifier_of_dataverse": "Sample_data",
387399
"name_of_dataverse": "Sample Data",
388400
"citation": "Métropole, 2021, \"JDD avec GeoJson 2021-07-13T10:23:46.409Z\", https://doi.org/10.5072/FK2/GIWCKB, Root, DRAFT VERSION",
401+
"publicationStatuses": [
402+
"Unpublished",
403+
"Draft"
404+
],
389405
"storageIdentifier": "file://10.5072/FK2/GIWCKB",
390406
"subjects": [
391407
"Other"

doc/sphinx-guides/source/contributor/code.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The primary codebase and issue tracker for Dataverse is <https://github.com/IQSS
2020
- <https://github.com/IQSS/dataverse-client-javascript> (TypeScript)
2121
- <https://github.com/gdcc/dataverse-previewers> (Javascript)
2222
- <https://github.com/gdcc/pyDataverse> (Python)
23+
- <https://github.com/gdcc/rust-dataverse> (Rust)
2324
- <https://github.com/gdcc/dataverse-ansible> (Ansible)
2425
- <https://github.com/gdcc/dv-metrics> (Javascript)
2526

doc/sphinx-guides/source/contributor/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ If you speak multiple languages, you are very welcome to help us translate Datav
4343

4444
## Code
4545

46-
Dataverse is open source and we love code contributions. Developers are not limited to the main Dataverse code in this git repo. We have projects in C, C++, Go, Java, Javascript, Julia, PHP, Python, R, Ruby, TypeScript and more. To get started, please see the following pages:
46+
Dataverse is open source and we love code contributions. Developers are not limited to the main Dataverse code in this git repo. We have projects in C, C++, Go, Java, Javascript, Julia, PHP, Python, R, Ruby, Rust, TypeScript and more. To get started, please see the following pages:
4747

4848
```{toctree}
4949
:maxdepth: 1

src/main/java/edu/harvard/iq/dataverse/DataCitation.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.io.OutputStream;
1616
import java.io.OutputStreamWriter;
1717
import java.io.Writer;
18+
import java.nio.charset.StandardCharsets;
1819
import java.text.SimpleDateFormat;
1920
import java.util.ArrayList;
2021
import java.util.Date;
@@ -253,7 +254,7 @@ public String toBibtexString() {
253254

254255
public void writeAsBibtexCitation(OutputStream os) throws IOException {
255256
// Use UTF-8
256-
Writer out = new BufferedWriter(new OutputStreamWriter(os, "utf-8"));
257+
Writer out = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
257258
if(getFileTitle() !=null && isDirect()) {
258259
out.write("@incollection{");
259260
} else {
@@ -317,7 +318,7 @@ public String toRISString() {
317318

318319
public void writeAsRISCitation(OutputStream os) throws IOException {
319320
// Use UTF-8
320-
Writer out = new BufferedWriter(new OutputStreamWriter(os, "utf-8"));
321+
Writer out = new BufferedWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
321322
out.write("Provider: " + publisher + "\r\n");
322323
out.write("Content: text/plain; charset=\"utf-8\"" + "\r\n");
323324
// Using type "DATA" - see https://github.com/IQSS/dataverse/issues/4816

src/main/java/edu/harvard/iq/dataverse/Shib.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.lang3.StringUtils;
2020

2121
import java.io.IOException;
22+
import java.nio.charset.StandardCharsets;
2223
import java.sql.Timestamp;
2324
import java.util.ArrayList;
2425
import java.util.Arrays;
@@ -458,9 +459,9 @@ private String getRequiredValueFromAssertion(String key) throws Exception {
458459
if (attributeValue.isEmpty()) {
459460
throw new Exception(key + " was empty");
460461
}
461-
if(systemConfig.isShibAttributeCharacterSetConversionEnabled()) {
462-
attributeValue= new String( attributeValue.getBytes("ISO-8859-1"), "UTF-8");
463-
}
462+
if (systemConfig.isShibAttributeCharacterSetConversionEnabled()) {
463+
attributeValue= new String( attributeValue.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
464+
}
464465
String trimmedValue = attributeValue.trim();
465466
logger.fine("The SAML assertion for \"" + key + "\" (required) was \"" + attributeValue + "\" and was trimmed to \"" + trimmedValue + "\".");
466467
return trimmedValue;

src/main/java/edu/harvard/iq/dataverse/api/Access.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ private DataFile findDataFileOrDieWrapper(String fileId){
286286
@GET
287287
@AuthRequired
288288
@Path("datafile/{fileId:.+}")
289-
@Produces({"application/xml"})
289+
@Produces({"application/xml","*/*"})
290290
public Response datafile(@Context ContainerRequestContext crc, @PathParam("fileId") String fileId, @QueryParam("gbrecs") boolean gbrecs, @Context UriInfo uriInfo, @Context HttpHeaders headers, @Context HttpServletResponse response) /*throws NotFoundException, ServiceUnavailableException, PermissionDeniedException, AuthorizationRequiredException*/ {
291291

292292
// check first if there's a trailing slash, and chop it:

src/main/java/edu/harvard/iq/dataverse/api/Admin.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565

6666
import java.io.InputStream;
6767
import java.io.StringReader;
68+
import java.nio.charset.StandardCharsets;
6869
import java.util.Map;
6970
import java.util.Map.Entry;
7071
import java.util.logging.Level;
@@ -1155,7 +1156,7 @@ public void write(OutputStream os) throws IOException,
11551156
os.write(",\n".getBytes());
11561157
}
11571158

1158-
os.write(output.build().toString().getBytes("UTF8"));
1159+
os.write(output.build().toString().getBytes(StandardCharsets.UTF_8));
11591160

11601161
if (!wroteObject) {
11611162
wroteObject = true;
@@ -1269,7 +1270,7 @@ public void write(OutputStream os) throws IOException,
12691270
os.write(",\n".getBytes());
12701271
}
12711272

1272-
os.write(output.build().toString().getBytes("UTF8"));
1273+
os.write(output.build().toString().getBytes(StandardCharsets.UTF_8));
12731274

12741275
if (!wroteObject) {
12751276
wroteObject = true;

src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java

+24
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public class Dataverses extends AbstractApiBean {
113113

114114
@EJB
115115
SwordServiceBean swordService;
116+
117+
@EJB
118+
PermissionServiceBean permissionService;
116119

117120
@POST
118121
@AuthRequired
@@ -1653,4 +1656,25 @@ public Response linkDataverse(@Context ContainerRequestContext crc, @PathParam("
16531656
}
16541657
}
16551658

1659+
@GET
1660+
@AuthRequired
1661+
@Path("{identifier}/userPermissions")
1662+
public Response getUserPermissionsOnDataverse(@Context ContainerRequestContext crc, @PathParam("identifier") String dvIdtf) {
1663+
Dataverse dataverse;
1664+
try {
1665+
dataverse = findDataverseOrDie(dvIdtf);
1666+
} catch (WrappedResponse wr) {
1667+
return wr.getResponse();
1668+
}
1669+
User requestUser = getRequestUser(crc);
1670+
JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
1671+
jsonObjectBuilder.add("canAddDataverse", permissionService.userOn(requestUser, dataverse).has(Permission.AddDataverse));
1672+
jsonObjectBuilder.add("canAddDataset", permissionService.userOn(requestUser, dataverse).has(Permission.AddDataset));
1673+
jsonObjectBuilder.add("canViewUnpublishedDataverse", permissionService.userOn(requestUser, dataverse).has(Permission.ViewUnpublishedDataverse));
1674+
jsonObjectBuilder.add("canEditDataverse", permissionService.userOn(requestUser, dataverse).has(Permission.EditDataverse));
1675+
jsonObjectBuilder.add("canManageDataversePermissions", permissionService.userOn(requestUser, dataverse).has(Permission.ManageDataversePermissions));
1676+
jsonObjectBuilder.add("canPublishDataverse", permissionService.userOn(requestUser, dataverse).has(Permission.PublishDataverse));
1677+
jsonObjectBuilder.add("canDeleteDataverse", permissionService.userOn(requestUser, dataverse).has(Permission.DeleteDataverse));
1678+
return ok(jsonObjectBuilder);
1679+
}
16561680
}

src/main/java/edu/harvard/iq/dataverse/authorization/providers/builtin/PasswordEncryption.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package edu.harvard.iq.dataverse.authorization.providers.builtin;
22

3-
import java.io.UnsupportedEncodingException;
3+
import java.nio.charset.StandardCharsets;
44
import java.security.MessageDigest;
55
import java.security.NoSuchAlgorithmException;
66
import org.apache.commons.lang3.RandomStringUtils;
@@ -36,13 +36,13 @@ public interface Algorithm {
3636
public String encrypt(String plainText) {
3737
try {
3838
MessageDigest md = MessageDigest.getInstance("SHA");
39-
md.update(plainText.getBytes("UTF-8"));
39+
md.update(plainText.getBytes(StandardCharsets.UTF_8));
4040
byte[] raw = md.digest();
4141
//String hash = Base64.encodeToString(raw, true);
4242
String hash = Base64.getEncoder().encodeToString(raw);
4343
return hash;
4444

45-
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
45+
} catch (NoSuchAlgorithmException e) {
4646
throw new RuntimeException(e);
4747
}
4848
}

src/main/java/edu/harvard/iq/dataverse/dataaccess/TabularSubsetGenerator.java

-14
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,16 @@
2020

2121
package edu.harvard.iq.dataverse.dataaccess;
2222

23-
import edu.harvard.iq.dataverse.DataFile;
24-
import edu.harvard.iq.dataverse.datavariable.DataVariable;
25-
26-
import java.io.BufferedInputStream;
27-
import java.io.BufferedOutputStream;
2823
import java.io.BufferedWriter;
2924
import java.io.File;
3025
import java.io.FileInputStream;
3126
import java.io.FileNotFoundException;
32-
import java.io.FileOutputStream;
3327
import java.io.FileWriter;
3428
import java.io.IOException;
3529
import java.io.InputStream;
3630
import java.util.ArrayList;
3731
import java.util.List;
3832
import java.util.Scanner;
39-
import java.util.Set;
40-
import java.math.BigDecimal;
41-
import java.math.MathContext;
42-
import java.math.RoundingMode;
43-
import java.nio.ByteBuffer;
44-
import java.nio.channels.FileChannel;
45-
import java.nio.file.Paths;
46-
import java.nio.file.StandardOpenOption;
4733
import java.util.logging.Logger;
4834
import java.util.regex.Matcher;
4935

0 commit comments

Comments
 (0)