Skip to content

Commit

Permalink
Merge pull request #10521 from GlobalDataverseCommunityConsortium/IQS…
Browse files Browse the repository at this point in the history
…S/10516_fix_perma-legacy_support

IQSS/10516 fix perma legacy support
  • Loading branch information
ofahimIQSS authored Jan 15, 2025
2 parents 802df48 + 554adfa commit 6f964a3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/release-notes/10516_legacy_permalink_config_fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support for legacy configuration of a PermaLink PID provider, e.g. using the :Protocol,:Authority, and :Shoulder settings, is fixed.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ private void loadProviders() {
passphrase);
break;
case "perma":
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookup();
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookupOptional().orElse(SystemConfig.getDataverseSiteUrlStatic());
legacy = new PermaLinkPidProvider("legacy", "legacy", authority, shoulder,
identifierGenerationStyle, dataFilePidFormat, "", "", baseUrl,
PermaLinkPidProvider.SEPARATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.harvard.iq.dataverse.GlobalId;
import edu.harvard.iq.dataverse.pidproviders.doi.AbstractDOIProvider;
import edu.harvard.iq.dataverse.pidproviders.handle.HandlePidProvider;
import edu.harvard.iq.dataverse.pidproviders.perma.PermaLinkPidProvider;
import edu.harvard.iq.dataverse.util.BundleUtil;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -252,7 +253,12 @@ public static void clearPidProviders() {
* Get a PidProvider by protocol/authority/shoulder.
*/
public static PidProvider getPidProvider(String protocol, String authority, String shoulder) {
return getPidProvider(protocol, authority, shoulder, AbstractPidProvider.SEPARATOR);
switch(protocol) {
case PermaLinkPidProvider.PERMA_PROTOCOL:
return getPidProvider(protocol, authority, shoulder, PermaLinkPidProvider.SEPARATOR);
default:
return getPidProvider(protocol, authority, shoulder, AbstractPidProvider.SEPARATOR);
}
}

public static PidProvider getPidProvider(String protocol, String authority, String shoulder, String separator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,4 +500,49 @@ public void testLegacyConfig() throws IOException {
assertEquals(pid1String, pid2.asString());
assertEquals("legacy", pid2.getProviderId());
}

//Tests support for legacy Perma provider - see #10516
@Test
@JvmSetting(key = JvmSettings.LEGACY_PERMALINK_BASEURL, value = "http://localhost:8080/")
public void testLegacyPermaConfig() throws IOException {
MockitoAnnotations.openMocks(this);
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Shoulder)).thenReturn("FK2");
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Protocol)).thenReturn(PermaLinkPidProvider.PERMA_PROTOCOL);
Mockito.when(settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Authority)).thenReturn("PermaTest");

String protocol = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Protocol);
String authority = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Authority);
String shoulder = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.Shoulder);

//Code mirrors the relevant part of PidProviderFactoryBean
if (protocol != null && authority != null && shoulder != null) {
// This line is different than in PidProviderFactoryBean because here we've
// already added the unmanaged providers, so we can't look for null
if (!PidUtil.getPidProvider(protocol, authority, shoulder).canManagePID()) {
PidProvider legacy = null;
// Try to add a legacy provider
String identifierGenerationStyle = settingsServiceBean
.getValueForKey(SettingsServiceBean.Key.IdentifierGenerationStyle, "random");
String dataFilePidFormat = settingsServiceBean.getValueForKey(SettingsServiceBean.Key.DataFilePIDFormat,
"DEPENDENT");
String baseUrl = JvmSettings.LEGACY_PERMALINK_BASEURL.lookupOptional().orElse(SystemConfig.getDataverseSiteUrlStatic());
legacy = new PermaLinkPidProvider("legacy", "legacy", authority, shoulder,
identifierGenerationStyle, dataFilePidFormat, "", "", baseUrl,
PermaLinkPidProvider.SEPARATOR);
if (legacy != null) {
// Not testing parts that require this bean
legacy.setPidProviderServiceBean(null);
PidUtil.addToProviderList(legacy);
}
} else {
System.out.println("Legacy PID provider settings found - ignored since a provider for the same protocol, authority, shoulder has been registered");
}

}
//Is a perma PID with the default "" separator recognized?
String pid1String = "perma:PermaTestFK2ABCDEF";
GlobalId pid2 = PidUtil.parseAsGlobalID(pid1String);
assertEquals(pid1String, pid2.asString());
assertEquals("legacy", pid2.getProviderId());
}
}

0 comments on commit 6f964a3

Please sign in to comment.