Search in sources :

Example 41 with Funding

use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method updateFunding.

/**
     * Updates a funding that belongs to the given user
     * @param orcid
     *          The user
     * @param funding
     *          The funding to update
     * @return the updated funding                  
     * */
@Override
public Funding updateFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, funding.getPutCode());
    Visibility originalVisibility = pfe.getVisibility();
    //Save the original source
    String existingSourceId = pfe.getSourceId();
    String existingClientSourceId = pfe.getClientSourceId();
    activityValidator.validateFunding(funding, sourceEntity, false, isApiRequest, originalVisibility);
    if (!isApiRequest) {
        List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid);
        for (ProfileFundingEntity existingFunding : existingFundings) {
            Funding existing = jpaJaxbFundingAdapter.toFunding(existingFunding);
            if (!existing.getPutCode().equals(funding.getPutCode())) {
                activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), existing.getExternalIdentifiers(), existing.getSource(), sourceEntity);
            }
        }
    }
    orcidSecurityManager.checkSource(pfe);
    jpaJaxbFundingAdapter.toProfileFundingEntity(funding, pfe);
    pfe.setVisibility(originalVisibility);
    //Be sure it doesn't overwrite the source
    pfe.setSourceId(existingSourceId);
    pfe.setClientSourceId(existingClientSourceId);
    //Updates the give organization with the latest organization from database, or, create a new one
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    pfe.setOrg(updatedOrganization);
    pfe = profileFundingDao.merge(pfe);
    profileFundingDao.flush();
    if (!isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItem(pfe));
    }
    return jpaJaxbFundingAdapter.toFunding(pfe);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) Visibility(org.orcid.jaxb.model.common_v2.Visibility) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 42 with Funding

use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.

the class ContributorUtils method filterContributorPrivateData.

public void filterContributorPrivateData(Funding funding) {
    if (funding.getContributors() != null && funding.getContributors().getContributor() != null) {
        for (FundingContributor contributor : funding.getContributors().getContributor()) {
            contributor.setContributorEmail(null);
            if (!PojoUtil.isEmpty(contributor.getContributorOrcid())) {
                String contributorOrcid = contributor.getContributorOrcid().getPath();
                if (profileEntityManager.orcidExists(contributorOrcid)) {
                    // contributor is an ORCID user - visibility of user's
                    // name in record must be taken into account
                    ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                    String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
                    CreditName creditName = new CreditName(publicContributorCreditName != null ? publicContributorCreditName : "");
                    contributor.setCreditName(creditName);
                }
            }
        }
    }
}
Also used : FundingContributor(org.orcid.jaxb.model.record_v2.FundingContributor) CreditName(org.orcid.jaxb.model.common_v2.CreditName) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Example 43 with Funding

use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.

the class SourceInActivitiesTest method sourceDoesntChange_Funding_Test.

@Test
@Transactional
public void sourceDoesntChange_Funding_Test() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Funding funding1 = getFunding(userOrcid);
    assertNotNull(funding1);
    assertNotNull(funding1.getTitle());
    assertNotNull(funding1.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding1.getTitle().getTitle().getContent()));
    assertEquals(userOrcid, funding1.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding funding2 = getFunding(userOrcid);
    assertNotNull(funding2.getTitle());
    assertNotNull(funding2.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding2.getTitle().getTitle().getContent()));
    assertEquals(CLIENT_1_ID, funding2.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_2_ID)));
    Funding funding3 = getFunding(userOrcid);
    assertNotNull(funding3.getTitle());
    assertNotNull(funding3.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding3.getTitle().getTitle().getContent()));
    assertEquals(CLIENT_2_ID, funding3.getSource().retrieveSourcePath());
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ProfileEntity(userOrcid)));
    Funding funding4 = getFunding(userOrcid);
    assertNotNull(funding4.getTitle());
    assertNotNull(funding4.getTitle().getTitle());
    assertFalse(PojoUtil.isEmpty(funding4.getTitle().getTitle().getContent()));
    assertEquals(userOrcid, funding4.getSource().retrieveSourcePath());
    Funding fromDb1 = profileFundingManager.getFunding(userOrcid, funding1.getPutCode());
    assertNotNull(fromDb1);
    assertEquals(userOrcid, fromDb1.getSource().retrieveSourcePath());
    Funding fromDb2 = profileFundingManager.getFunding(userOrcid, funding2.getPutCode());
    assertNotNull(fromDb2);
    assertEquals(CLIENT_1_ID, fromDb2.getSource().retrieveSourcePath());
    Funding fromDb3 = profileFundingManager.getFunding(userOrcid, funding3.getPutCode());
    assertNotNull(fromDb3);
    assertEquals(CLIENT_2_ID, fromDb3.getSource().retrieveSourcePath());
    Funding fromDb4 = profileFundingManager.getFunding(userOrcid, funding4.getPutCode());
    assertNotNull(fromDb4);
    assertEquals(userOrcid, fromDb4.getSource().retrieveSourcePath());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 44 with Funding

use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method displayIndexIsSetTo_0_FromAPI.

@Test
public void displayIndexIsSetTo_0_FromAPI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding f1 = getFunding("fromAPI-1");
    f1 = profileFundingManager.createFunding(claimedOrcid, f1, true);
    ProfileFundingEntity f = profileFundingDao.find(f1.getPutCode());
    assertNotNull(f);
    assertEquals(Long.valueOf(0), f.getDisplayIndex());
}
Also used : ClientDetailsEntity(org.orcid.persistence.jpa.entities.ClientDetailsEntity) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Example 45 with Funding

use of org.orcid.jaxb.model.record_v2.Funding in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method testGetAll.

@Test
public void testGetAll() {
    String orcid = "0000-0000-0000-0003";
    List<Funding> elements = profileFundingManager.getFundingList(orcid, System.currentTimeMillis());
    assertNotNull(elements);
    assertEquals(5, elements.size());
    boolean found1 = false, found2 = false, found3 = false, found4 = false, found5 = false;
    for (Funding element : elements) {
        if (10 == element.getPutCode()) {
            found1 = true;
        } else if (11 == element.getPutCode()) {
            found2 = true;
        } else if (12 == element.getPutCode()) {
            found3 = true;
        } else if (13 == element.getPutCode()) {
            found4 = true;
        } else if (14 == element.getPutCode()) {
            found5 = true;
        } else {
            fail("Invalid put code found: " + element.getPutCode());
        }
    }
    assertTrue(found1);
    assertTrue(found2);
    assertTrue(found3);
    assertTrue(found4);
    assertTrue(found5);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) Test(org.junit.Test) BaseTest(org.orcid.core.BaseTest)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)75 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)21 ArrayList (java.util.ArrayList)19 Response (javax.ws.rs.core.Response)16 Url (org.orcid.jaxb.model.common_v2.Url)16 DBUnitTest (org.orcid.test.DBUnitTest)16 Title (org.orcid.jaxb.model.common_v2.Title)12 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)12 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)11 FundingSummary (org.orcid.jaxb.model.record.summary_v2.FundingSummary)10 OtherName (org.orcid.jaxb.model.record_v2.OtherName)10 Work (org.orcid.jaxb.model.record_v2.Work)10 ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)10 List (java.util.List)9 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)9 FundingContributor (org.orcid.jaxb.model.record_v2.FundingContributor)8 IOException (java.io.IOException)7 BaseTest (org.orcid.core.BaseTest)7