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;
}
});
}
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);
}
Aggregations