From c6d42695585b1535df34c5a552dadcc0a99161af Mon Sep 17 00:00:00 2001 From: qqmyers Date: Wed, 19 Jul 2023 17:17:42 -0400 Subject: [PATCH] Revert "guides updates, release note" This reverts commit 36c9be561509ec6ed380d2c25778be870999edd8. Revert "no need to delete since we aren't using the null/unset val now" This reverts commit a0ac9e3ce23d6ae94ffff8f21de9ac2b901790a4. Revert "add second setting" This reverts commit 694482339a677e93e81ed89c965618269a163110. Revert "check collection-level setting" This reverts commit 4d6ea3e309c9ebb1b7fefea4004e82cbc66eea8f. Revert "flip to default being false" This reverts commit 14e59ca01ca7aaf72aff17d2fd8bc7b5e2b64cb5. Revert "check PID setting in create dataverse command" This reverts commit 33f994d7a278f462825cb2b0e3b42e38cb229759. Revert "also only sleep when reigstering in this call" This reverts commit d9f8e8abed1f9393c3aeb6e3194cd3faadc6db06. Revert "update docs" This reverts commit dc5d000fd79f52a02fcf654a1dd1d8b0427b04bf. Revert "require superuser and for :FilePIDsEnabled to be set to allow changes" This reverts commit 3e9262feeec593f4b92caf6d65d8befaf689d053. Revert "don't mint file PIDs in collections where they are not allowed" This reverts commit aef24bbed5ab436ca2bceb15acfe04006e145244. --- .../8889-2-filepids-in-collections-changes.md | 5 --- .../source/admin/dataverses-datasets.rst | 9 ++--- doc/sphinx-guides/source/api/native-api.rst | 2 +- .../source/installation/config.rst | 31 +++-------------- .../edu/harvard/iq/dataverse/api/Admin.java | 33 +++++++------------ .../harvard/iq/dataverse/api/Dataverses.java | 6 ---- .../importer/filesystem/FileRecordWriter.java | 5 +-- .../command/impl/CreateDataverseCommand.java | 4 --- .../settings/SettingsServiceBean.java | 6 +--- .../iq/dataverse/util/SystemConfig.java | 2 +- ...5.13.0.3__8889-change-filepids-default.sql | 3 -- .../edu/harvard/iq/dataverse/api/FilesIT.java | 18 +++------- 12 files changed, 29 insertions(+), 95 deletions(-) delete mode 100644 doc/release-notes/8889-2-filepids-in-collections-changes.md delete mode 100644 src/main/resources/db/migration/V5.13.0.3__8889-change-filepids-default.sql diff --git a/doc/release-notes/8889-2-filepids-in-collections-changes.md b/doc/release-notes/8889-2-filepids-in-collections-changes.md deleted file mode 100644 index 32bf824a455..00000000000 --- a/doc/release-notes/8889-2-filepids-in-collections-changes.md +++ /dev/null @@ -1,5 +0,0 @@ -The default for whether PIDs are registerd for files or not is now false. For those who had file PIDs enabled by default, updating to this release will add the :FilePIDsEnabled = true setting to maintain your existing functionality. - -It is now possible to allow File PIDs to be enabled/disabled per collection. See the [:AllowEnablingFilePIDsPerCollection](https://guides.dataverse.org/en/latest/installation/config.html#filepidsenabled) section of the Configuration guide for details. - -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. \ No newline at end of file diff --git a/doc/sphinx-guides/source/admin/dataverses-datasets.rst b/doc/sphinx-guides/source/admin/dataverses-datasets.rst index e61ad453557..92e01578f71 100644 --- a/doc/sphinx-guides/source/admin/dataverses-datasets.rst +++ b/doc/sphinx-guides/source/admin/dataverses-datasets.rst @@ -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:: @@ -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 diff --git a/doc/sphinx-guides/source/api/native-api.rst b/doc/sphinx-guides/source/api/native-api.rst index 27720369c09..ccf172eb84e 100644 --- a/doc/sphinx-guides/source/api/native-api.rst +++ b/doc/sphinx-guides/source/api/native-api.rst @@ -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 diff --git a/doc/sphinx-guides/source/installation/config.rst b/doc/sphinx-guides/source/installation/config.rst index 74e483c4f0d..ca17fe09c15 100644 --- a/doc/sphinx-guides/source/installation/config.rst +++ b/doc/sphinx-guides/source/installation/config.rst @@ -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: @@ -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: @@ -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: diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Admin.java b/src/main/java/edu/harvard/iq/dataverse/api/Admin.java index 02e8fc89ce3..45fb5480577 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Admin.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Admin.java @@ -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 { @@ -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); @@ -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"); @@ -1582,7 +1567,11 @@ 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()); @@ -1590,7 +1579,6 @@ public Response registerDataFileAll(@Context ContainerRequestContext crc) { 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."); @@ -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"); @@ -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()); diff --git a/src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java b/src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java index 20dc5e99bac..70199c64fa4 100644 --- a/src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java +++ b/src/main/java/edu/harvard/iq/dataverse/api/Dataverses.java @@ -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: diff --git a/src/main/java/edu/harvard/iq/dataverse/batch/jobs/importer/filesystem/FileRecordWriter.java b/src/main/java/edu/harvard/iq/dataverse/batch/jobs/importer/filesystem/FileRecordWriter.java index 195ed57bd43..291396b4d33 100644 --- a/src/main/java/edu/harvard/iq/dataverse/batch/jobs/importer/filesystem/FileRecordWriter.java +++ b/src/main/java/edu/harvard/iq/dataverse/batch/jobs/importer/filesystem/FileRecordWriter.java @@ -358,8 +358,9 @@ private DataFile createPackageDataFile(List 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)); diff --git a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDataverseCommand.java b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDataverseCommand.java index 3efefe90681..cece4230eed 100644 --- a/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDataverseCommand.java +++ b/src/main/java/edu/harvard/iq/dataverse/engine/command/impl/CreateDataverseCommand.java @@ -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); diff --git a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java index ead0ac3bd39..d1ed3191556 100644 --- a/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java +++ b/src/main/java/edu/harvard/iq/dataverse/settings/SettingsServiceBean.java @@ -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 diff --git a/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java b/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java index b9459e748bf..45f7f396783 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java @@ -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(); } diff --git a/src/main/resources/db/migration/V5.13.0.3__8889-change-filepids-default.sql b/src/main/resources/db/migration/V5.13.0.3__8889-change-filepids-default.sql deleted file mode 100644 index 22eca6b0986..00000000000 --- a/src/main/resources/db/migration/V5.13.0.3__8889-change-filepids-default.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO setting(content, lang, name) VALUES - ('true', '', ':FilePIDsEnabled') - ON CONFLICT DO NOTHING; diff --git a/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java b/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java index f53c6bfc0be..43dc1381221 100644 --- a/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java +++ b/src/test/java/edu/harvard/iq/dataverse/api/FilesIT.java @@ -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); @@ -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: @@ -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); - } + } }