-
Notifications
You must be signed in to change notification settings - Fork 534
feat: migrate personOrOrg settings to MPConfig #11485
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
Changes from 1 commit
f0296da
ad8a449
c33fd05
9a5a102
39bef7f
e37fbce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,11 @@ | ||
| package edu.harvard.iq.dataverse.util; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.logging.Logger; | ||
|
|
||
| import jakarta.json.JsonArray; | ||
| import edu.harvard.iq.dataverse.settings.JvmSettings; | ||
| import jakarta.json.JsonObject; | ||
| import jakarta.json.JsonObjectBuilder; | ||
| import jakarta.json.JsonString; | ||
|
|
||
| import edu.harvard.iq.dataverse.util.json.JsonUtil; | ||
| import edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder; | ||
|
|
||
| /** | ||
|
|
@@ -38,14 +34,6 @@ public class PersonOrOrgUtil { | |
|
|
||
| private static final Logger logger = Logger.getLogger(PersonOrOrgUtil.class.getCanonicalName()); | ||
|
|
||
| static boolean assumeCommaInPersonName = false; | ||
| static List<String> orgPhrases; | ||
|
|
||
| static { | ||
| setAssumeCommaInPersonName(Boolean.parseBoolean(System.getProperty("dataverse.personOrOrg.assumeCommaInPersonName", "false"))); | ||
| setOrgPhraseArray(System.getProperty("dataverse.personOrOrg.orgPhraseArray", null)); | ||
| } | ||
|
|
||
| /** | ||
| * This method tries to determine if a name belongs to a person or an | ||
| * organization and, if it is a person, what the given and family names are. The | ||
|
|
@@ -73,6 +61,7 @@ public static JsonObject getPersonOrOrganization(String name, boolean organizati | |
|
|
||
| boolean isOrganization = !isPerson && Organizations.getInstance().isOrganization(name); | ||
| if (!isOrganization) { | ||
| String[] orgPhrases = JvmSettings.ORG_PHRASE_ARRAY.lookupOptional(String[].class).orElse(new String[]{}); | ||
|
||
| for (String phrase : orgPhrases) { | ||
| if (name.contains(phrase)) { | ||
| isOrganization = true; | ||
|
|
@@ -99,6 +88,7 @@ public static JsonObject getPersonOrOrganization(String name, boolean organizati | |
| } | ||
|
|
||
| } else { | ||
| boolean assumeCommaInPersonName = JvmSettings.ASSUME_COMMA_IN_PERSON_NAME.lookupOptional(Boolean.class).orElse(false); | ||
| if (assumeCommaInPersonName && !isPerson) { | ||
| isOrganization = true; | ||
| } else { | ||
|
|
@@ -135,27 +125,4 @@ public static JsonObject getPersonOrOrganization(String name, boolean organizati | |
| return job.build(); | ||
|
|
||
| } | ||
|
|
||
| // Public for testing | ||
| public static void setOrgPhraseArray(String phraseArray) { | ||
| orgPhrases = new ArrayList<String>(); | ||
| if (!StringUtil.isEmpty(phraseArray)) { | ||
| try { | ||
| JsonArray phrases = JsonUtil.getJsonArray(phraseArray); | ||
| phrases.forEach(val -> { | ||
| JsonString strVal = (JsonString) val; | ||
| orgPhrases.add(strVal.getString()); | ||
| }); | ||
| } catch (Exception e) { | ||
| logger.warning("Could not parse Org phrase list"); | ||
| } | ||
| } | ||
|
|
||
| } | ||
|
|
||
| // Public for testing | ||
| public static void setAssumeCommaInPersonName(boolean assume) { | ||
| assumeCommaInPersonName = assume; | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm,
ASSUMECOMMAINPERSONNAMEis a bit hard to read. I understand you're keeping it the same as the old setting:dataverse.personOrOrg.assumeCommaInPersonName.What sort of options do we have? Can we add underscores like
ASSUME_COMMA_IN_PERSON_NAMEand still have backward compatibility? (I'm not sure if there's backward compatibility with theASSUMECOMMAINPERSONNAMEanyway.)Also, can we please have a release note snippet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now changed the names of the two settings to kebab case, which is what they should be called according to the naming conventions (https://guides.dataverse.org/en/latest/developers/configuration.html#adding-a-jvm-setting).
This means they can now be set using
DATAVERSE_PERSON_OR_ORG_ASSUME_COMMA_IN_PERSON_NAMEandDATAVERSE_PERSON_OR_ORG_ORG_PHRASE_ARRAY. (Orasadmin create-jvm-options '-Ddataverse.person-or-org.assume-comma-in-person-name=trueandasadmin create-jvm-options '-Ddataverse.person-or-org.org-phrase-array=Org,GmbH'). I've tested to confirm all of these options work.For backwards compatibility, adding an alias so that the old name
asadmin create-jvm-options '-Ddataverse.personOrOrg.assumeCommaInPersonName=true'can still be used was easy.However, for the
orgPhraseArraysetting, the expected value format has changed as well. Previously, a list like["Org","GmbH"]was expected, but now it's a list likeOrg,GmbH. Afaik it wouldn't be as easy to still support parsing the old value format. So I haven't added an alias for that option.Is it OK to drop support for the old
orgPhraseArraysetting and require admins to migrate option name + value format? Considering it's documented as an experimental setting.Also, I've just added a release note snippet that documents all this as well.