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

Changes for v2 fields stored in SOLR #7043

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.orcid.core.manager.OrgDisambiguatedManager;
import org.orcid.core.messaging.JmsMessageSender;
import org.orcid.core.orgs.OrgDisambiguatedSourceType;
Expand Down Expand Up @@ -141,16 +143,25 @@ private OrgDisambiguatedSolrDocument convertEntityToDocument(OrgDisambiguatedEnt
document.setOrgDisambiguatedId(String.valueOf(entity.getId()));
document.setOrgDisambiguatedName(entity.getName());
document.setOrgDisambiguatedCity(entity.getCity());
document.setOrgDisambiguatedRegion(entity.getRegion());
if (entity.getRegion() != null)
document.setOrgDisambiguatedRegion(entity.getRegion());
if (entity.getCountry() != null)
document.setOrgDisambiguatedCountry(entity.getCountry());
document.setOrgDisambiguatedIdFromSource(entity.getSourceId());
document.setOrgDisambiguatedIdSourceType(entity.getSourceType());
document.setOrgDisambiguatedType(entity.getOrgType());
document.setOrgDisambiguatedPopularity(entity.getPopularity());
Set<String> orgNames = new HashSet<>();
orgNames.add(entity.getName());

Set<String> orgNames = getOrgNamesFromJson(entity.getNamesJson(), entity.getName());

if(entity.getLocationsJson() != null) {
document.setOrgLocationsJson(entity.getLocationsJson());
}

if(entity.getNamesJson() != null) {
document.setOrgLocationsJson(entity.getNamesJson());
}

List<OrgEntity> orgs = orgDao.findByOrgDisambiguatedId(entity.getId());
if (orgs != null) {
for (OrgEntity org : orgs) {
Expand Down Expand Up @@ -244,6 +255,8 @@ private OrgDisambiguated convertSolrDocument(OrgDisambiguatedSolrDocument doc) {
org.setDisambiguatedAffiliationIdentifier(doc.getOrgDisambiguatedId());
org.setSourceType(doc.getOrgDisambiguatedIdSourceType());
org.setSourceId(doc.getOrgDisambiguatedIdFromSource());
org.setLocationsJson(doc.getOrgLocationsJson());
org.setNamesJson(doc.getOrgNamesJson());
return org;
}

Expand Down Expand Up @@ -320,6 +333,8 @@ private OrgDisambiguated convertEntity(OrgDisambiguatedEntity orgDisambiguatedEn
org.setSourceId(orgDisambiguatedEntity.getSourceId());
org.setSourceType(orgDisambiguatedEntity.getSourceType());
org.setUrl(orgDisambiguatedEntity.getUrl());
org.setNamesJson(orgDisambiguatedEntity.getNamesJson());
org.setLocationsJson(orgDisambiguatedEntity.getLocationsJson());
Map<String, OrgDisambiguatedExternalIdentifiers> externalIdsMap = new HashMap<String, OrgDisambiguatedExternalIdentifiers>();
if (orgDisambiguatedEntity.getExternalIdentifiers() != null && !orgDisambiguatedEntity.getExternalIdentifiers().isEmpty()) {
for (OrgDisambiguatedExternalIdentifierEntity extIdEntity : orgDisambiguatedEntity.getExternalIdentifiers()) {
Expand Down Expand Up @@ -407,4 +422,25 @@ public void cleanDuplicatedExternalIdentifiersForOrgDisambiguated(OrgDisambiguat

}
}

private Set<String> getOrgNamesFromJson(String orgNamesStr, String name){
Set<String> orgNames = new HashSet<>();
orgNames.add(name);
if(orgNamesStr != null) {

//add aliases, labels, acronyms
try {
JSONArray namesArr = new JSONArray(orgNamesStr);
for(Object nameObj: namesArr) {
JSONObject nameJson = (JSONObject)nameObj;
orgNames.add(nameJson.getString("value"));
}
}
catch (Exception ex) {
LOGGER.error("ORG Disambiguated exception when parsing names json: " + orgNamesStr, ex);
}
}

return orgNames;
}
}
22 changes: 22 additions & 0 deletions orcid-core/src/main/java/org/orcid/pojo/OrgDisambiguated.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public class OrgDisambiguated implements Serializable {
public String sourceType;
public String url;
public String disambiguatedAffiliationIdentifier;
private String locationsJson;
private String namesJson;

private List<OrgDisambiguatedExternalIdentifiers> orgDisambiguatedExternalIdentifiers;

Expand Down Expand Up @@ -109,6 +111,22 @@ public void setOrgDisambiguatedExternalIdentifiers(List<OrgDisambiguatedExternal
public String getAffiliationKey() {
return (value != null ? value : "") + " " + (city != null ? city : "") + " " + (region != null ? region : "") + " " + (country != null ? country : "");
}

public String getLocationsJson() {
return locationsJson;
}

public void setLocationsJson(String locationsJson) {
this.locationsJson = locationsJson;
}

public String getNamesJson() {
return namesJson;
}

public void setNamesJson(String namesJson) {
this.namesJson = namesJson;
}

public Map<String, String> toMap() {
HashMap<String, String> datum = new HashMap<String, String>();
Expand All @@ -123,10 +141,14 @@ public Map<String, String> toMap() {
datum.put("countryForDisplay", this.getCountryForDisplay());
datum.put("disambiguatedAffiliationIdentifier", this.getDisambiguatedAffiliationIdentifier());
datum.put("affiliationKey", this.getAffiliationKey());
datum.put("locationJson", this.getLocationsJson());
datum.put("namesJson", this.getNamesJson());
return datum;
}

public String toString() {
return this.toMap().toString();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public class OrgDisambiguatedSolrDocument implements Serializable {
@Field(SolrConstants.ORG_CHOSEN_BY_MEMBER)
private boolean isOrgChosenByMember;

@Field(SolrConstants.ORG_NAMES_JSON)
private String orgNamesJson;

@Field(SolrConstants.ORG_LOCATIONS_JSON)
private String orgLocationsJson;

public String getOrgDisambiguatedId() {
return orgDisambiguatedId;
}
Expand Down Expand Up @@ -163,6 +169,22 @@ public void setOrgDisambiguatedStatus(String orgDisambiguatedStatus) {
this.orgDisambiguatedStatus = orgDisambiguatedStatus;
}

public String getOrgNamesJson() {
return orgNamesJson;
}

public void setOrgNamesJson(String orgNamesJson) {
this.orgNamesJson = orgNamesJson;
}

public String getOrgLocationsJson() {
return orgLocationsJson;
}

public void setOrgLocationsJson(String orgLocationsJson) {
this.orgLocationsJson = orgLocationsJson;
}

@Override
public int hashCode() {
final int prime = 31;
Expand All @@ -180,6 +202,8 @@ public int hashCode() {
result = prime * result + ((orgDisambiguatedStatus == null) ? 0 : orgDisambiguatedStatus.hashCode());
result = prime * result + ((orgDisambiguatedType == null) ? 0 : orgDisambiguatedType.hashCode());
result = prime * result + ((orgNames == null) ? 0 : orgNames.hashCode());
result = prime * result + ((orgNamesJson == null) ? 0 : orgNamesJson.hashCode());
result = prime * result + ((orgLocationsJson == null) ? 0 : orgLocationsJson.hashCode());
return result;
}

Expand Down Expand Up @@ -251,6 +275,17 @@ public boolean equals(Object obj) {
return false;
} else if (!orgNames.equals(other.orgNames))
return false;
if (orgLocationsJson == null) {
if (other.orgLocationsJson != null)
return false;
} else if (!orgLocationsJson.equals(other.orgLocationsJson))
return false;
if (orgNamesJson == null) {
if (other.orgNamesJson != null)
return false;
} else if (!orgNamesJson.equals(other.orgNamesJson))
return false;
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class SolrConstants {
public static final String ORG_DISAMBIGUATED_POPULARITY = "org-disambiguated-popularity";
public static final String ORG_DEFINED_FUNDING_TYPE = "org-defined-funding-type";
public static final String ORG_CHOSEN_BY_MEMBER = "org-chosen-by-member";
public static final String ORG_LOCATIONS_JSON = "org-locations-json";
public static final String ORG_NAMES_JSON = "org-names-json";
public static final String ORG_NAMES = "org-names";
public static final String IS_FUNDING_ORG = "is-funding-org";
public static final String DYNAMIC_SELF = "-self";
Expand Down
4 changes: 4 additions & 0 deletions solr-config/cores/org/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@
multiValued="false" />
<field name="org-disambiguated-status" type="string" indexed="false" stored="false"
multiValued="false" />
<field name="org-locations-json" type="string" indexed="true" stored="true"
multiValued="false" />
<field name="org-names-json" type="string" indexed="true" stored="true"
multiValued="false" />

<uniqueKey>org-disambiguated-id</uniqueKey>

Expand Down
Loading