use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerTest method getOrgDisambiguatedEntity.
private OrgDisambiguatedEntity getOrgDisambiguatedEntity(Boolean withExtIds) {
OrgDisambiguatedEntity org = new OrgDisambiguatedEntity();
org.setCity("city");
org.setCountry(Iso3166Country.US);
org.setName("name");
org.setOrgType("orgType");
org.setRegion("region");
org.setSourceId("sourceId");
org.setSourceType("sourceType");
org.setUrl("url");
if (withExtIds) {
Set<OrgDisambiguatedExternalIdentifierEntity> orgDisambiguatedExternalIdentifiers = new HashSet<OrgDisambiguatedExternalIdentifierEntity>();
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type1", "type1_identifier1", true));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type1", "type1_identifier2", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type1", "type1_identifier3", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type2", "type2_identifier1", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type2", "type2_identifier2", true));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type2", "type2_identifier3", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type3", "type3_identifier1", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type3", "type3_identifier2", false));
orgDisambiguatedExternalIdentifiers.add(getOrgDisambiguatedExternalIdentifierEntity("type3", "type3_identifier3", true));
org.setExternalIdentifiers(orgDisambiguatedExternalIdentifiers);
}
return org;
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadFundRefData method createExternalIdentifier.
/**
* Creates an external identifier in the
* org_disambiguated_external_identifier table
* */
private boolean createExternalIdentifier(OrgDisambiguatedEntity disambiguatedOrg, String identifier) {
LOGGER.info("Creating external identifier for {}", disambiguatedOrg.getId());
Date creationDate = new Date();
OrgDisambiguatedExternalIdentifierEntity externalIdentifier = new OrgDisambiguatedExternalIdentifierEntity();
externalIdentifier.setIdentifier(identifier);
externalIdentifier.setIdentifierType(FUNDREF_SOURCE_TYPE);
externalIdentifier.setOrgDisambiguated(disambiguatedOrg);
externalIdentifier.setDateCreated(creationDate);
externalIdentifier.setLastModified(creationDate);
orgDisambiguatedExternalIdentifierDao.persist(externalIdentifier);
return true;
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadGridData method processExternalIdentifiers.
private void processExternalIdentifiers(OrgDisambiguatedEntity org, JsonNode institute) {
JsonNode externalIdsContainer = institute.get("external_ids") == null ? null : institute.get("external_ids");
if (externalIdsContainer != null) {
Iterator<Entry<String, JsonNode>> nodes = externalIdsContainer.fields();
while (nodes.hasNext()) {
Map.Entry<String, JsonNode> entry = (Map.Entry<String, JsonNode>) nodes.next();
String identifierTypeName = entry.getKey().toUpperCase();
String preferredId = entry.getValue().get("preferred").isNull() ? null : entry.getValue().get("preferred").asText();
ArrayNode elements = (ArrayNode) entry.getValue().get("all");
for (JsonNode extId : elements) {
// If the external identifier doesn't exists yet
OrgDisambiguatedExternalIdentifierEntity existingExternalId = orgDisambiguatedExternalIdentifierDao.findByDetails(org.getId(), extId.asText(), identifierTypeName);
Boolean preferred = extId.asText().equals(preferredId);
if (existingExternalId == null) {
if (preferred) {
createExternalIdentifier(org, extId.asText(), identifierTypeName, true);
} else {
createExternalIdentifier(org, extId.asText(), identifierTypeName, false);
}
} else {
if (existingExternalId.getPreferred() != preferred) {
existingExternalId.setPreferred(preferred);
orgDisambiguatedExternalIdentifierDao.merge(existingExternalId);
LOGGER.info("External identifier for {} with ext id {} and type {} was updated", new Object[] { org.getId(), extId.asText(), identifierTypeName });
updatedExternalIdentifiers++;
} else {
LOGGER.info("External identifier for {} with ext id {} and type {} already exists", new Object[] { org.getId(), extId.asText(), identifierTypeName });
}
}
}
}
}
if (!institute.get(WIKIPEDIA_URL).isNull()) {
String url = institute.get(WIKIPEDIA_URL).asText();
// If the external identifier doesn't exists yet
if (orgDisambiguatedExternalIdentifierDao.findByDetails(org.getId(), url, WIKIPEDIA_URL.toUpperCase()) == null) {
createExternalIdentifier(org, url, WIKIPEDIA_URL.toUpperCase(), true);
} else {
LOGGER.info("Wikipedia URL for {} already exists", org.getId());
}
}
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadRinggoldData method generateExternalIdentifiers.
private void generateExternalIdentifiers(OrgDisambiguatedEntity disambiguatedEntity, List<JsonNode> identifiers) {
Set<OrgDisambiguatedExternalIdentifierEntity> existingExternalIdentifiers = disambiguatedEntity.getExternalIdentifiers();
Map<Pair<String, String>, OrgDisambiguatedExternalIdentifierEntity> existingExternalIdentifiersMap = new HashMap<>();
if (existingExternalIdentifiers != null) {
for (OrgDisambiguatedExternalIdentifierEntity entity : existingExternalIdentifiers) {
Pair<String, String> id = Pair.of(entity.getIdentifierType(), entity.getIdentifier());
existingExternalIdentifiersMap.put(id, entity);
}
}
if (identifiers != null && !identifiers.isEmpty()) {
identifiers.forEach(identifierNode -> {
String type = identifierNode.get("identifier_type").asText();
LOGGER.info("Processing external identifier {} for {}", type, disambiguatedEntity.getId());
String value = identifierNode.get("value").asText();
Pair<String, String> id = Pair.of(type, value);
OrgDisambiguatedExternalIdentifierEntity existingEntity = existingExternalIdentifiersMap.get(id);
// If the external identifier doesn't exists or it doesn't belong to the disambiguatedEntity, lets create it
if (existingEntity == null || !existingEntity.getOrgDisambiguated().getId().equals(disambiguatedEntity.getId())) {
OrgDisambiguatedExternalIdentifierEntity newEntity = new OrgDisambiguatedExternalIdentifierEntity();
Date now = new Date();
newEntity.setDateCreated(now);
newEntity.setLastModified(now);
newEntity.setIdentifier(value);
newEntity.setIdentifierType(type);
newEntity.setOrgDisambiguated(disambiguatedEntity);
newEntity.setPreferred(false);
orgDisambiguatedExternalIdentifierDao.persist(newEntity);
numAddedExtIds++;
} else {
existingExternalIdentifiersMap.remove(id);
}
});
}
// Then, remove all existing external identifiers that are not present in the ringgold data anymore
for (OrgDisambiguatedExternalIdentifierEntity extIdToBeRemoved : existingExternalIdentifiersMap.values()) {
orgDisambiguatedExternalIdentifierDao.remove(extIdToBeRemoved.getId());
}
}
use of org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity in project ORCID-Source by ORCID.
the class LoadGridDataTest method execute_UpdateExistingInstitute_Test.
@Test
public void execute_UpdateExistingInstitute_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.setStatus("active");
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_updated_5_external_identifiers.json").toURI());
File testFile = path.toFile();
loadGridData.setFileToLoad(testFile);
loadGridData.execute();
assertEquals(0L, loadGridData.getAddedDisambiguatedOrgs());
assertEquals(0L, loadGridData.getAddedExternalIdentifiers());
assertEquals(1L, loadGridData.getUpdatedOrgs());
assertEquals(0L, loadGridData.getDeprecatedOrgs());
assertEquals(0L, loadGridData.getObsoletedOrgs());
assertEquals(0L, loadGridData.getUpdatedExternalIdentifiers());
ArgumentCaptor<OrgDisambiguatedEntity> captor = ArgumentCaptor.forClass(OrgDisambiguatedEntity.class);
verify(orgDisambiguatedDao).merge(captor.capture());
OrgDisambiguatedEntity orgToBeUpdated = captor.getValue();
assertEquals(Iso3166Country.CR, orgToBeUpdated.getCountry());
assertEquals(Long.valueOf(1), orgToBeUpdated.getId());
assertEquals("City One Updated", orgToBeUpdated.getCity());
assertEquals(IndexingStatus.PENDING, orgToBeUpdated.getIndexingStatus());
assertEquals("org_1_updated", orgToBeUpdated.getName());
assertEquals("type_1,type_2", orgToBeUpdated.getOrgType());
assertEquals("San Jose", orgToBeUpdated.getRegion());
assertEquals("grid.1", orgToBeUpdated.getSourceId());
assertEquals("GRID", orgToBeUpdated.getSourceType());
assertEquals("active", orgToBeUpdated.getStatus());
assertEquals("http://link1.com/updated", orgToBeUpdated.getUrl());
}
Aggregations