-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #534 from wcmc-its/Enclose-email-in-quotes
Update EmailRetrievalStrategy.java
- Loading branch information
Showing
1 changed file
with
29 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,38 +51,38 @@ public String getRetrievalStrategyName() { | |
/** | ||
* Concatenate email strings with " or ". | ||
*/ | ||
|
||
private String constructEmailQuery(Identity identity) { | ||
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) { | ||
|
||
// Below is code from Apache's StringUtils class, modified to remove null checks. | ||
Iterator<String> iterator = identity.getEmails().iterator(); | ||
|
||
final String first = iterator.next().replace(',', '.'); | ||
if (!iterator.hasNext()) { | ||
return first; | ||
} | ||
|
||
// two or more elements | ||
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings. | ||
if (first != null) { | ||
buf.append(first); | ||
} | ||
|
||
while (iterator.hasNext()) { | ||
buf.append(" OR "); | ||
final String obj = iterator.next(); | ||
|
||
// data cleaning: sometimes emails would have ',' instead of '.' | ||
// i.e. ([email protected],edu) | ||
// replace ',' with '.' | ||
buf.append(obj.replace(',', '.')); | ||
} | ||
return buf.toString(); | ||
} else { | ||
return null; | ||
} | ||
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) { | ||
|
||
// Initialize the iterator for the email set | ||
Iterator<String> iterator = identity.getEmails().iterator(); | ||
|
||
// Enclose the first email in double quotes | ||
final String first = "\"" + iterator.next().replace(',', '.') + "\""; | ||
if (!iterator.hasNext()) { | ||
return first; | ||
} | ||
|
||
// For multiple emails, build the query string with double quotes | ||
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings. | ||
buf.append(first); | ||
|
||
while (iterator.hasNext()) { | ||
buf.append(" OR "); | ||
final String obj = iterator.next(); | ||
|
||
// Replace any commas with dots and enclose in double quotes | ||
buf.append("\"" + obj.replace(',', '.') + "\""); | ||
} | ||
return buf.toString(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
|
||
|
||
@Override | ||
protected List<PubMedQueryType> buildQuery(Identity identity, Map<IdentityNameType, Set<AuthorName>> identityNames) { | ||
List<PubMedQueryType> pubMedQueries = new ArrayList<PubMedQueryType>(); | ||
|