Search in sources :

Example 1 with OrgDisambiguatedExternalIdentifierEntity

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;
}
Also used : OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) Date(java.util.Date)

Example 2 with OrgDisambiguatedExternalIdentifierEntity

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) OrgDisambiguated(org.orcid.pojo.OrgDisambiguated) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) OrgDisambiguatedExternalIdentifiers(org.orcid.pojo.OrgDisambiguatedExternalIdentifiers) Transactional(javax.transaction.Transactional)

Example 3 with OrgDisambiguatedExternalIdentifierEntity

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());
}
Also used : Path(java.nio.file.Path) InvocationOnMock(org.mockito.invocation.InvocationOnMock) OrgDisambiguatedEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) File(java.io.File) Test(org.junit.Test)

Example 4 with OrgDisambiguatedExternalIdentifierEntity

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());
}
Also used : Path(java.nio.file.Path) OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity) File(java.io.File) Test(org.junit.Test)

Example 5 with OrgDisambiguatedExternalIdentifierEntity

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;
}
Also used : OrgDisambiguatedExternalIdentifierEntity(org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity)

Aggregations

OrgDisambiguatedExternalIdentifierEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity)16 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)9 File (java.io.File)8 Path (java.nio.file.Path)8 Test (org.junit.Test)8 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Date (java.util.Date)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)2 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Transactional (javax.transaction.Transactional)1 Pair (org.apache.commons.lang3.tuple.Pair)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1