Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
316ce03
Moved isDuplicate method to datasetutility package. No changes to ac…
raprasad Sep 21, 2016
22239b5
created WorldMapPermissionHelper.java to move checks out of the Datas…
raprasad Sep 21, 2016
b77ab37
further updates, methods for api calls and file page
raprasad Sep 21, 2016
0badbf8
For #2290 and #2465. Move twoRavens code from dataset page to separa…
raprasad Sep 21, 2016
7810af4
adding typo change before mucking up repo too much...
raprasad Sep 22, 2016
53616da
should have been in last commit with typo fix
raprasad Sep 22, 2016
26afcdf
Work in progress. Lots of debug stmts
raprasad Sep 22, 2016
eb7e5e5
almost to getting file to save. crashing on command submit. Need to…
raprasad Sep 22, 2016
eea4655
WARNING - NEEDS TO BE ADDED BACK. trying to avoid local error
raprasad Sep 23, 2016
8a02e79
proof of concept for api upload
raprasad Sep 23, 2016
e1e2e78
basic concept working. need to add form upload + refactor
raprasad Sep 23, 2016
b2b6a35
Adding attributes for #2290 -- attributes are described in #3220
raprasad Sep 26, 2016
482b359
add file replace attributes to the DataFile object #2290
raprasad Sep 26, 2016
a03417c
Part of #2290. See 13 and 14 under comment 2290#issuecomment-249582593
raprasad Sep 26, 2016
d073238
merge with develop
raprasad Sep 26, 2016
688aeb9
container class for file add/replace steps. need to test tomorrow. …
raprasad Sep 26, 2016
4bb44a6
2290- on our way. basic replace (w/o notifications) is working in Add…
raprasad Sep 27, 2016
30d6256
working on replace example #2290
raprasad Sep 27, 2016
4cf21c1
#2291 troubleshooting where file save is called from ingestServiceBea…
raprasad Sep 27, 2016
9da79c7
rootId now working via UI #2290
raprasad Sep 27, 2016
63172a0
add API test to exercise rootDataFileId #2290
pdurbin Sep 27, 2016
f101a46
Almost there. Replace working for published version but not draft. #…
raprasad Sep 28, 2016
2b25de1
basic replace working. #2290
raprasad Sep 28, 2016
ae0cadf
check for differing content types #2290. needs testing
raprasad Sep 28, 2016
b399d49
error check for running a replace on a file that is not in the most r…
raprasad Sep 28, 2016
abaab77
DatasetPage.java was missing
raprasad Sep 29, 2016
0482e11
Starting to move error messages to bundles. Prep for rest assured te…
raprasad Sep 29, 2016
51ffa62
#3387 #2290 moved add/replace error messages to bundles. api endpoin…
raprasad Oct 3, 2016
fe9c0cf
Similar. #2290 #3387 - two additional error messages moved to the bu…
raprasad Oct 3, 2016
d1a76d3
Part of #2290. starting basic ui test
raprasad Oct 3, 2016
b7ffd04
#2290 - UI to test replace functionality
raprasad Oct 4, 2016
c42887c
merging with develop for checksum change #2291
raprasad Oct 4, 2016
dc2910e
#2290 Set error if single replacement file ingests into multiple file…
raprasad Oct 6, 2016
2541ef9
#2290 working example of @scolapasta configuration for file upload vi…
raprasad Oct 6, 2016
2403cdb
#2290 - Use the FormDataBodyPart class to get the mime type of the up…
raprasad Oct 6, 2016
3831f4e
working on #2290
raprasad Oct 7, 2016
9fd2be1
2290 - serialization of DataFile and FileMetadata in order to return …
raprasad Oct 11, 2016
6d6c7dd
api endpoint for replace #2290
raprasad Oct 11, 2016
1c86f91
#2290 fix where not running 'major cleanup' when old file not in curr…
raprasad Oct 11, 2016
b94560f
#2290 for UI - break down add/replace sequence into two methods
raprasad Oct 11, 2016
573cd26
temp removed kick off of ingest until it is async. #2290
raprasad Oct 13, 2016
94e302c
add API tests for file replace and native add #2290
pdurbin Oct 13, 2016
ebef1a2
Let add/replace tests pass by making person superuser
raprasad Oct 13, 2016
6adb10e
#2290 Fix for ingest issue. Two errors: (a) API bean was incorrectly…
raprasad Oct 14, 2016
86c4210
#2290 - Restructured so Replace only requires a FileId, not a Dataset…
raprasad Oct 14, 2016
562301d
Moved add/replace API endpoints to correct paths. e.g. datasets/{id…
raprasad Oct 14, 2016
26cb18b
Fix to broken clean/build/compile on last commit #2290
raprasad Oct 14, 2016
8ba9748
#2290 json data in form param -- next try as data string
raprasad Oct 14, 2016
6577b66
#2290 replace with data in JSON under a form param
raprasad Oct 14, 2016
9ecefe0
#2290 add jsonData placeholder for 'add'
raprasad Oct 14, 2016
3546c27
get file add/replace API tests working again #2290
pdurbin Oct 14, 2016
9cbc456
remove old params from replace test util #2290
raprasad Oct 17, 2016
e5271f7
#2290 adjust api output to begin more tests. (still need to integrate…
raprasad Oct 17, 2016
646c000
put 3354-alt-checksum.sql in upgrade_v4.5.1_to_v4.6.sql #3354
pdurbin Oct 17, 2016
d784c92
Part of #2290 tests and code re-adjustments for err messages.
raprasad Oct 17, 2016
1bb50d9
test for unpublished file and bad file id #2290
raprasad Oct 17, 2016
318eaff
Merge branch '2290-api-replace' of github.com:IQSS/dataverse into 229…
raprasad Oct 17, 2016
65d924a
#2290 test. attempt to replace deleted file that was previously publ…
raprasad Oct 17, 2016
b7c976b
#2290 test. try to add same file twice
raprasad Oct 17, 2016
e7c0742
#2290 test. try to replace file w/ different content type
raprasad Oct 17, 2016
07df447
#2290 tests. remove unused packages
raprasad Oct 17, 2016
de93ffa
#2290 signatures (but not implementation) for adding optionalFilePara…
raprasad Oct 18, 2016
78de5f5
#2290, remove currently un-needed method
raprasad Oct 18, 2016
ac28819
#2290 OptionalFileParams object to use for API when adding descriptio…
raprasad Oct 18, 2016
ee5245b
#2290 changed tabularTags to fileDataTags
raprasad Oct 18, 2016
8583c6c
#2290 Add descriptiona and tags via API for add/replace.
raprasad Oct 18, 2016
8741a04
#2290 Tag fix to avoid adding duplicates
raprasad Oct 19, 2016
007dc57
Add tag labels #2290 to output json
raprasad Oct 19, 2016
dfee568
#2290 remove print statemetns
raprasad Oct 19, 2016
3d9446a
#1612 add dataset & dataverse info to API output
raprasad Oct 19, 2016
10abf73
#1612 allow persistentId use for add file
raprasad Oct 19, 2016
84ce907
#1612 documentation for adding a file
raprasad Oct 19, 2016
3f4c3a9
#1612 - allow adding file by persistent id + fixed tests
raprasad Oct 19, 2016
e199fbd
#1612 - documentation for file replace via API
raprasad Oct 19, 2016
6157d73
Merge remote-tracking branch 'origin/develop' into 1612-api-add-file
raprasad Oct 21, 2016
78f3267
Fix for #1612 multiple file upload'
raprasad Oct 24, 2016
b2dafc6
#1612 - Test updated to reflect the API returning a list of files
raprasad Oct 24, 2016
078fbd4
#1612. In anticipation of API cleanup #3358, ability to add alternat…
raprasad Oct 24, 2016
2f6570a
#1612, merge with develop
raprasad Oct 25, 2016
634029e
#1612 - remove commented out @Test decorators
raprasad Oct 25, 2016
b1421cb
#1641 - post code review. In addCategoryByName already checks for e…
raprasad Oct 26, 2016
62b98ad
#1612 - post code review. For add file API endpoint, we now have the …
raprasad Oct 26, 2016
0ab1223
#1612 - In OptionalFileParams, change 'tags' to 'categories'; also in…
raprasad Oct 26, 2016
346387e
#1612 - Adding dataFileTags for a non-tabular file now returns an err…
raprasad Oct 26, 2016
4fcab0d
#1641 Consolidate calls to UpdateDatasetCommand in step_070_run_updat…
raprasad Oct 26, 2016
df804bc
1612 - switch to checking specific permission to checking perms on a …
raprasad Oct 26, 2016
6cfc036
part of #1612 post code review. update native file API to include ta…
raprasad Oct 26, 2016
aa70f06
Bundle-ize Find Dataset Error Messages
sekmiller Oct 26, 2016
fe22488
move removeDuplicates... method to Util
sekmiller Oct 26, 2016
e39d049
#1612 - Native JSON updated--tags and categories added. New endpoint…
raprasad Oct 26, 2016
ea21a06
#1612 - removed okResponseGsonObject
raprasad Oct 26, 2016
cdec856
Merge branch '1612-api-add-file' of github.com:IQSS/dataverse into 16…
raprasad Oct 26, 2016
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
164 changes: 164 additions & 0 deletions doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,170 @@ Delete a Private URL from a dataset (if it exists)::

DELETE http://$SERVER/api/datasets/$id/privateUrl?key=$apiKey

Add a file to an existing Dataset. Description and tags are optional::

PUT http://$SERVER/api/datasets/$id/add?key=$apiKey


Example python code to add a file. This may be run by changing these parameters in the sample code:

* ``dataverse_server`` - e.g. https://dataverse.harvard.edu
* ``api_key`` - See the top of this document for a description
* ``persistentId`` - Example: ``doi:10.5072/FK2/6XACVA``
* ``dataset_id`` - Database id of the dataset

In practice, you only need one the ``dataset_id`` or the ``persistentId``. The example below shows both uses.

.. code-block:: python

from datetime import datetime
import json
import requests # http://docs.python-requests.org/en/master/

# --------------------------------------------------
# Update the 4 params below to run this code
# --------------------------------------------------
dataverse_server = 'https://your dataverse server' # no trailing slash
api_key = 'api key'
dataset_id = 1 # database id of the dataset
persistentId = 'doi:10.5072/FK2/6XACVA' # doi or hdl of the dataset

# --------------------------------------------------
# Prepare "file"
# --------------------------------------------------
file_content = 'content: %s' % datetime.now()
files = {'file': ('sample_file.txt', file_content)}

# --------------------------------------------------
# Using a "jsonData" parameter, add optional description + file tags
# --------------------------------------------------
params = dict(description='Blue skies!',
tags=['Lily', 'Rosemary', 'Jack of Hearts'])

params_as_json_string = json.dumps(params)

payload = dict(jsonData=params_as_json_string)

# --------------------------------------------------
# Add file using the Dataset's id
# --------------------------------------------------
url_dataset_id = '%s/api/datasets/%s/add?key=%s' % (dataverse_server, dataset_id, api_key)

# -------------------
# Make the request
# -------------------
print '-' * 40
print 'making request: %s' % url_dataset_id
r = requests.post(url_dataset_id, data=payload, files=files)

# -------------------
# Print the response
# -------------------
print '-' * 40
print r.json()
print r.status_code

# --------------------------------------------------
# Add file using the Dataset's persistentId (e.g. doi, hdl, etc)
# --------------------------------------------------
url_persistent_id = '%s/api/datasets/:persistentId/add?persistentId=%s&key=%s' % (dataverse_server, persistentId, api_key)

# -------------------
# Update the file content to avoid a duplicate file error
# -------------------
file_content = 'content2: %s' % datetime.now()
files = {'file': ('sample_file2.txt', file_content)}


# -------------------
# Make the request
# -------------------
print '-' * 40
print 'making request: %s' % url_persistent_id
r = requests.post(url_persistent_id, data=payload, files=files)

# -------------------
# Print the response
# -------------------
print '-' * 40
print r.json()
print r.status_code

Files
~~~~~~~~~~~

Replace an existing file where ``id`` is the Database id of the file to replace::

POST http://$SERVER/api/files/{id}/replace?key=$apiKey

Example python code to replace a file. This may be run by changing these parameters in the sample code:

* ``dataverse_server`` - e.g. https://dataverse.harvard.edu
* ``api_key`` - See the top of this document for a description
* ``file_id`` - Database id of the file to replace (returned in the GET API for a Dataset)

.. code-block:: python

from datetime import datetime
import json
import requests # http://docs.python-requests.org/en/master/

# --------------------------------------------------
# Update params below to run code
# --------------------------------------------------
dataverse_server = 'http://127.0.0.1:8080' # no trailing slash
api_key = 'some key'
file_id = 1401 # id of the file to replace

# --------------------------------------------------
# Prepare replacement "file"
# --------------------------------------------------
file_content = 'content: %s' % datetime.now()
files = {'file': ('replacement_file.txt', file_content)}

# --------------------------------------------------
# Using a "jsonData" parameter, add optional description + file tags
# --------------------------------------------------
params = dict(description='Sunset',
tags=['One', 'More', 'Cup of Coffee'])

# -------------------
# IMPORTANT: If the mimetype of the replacement file differs
# from the origina file, the replace will fail
#
# e.g. if you try to replace a ".csv" with a ".png" or something similar
#
# You can override this with a "forceReplace" parameter
# -------------------
params['forceReplace'] = True


params_as_json_string = json.dumps(params)

payload = dict(jsonData=params_as_json_string)

print 'payload', payload
# --------------------------------------------------
# Replace file using the id of the file to replace
# --------------------------------------------------
url_replace = '%s/api/v1/files/%s/replace?key=%s' % (dataverse_server, file_id, api_key)

# -------------------
# Make the request
# -------------------
print '-' * 40
print 'making request: %s' % url_replace
r = requests.post(url_replace, data=payload, files=files)

# -------------------
# Print the response
# -------------------
print '-' * 40
print r.json()
print r.status_code



Builtin Users
~~~~~~~~~~~~~

Expand Down
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,18 @@
<optional>true</optional>
<type>jar</type>
</dependency>
<!-- For API File Upload: 1 of 2 -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
</dependency>
<!-- For API File Upload: 2 of 2 -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.23.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
-- For supporting SHA1 rather than MD5 as a checksum on a per file basis #3354
ALTER TABLE datafile ADD COLUMN checksumtype character varying(255);
UPDATE datafile SET checksumtype = 'MD5';
ALTER TABLE datafile ALTER COLUMN checksumtype SET NOT NULL;
-- alternate statement for sbgrid.org and others interested in SHA-1 support
-- note that in the database we use "SHA1" (no hyphen) but the GUI will show "SHA-1"
--UPDATE datafile SET checksumtype = 'SHA1';
ALTER TABLE datafile RENAME md5 TO checksumvalue;
-- For DataFile, file replace functionality:
ALTER TABLE datafile ADD COLUMN rootdatafileid bigint default -1;
ALTER TABLE datafile ADD COLUMN previousdatafileid bigint default null;
-- For existing DataFile objects, update rootDataFileId values:
UPDATE datafile SET rootdatafileid = -1;
1 change: 1 addition & 0 deletions scripts/search/data/replace_test/003.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3
1 change: 1 addition & 0 deletions scripts/search/data/replace_test/004.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4
1 change: 1 addition & 0 deletions scripts/search/data/replace_test/005.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
43 changes: 43 additions & 0 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1427,3 +1427,46 @@ citationFrame.banner.message.here=here
citationFrame.banner.closeIcon=Close this message, go to dataset
citationFrame.banner.countdownMessage= This message will close in
citationFrame.banner.countdownMessage.seconds=seconds


# File metadata error
file.metadata.datafiletag.not_tabular=You cannot add data file tags to a non-tabular file.

# File Add/Replace operation messages
file.addreplace.error.dataset_is_null=The dataset cannot be null.
file.addreplace.error.dataset_id_is_null=The dataset ID cannot be null.
find.dataset.error.dataset_id_is_null=When accessing a dataset based on persistent id, a {0} query parameter must be present
find.dataset.error.dataset.not.found.persistentId=Dataset with persistent id {0} not found
find.dataset.error.dataset.not.found.id=Dataset with id {0} not found
find.dataset.error.dataset.not.found.bad.id=Bad dataset id number: {0}
file.addreplace.error.dataset_id_not_found=There was no dataset found for id:
file.addreplace.error.no_edit_dataset_permission=You do not have permission to edit this dataset.
file.addreplace.error.filename_is_null=The fileName cannot be null.
file.addreplace.error.file_content_type_is_null=The file content type cannot be null.
file.addreplace.error.file_input_stream_is_null=The file upload cannot be null.
file.addreplace.error.duplicate_file=This file has a duplicate already in the dataset:
file.addreplace.error.existing_file_to_replace_id_is_null=The id of the existing file to replace cannot be null
file.addreplace.error.existing_file_to_replace_not_found_by_id=Replacement file not found. There was no file found for id:
file.addreplace.error.existing_file_to_replace_is_null=The existing file to replace cannot be null
file.addreplace.error.existing_file_to_replace_not_in_dataset=The existing file to replace does not belong to this dataset
file.addreplace.error.existing_file_not_in_latest_published_version=You cannot replace a file that is not in the most recently published Dataset. (The file is unpublished or was deleted from a previous version.)
file.addreplace.error.replace.new_file_same_as_replacement=The new file contains the same content as the file to be replaced.
file.addreplace.error.replace.new_file_has_different_content_type=Warning! The new and old file have different content types.
file.addreplace.error.unpublished_file_cannot_be_replaced=You cannot replace an unpublished file. Please delete it instead of replacing it.
file.addreplace.error.ingest_create_file_err=There was an error when trying to add the new file.
file.addreplace.error.initial_file_list_empty=Sorry! An error occurred and the new file was not added.
file.addreplace.error.initial_file_list_more_than_one=You cannot replace a single file with multiple files. The file you uploaded was ingested into multiple files.
file.addreplace.error.final_file_list_empty=There are no files to add. (This error should not happen if steps called in sequence....)
file.addreplace.error.only_replace_operation=This should ONLY be called for file replace operations!!
file.addreplace.error.failed_to_remove_old_file_from_dataset=Unable to remove old file from new DatasetVersion.
file.addreplace.error.add.command_engine_error=Failed to update the dataset. Please contact the administrator. (CommandException)
file.addreplace.error.add.ejb_exception=Failed to update the dataset. Please contact the administrator. (EJBException)
file.addreplace.error.replace.command_engine_error=Failed to update the dataset. Please contact the administrator. (CommandException)
file.addreplace.error.replace.ejb_exception=Failed to update the dataset. Please contact the administrator. (EJBException)
file.addreplace.error.remove_linked_file.dataset=dataset cannot be null in removeLinkedFileFromDataset
file.addreplace.error.remove_linked_file.file=file cannot be null in removeLinkedFileFromDataset
file.addreplace.error.phase2_called_early_no_new_files=There was an error saving the dataset--no new files found.
file.addreplace.success.add=File successfully added!
file.addreplace.success.replace=File successfully replaced!
file.addreplace.error.auth=The API key is invalid.
file.addreplace.error.invalid_datafile_tag=Not a valid Tabular Tag:
Loading