Skip to content

Commit 6f964a3

Browse files
authored
Merge pull request #10521 from GlobalDataverseCommunityConsortium/IQSS/10516_fix_perma-legacy_support
IQSS/10516 fix perma legacy support
2 parents 802df48 + 554adfa commit 6f964a3

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Support for legacy configuration of a PermaLink PID provider, e.g. using the :Protocol,:Authority, and :Shoulder settings, is fixed.

src/main/java/edu/harvard/iq/dataverse/pidproviders/PidProviderFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void loadProviders() {
205205
passphrase);
206206
break;
207207
case "perma":
208-
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookup();
208+
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookupOptional().orElse(SystemConfig.getDataverseSiteUrlStatic());
209209
legacy = new PermaLinkPidProvider("legacy", "legacy", authority, shoulder,
210210
identifierGenerationStyle, dataFilePidFormat, "", "", baseUrl,
211211
PermaLinkPidProvider.SEPARATOR);

src/main/java/edu/harvard/iq/dataverse/pidproviders/PidUtil.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import edu.harvard.iq.dataverse.GlobalId;
44
import edu.harvard.iq.dataverse.pidproviders.doi.AbstractDOIProvider;
55
import edu.harvard.iq.dataverse.pidproviders.handle.HandlePidProvider;
6+
import edu.harvard.iq.dataverse.pidproviders.perma.PermaLinkPidProvider;
67
import edu.harvard.iq.dataverse.util.BundleUtil;
78
import java.io.IOException;
89
import java.io.InputStream;
@@ -252,7 +253,12 @@ public static void clearPidProviders() {
252253
* Get a PidProvider by protocol/authority/shoulder.
253254
*/
254255
public static PidProvider getPidProvider(String protocol, String authority, String shoulder) {
255-
return getPidProvider(protocol, authority, shoulder, AbstractPidProvider.SEPARATOR);
256+
switch(protocol) {
257+
case PermaLinkPidProvider.PERMA_PROTOCOL:
258+
return getPidProvider(protocol, authority, shoulder, PermaLinkPidProvider.SEPARATOR);
259+
default:
260+
return getPidProvider(protocol, authority, shoulder, AbstractPidProvider.SEPARATOR);
261+
}
256262
}
257263

258264
public static PidProvider getPidProvider(String protocol, String authority, String shoulder, String separator) {

src/test/java/edu/harvard/iq/dataverse/pidproviders/PidUtilTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,49 @@ public void testLegacyConfig() throws IOException {
500500
assertEquals(pid1String, pid2.asString());
501501
assertEquals("legacy", pid2.getProviderId());
502502
}
503+
504+
//Tests support for legacy Perma provider - see #10516
505+
@Test
506+
@JvmSetting(key = JvmSettings.LEGACY_PERMALINK_BASEURL, value = "http://localhost:8080/")
507+
public void testLegacyPermaConfig() throws IOException {
508+
MockitoAnnotations.openMocks(this);
509+
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Shoulder)).thenReturn("FK2");
510+
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Protocol)).thenReturn(PermaLinkPidProvider.PERMA_PROTOCOL);
511+
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Authority)).thenReturn("PermaTest");
512+
513+
String protocol = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Protocol);
514+
String authority = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Authority);
515+
String shoulder = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Shoulder);
516+
517+
//Code mirrors the relevant part of PidProviderFactoryBean
518+
if (protocol != null && authority != null && shoulder != null) {
519+
// This line is different than in PidProviderFactoryBean because here we've
520+
// already added the unmanaged providers, so we can't look for null
521+
if (!PidUtil.getPidProvider(protocol, authority, shoulder).canManagePID()) {
522+
PidProvider legacy = null;
523+
// Try to add a legacy provider
524+
String identifierGenerationStyle = settingsServiceBean
525+
.getValueForKey(SettingsServiceBean.Key.IdentifierGenerationStyle, "random");
526+
String dataFilePidFormat = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat,
527+
"DEPENDENT");
528+
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookupOptional().orElse(SystemConfig.getDataverseSiteUrlStatic());
529+
legacy = new PermaLinkPidProvider("legacy", "legacy", authority, shoulder,
530+
identifierGenerationStyle, dataFilePidFormat, "", "", baseUrl,
531+
PermaLinkPidProvider.SEPARATOR);
532+
if (legacy != null) {
533+
// Not testing parts that require this bean
534+
legacy.setPidProviderServiceBean(null);
535+
PidUtil.addToProviderList(legacy);
536+
}
537+
} else {
538+
System.out.println("Legacy PID provider settings found - ignored since a provider for the same protocol, authority, shoulder has been registered");
539+
}
540+
541+
}
542+
//Is a perma PID with the default "" separator recognized?
543+
String pid1String = "perma:PermaTestFK2ABCDEF";
544+
GlobalId pid2 = PidUtil.parseAsGlobalID(pid1String);
545+
assertEquals(pid1String, pid2.asString());
546+
assertEquals("legacy", pid2.getProviderId());
547+
}
503548
}

0 commit comments

Comments
 (0)