use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadGridData method createExternalIdentifier.
/**
* Creates an external identifier in the
* org_disambiguated_external_identifier table
*/
private boolean createExternalIdentifier(OrgDisambiguatedEntity disambiguatedOrg, String identifier, String externalIdType, Boolean preferred) {
LOGGER.info("Creating external identifier for {}", disambiguatedOrg.getId());
Date creationDate = new Date();
OrgDisambiguatedExternalIdentifierEntity externalIdentifier = new OrgDisambiguatedExternalIdentifierEntity();
externalIdentifier.setIdentifier(identifier);
externalIdentifier.setIdentifierType(externalIdType);
externalIdentifier.setOrgDisambiguated(disambiguatedOrg);
externalIdentifier.setDateCreated(creationDate);
externalIdentifier.setLastModified(creationDate);
externalIdentifier.setPreferred(preferred);
orgDisambiguatedExternalIdentifierDao.persist(externalIdentifier);
addedExternalIdentifiers++;
return true;
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerImpl method findInDB.
@Override
@Transactional
public OrgDisambiguated findInDB(Long id) {
OrgDisambiguatedEntity orgDisambiguatedEntity = orgDisambiguatedDaoReadOnly.find(id);
OrgDisambiguated org = new OrgDisambiguated();
org.setValue(orgDisambiguatedEntity.getName());
org.setCity(orgDisambiguatedEntity.getCity());
org.setRegion(orgDisambiguatedEntity.getRegion());
org.setCountry(orgDisambiguatedEntity.getCountry() != null ? orgDisambiguatedEntity.getCountry().value() : null);
org.setOrgType(orgDisambiguatedEntity.getOrgType());
org.setSourceId(orgDisambiguatedEntity.getSourceId());
org.setSourceType(orgDisambiguatedEntity.getSourceType());
org.setUrl(orgDisambiguatedEntity.getUrl());
Map<String, OrgDisambiguatedExternalIdentifiers> externalIdsMap = new HashMap<String, OrgDisambiguatedExternalIdentifiers>();
if (orgDisambiguatedEntity.getExternalIdentifiers() != null && !orgDisambiguatedEntity.getExternalIdentifiers().isEmpty()) {
for (OrgDisambiguatedExternalIdentifierEntity extIdEntity : orgDisambiguatedEntity.getExternalIdentifiers()) {
String type = extIdEntity.getIdentifierType();
String identifier = extIdEntity.getIdentifier();
Boolean preferred = extIdEntity.getPreferred();
OrgDisambiguatedExternalIdentifiers extId = null;
if (externalIdsMap.containsKey(type)) {
extId = externalIdsMap.get(type);
} else {
extId = new OrgDisambiguatedExternalIdentifiers();
extId.setIdentifierType(type);
externalIdsMap.put(type, extId);
}
if (preferred) {
extId.setPreferred(identifier);
}
extId.getAll().add(identifier);
}
if (!externalIdsMap.isEmpty()) {
List<OrgDisambiguatedExternalIdentifiers> extIds = new ArrayList<OrgDisambiguatedExternalIdentifiers>();
externalIdsMap.keySet().stream().sorted().collect(Collectors.toList()).forEach(k -> {
extIds.add(externalIdsMap.get(k));
});
org.setOrgDisambiguatedExternalIdentifiers(extIds);
}
}
return org;
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadGridDataTest method execute_NothingToCreateNothingToUpdate_Test.
@SuppressWarnings("deprecation")
@Test
public void execute_NothingToCreateNothingToUpdate_Test() throws URISyntaxException {
when(orgDisambiguatedDao.findBySourceIdAndSourceType("grid.1", "GRID")).thenAnswer(new Answer<OrgDisambiguatedEntity>() {
@Override
public OrgDisambiguatedEntity answer(InvocationOnMock invocation) throws Throwable {
OrgDisambiguatedEntity entity = new OrgDisambiguatedEntity();
entity.setId(1L);
entity.setName("org_1");
entity.setSourceId("grid.1");
entity.setCity("City One");
entity.setCountry(Iso3166Country.US);
entity.setOrgType("type_1");
entity.setRegion("Alabama");
entity.setSourceType("GRID");
entity.setUrl("http://link1.com");
return entity;
}
});
OrgDisambiguatedExternalIdentifierEntity extId = new OrgDisambiguatedExternalIdentifierEntity();
extId.setPreferred(Boolean.FALSE);
OrgDisambiguatedExternalIdentifierEntity extIdPreferred = new OrgDisambiguatedExternalIdentifierEntity();
extIdPreferred.setPreferred(Boolean.TRUE);
when(orgDisambiguatedExternalIdentifierDao.findByDetails(1L, "ISNI1", "ISNI")).thenReturn(extId);
when(orgDisambiguatedExternalIdentifierDao.findByDetails(1L, "FUNDREF1", "FUNDREF")).thenReturn(extIdPreferred);
when(orgDisambiguatedExternalIdentifierDao.findByDetails(1L, "ORGREF1", "ORGREF")).thenReturn(extId);
when(orgDisambiguatedExternalIdentifierDao.findByDetails(1L, "WIKIDATA1", "WIKIDATA")).thenReturn(extId);
when(orgDisambiguatedExternalIdentifierDao.findByDetails(1L, "http://en.wikipedia.org/wiki/org_1", "WIKIPEDIA_URL")).thenReturn(extId);
Path path = Paths.get(getClass().getClassLoader().getResource("grid/grid_1_org_5_external_identifiers.json").toURI());
File testFile = path.toFile();
loadGridData.setFileToLoad(testFile);
loadGridData.execute();
verify(orgDisambiguatedDao, times(0)).persist(Matchers.any(OrgDisambiguatedEntity.class));
verify(orgDisambiguatedDao, times(0)).merge(Matchers.any(OrgDisambiguatedEntity.class));
verify(orgDisambiguatedExternalIdentifierDao, times(0)).persist(Matchers.any(OrgDisambiguatedExternalIdentifierEntity.class));
assertEquals(0L, loadGridData.getAddedDisambiguatedOrgs());
assertEquals(0L, loadGridData.getAddedExternalIdentifiers());
assertEquals(0L, loadGridData.getUpdatedOrgs());
assertEquals(0L, loadGridData.getDeprecatedOrgs());
assertEquals(0L, loadGridData.getObsoletedOrgs());
assertEquals(0L, loadGridData.getUpdatedExternalIdentifiers());
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadRinggoldDataTest method test_AddExternalIdentifier.
@Test
public void test_AddExternalIdentifier() throws URISyntaxException {
setupInitialMocks();
Path path = Paths.get(getClass().getClassLoader().getResource("ringgold/test_AddExternalIdentifier/").toURI());
File testDirectory = path.toFile();
assertTrue(testDirectory.exists());
loader.setDirectory(testDirectory);
loader.execute();
verify(mockOrgDisambiguatedDao, times(0)).persist(any());
verify(mockOrgDisambiguatedDao, times(0)).merge(any());
ArgumentCaptor<OrgDisambiguatedExternalIdentifierEntity> captor = ArgumentCaptor.forClass(OrgDisambiguatedExternalIdentifierEntity.class);
verify(mockOrgDisambiguatedExternalIdentifierDao, times(1)).persist(captor.capture());
verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).merge(any());
verify(mockOrgDisambiguatedExternalIdentifierDao, times(0)).remove(anyLong());
List<OrgDisambiguatedExternalIdentifierEntity> list = captor.getAllValues();
assertEquals(1, list.size());
OrgDisambiguatedExternalIdentifierEntity entity = list.get(0);
assertEquals("9", entity.getIdentifier());
assertEquals("ISNI", entity.getIdentifierType());
assertEquals(false, entity.getPreferred());
assertEquals(Long.valueOf(1000), entity.getOrgDisambiguated().getId());
verify(mockOrgDao, times(0)).persist(any());
verify(mockOrgDao, times(0)).merge(any());
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerTest method getOrgDisambiguatedExternalIdentifierEntity.
private OrgDisambiguatedExternalIdentifierEntity getOrgDisambiguatedExternalIdentifierEntity(String identifierType, String identifier, Boolean preferred) {
OrgDisambiguatedExternalIdentifierEntity entity = new OrgDisambiguatedExternalIdentifierEntity();
entity.setIdentifierType(identifierType);
entity.setIdentifier(identifier);
entity.setPreferred(preferred);
return entity;
}
Aggregations