Updated orcid external search (expanded Search)

This commit is contained in:
George Kalampokis 2020-03-27 14:34:11 +02:00
parent 4a4dd03b87
commit 9cd7e24313
4 changed files with 118 additions and 17 deletions

View File

@ -321,23 +321,43 @@ public class RemoteFetcher {
}
ObjectMapper objectMapper = new ObjectMapper();
List<Map<String, String>> values = new ArrayList<>();
Map<String, String> map = objectMapper.convertValue( reader != null ? reader.invoke(data) : data, Map.class);
if (jsonDataPath.getMergedFields() != null && !jsonDataPath.getMergedFields().isEmpty() && jsonDataPath.getMergedFieldName() != null && !jsonDataPath.getMergedFieldName().isEmpty()) {
Map<String, String> finalMap = new HashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) {
if (jsonDataPath.getMergedFields().contains(entry.getKey())) {
if (!finalMap.containsKey(jsonDataPath.getMergedFieldName())) {
finalMap.put(jsonDataPath.getMergedFieldName(), entry.getValue());
} else {
finalMap.put(jsonDataPath.getMergedFieldName(), finalMap.get(jsonDataPath.getMergedFieldName())+ " " + entry.getValue());
}
} else {
finalMap.put(entry.getKey(), entry.getValue());
}
int max = 1;
if (reader != null) {
Object invokedField = reader.invoke(data);
if (invokedField instanceof Collection) {
max = ((Collection) invokedField).size();
}
}
for (int i = 0; i< max; i++) {
Object value;
if (reader != null) {
Object invokedField = reader.invoke(data);
if (invokedField instanceof Collection) {
value = ((Collection) invokedField).toArray()[i];
} else {
value = invokedField;
}
} else {
value = data;
}
Map<String, String> map = objectMapper.convertValue(value, Map.class);
if (jsonDataPath.getMergedFields() != null && !jsonDataPath.getMergedFields().isEmpty() && jsonDataPath.getMergedFieldName() != null && !jsonDataPath.getMergedFieldName().isEmpty()) {
Map<String, String> finalMap = new HashMap<>();
for (Map.Entry<String, String> entry : map.entrySet()) {
if (jsonDataPath.getMergedFields().contains(entry.getKey())) {
if (!finalMap.containsKey(jsonDataPath.getMergedFieldName())) {
finalMap.put(jsonDataPath.getMergedFieldName(), entry.getValue());
} else {
finalMap.put(jsonDataPath.getMergedFieldName(), finalMap.get(jsonDataPath.getMergedFieldName()) + " " + entry.getValue());
}
} else {
finalMap.put(entry.getKey(), entry.getValue());
}
}
values.add(finalMap);
} else {
values.add(map);
}
values.add(finalMap);
} else {
values.add(map);
}
results = new Results(values, new HashMap<>(1, 1));
}

View File

@ -0,0 +1,44 @@
package eu.eudat.models.data.external.orcid;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "expanded-result", namespace = "http://www.orcid.org/ns/expanded-search")
public class ExpandedResult {
private String pid;
private String givenNames;
private String familyName;
public ExpandedResult(String givenNames, String familyName) {
this.givenNames = givenNames;
this.familyName = familyName;
}
public ExpandedResult() {
}
@XmlElement(name = "orcid-id", namespace = "http://www.orcid.org/ns/expanded-search")
public String getPid() {
return pid;
}
public void setPid(String pid) {
this.pid = pid;
}
@XmlElement(name = "given-names", namespace = "http://www.orcid.org/ns/expanded-search")
public String getGivenNames() {
return givenNames;
}
public void setGivenNames(String givenNames) {
this.givenNames = givenNames;
}
@XmlElement(name = "family-names", namespace = "http://www.orcid.org/ns/expanded-search")
public String getFamilyName() {
return familyName;
}
public void setFamilyName(String familyName) {
this.familyName = familyName;
}
}

View File

@ -0,0 +1,18 @@
package eu.eudat.models.data.external.orcid;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.List;
@XmlRootElement(name = "expanded-search", namespace = "http://www.orcid.org/ns/expanded-search")
public class ExpandedSearch {
List<ExpandedResult> expandedResults;
@XmlElement(name = "expanded-result", namespace = "http://www.orcid.org/ns/expanded-search")
public List<ExpandedResult> getExpandedResults() {
return expandedResults;
}
public void setExpandedResults(List<ExpandedResult> expandedResults) {
this.expandedResults = expandedResults;
}
}

View File

@ -642,7 +642,7 @@
</data>
<paginationpath>$['meta']['pagination']['page','pages','count']</paginationpath>
</urlConfig>
<urlConfig>
<!--<urlConfig>
<key>orcid</key>
<label>ORCID</label>
<ordinal>2</ordinal>
@ -679,6 +679,25 @@
</urlConfig>
</data>
<paginationpath>$['num-found']</paginationpath>
</urlConfig>-->
<urlConfig>
<key>orcid</key>
<label>ORCID</label>
<ordinal>2</ordinal>
<type>External</type>
<url>https://pub.sandbox.orcid.org/v3.0/expanded-search/?q={like}&amp;start={page}&amp;rows={pageSize}</url>
<firstPage>0</firstPage>
<contenttype>application/vnd.orcid+xml; qs=5;charset=UTF-8</contenttype>
<data>
<parse-class>eu.eudat.models.data.external.orcid.ExpandedSearch</parse-class>
<parse-field>expandedResults</parse-field>
<merge-fields>
<field>givenNames</field>
<field>familyName</field>
</merge-fields>
<merge-field-name>name</merge-field-name>
</data>
<paginationpath>$['num-found']</paginationpath>
</urlConfig>
<!-- <urlConfig>
<key>openAire</key>