Skip to content

Commit

Permalink
Revert "guides updates, release note"
Browse files Browse the repository at this point in the history
This reverts commit 36c9be5.

Revert "no need to delete since we aren't using the null/unset val now"

This reverts commit a0ac9e3.

Revert "add second setting"

This reverts commit 6944823.

Revert "check collection-level setting"

This reverts commit 4d6ea3e.

Revert "flip to default being false"

This reverts commit 14e59ca.

Revert "check PID setting in create dataverse command"

This reverts commit 33f994d.

Revert "also only sleep when reigstering in this call"

This reverts commit d9f8e8a.

Revert "update docs"

This reverts commit dc5d000.

Revert "require superuser and for :FilePIDsEnabled to be set to allow changes"

This reverts commit 3e9262f.

Revert "don't mint file PIDs in collections where they are not allowed"

This reverts commit aef24bb.
  • Loading branch information
qqmyers committed Jul 19, 2023
1 parent 36c9be5 commit c6d4269
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 95 deletions.
5 changes: 0 additions & 5 deletions doc/release-notes/8889-2-filepids-in-collections-changes.md

This file was deleted.

9 changes: 3 additions & 6 deletions doc/sphinx-guides/source/admin/dataverses-datasets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,15 @@ In the following example, the database id of the file is 42::

export FILE_ID=42
curl "http://localhost:8080/api/admin/$FILE_ID/registerDataFile"
This method will return a FORBIDDEN response if minting of file PIDs is not enabled for the collection the file is in. (Note that it is possible to have it enabled for a specific collection, even when it is disabled for the Dataverse installation as a whole. See :ref:`collection-attributes-api` in the Native API Guide.)

Mint PIDs for all unregistered published files in the specified collection
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following API will register the PIDs for all the yet unregistered published files in the datasets **directly within the collection** specified by its alias.::
The following API will register the PIDs for all the yet unregistered published files in the datasets **directly within the collection** specified by its alias::

curl "http://localhost:8080/api/admin/registerDataFiles/{collection_alias}"

It will not attempt to register the datafiles in its sub-collections, so this call will need to be repeated on any sub-collections where files need to be registered as well.
File-level PID registration must be enabled on the collection. (Note that it is possible to have it enabled for a specific collection, even when it is disabled for the Dataverse installation as a whole. See :ref:`collection-attributes-api` in the Native API Guide.)
It will not attempt to register the datafiles in its sub-collections, so this call will need to be repeated on any sub-collections where files need to be registered as well. File-level PID registration must be enabled on the collection. (Note that it is possible to have it enabled for a specific collection, even when it is disabled for the Dataverse installation as a whole. See :ref:`collection-attributes-api` in the Native API Guide.)

This API will sleep for 1 second between registration calls by default. A longer sleep interval can be specified with an optional ``sleep=`` parameter::

Expand All @@ -174,7 +171,7 @@ This API will sleep for 1 second between registration calls by default. A longer
Mint PIDs for ALL unregistered files in the database
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The following API will attempt to register the PIDs for all the published files in your instance, in collections that allow file PIDs, that do not yet have them::
The following API will attempt to register the PIDs for all the published files in your instance that do not yet have them::

curl http://localhost:8080/api/admin/registerDataFileAll

Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx-guides/source/api/native-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ The following attributes are supported:
* ``name`` Name
* ``description`` Description
* ``affiliation`` Affiliation
* ``filePIDsEnabled`` ("true" or "false") Restricted to use by superusers and only when the :ref:`:AllowEnablingFilePIDsPerCollection <:AllowEnablingFilePIDsPerCollection>` setting is true. Enables or disables registration of file-level PIDs in datasets within the collection (overriding the instance-wide setting).
* ``filePIDsEnabled`` ("true" or "false") Enables or disables registration of file-level PIDs in datasets within the collection (overriding the instance-wide setting).


Datasets
Expand Down
31 changes: 5 additions & 26 deletions doc/sphinx-guides/source/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ this provider.
- :ref:`:Shoulder <:Shoulder>`
- :ref:`:IdentifierGenerationStyle <:IdentifierGenerationStyle>` (optional)
- :ref:`:DataFilePIDFormat <:DataFilePIDFormat>` (optional)
- :ref:`:FilePIDsEnabled <:FilePIDsEnabled>` (optional, defaults to false)
- :ref:`:FilePIDsEnabled <:FilePIDsEnabled>` (optional, defaults to true)

.. _pids-handle-configuration:

Expand Down Expand Up @@ -297,7 +297,7 @@ Here are the configuration options for PermaLinks:
- :ref:`:Shoulder <:Shoulder>`
- :ref:`:IdentifierGenerationStyle <:IdentifierGenerationStyle>` (optional)
- :ref:`:DataFilePIDFormat <:DataFilePIDFormat>` (optional)
- :ref:`:FilePIDsEnabled <:FilePIDsEnabled>` (optional, defaults to false)
- :ref:`:FilePIDsEnabled <:FilePIDsEnabled>` (optional, defaults to true)

.. _auth-modes:

Expand Down Expand Up @@ -2775,35 +2775,14 @@ timestamps.
:FilePIDsEnabled
++++++++++++++++

Toggles publishing of file-level PIDs for the entire installation. By default this setting is absent and Dataverse Software assumes it to be false. If enabled, the registration will be performed asynchronously (in the background) during publishing of a dataset.
Toggles publishing of file-level PIDs for the entire installation. By default this setting is absent and Dataverse Software assumes it to be true. If enabled, the registration will be performed asynchronously (in the background) during publishing of a dataset.

It is possible to override the installation-wide setting for specific collections, but only if it is set to true or false (and not left undefined). For example, registration of PIDs for files can be enabled in a specific collection when it is disabled instance-wide. Or it can be disabled in specific collections where it is enabled by default. See :ref:`collection-attributes-api` for details.

To enable file-level PIDs for the entire installation::

``curl -X PUT -d 'true' http://localhost:8080/api/admin/settings/:FilePIDsEnabled``


If you don't want to register file-based PIDs for your entire installation, but do want to allow them to be enabled for a given collection set:
If you don't want to register file-based PIDs for your installation, set:

``curl -X PUT -d 'false' http://localhost:8080/api/admin/settings/:FilePIDsEnabled``

.. _:AllowEnablingFilePIDsPerCollection:

:AllowEnablingFilePIDsPerCollection
+++++++++++++++++++++++++++++++++++

Toggles whether superusers can change the File PIDs policy per collection. publishing of file-level PIDs for the entire installation. By default this setting is absent and Dataverse Software assumes it to be false. If enabled, the registration will be performed asynchronously (in the background) during publishing of a dataset.

For example, registration of PIDs for files can be enabled in a specific collection when it is disabled instance-wide. Or it can be disabled in specific collections where it is enabled by default. See :ref:`collection-attributes-api` for details.

To enable setting file-level PIDs per collection::

``curl -X PUT -d 'true' http://localhost:8080/api/admin/settings/:AllowEnablingFilePIDsPerCollection``


When :AllowEnablingFilePIDsPerCollection is true, setting File PIDs to be enabled/disabled for a given collection can be done via the Native API - see :ref:`collection-attributes-api` in the Native API Guide.

It is possible to override the installation-wide setting for specific collections. For example, registration of PIDs for files can be enabled in a specific collection when it is disabled instance-wide. Or it can be disabled in specific collections where it is enabled by default. See :ref:`collection-attributes-api` for details.

.. _:IndependentHandleService:

Expand Down
33 changes: 11 additions & 22 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1514,9 +1514,6 @@ public Response registerDataFile(@Context ContainerRequestContext crc, @PathPara
User u = getRequestUser(crc);
DataverseRequest r = createDataverseRequest(u);
DataFile df = findDataFileOrDie(id);
if(!systemConfig.isFilePIDsEnabledForCollection(df.getOwner().getOwner())) {
return forbidden("PIDs are not enabled for this file's collection.");
}
if (df.getIdentifier() == null || df.getIdentifier().isEmpty()) {
execCommand(new RegisterDvObjectCommand(r, df));
} else {
Expand All @@ -1540,18 +1537,11 @@ public Response registerDataFileAll(@Context ContainerRequestContext crc) {
Integer alreadyRegistered = 0;
Integer released = 0;
Integer draft = 0;
Integer skipped = 0;
logger.info("Starting to register: analyzing " + count + " files. " + new Date());
logger.info("Only unregistered, published files will be registered.");
for (DataFile df : fileService.findAll()) {
try {
if ((df.getIdentifier() == null || df.getIdentifier().isEmpty())) {
if(!systemConfig.isFilePIDsEnabledForCollection(df.getOwner().getOwner())) {
skipped++;
if (skipped % 100 == 0) {
logger.info(skipped + " of " + count + " files not in collections that allow file PIDs. " + new Date());
}
}
if (df.isReleased()) {
released++;
User u = getRequestAuthenticatedUserOrDie(crc);
Expand All @@ -1561,11 +1551,6 @@ public Response registerDataFileAll(@Context ContainerRequestContext crc) {
if (successes % 100 == 0) {
logger.info(successes + " of " + count + " files registered successfully. " + new Date());
}
try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warning("Interrupted Exception when attempting to execute Thread.sleep()!");
}
} else {
draft++;
logger.info(draft + " of " + count + " files not yet published");
Expand All @@ -1582,15 +1567,18 @@ public Response registerDataFileAll(@Context ContainerRequestContext crc) {
logger.info("Unexpected Exception: " + e.getMessage());
}


try {
Thread.sleep(1000);
} catch (InterruptedException ie) {
logger.warning("Interrupted Exception when attempting to execute Thread.sleep()!");
}
}
logger.info("Final Results:");
logger.info(alreadyRegistered + " of " + count + " files were already registered. " + new Date());
logger.info(draft + " of " + count + " files are not yet published. " + new Date());
logger.info(released + " of " + count + " unregistered, published files to register. " + new Date());
logger.info(successes + " of " + released + " unregistered, published files registered successfully. "
+ new Date());
logger.info(skipped + " of " + count + " files not in collections that allow file PIDs. " + new Date());

return ok("Datafile registration complete." + successes + " of " + released
+ " unregistered, published files registered successfully.");
Expand Down Expand Up @@ -1645,11 +1633,6 @@ public Response registerDataFilesInCollection(@Context ContainerRequestContext c
if (countSuccesses % 100 == 0) {
logger.info(countSuccesses + " out of " + count + " files registered successfully. " + new Date());
}
try {
Thread.sleep(sleepInterval * 1000);
} catch (InterruptedException ie) {
logger.warning("Interrupted Exception when attempting to execute Thread.sleep()!");
}
} else {
countDrafts++;
logger.fine(countDrafts + " out of " + count + " files not yet published");
Expand All @@ -1665,6 +1648,12 @@ public Response registerDataFilesInCollection(@Context ContainerRequestContext c
} catch (Exception e) {
logger.info("Unexpected Exception: " + e.getMessage());
}

try {
Thread.sleep(sleepInterval * 1000);
} catch (InterruptedException ie) {
logger.warning("Interrupted Exception when attempting to execute Thread.sleep()!");
}
}

logger.info(countAlreadyRegistered + " out of " + count + " files were already registered. " + new Date());
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java
Original file line number Diff line number Diff line change
Expand Up @@ -636,12 +636,6 @@ public Response updateAttribute(@Context ContainerRequestContext crc, @PathParam
break;
*/
case "filePIDsEnabled":
if(!user.isSuperuser()) {
return forbidden("You must be a superuser to change this setting");
}
if(settingsService.isTrueForKey(SettingsServiceBean.Key.AllowEnablingFilePIDsPerCollection, false)) {
return forbidden("File PIDs are not enabled on this server");
}
collection.setFilePIDsEnabled(parseBooleanOrDie(value));
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ private DataFile createPackageDataFile(List<File> files) {
dataset.getLatestVersion().getFileMetadatas().add(fmd);
fmd.setDatasetVersion(dataset.getLatestVersion());

if (commandEngine.getContext().systemConfig().isFilePIDsEnabledForCollection(dataset.getOwner())) {

String isFilePIDsEnabled = commandEngine.getContext().settings().getValueForKey(SettingsServiceBean.Key.FilePIDsEnabled, "true"); //default value for file PIDs is 'true'
if ("true".contentEquals( isFilePIDsEnabled )) {

GlobalIdServiceBean idServiceBean = GlobalIdServiceBean.getBean(packageFile.getProtocol(), commandEngine.getContext());
if (packageFile.getIdentifier() == null || packageFile.getIdentifier().isEmpty()) {
packageFile.setIdentifier(idServiceBean.generateDataFileIdentifier(packageFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ public Dataverse execute(CommandContext ctxt) throws CommandException {
if (ctxt.dataverses().findByAlias(created.getAlias()) != null) {
throw new IllegalCommandException("A dataverse with alias " + created.getAlias() + " already exists", this);
}

if(created.getFilePIDsEnabled()!=null && !ctxt.settings().isTrueForKey(SettingsServiceBean.Key.AllowEnablingFilePIDsPerCollection, false)) {
throw new IllegalCommandException("File PIDs cannot be enabled per collection", this);
}

// Save the dataverse
Dataverse managedDv = ctxt.dataverses().save(created);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,11 +595,7 @@ Whether Harvesting (OAI) service is enabled
* True/false(default) option deciding whether the dataset file table display should include checkboxes
* allowing users to dynamically turn folder and category ordering on/off.
*/
AllowUserManagementOfOrder,
/*
* True/false(default) option deciding whether file PIDs can be enabled per collection - using the Dataverse/collection set attribute API call.
*/
AllowEnablingFilePIDsPerCollection
AllowUserManagementOfOrder
;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ public boolean isFilePIDsEnabledForCollection(Dataverse collection) {
// hasn't been explicitly enabled, therefore we presume that it is
// subject to how the registration is configured for the
// entire instance:
return settingsService.isTrueForKey(SettingsServiceBean.Key.FilePIDsEnabled, false);
return settingsService.isTrueForKey(SettingsServiceBean.Key.FilePIDsEnabled, true);
}
thisCollection = thisCollection.getOwner();
}
Expand Down

This file was deleted.

18 changes: 4 additions & 14 deletions src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2025,14 +2025,7 @@ public void testDeleteFile() {
@Test
public void testFilePIDsBehavior() {
// Create user
Response createUser = UtilIT.createRandomUser();
String apiToken = UtilIT.getApiTokenFromResponse(createUser);
String username = UtilIT.getUsernameFromResponse(createUser);
Response toggleSuperuser = UtilIT.makeSuperUser(username);
toggleSuperuser.then().assertThat()
.statusCode(OK.getStatusCode());
try {
UtilIT.enableSetting(SettingsServiceBean.Key.FilePIDsEnabled);
String apiToken = createUserGetToken();

// Create Dataverse
String collectionAlias = createDataverseGetAlias(apiToken);
Expand Down Expand Up @@ -2071,14 +2064,14 @@ public void testFilePIDsBehavior() {
assertNotNull("The file did not get a persistent identifier assigned (check that file PIDs are enabled instance-wide!)", origFilePersistentId);

// Now change the file PIDs registration configuration for the collection:
UtilIT.enableSetting(SettingsServiceBean.Key.AllowEnablingFilePIDsPerCollection);

Response changeAttributeResp = UtilIT.setCollectionAttribute(collectionAlias, "filePIDsEnabled", "false", apiToken);

// ... And do the whole thing with creating another dataset with a file:

datasetId = createDatasetGetId(collectionAlias, apiToken);
addResponse = UtilIT.uploadFileViaNative(datasetId.toString(), pathToFile, apiToken);
addResponse.then().assertThat().statusCode(OK.getStatusCode());
addResponse.then().assertThat().statusCode(OK.getStatusCode());
Long newFileId = JsonPath.from(addResponse.body().asString()).getLong("data.files[0].dataFile.id");

// And publish this dataset:
Expand All @@ -2096,9 +2089,6 @@ public void testFilePIDsBehavior() {
msg(fileInfoResponseString);

org.junit.Assert.assertEquals("The file was NOT supposed to be issued a PID", "", JsonPath.from(fileInfoResponseString).getString("data.dataFile.persistentId"));
} finally {
UtilIT.deleteSetting(SettingsServiceBean.Key.FilePIDsEnabled);
UtilIT.deleteSetting(SettingsServiceBean.Key.AllowEnablingFilePIDsPerCollection);
}

}
}

0 comments on commit c6d4269

Please sign in to comment.