Search in sources :

Example 6 with Iso3166Country

use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.

the class LoadRinggoldData method processLine.

private void processLine(String[] line, Map<String, String> altNames) {
    String gpCode = line[0];
    String pCode = line[1];
    String name = line[2];
    String extName = line[3];
    if (StringUtils.isNotBlank(extName)) {
        name = extName;
    }
    String city = line[4];
    String extCity = line[5];
    if (StringUtils.isNotBlank(extCity)) {
        city = extCity;
    }
    Iso3166Country country = parseCountry(line[7]);
    String state = line[8];
    if (StringUtils.isBlank(state)) {
        state = null;
    }
    String type = line[9];
    /**
         * Look for the name in the alt names map, if there is one name, replace
         * the one found in the parents file
         */
    if (altNames != null && altNames.containsKey(pCode)) {
        if (!PojoUtil.isEmpty(altNames.get(pCode))) {
            name = altNames.get(pCode);
        }
    }
    processOrg(gpCode, pCode, name, city, state, country, type);
}
Also used : Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country)

Example 7 with Iso3166Country

use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.

the class OrgManagerImpl method getOrgEntity.

@Override
public OrgEntity getOrgEntity(Organization org) {
    String name = org.getName();
    String city = "";
    String region = "";
    Iso3166Country country = null;
    if (org.getAddress() != null) {
        city = org.getAddress().getCity();
        region = org.getAddress().getRegion();
        country = org.getAddress().getCountry();
    }
    return orgDao.findByNameCityRegionAndCountry(name, city, region, country);
}
Also used : Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country)

Example 8 with Iso3166Country

use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.

the class LoadFundRefData method createDisambiguatedOrg.

/**
 * Creates a disambiguated ORG in the org_disambiguated table
 */
private OrgDisambiguatedEntity createDisambiguatedOrg(RDFOrganization organization) {
    LOGGER.info("Creating disambiguated org {}", organization.name);
    String orgType = organization.type + (StringUtils.isEmpty(organization.subtype) ? "" : "/" + organization.subtype);
    Iso3166Country country = StringUtils.isNotBlank(organization.country) ? Iso3166Country.fromValue(organization.country) : null;
    OrgDisambiguatedEntity orgDisambiguatedEntity = new OrgDisambiguatedEntity();
    orgDisambiguatedEntity.setName(organization.name);
    orgDisambiguatedEntity.setCountry(country);
    orgDisambiguatedEntity.setCity(organization.city);
    orgDisambiguatedEntity.setRegion(organization.stateCode);
    orgDisambiguatedEntity.setOrgType(orgType);
    orgDisambiguatedEntity.setSourceId(organization.doi);
    orgDisambiguatedEntity.setSourceUrl(organization.doi);
    // Is it deprecated?
    if (!PojoUtil.isEmpty(organization.status)) {
        orgDisambiguatedEntity.setStatus(OrganizationStatus.DEPRECATED.name());
    }
    // Is it replaced?
    if (!PojoUtil.isEmpty(organization.isReplacedBy)) {
        orgDisambiguatedEntity.setSourceParentId(organization.isReplacedBy);
        orgDisambiguatedEntity.setStatus(OrganizationStatus.DEPRECATED.name());
    }
    orgDisambiguatedEntity.setSourceType(FUNDREF_SOURCE_TYPE);
    orgDisambiguatedDao.persist(orgDisambiguatedEntity);
    return orgDisambiguatedEntity;
}
Also used : OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country)

Example 9 with Iso3166Country

use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.

the class LoadFundRefData method execute.

/**
 * Executes the import process
 */
private void execute() {
    try {
        long start = System.currentTimeMillis();
        FileInputStream file = new FileInputStream(fileToLoad);
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document xmlDocument = builder.parse(file);
        // Parent node
        NodeList nodeList = (NodeList) xPath.compile(conceptsExpression).evaluate(xmlDocument, XPathConstants.NODESET);
        for (int i = 0; i < nodeList.getLength(); i++) {
            RDFOrganization rdfOrganization = getOrganization(xmlDocument, nodeList.item(i).getAttributes());
            LOGGER.info("Processing organization from RDF, doi:{}", new String[] { rdfOrganization.doi });
            // #1: Look for an existing org
            OrgDisambiguatedEntity existingEntity = findById(rdfOrganization);
            if (existingEntity != null) {
                // #2: If the name, city or region changed, update those values
                if (entityChanged(rdfOrganization, existingEntity)) {
                    existingEntity.setCity(rdfOrganization.city);
                    Iso3166Country country = StringUtils.isNotBlank(rdfOrganization.country) ? Iso3166Country.fromValue(rdfOrganization.country) : null;
                    existingEntity.setCountry(country);
                    existingEntity.setName(rdfOrganization.name);
                    String orgType = rdfOrganization.type + (StringUtils.isNotBlank(rdfOrganization.subtype) ? ('/' + rdfOrganization.subtype) : "");
                    existingEntity.setOrgType(orgType);
                    existingEntity.setRegion(rdfOrganization.stateCode);
                    existingEntity.setSourceId(rdfOrganization.doi);
                    existingEntity.setSourceType(FUNDREF_SOURCE_TYPE);
                    existingEntity.setSourceUrl(rdfOrganization.doi);
                    existingEntity.setLastModified(new Date());
                    existingEntity.setIndexingStatus(IndexingStatus.PENDING);
                    existingEntity.setStatus(rdfOrganization.status);
                    orgDisambiguatedDao.merge(existingEntity);
                    updatedOrgs += 1;
                } else if (statusChanged(rdfOrganization, existingEntity)) {
                    // If the status changed, update the status
                    existingEntity.setStatus(rdfOrganization.status);
                    existingEntity.setLastModified(new Date());
                    existingEntity.setIndexingStatus(IndexingStatus.PENDING);
                    orgDisambiguatedDao.merge(existingEntity);
                    depreciatedOrgs += 1;
                } else {
                    // Check if it is depreciated
                    if (StringUtils.isNotBlank(rdfOrganization.isReplacedBy)) {
                        if (!rdfOrganization.isReplacedBy.equals(existingEntity.getSourceParentId())) {
                            existingEntity.setSourceParentId(rdfOrganization.isReplacedBy);
                            existingEntity.setStatus(OrganizationStatus.DEPRECATED.name());
                            existingEntity.setLastModified(new Date());
                            existingEntity.setIndexingStatus(IndexingStatus.PENDING);
                            orgDisambiguatedDao.merge(existingEntity);
                            depreciatedOrgs += 1;
                        }
                    }
                }
            } else {
                // If it doesn't exists, create the new org
                createDisambiguatedOrg(rdfOrganization);
                addedDisambiguatedOrgs += 1;
            }
        }
        long end = System.currentTimeMillis();
        LOGGER.info("Time taken to process the files: {}", (end - start));
    } catch (FileNotFoundException fne) {
        LOGGER.error("Unable to read file {}", fileToLoad);
    } catch (ParserConfigurationException pce) {
        LOGGER.error("Unable to initialize the DocumentBuilder");
    } catch (IOException ioe) {
        LOGGER.error("Unable to parse document {}", fileToLoad);
    } catch (SAXException se) {
        LOGGER.error("Unable to parse document {}", fileToLoad);
    } catch (XPathExpressionException xpe) {
        LOGGER.error("XPathExpressionException {}", xpe.getMessage());
    } finally {
        LOGGER.info("Number new Disambiguated Orgs={}, Updated Orgs={}, Depreciated Orgs={}", new Object[] { addedDisambiguatedOrgs, updatedOrgs, depreciatedOrgs });
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Document(org.w3c.dom.Document) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) FileInputStream(java.io.FileInputStream) Date(java.util.Date) SAXException(org.xml.sax.SAXException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 10 with Iso3166Country

use of org.orcid.jaxb.model.message.Iso3166Country in project ORCID-Source by ORCID.

the class LoadRinggoldData method processInstitution.

private OrgDisambiguatedEntity processInstitution(JsonNode institution) {
    Integer recId = institution.get("rec_id").asInt();
    Integer ringgoldId = institution.get("ringgold_id").asInt();
    LOGGER.info("Processing ringgold_id: {} rec_id: {}", ringgoldId, recId);
    Integer parentId = institution.get("parent_ringgold_id").asInt() == 0 ? null : institution.get("parent_ringgold_id").asInt();
    String name = institution.get("name").asText();
    Iso3166Country country = Iso3166Country.fromValue(institution.get("country").asText());
    String state = institution.has("state") ? institution.get("state").asText() : null;
    String city = institution.get("city").asText();
    String type = institution.get("type").asText();
    String originalName = null;
    // Replace the name with the DN (Diacritic Name) name
    if (dnNameMap.containsKey(ringgoldId)) {
        // Save the original name
        originalName = name;
        name = dnNameMap.get(ringgoldId).get("name").asText();
    }
    OrgDisambiguatedEntity entity = orgDisambiguatedDao.findBySourceIdAndSourceType(String.valueOf(ringgoldId), RINGGOLD_SOURCE_TYPE);
    Date now = new Date();
    if (entity == null) {
        entity = new OrgDisambiguatedEntity();
        entity.setDateCreated(now);
        entity.setLastIndexedDate(now);
        entity.setCity(city);
        entity.setCountry(country);
        entity.setName(name);
        entity.setOrgType(type);
        entity.setRegion(state);
        entity.setSourceId(String.valueOf(ringgoldId));
        if (parentId != null && parentId > 0) {
            entity.setSourceParentId(String.valueOf(parentId));
        }
        entity.setSourceType(RINGGOLD_SOURCE_TYPE);
        entity.setIndexingStatus(IndexingStatus.PENDING);
        orgDisambiguatedDao.persist(entity);
        numAdded++;
    } else {
        // If the element have changed
        if (changed(entity, parentId, name, country, city, state, type)) {
            entity.setCity(city);
            entity.setCountry(country);
            entity.setLastModified(now);
            entity.setName(name);
            entity.setOrgType(type);
            entity.setRegion(state);
            entity.setIndexingStatus(IndexingStatus.REINDEX);
            orgDisambiguatedDao.merge(entity);
            numUpdated++;
        } else {
            numUnchanged++;
        }
    }
    // with the original name
    if (originalName != null) {
        generateOrganizationFromInstitutionNode(entity, originalName, country, city, state);
    }
    return entity;
}
Also used : OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) Date(java.util.Date)

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