Search in sources :

Example 11 with Iso3166Country

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

the class LoadRinggoldDataTest method setupInitialMocks.

private void setupInitialMocks() {
    when(mockOrgDisambiguatedDao.findBySourceIdAndSourceType(anyString(), eq("RINGGOLD"))).thenAnswer(new Answer<OrgDisambiguatedEntity>() {

        @Override
        public OrgDisambiguatedEntity answer(InvocationOnMock invocation) throws Throwable {
            Long ringgoldId = Long.valueOf((String) invocation.getArgument(0));
            if (ringgoldId < 1L || ringgoldId > 4L) {
                return null;
            }
            OrgDisambiguatedEntity entity = new OrgDisambiguatedEntity();
            // 1000, 2000, 3000, 4000
            entity.setId(ringgoldId * 1000);
            entity.setSourceId(String.valueOf(ringgoldId));
            entity.setSourceType("RINGGOLD");
            OrgDisambiguatedExternalIdentifierEntity extId1, extId2;
            Set<OrgDisambiguatedExternalIdentifierEntity> extIds;
            switch(String.valueOf(ringgoldId)) {
                case "1":
                    entity.setName("1. Name");
                    entity.setCountry(Iso3166Country.US);
                    entity.setCity("City#1");
                    entity.setRegion("State#1");
                    entity.setOrgType("type/1");
                    entity.setSourceParentId(null);
                    entity.setStatus(null);
                    extId1 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId1.setId(1L);
                    extId1.setOrgDisambiguated(entity);
                    extId1.setIdentifier("1");
                    extId1.setIdentifierType("ISNI");
                    extId2 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId2.setId(2L);
                    extId2.setOrgDisambiguated(entity);
                    extId2.setIdentifier("2");
                    extId2.setIdentifierType("IPED");
                    extIds = new HashSet<>();
                    extIds.add(extId1);
                    extIds.add(extId2);
                    entity.setExternalIdentifiers(extIds);
                    break;
                case "2":
                    entity.setName("2. Name");
                    entity.setCountry(Iso3166Country.CR);
                    entity.setCity("City#2");
                    entity.setRegion(null);
                    entity.setOrgType("type/2");
                    entity.setSourceParentId(null);
                    entity.setStatus(null);
                    extId1 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId1.setId(3L);
                    extId1.setOrgDisambiguated(entity);
                    extId1.setIdentifier("3");
                    extId1.setIdentifierType("NCES");
                    extId2 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId2.setId(4L);
                    extId2.setOrgDisambiguated(entity);
                    extId2.setIdentifier("4");
                    extId2.setIdentifierType("OFR");
                    extIds = new HashSet<>();
                    extIds.add(extId1);
                    extIds.add(extId2);
                    entity.setExternalIdentifiers(extIds);
                    break;
                case "3":
                    entity.setName("3. Name");
                    entity.setCountry(Iso3166Country.US);
                    entity.setCity("City#3");
                    entity.setRegion(null);
                    entity.setOrgType("type/3");
                    entity.setSourceParentId(null);
                    entity.setStatus(null);
                    extId1 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId1.setId(5L);
                    extId1.setOrgDisambiguated(entity);
                    extId1.setIdentifier("5");
                    extId1.setIdentifierType("ISNI");
                    extId2 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId2.setId(6L);
                    extId2.setOrgDisambiguated(entity);
                    extId2.setIdentifier("6");
                    extId2.setIdentifierType("IPED");
                    extIds = new HashSet<>();
                    extIds.add(extId1);
                    extIds.add(extId2);
                    entity.setExternalIdentifiers(extIds);
                    break;
                case "4":
                    entity.setName("4. Name");
                    entity.setCountry(Iso3166Country.CR);
                    entity.setCity("City#4");
                    entity.setRegion("State#4");
                    entity.setOrgType("type/4");
                    entity.setSourceParentId("1");
                    entity.setStatus(null);
                    extId1 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId1.setId(7L);
                    extId1.setOrgDisambiguated(entity);
                    extId1.setIdentifier("7");
                    extId1.setIdentifierType("NCES");
                    extId2 = new OrgDisambiguatedExternalIdentifierEntity();
                    extId1.setId(8L);
                    extId2.setOrgDisambiguated(entity);
                    extId2.setIdentifier("8");
                    extId2.setIdentifierType("OFR");
                    extIds = new HashSet<>();
                    extIds.add(extId1);
                    extIds.add(extId2);
                    entity.setExternalIdentifiers(extIds);
                    break;
            }
            return entity;
        }
    });
    when(mockOrgDao.findByNameCityRegionAndCountry(anyString(), anyString(), nullable(String.class), any())).thenAnswer(new Answer<OrgEntity>() {

        @Override
        public OrgEntity answer(InvocationOnMock invocation) throws Throwable {
            String name = invocation.getArgument(0);
            String city = invocation.getArgument(1);
            String region = invocation.getArgument(2);
            Iso3166Country country = (Iso3166Country) invocation.getArgument(3);
            OrgEntity entity = new OrgEntity();
            entity.setName(name);
            entity.setCity(city);
            entity.setRegion(region);
            entity.setCountry(country);
            if ("1. Alt Name".equals(name) && "AltCity#1".equals(city) && region == null && Iso3166Country.MX.equals(country)) {
                OrgDisambiguatedEntity od = new OrgDisambiguatedEntity();
                // ringgold_id * 1000
                od.setId(Long.valueOf(1000));
                entity.setOrgDisambiguated(od);
            } else if ("2. Alt Name".equals(name) && "AltCity#2".equals(city) && region == null && Iso3166Country.BR.equals(country)) {
                OrgDisambiguatedEntity od = new OrgDisambiguatedEntity();
                // ringgold_id * 1000
                od.setId(Long.valueOf(2000));
                entity.setOrgDisambiguated(od);
            } else if ("Testing Org".equals(name)) {
            // This is an org not linked to any disambiguated org yet
            } else {
                return null;
            }
            return entity;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) Iso3166Country(org.orcid.jaxb.model.message.Iso3166Country) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) HashSet(java.util.HashSet)

Example 12 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)

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