Search in sources :

Example 41 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity 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 42 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class LoadRinggoldDataTest method test_EmptyDB.

@Test
public void test_EmptyDB() throws URISyntaxException {
    when(mockOrgDisambiguatedDao.findBySourceIdAndSourceType(anyString(), eq("RINGGOLD"))).thenReturn(null);
    when(mockOrgDao.findByNameCityRegionAndCountry(anyString(), anyString(), anyString(), any())).thenReturn(null);
    Path path = Paths.get(getClass().getClassLoader().getResource("ringgold/test_base/").toURI());
    File testDirectory = path.toFile();
    assertTrue(testDirectory.exists());
    loader.setDirectory(testDirectory);
    loader.execute();
    ArgumentCaptor<OrgDisambiguatedEntity> orgDisambiguatedEntityCaptor = ArgumentCaptor.forClass(OrgDisambiguatedEntity.class);
    verify(mockOrgDisambiguatedDao, times(0)).merge(any());
    verify(mockOrgDisambiguatedDao, times(4)).persist(orgDisambiguatedEntityCaptor.capture());
    List<OrgDisambiguatedEntity> newOrgDisambiguatedEntities = orgDisambiguatedEntityCaptor.getAllValues();
    assertEquals(4, newOrgDisambiguatedEntities.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false;
    for (OrgDisambiguatedEntity entity : newOrgDisambiguatedEntities) {
        assertEquals(IndexingStatus.PENDING, entity.getIndexingStatus());
        assertEquals("RINGGOLD", entity.getSourceType());
        switch(entity.getSourceId()) {
            case "1":
                assertNull(entity.getSourceParentId());
                assertEquals("1. Name", entity.getName());
                assertEquals("City#1", entity.getCity());
                assertEquals("State#1", entity.getRegion());
                assertEquals(Iso3166Country.US, entity.getCountry());
                assertEquals("type/1", entity.getOrgType());
                found1 = true;
                break;
            case "2":
                assertNull(entity.getSourceParentId());
                assertEquals("2. Name", entity.getName());
                assertEquals("City#2", entity.getCity());
                assertNull(entity.getRegion());
                assertEquals(Iso3166Country.CR, entity.getCountry());
                assertEquals("type/2", entity.getOrgType());
                found2 = true;
                break;
            case "3":
                assertNull(entity.getSourceParentId());
                assertEquals("3. Name", entity.getName());
                assertEquals("City#3", entity.getCity());
                assertNull(entity.getRegion());
                assertEquals(Iso3166Country.US, entity.getCountry());
                assertEquals("type/3", entity.getOrgType());
                found3 = true;
                break;
            case "4":
                assertEquals("1", entity.getSourceParentId());
                assertEquals("4. Name", entity.getName());
                assertEquals("City#4", entity.getCity());
                assertEquals("State#4", entity.getRegion());
                assertEquals(Iso3166Country.CR, entity.getCountry());
                assertEquals("type/4", entity.getOrgType());
                found4 = true;
                break;
            default:
                fail("Invalid ringgold id found: " + entity.getSourceId());
                break;
        }
    }
    ;
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    ArgumentCaptor<OrgDisambiguatedExternalIdentifierEntity> orgDisambiguatedExaternalIdentifierEntityCaptor = ArgumentCaptor.forClass(OrgDisambiguatedExternalIdentifierEntity.class);
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).merge(any());
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).remove(anyLong());
    verify(mockOrgDisambiguatedExternalIdentifierDao, times(8)).persist(orgDisambiguatedExaternalIdentifierEntityCaptor.capture());
    List<OrgDisambiguatedExternalIdentifierEntity> extIds = orgDisambiguatedExaternalIdentifierEntityCaptor.getAllValues();
    assertEquals(8, extIds.size());
    found1 = found2 = found3 = found4 = false;
    boolean found5 = false, found6 = false, found7 = false, found8 = false;
    for (OrgDisambiguatedExternalIdentifierEntity entity : extIds) {
        switch(entity.getIdentifier()) {
            case "1":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("ISNI", entity.getIdentifierType());
                assertEquals("1", entity.getIdentifier());
                found1 = true;
                break;
            case "2":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("IPED", entity.getIdentifierType());
                assertEquals("2", entity.getIdentifier());
                found2 = true;
                break;
            case "3":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("NCES", entity.getIdentifierType());
                assertEquals("3", entity.getIdentifier());
                found3 = true;
                break;
            case "4":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("OFR", entity.getIdentifierType());
                assertEquals("4", entity.getIdentifier());
                found4 = true;
                break;
            case "5":
                assertEquals("3", entity.getOrgDisambiguated().getSourceId());
                assertEquals("ISNI", entity.getIdentifierType());
                assertEquals("5", entity.getIdentifier());
                found5 = true;
                break;
            case "6":
                assertEquals("3", entity.getOrgDisambiguated().getSourceId());
                assertEquals("IPED", entity.getIdentifierType());
                assertEquals("6", entity.getIdentifier());
                found6 = true;
                break;
            case "7":
                assertEquals("4", entity.getOrgDisambiguated().getSourceId());
                assertEquals("NCES", entity.getIdentifierType());
                assertEquals("7", entity.getIdentifier());
                found7 = true;
                break;
            case "8":
                assertEquals("4", entity.getOrgDisambiguated().getSourceId());
                assertEquals("OFR", entity.getIdentifierType());
                assertEquals("8", entity.getIdentifier());
                found8 = true;
                break;
            default:
                fail("Invalid ext id found: " + entity.getIdentifier());
                break;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
    assertTrue(found6);
    assertTrue(found7);
    assertTrue(found8);
    ArgumentCaptor<OrgEntity> orgEntityCaptor = ArgumentCaptor.forClass(OrgEntity.class);
    verify(mockOrgDao, times(0)).merge(any());
    verify(mockOrgDao, times(2)).persist(orgEntityCaptor.capture());
    List<OrgEntity> orgs = orgEntityCaptor.getAllValues();
    assertEquals(2, orgs.size());
    found1 = found2 = false;
    for (OrgEntity entity : orgs) {
        switch(entity.getName()) {
            case "1. Alt Name":
                assertEquals("1", entity.getOrgDisambiguated().getSourceId());
                assertEquals("AltCity#1", entity.getCity());
                assertEquals(Iso3166Country.MX, entity.getCountry());
                found1 = true;
                break;
            case "2. Alt Name":
                assertEquals("2", entity.getOrgDisambiguated().getSourceId());
                assertEquals("AltCity#2", entity.getCity());
                assertEquals(Iso3166Country.BR, entity.getCountry());
                found2 = true;
                break;
            default:
                fail("Invalid org found: " + entity.getName());
                break;
        }
    }
    assertTrue(found1);
    assertTrue(found2);
}
Also used : Path(java.nio.file.Path) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) File(java.io.File) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Test(org.junit.Test)

Example 43 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class JpaJaxbMembershipAdapterTest method getEntity.

private OrgAffiliationRelationEntity getEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
    result.setAffiliationType(AffiliationType.MEMBERSHIP);
    result.setDepartment("membership:department");
    result.setEndDate(new EndDateEntity(2020, 2, 2));
    result.setId(123456L);
    result.setOrg(orgEntity);
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setTitle("membership:title");
    result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 44 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class JpaJaxbPeerReviewAdapterTest method getPeerReviewEntity.

private PeerReviewEntity getPeerReviewEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    PeerReviewEntity result = new PeerReviewEntity();
    result.setOrg(orgEntity);
    result.setCompletionDate(new CompletionDateEntity(2015, 1, 1));
    result.setExternalIdentifiersJson("{\"workExternalIdentifier\":[{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:external-identifier-id\"}}]}");
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setRole(org.orcid.jaxb.model.record_v2.Role.MEMBER);
    result.setType(org.orcid.jaxb.model.record_v2.PeerReviewType.EVALUATION);
    result.setUrl("peer-review:url");
    result.setSubjectExternalIdentifiersJson("{\"relationship\":\"SELF\",\"url\":{\"value\":\"http://orcid.org\"},\"workExternalIdentifierType\":\"SOURCE_WORK_ID\",\"workExternalIdentifierId\":{\"content\":\"peer-review:subject-external-identifier-id\"}}");
    result.setSubjectContainerName("peer-review:subject-container-name");
    result.setSubjectName("peer-review:subject-name");
    result.setSubjectTranslatedName("peer-review:subject-translated-name");
    result.setSubjectTranslatedNameLanguageCode("en");
    result.setSubjectUrl("peer-review:subject-url");
    result.setSubjectType(org.orcid.jaxb.model.record_v2.WorkType.BOOK_REVIEW);
    result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    result.setGroupId("orcid-generated:12345");
    result.setId(12345L);
    return result;
}
Also used : CompletionDateEntity(org.orcid.persistence.jpa.entities.CompletionDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PeerReviewEntity(org.orcid.persistence.jpa.entities.PeerReviewEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 45 with OrgEntity

use of org.orcid.persistence.jpa.entities.OrgEntity in project ORCID-Source by ORCID.

the class JpaJaxbQualificationAdapterTest method getEntity.

private OrgAffiliationRelationEntity getEntity() {
    OrgEntity orgEntity = new OrgEntity();
    orgEntity.setCity("org:city");
    orgEntity.setCountry(org.orcid.jaxb.model.message.Iso3166Country.US);
    orgEntity.setName("org:name");
    orgEntity.setRegion("org:region");
    orgEntity.setUrl("org:url");
    orgEntity.setSource(new SourceEntity("APP-000000001"));
    OrgAffiliationRelationEntity result = new OrgAffiliationRelationEntity();
    result.setAffiliationType(AffiliationType.QUALIFICATION);
    result.setDepartment("qualification:department");
    result.setEndDate(new EndDateEntity(2020, 2, 2));
    result.setId(123456L);
    result.setOrg(orgEntity);
    result.setProfile(new ProfileEntity("0000-0001-0002-0003"));
    result.setStartDate(new StartDateEntity(2000, 1, 1));
    result.setTitle("qualification:title");
    result.setVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
    result.setClientSourceId("APP-000000001");
    return result;
}
Also used : EndDateEntity(org.orcid.persistence.jpa.entities.EndDateEntity) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) StartDateEntity(org.orcid.persistence.jpa.entities.StartDateEntity) OrgAffiliationRelationEntity(org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Aggregations

OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)53 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)30 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)26 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)17 EndDateEntity (org.orcid.persistence.jpa.entities.EndDateEntity)11 StartDateEntity (org.orcid.persistence.jpa.entities.StartDateEntity)11 Test (org.junit.Test)10 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)8 PeerReviewEntity (org.orcid.persistence.jpa.entities.PeerReviewEntity)8 AmbiguousOrgEntity (org.orcid.persistence.jpa.entities.AmbiguousOrgEntity)7 File (java.io.File)6 Path (java.nio.file.Path)6 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)6 Transactional (org.springframework.transaction.annotation.Transactional)5 Date (java.util.Date)4 Visibility (org.orcid.jaxb.model.common_v2.Visibility)4 Organization (org.orcid.jaxb.model.message.Organization)4 CompletionDateEntity (org.orcid.persistence.jpa.entities.CompletionDateEntity)4 HashSet (java.util.HashSet)3 Iso3166Country (org.orcid.jaxb.model.message.Iso3166Country)3