Search in sources :

Example 41 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class Jaxb2JpaAdapterImpl method getWorkEntities.

private SortedSet<WorkEntity> getWorkEntities(ProfileEntity profileEntity, OrcidWorks orcidWorks) {
    SortedSet<WorkEntity> existingWorkEntities = profileEntity.getWorks();
    Map<String, WorkEntity> existingWorkEntitiesMap = createWorkEntitiesMap(existingWorkEntities);
    SortedSet<WorkEntity> workEntities = null;
    if (existingWorkEntities == null) {
        workEntities = new TreeSet<WorkEntity>();
    } else {
        // To allow for orphan deletion
        existingWorkEntities.clear();
        workEntities = existingWorkEntities;
    }
    if (orcidWorks != null && orcidWorks.getOrcidWork() != null && !orcidWorks.getOrcidWork().isEmpty()) {
        List<OrcidWork> orcidWorkList = orcidWorks.getOrcidWork();
        for (OrcidWork orcidWork : orcidWorkList) {
            WorkEntity workEntity = getWorkEntity(orcidWork, existingWorkEntitiesMap.get(orcidWork.getPutCode()));
            if (workEntity != null) {
                workEntity.setProfile(profileEntity);
                workEntities.add(workEntity);
            }
        }
    }
    return workEntities;
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork)

Example 42 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidProfileManagerImpl method checkForAlreadyExistingWorks.

private void checkForAlreadyExistingWorks(OrcidWorks existingOrcidWorks, List<OrcidWork> updatedOrcidWorksList) {
    if (existingOrcidWorks != null) {
        Set<OrcidWork> existingOrcidWorksSet = new HashSet<>();
        for (OrcidWork existingWork : existingOrcidWorks.getOrcidWork()) {
            existingOrcidWorksSet.add(existingWork);
        }
        for (Iterator<OrcidWork> updatedWorkIterator = updatedOrcidWorksList.iterator(); updatedWorkIterator.hasNext(); ) {
            OrcidWork updatedWork = updatedWorkIterator.next();
            for (OrcidWork orcidWork : existingOrcidWorksSet) {
                if (orcidWork.isDuplicated(updatedWork)) {
                    // Update the existing work
                    long workId = Long.valueOf(orcidWork.getPutCode());
                    WorkEntity workEntity = workDao.find(workId);
                    workEntity.clean();
                    workEntity = jaxb2JpaAdapter.getWorkEntity(updatedWork, workEntity);
                    workDao.persist(workEntity);
                    // Since it was already updated, remove it from the list
                    // of updated works
                    updatedWorkIterator.remove();
                    break;
                }
            }
        }
    }
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Example 43 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class OrcidMessageUtil method setSourceName.

public void setSourceName(OrcidProfile orcidProfile) {
    if (orcidProfile != null) {
        if (orcidProfile.getOrcidActivities() != null) {
            OrcidActivities orcidActivities = orcidProfile.getOrcidActivities();
            if (orcidActivities.getAffiliations() != null) {
                Affiliations affs = orcidActivities.getAffiliations();
                List<Affiliation> affList = affs.getAffiliation();
                if (affList != null) {
                    for (Affiliation aff : affList) {
                        setSourceName(aff);
                    }
                }
            }
            if (orcidActivities.getFundings() != null) {
                FundingList fundingList = orcidActivities.getFundings();
                List<Funding> fundings = fundingList.getFundings();
                if (fundings != null) {
                    for (Funding funding : fundings) {
                        setSourceName(funding);
                    }
                }
            }
            if (orcidActivities.getOrcidWorks() != null) {
                OrcidWorks orcidWorks = orcidActivities.getOrcidWorks();
                List<OrcidWork> works = orcidWorks.getOrcidWork();
                if (works != null) {
                    for (OrcidWork work : works) {
                        setSourceName(work);
                    }
                }
            }
        }
        if (orcidProfile.getOrcidBio() != null) {
            OrcidBio orcidBio = orcidProfile.getOrcidBio();
            if (orcidBio.getContactDetails() != null) {
                Address address = orcidBio.getContactDetails().getAddress();
                if (address != null) {
                    setSourceName(address);
                }
            }
            if (orcidBio.getExternalIdentifiers() != null) {
                ExternalIdentifiers extIds = orcidBio.getExternalIdentifiers();
                List<ExternalIdentifier> extIdsList = extIds.getExternalIdentifier();
                if (extIdsList != null) {
                    for (ExternalIdentifier extId : extIdsList) {
                        setSourceName(extId);
                    }
                }
            }
            if (orcidBio.getKeywords() != null) {
                Keywords keywords = orcidBio.getKeywords();
                List<Keyword> keywordList = keywords.getKeyword();
                if (keywordList != null) {
                    for (Keyword keyword : keywordList) {
                        setSourceName(keyword);
                    }
                }
            }
            if (orcidBio.getPersonalDetails() != null) {
                OtherNames otherNames = orcidBio.getPersonalDetails().getOtherNames();
                if (otherNames != null) {
                    List<OtherName> otherNameList = otherNames.getOtherName();
                    if (otherNameList != null) {
                        for (OtherName otherName : otherNameList) {
                            setSourceName(otherName);
                        }
                    }
                }
            }
            if (orcidBio.getResearcherUrls() != null) {
                ResearcherUrls rUrls = orcidBio.getResearcherUrls();
                List<ResearcherUrl> rUrlList = rUrls.getResearcherUrl();
                if (rUrlList != null) {
                    for (ResearcherUrl rUrl : rUrlList) {
                        setSourceName(rUrl);
                    }
                }
            }
        }
    }
}
Also used : Keywords(org.orcid.jaxb.model.message.Keywords) OrcidBio(org.orcid.jaxb.model.message.OrcidBio) Address(org.orcid.jaxb.model.message.Address) Keyword(org.orcid.jaxb.model.message.Keyword) Funding(org.orcid.jaxb.model.message.Funding) ExternalIdentifier(org.orcid.jaxb.model.message.ExternalIdentifier) OtherNames(org.orcid.jaxb.model.message.OtherNames) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) OtherName(org.orcid.jaxb.model.message.OtherName) OrcidActivities(org.orcid.jaxb.model.message.OrcidActivities) OrcidWorks(org.orcid.jaxb.model.message.OrcidWorks) FundingList(org.orcid.jaxb.model.message.FundingList) Affiliations(org.orcid.jaxb.model.message.Affiliations) ResearcherUrls(org.orcid.jaxb.model.message.ResearcherUrls) ResearcherUrl(org.orcid.jaxb.model.message.ResearcherUrl) ExternalIdentifiers(org.orcid.jaxb.model.message.ExternalIdentifiers) Affiliation(org.orcid.jaxb.model.message.Affiliation)

Example 44 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class JpaJaxbEntityAdapterToProfileEntityTest method testReligiousTextConvertedFromBible.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
@Rollback(true)
public void testReligiousTextConvertedFromBible() throws Exception {
    OrcidMessage orcidMessage = getOrcidMessage(ORCID_INTERNAL_FULL_XML);
    List<OrcidWork> currentOrcidWorks = orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork();
    assertTrue(currentOrcidWorks.size() == 1);
    currentOrcidWorks.get(0).setWorkType(WorkType.DATA_SET);
    ProfileEntity profileEntity = adapter.toProfileEntity(orcidMessage.getOrcidProfile());
    List<WorkEntity> works = new ArrayList<WorkEntity>(profileEntity.getWorks());
    assertEquals(1, works.size());
    assertTrue(works.get(0).getWorkType().equals(org.orcid.jaxb.model.record_v2.WorkType.DATA_SET));
}
Also used : WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidWork(org.orcid.jaxb.model.message.OrcidWork) ArrayList(java.util.ArrayList) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 45 with OrcidWork

use of org.orcid.jaxb.model.message.OrcidWork in project ORCID-Source by ORCID.

the class ValidationManagerImpl method doWorkTypeValidation.

private void doWorkTypeValidation(OrcidMessage orcidMessage) {
    if (orcidMessage == null || orcidMessage.getOrcidProfile() == null || orcidMessage.getOrcidProfile().getOrcidActivities() == null || orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks() == null || orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork() == null || orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().isEmpty())
        return;
    List<OrcidWork> works = orcidMessage.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork();
    for (OrcidWork work : works) {
        if (work.getWorkType() == null)
            if (work.getWorkTitle() != null && work.getWorkTitle().getTitle() != null && !PojoUtil.isEmpty(work.getWorkTitle().getTitle().getContent()))
                handleError("work-type is missing or invalid for work: '" + work.getWorkTitle().getTitle().getContent() + "'");
            else
                handleError("work-type is missing or invalid");
    }
}
Also used : OrcidWork(org.orcid.jaxb.model.message.OrcidWork)

Aggregations

OrcidWork (org.orcid.jaxb.model.message.OrcidWork)81 Test (org.junit.Test)44 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)42 OrcidWorks (org.orcid.jaxb.model.message.OrcidWorks)32 Transactional (org.springframework.transaction.annotation.Transactional)26 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)24 Title (org.orcid.jaxb.model.message.Title)23 FundingTitle (org.orcid.jaxb.model.message.FundingTitle)20 WorkTitle (org.orcid.jaxb.model.message.WorkTitle)18 OrcidActivities (org.orcid.jaxb.model.message.OrcidActivities)16 WorkExternalIdentifier (org.orcid.jaxb.model.message.WorkExternalIdentifier)16 Source (org.orcid.jaxb.model.message.Source)14 Rollback (org.springframework.test.annotation.Rollback)13 ArrayList (java.util.ArrayList)12 Funding (org.orcid.jaxb.model.message.Funding)12 WorkExternalIdentifierId (org.orcid.jaxb.model.message.WorkExternalIdentifierId)12 BaseTest (org.orcid.core.BaseTest)11 Contributor (org.orcid.jaxb.model.message.Contributor)11 WorkExternalIdentifiers (org.orcid.jaxb.model.message.WorkExternalIdentifiers)11 OrcidBio (org.orcid.jaxb.model.message.OrcidBio)10