use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.
the class LoadFundRefData method findByDetails.
/**
* DATABASE FUNCTIONS
* */
/**
* TODO
* */
private OrgDisambiguatedEntity findByDetails(RDFOrganization org) {
Iso3166Country country = StringUtils.isBlank(org.country) ? null : Iso3166Country.valueOf(org.country);
// Find the org by name, city, country and state
OrgDisambiguatedEntity existingEntity = orgDisambiguatedDao.findByNameCityRegionCountryAndSourceType(org.name, org.stateCode, org.stateCode, country, FUNDREF_SOURCE_TYPE);
// If no match is found, try with the doi and source type
if (existingEntity == null) {
existingEntity = orgDisambiguatedDao.findBySourceIdAndSourceType(org.doi, FUNDREF_SOURCE_TYPE);
}
return existingEntity;
}
use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.
the class LoadGridData method execute.
public void execute() {
Instant start = Instant.now();
JsonNode rootNode = JsonUtils.read(fileToLoad);
ArrayNode institutes = (ArrayNode) rootNode.get("institutes");
institutes.forEach(institute -> {
String sourceId = institute.get("id").isNull() ? null : institute.get("id").asText();
// Case that should never happen
if (PojoUtil.isEmpty(sourceId)) {
LOGGER.error("Invalid institute with null id found {}", institute.toString());
}
String status = institute.get("status").isNull() ? null : institute.get("status").asText();
if ("active".equals(status)) {
String name = institute.get("name").isNull() ? null : institute.get("name").asText();
StringJoiner sj = new StringJoiner(",");
String orgType = null;
if (!institute.get("types").isNull()) {
((ArrayNode) institute.get("types")).forEach(x -> sj.add(x.textValue()));
orgType = sj.toString();
}
ArrayNode addresses = institute.get("addresses").isNull() ? null : (ArrayNode) institute.get("addresses");
String city = null;
String region = null;
Iso3166Country country = null;
if (addresses != null) {
for (JsonNode address : addresses) {
if (addresses.size() == 1 || (address.get("primary") != null && address.get("primary").asBoolean())) {
city = address.get("city").isNull() ? null : address.get("city").asText();
region = address.get("state").isNull() ? null : address.get("state").asText();
String countryCode = address.get("country_code").isNull() ? null : address.get("country_code").asText();
country = StringUtils.isBlank(countryCode) ? null : Iso3166Country.fromValue(countryCode);
}
}
}
ArrayNode urls = institute.get("links").isNull() ? null : (ArrayNode) institute.get("links");
// Use the first URL
String url = (urls != null && urls.size() > 0) ? urls.get(0).asText() : null;
// Creates or updates an institute
OrgDisambiguatedEntity entity = processInstitute(sourceId, name, country, city, region, url, orgType);
// Creates external identifiers
processExternalIdentifiers(entity, institute);
} else if ("redirected".equals(status)) {
String primaryId = institute.get("redirect").isNull() ? null : institute.get("redirect").asText();
deprecateOrg(sourceId, primaryId);
} else if ("obsolete".equals(status)) {
obsoleteOrg(sourceId);
} else {
LOGGER.error("Illegal status '" + status + "' for institute " + sourceId);
}
});
LOGGER.info("Updated orgs: {}", updatedOrgs);
LOGGER.info("New orgs: {}", addedDisambiguatedOrgs);
LOGGER.info("New external identifiers: {}", addedExternalIdentifiers);
LOGGER.info("Updated external identifiers: {}", updatedExternalIdentifiers);
LOGGER.info("Deprecated orgs: {}", deprecatedOrgs);
LOGGER.info("Obsoleted orgs: {}", obsoletedOrgs);
LOGGER.info("Time taken to process the data: {}", Duration.between(start, Instant.now()).toString());
}
use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.
the class LoadLEIData method processOrg.
/**
* Add/Update Orgs in the DB
*
* @param org
*/
public void processOrg(LEIOrganization org) {
Date now = new Date();
OrgDisambiguatedEntity existingDO = orgDisambiguatedDao.findBySourceIdAndSourceType(org.id, LEI_SOURCE_TYPE);
if (existingDO != null) {
// update
if (org.differentFrom(existingDO)) {
existingDO.setCity(org.hqAddres.city);
existingDO.setCountry(org.hqAddres.country);
existingDO.setName(org.name);
existingDO.setOrgType(org.type);
existingDO.setRegion(org.hqAddres.region);
existingDO.setUrl("https://www.gleif.org/lei/" + org.id);
existingDO.setLastModified(now);
existingDO.setIndexingStatus(IndexingStatus.PENDING);
// Is it replaced?
if (!PojoUtil.isEmpty(org.successorLEI)) {
existingDO.setSourceParentId(org.successorLEI);
existingDO.setStatus(OrganizationStatus.DEPRECATED.name());
} else // or is is simply gone
if ("INACTIVE".equals(org.status)) {
existingDO.setStatus(OrganizationStatus.OBSOLETE.name());
}
LOGGER.info("Merging LEI:" + org.id);
existingDO = orgDisambiguatedDao.merge(existingDO);
updatedDisambiguatedOrgs++;
}
} else {
// create
Iso3166Country country = org.hqAddres.country;
OrgDisambiguatedEntity orgDisambiguatedEntity = new OrgDisambiguatedEntity();
orgDisambiguatedEntity.setName(org.name);
orgDisambiguatedEntity.setCountry(country);
orgDisambiguatedEntity.setCity(org.hqAddres.city);
orgDisambiguatedEntity.setRegion(org.hqAddres.region);
orgDisambiguatedEntity.setOrgType(org.type);
orgDisambiguatedEntity.setSourceId(org.id);
orgDisambiguatedEntity.setSourceUrl("https://www.gleif.org/lei/" + org.id);
// Is it replaced?
if (!PojoUtil.isEmpty(org.successorLEI)) {
orgDisambiguatedEntity.setSourceParentId(org.successorLEI);
orgDisambiguatedEntity.setStatus(OrganizationStatus.DEPRECATED.name());
} else // or is is simply gone
if ("INACTIVE".equals(org.status)) {
orgDisambiguatedEntity.setStatus(OrganizationStatus.OBSOLETE.name());
}
orgDisambiguatedEntity.setSourceType(LEI_SOURCE_TYPE);
LOGGER.info("Creating LEI:" + org.id);
orgDisambiguatedDao.persist(orgDisambiguatedEntity);
existingDO = orgDisambiguatedEntity;
addedDisambiguatedOrgs++;
}
// Other names
for (LEIOrganization otherOrg : org.toOtherOrgs()) {
OrgEntity existingOrg = orgDao.findByAddressAndDisambiguatedOrg(otherOrg.name, otherOrg.hqAddres.city, otherOrg.hqAddres.region, otherOrg.hqAddres.country, existingDO);
if (existingOrg != null) {
// do nothing (nothing to update!)
} else {
OrgEntity newOrg = new OrgEntity();
newOrg.setDateCreated(now);
newOrg.setLastModified(now);
newOrg.setCity(otherOrg.hqAddres.city);
newOrg.setCountry(otherOrg.hqAddres.country);
newOrg.setRegion(otherOrg.hqAddres.region);
newOrg.setName(otherOrg.name);
newOrg.setOrgDisambiguated(existingDO);
LOGGER.info("Creating org LEI:" + org.id);
orgDao.persist(newOrg);
addedOrgs++;
}
}
}
use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.
the class LoadRinggoldData method generateOrganizations.
private void generateOrganizations(OrgDisambiguatedEntity disambiguatedEntity, List<JsonNode> altNames) {
Date now = new Date();
altNames.forEach(altName -> {
String name = altName.get("name").asText();
LOGGER.info("Processing organization {} for {}", name, disambiguatedEntity.getId());
String city = altName.get("city").asText();
Iso3166Country country = Iso3166Country.fromValue(altName.get("country").asText());
// Not happy with line below. Can steal from other ORG ID types.
OrgEntity existingOrg = orgDao.findByNameCityRegionAndCountry(name, city, null, country);
if (existingOrg != null) {
if (existingOrg.getOrgDisambiguated() == null) {
existingOrg.setOrgDisambiguated(disambiguatedEntity);
existingOrg.setLastModified(now);
orgDao.merge(existingOrg);
numUpdatedOrgs++;
}
} else {
OrgEntity newOrg = new OrgEntity();
newOrg.setDateCreated(now);
newOrg.setLastModified(now);
newOrg.setCity(city);
newOrg.setCountry(country);
newOrg.setName(name);
newOrg.setOrgDisambiguated(disambiguatedEntity);
orgDao.persist(newOrg);
numAddedOrgs++;
}
});
}
use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setCountry.
private void setCountry(ProfileEntity profileEntity, ContactDetails contactDetails) {
Country contactCountry = contactDetails.getAddress() != null && contactDetails.getAddress().getCountry() != null ? contactDetails.getAddress().getCountry() : null;
Iso3166Country country = contactCountry != null ? contactCountry.getValue() : null;
if (country != null) {
Set<AddressEntity> addresses = profileEntity.getAddresses();
if (addresses == null) {
addresses = new HashSet<AddressEntity>();
profileEntity.setAddresses(addresses);
}
boolean addIt = true;
// If the address exists, don't add it
for (AddressEntity address : addresses) {
if (Objects.equals(country.value(), address.getIso2Country().value())) {
addIt = false;
}
}
if (addIt) {
AddressEntity newAddress = new AddressEntity();
newAddress.setDateCreated(new Date());
// The default country is the smallest one, so, lets add this one as the biggest display index possible for the record
newAddress.setIso2Country(org.orcid.jaxb.model.common_v2.Iso3166Country.fromValue(country.value()));
newAddress.setLastModified(new Date());
newAddress.setUser(profileEntity);
newAddress.setVisibility(getDefaultVisibility(profileEntity, contactCountry.getVisibility(), OrcidVisibilityDefaults.COUNTRY_DEFAULT));
// Set source
SourceEntity source = sourceManager.retrieveSourceEntity();
setSource(source, newAddress);
newAddress.setDisplayIndex(0L);
for (AddressEntity address : addresses) address.setDisplayIndex(address.getDisplayIndex() + 1L);
addresses.add(newAddress);
}
}
}
Aggregations