Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IQSS/10516 fix perma legacy support #10521

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
Loading