Search in sources :

Example 1 with OrgDisambiguatedExternalIdentifiers

use of org.orcid.pojo.OrgDisambiguatedExternalIdentifiers 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)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Transactional (javax.transaction.Transactional)1 OrgDisambiguatedEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedEntity)1 OrgDisambiguatedExternalIdentifierEntity (org.orcid.persistence.jpa.entities.OrgDisambiguatedExternalIdentifierEntity)1 OrgDisambiguated (org.orcid.pojo.OrgDisambiguated)1 OrgDisambiguatedExternalIdentifiers (org.orcid.pojo.OrgDisambiguatedExternalIdentifiers)1