Search in sources :

Example 1 with Iso3166Country

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;
}
Also used : OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country)

Example 2 with Iso3166Country

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());
}
Also used : Instant(java.time.Instant) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) StringJoiner(java.util.StringJoiner)

Example 3 with Iso3166Country

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++;
        }
    }
}
Also used : OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Date(java.util.Date) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 4 with Iso3166Country

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++;
        }
    });
}
Also used : Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Date(java.util.Date) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 5 with Iso3166Country

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);
        }
    }
}
Also used : SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Country(org.orcid.jaxb.model.message.Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) AddressEntity(org.orcid.persistence.jpa.entities.AddressEntity) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.message.FuzzyDate) PublicationDate(org.orcid.jaxb.model.message.PublicationDate) DeactivationDate(org.orcid.jaxb.model.message.DeactivationDate)

Aggregations

Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)12 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)7 Date (java.util.Date)5 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 StringJoiner (java.util.StringJoiner)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1