Skip to content

Commit 0cc74bc

Browse files
paulalbert1mrj4001
authored andcommitted
Update EmailRetrievalStrategy.java
1 parent dd525c3 commit 0cc74bc

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/main/java/reciter/xml/retriever/pubmed/EmailRetrievalStrategy.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,38 @@ public String getRetrievalStrategyName() {
5151
/**
5252
* Concatenate email strings with " or ".
5353
*/
54+
5455
private String constructEmailQuery(Identity identity) {
55-
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) {
56-
57-
// Below is code from Apache's StringUtils class, modified to remove null checks.
58-
Iterator<String> iterator = identity.getEmails().iterator();
59-
60-
final String first = iterator.next().replace(',', '.');
61-
if (!iterator.hasNext()) {
62-
return first;
63-
}
64-
65-
// two or more elements
66-
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings.
67-
if (first != null) {
68-
buf.append(first);
69-
}
70-
71-
while (iterator.hasNext()) {
72-
buf.append(" OR ");
73-
final String obj = iterator.next();
74-
75-
// data cleaning: sometimes emails would have ',' instead of '.'
76-
// i.e. ([email protected],edu)
77-
// replace ',' with '.'
78-
buf.append(obj.replace(',', '.'));
79-
}
80-
return buf.toString();
81-
} else {
82-
return null;
83-
}
56+
if (identity.getEmails() != null && !identity.getEmails().isEmpty()) {
57+
58+
// Initialize the iterator for the email set
59+
Iterator<String> iterator = identity.getEmails().iterator();
60+
61+
// Enclose the first email in double quotes
62+
final String first = "\"" + iterator.next().replace(',', '.') + "\"";
63+
if (!iterator.hasNext()) {
64+
return first;
65+
}
66+
67+
// For multiple emails, build the query string with double quotes
68+
final StringBuilder buf = new StringBuilder(30); // 30 is approx length of 2 email strings.
69+
buf.append(first);
70+
71+
while (iterator.hasNext()) {
72+
buf.append(" OR ");
73+
final String obj = iterator.next();
74+
75+
// Replace any commas with dots and enclose in double quotes
76+
buf.append("\"" + obj.replace(',', '.') + "\"");
77+
}
78+
return buf.toString();
79+
} else {
80+
return null;
81+
}
8482
}
8583

84+
85+
8686
@Override
8787
protected List<PubMedQueryType> buildQuery(Identity identity, Map<IdentityNameType, Set<AuthorName>> identityNames) {
8888
List<PubMedQueryType> pubMedQueries = new ArrayList<PubMedQueryType>();

0 commit comments

Comments
 (0)