Skip to content

Commit d76a738

Browse files
committed
check if file PIDs used once, use constants - per comments
1 parent 77bd653 commit d76a738

6 files changed

Lines changed: 26 additions & 17 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ public List<Long> selectFilesWithMissingOriginalSizes() {
14631463

14641464
public String generateDataFileIdentifier(DataFile datafile, GlobalIdServiceBean idServiceBean) {
14651465
String doiIdentifierType = settingsService.getValueForKey(SettingsServiceBean.Key.IdentifierGenerationStyle, "randomString");
1466-
String doiDataFileFormat = settingsService.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
1466+
String doiDataFileFormat = settingsService.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, SystemConfig.DataFilePIDFormat.DEPENDENT.toString());
14671467

14681468
String prepend = "";
14691469
if (doiDataFileFormat.equals(SystemConfig.DataFilePIDFormat.DEPENDENT.toString())){

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/AbstractDatasetCommand.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import edu.harvard.iq.dataverse.engine.command.exception.CommandExecutionException;
1515
import edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException;
1616
import edu.harvard.iq.dataverse.util.BundleUtil;
17+
import edu.harvard.iq.dataverse.util.SystemConfig;
18+
1719
import java.sql.Timestamp;
1820
import java.util.Date;
1921
import java.util.Iterator;
@@ -231,21 +233,23 @@ protected void registerFilePidsIfNeeded(Dataset theDataset, CommandContext ctxt,
231233
GlobalIdServiceBean idServiceBean = GlobalIdServiceBean.getBean(protocol, ctxt);
232234
String currentGlobalIdProtocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, "");
233235
String currentGlobalAuthority = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Authority, "");
234-
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
236+
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, SystemConfig.DataFilePIDFormat.DEPENDENT.toString());
235237
boolean shouldRegister = ctxt.systemConfig().isFilePIDsEnabled() // We use file PIDs
236238
&& !idServiceBean.registerWhenPublished() // The provider can pre-register
237239
&&((currentGlobalIdProtocol.equals(protocol) && currentGlobalAuthority.equals(authority)) // the dataset PID is a protocol/authority Dataverse can create new PIDs in
238-
|| dataFilePIDFormat.equals("INDEPENDENT")); // or the files can use a different protocol/authority
240+
|| dataFilePIDFormat.equals(SystemConfig.DataFilePIDFormat.INDEPENDENT.toString())); // or the files can use a different protocol/authority
239241
logger.fine("IsFilePIDsEnabled: " + ctxt.systemConfig().isFilePIDsEnabled());
240242
logger.fine("RegWhenPub: " + !idServiceBean.registerWhenPublished());
241243
logger.fine("OK provider: " + ((currentGlobalIdProtocol.equals(protocol) && currentGlobalAuthority.equals(authority)) // the dataset PID is a protocol/authority Dataverse can create new PIDs in
242-
|| dataFilePIDFormat.equals("INDEPENDENT")));
244+
|| dataFilePIDFormat.equals(SystemConfig.DataFilePIDFormat.INDEPENDENT.toString())));
243245
logger.fine("Should register: " + shouldRegister);
244-
for (DataFile dataFile : theDataset.getFiles()) {
245-
logger.fine(dataFile.getId() + " is registered?: " + dataFile.isIdentifierRegistered());
246-
if (shouldRegister && !dataFile.isIdentifierRegistered()) {
247-
// pre-register a persistent id
248-
registerFileExternalIdentifier(dataFile, idServiceBean, ctxt, true);
246+
if (shouldRegister) {
247+
for (DataFile dataFile : theDataset.getFiles()) {
248+
logger.fine(dataFile.getId() + " is registered?: " + dataFile.isIdentifierRegistered());
249+
if (!dataFile.isIdentifierRegistered()) {
250+
// pre-register a persistent id
251+
registerFileExternalIdentifier(dataFile, idServiceBean, ctxt, true);
252+
}
249253
}
250254
}
251255
}

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/FinalizeDatasetPublicationCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import edu.harvard.iq.dataverse.batch.util.LoggingUtil;
3333
import edu.harvard.iq.dataverse.engine.command.Command;
3434
import edu.harvard.iq.dataverse.util.FileUtil;
35+
import edu.harvard.iq.dataverse.util.SystemConfig;
36+
3537
import java.util.concurrent.Future;
3638
import org.apache.solr.client.solrj.SolrServerException;
3739

@@ -328,7 +330,7 @@ private void publicizeExternalIdentifier(Dataset dataset, CommandContext ctxt) t
328330
try {
329331
String currentGlobalIdProtocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, "");
330332
String currentGlobalAuthority = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Authority, "");
331-
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
333+
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, SystemConfig.DataFilePIDFormat.DEPENDENT.toString());
332334
boolean isFilePIDsEnabled = ctxt.systemConfig().isFilePIDsEnabled();
333335
// We will skip trying to register the global identifiers for datafiles
334336
// if "dependent" file-level identifiers are requested, AND the naming
@@ -340,7 +342,7 @@ private void publicizeExternalIdentifier(Dataset dataset, CommandContext ctxt) t
340342
// Additionaly in 4.9.3 we have added a system variable to disable
341343
// registering file PIDs on the installation level.
342344
if (((currentGlobalIdProtocol.equals(protocol) && currentGlobalAuthority.equals(authority))
343-
|| dataFilePIDFormat.equals("INDEPENDENT"))
345+
|| dataFilePIDFormat.equals(SystemConfig.DataFilePIDFormat.INDEPENDENT.toString()))
344346
&& isFilePIDsEnabled
345347
&& dataset.getLatestVersion().getMinorVersionNumber() != null
346348
&& dataset.getLatestVersion().getMinorVersionNumber().equals((long) 0)) {

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/PublishDatasetCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import edu.harvard.iq.dataverse.privateurl.PrivateUrl;
1515
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
1616
import edu.harvard.iq.dataverse.util.BundleUtil;
17+
import edu.harvard.iq.dataverse.util.SystemConfig;
1718
import edu.harvard.iq.dataverse.workflow.Workflow;
1819
import edu.harvard.iq.dataverse.workflow.WorkflowContext.TriggerType;
1920
import java.util.Date;
@@ -109,9 +110,9 @@ public PublishDatasetResult execute(CommandContext ctxt) throws CommandException
109110
// registering file PIDs on the installation level.
110111
String currentGlobalIdProtocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, "");
111112
String currentGlobalAuthority= ctxt.settings().getValueForKey(SettingsServiceBean.Key.Authority, "");
112-
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
113+
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, SystemConfig.DataFilePIDFormat.DEPENDENT.toString());
113114
boolean registerGlobalIdsForFiles =
114-
(currentGlobalIdProtocol.equals(theDataset.getProtocol()) || dataFilePIDFormat.equals("INDEPENDENT"))
115+
(currentGlobalIdProtocol.equals(theDataset.getProtocol()) || dataFilePIDFormat.equals(SystemConfig.DataFilePIDFormat.INDEPENDENT.toString()))
115116
&& ctxt.systemConfig().isFilePIDsEnabled();
116117

117118
if ( registerGlobalIdsForFiles ){

src/main/java/edu/harvard/iq/dataverse/engine/command/impl/UpdateDvObjectPIDMetadataCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import edu.harvard.iq.dataverse.engine.command.exception.PermissionException;
1414
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
1515
import edu.harvard.iq.dataverse.util.BundleUtil;
16+
import edu.harvard.iq.dataverse.util.SystemConfig;
17+
1618
import java.sql.Timestamp;
1719
import java.util.Collections;
1820
import java.util.Date;
@@ -56,7 +58,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
5658
// When updating, we want to traverse through files even if the dataset itself
5759
// didn't need updating.
5860
String currentGlobalIdProtocol = ctxt.settings().getValueForKey(SettingsServiceBean.Key.Protocol, "");
59-
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
61+
String dataFilePIDFormat = ctxt.settings().getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, SystemConfig.DataFilePIDFormat.DEPENDENT.toString());
6062
boolean isFilePIDsEnabled = ctxt.systemConfig().isFilePIDsEnabled();
6163
// We will skip trying to update the global identifiers for datafiles if they
6264
// aren't being used.
@@ -68,7 +70,7 @@ protected void executeImpl(CommandContext ctxt) throws CommandException {
6870
if (isFilePIDsEnabled && // using file PIDs and
6971
(!(df.getIdentifier() == null || df.getIdentifier().isEmpty()) || // identifier exists, or
7072
currentGlobalIdProtocol.equals(protocol) || // right protocol to create dependent DOIs, or
71-
dataFilePIDFormat.equals("INDEPENDENT"))// or independent. TODO(pm) - check authority too
73+
dataFilePIDFormat.equals(SystemConfig.DataFilePIDFormat.INDEPENDENT.toString()))// or independent. TODO(pm) - check authority too
7274
) {
7375
doiRetString = idServiceBean.publicizeIdentifier(df);
7476
if (doiRetString) {

src/main/java/edu/harvard/iq/dataverse/util/SystemConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,8 +1014,8 @@ public Integer getUploadMethodCount(){
10141014
}
10151015
public boolean isDataFilePIDSequentialDependent(){
10161016
String doiIdentifierType = settingsService.getValueForKey(SettingsServiceBean.Key.IdentifierGenerationStyle, "randomString");
1017-
String doiDataFileFormat = settingsService.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, "DEPENDENT");
1018-
if (doiIdentifierType.equals("sequentialNumber") && doiDataFileFormat.equals("DEPENDENT")){
1017+
String doiDataFileFormat = settingsService.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat, DataFilePIDFormat.DEPENDENT.toString());
1018+
if (doiIdentifierType.equals("sequentialNumber") && doiDataFileFormat.equals(DataFilePIDFormat.DEPENDENT.toString())){
10191019
return true;
10201020
}
10211021
return false;

0 commit comments

Comments
 (0)