Search in sources :

Example 31 with Funding

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

the class MemberV2ApiServiceDelegator_FundingTest method testViewLimitedFunding.

@Test
public void testViewLimitedFunding() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4443", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4443", 1L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    Utils.verifyLastModified(funding.getLastModifiedDate());
    assertNotNull(funding.getTitle());
    assertNotNull(funding.getTitle().getTitle());
    assertEquals(Long.valueOf(1), funding.getPutCode());
    assertEquals("/4444-4444-4444-4443/funding/1", funding.getPath());
    assertEquals("Grant # 1", funding.getTitle().getTitle().getContent());
    assertEquals(Visibility.LIMITED.value(), funding.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 32 with Funding

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

the class MemberV2ApiServiceDelegator_FundingTest method testViewFundingReadPublic.

@Test
public void testViewFundingReadPublic() {
    SecurityContextTestUtils.setUpSecurityContextForClientOnly("APP-5555555555555555", ScopePathType.READ_PUBLIC);
    Response r = serviceDelegator.viewFunding(ORCID, 10L);
    Funding element = (Funding) r.getEntity();
    assertNotNull(element);
    assertEquals("/0000-0000-0000-0003/funding/10", element.getPath());
    Utils.assertIsPublicOrSource(element, "APP-5555555555555555");
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 33 with Funding

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

the class MemberV2ApiServiceDelegator_FundingTest method testViewPublicFunding.

@Test
public void testViewPublicFunding() {
    SecurityContextTestUtils.setUpSecurityContext("4444-4444-4444-4446", ScopePathType.READ_LIMITED);
    Response response = serviceDelegator.viewFunding("4444-4444-4444-4446", 5L);
    assertNotNull(response);
    Funding funding = (Funding) response.getEntity();
    assertNotNull(funding);
    Utils.verifyLastModified(funding.getLastModifiedDate());
    assertNotNull(funding.getTitle());
    assertNotNull(funding.getTitle().getTitle());
    assertEquals(Long.valueOf(5), funding.getPutCode());
    assertEquals("/4444-4444-4444-4446/funding/5", funding.getPath());
    assertEquals("Public Funding", funding.getTitle().getTitle().getContent());
    assertEquals(Visibility.PUBLIC.value(), funding.getVisibility().value());
}
Also used : Response(javax.ws.rs.core.Response) Funding(org.orcid.jaxb.model.record_v2.Funding) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 34 with Funding

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

the class ProfileFundingManagerImpl method createFunding.

/**
     * Add a new funding to the given user
     * @param orcid
     *          The user to add the funding
     * @param funding
     *          The funding to add
     * @return the added funding                  
     * */
@Override
@Transactional
public Funding createFunding(String orcid, Funding funding, boolean isApiRequest) {
    SourceEntity sourceEntity = sourceManager.retrieveSourceEntity();
    activityValidator.validateFunding(funding, sourceEntity, true, isApiRequest, null);
    //Check for duplicates
    List<ProfileFundingEntity> existingFundings = profileFundingDao.getByUser(orcid);
    List<Funding> fundings = jpaJaxbFundingAdapter.toFunding(existingFundings);
    if (fundings != null && isApiRequest) {
        for (Funding exstingFunding : fundings) {
            activityValidator.checkFundingExternalIdentifiersForDuplicates(funding.getExternalIdentifiers(), exstingFunding.getExternalIdentifiers(), exstingFunding.getSource(), sourceEntity);
        }
    }
    ProfileFundingEntity profileFundingEntity = jpaJaxbFundingAdapter.toProfileFundingEntity(funding);
    //Updates the give organization with the latest organization from database
    OrgEntity updatedOrganization = orgManager.getOrgEntity(funding);
    profileFundingEntity.setOrg(updatedOrganization);
    //Set the source
    if (sourceEntity.getSourceProfile() != null) {
        profileFundingEntity.setSourceId(sourceEntity.getSourceProfile().getId());
    }
    if (sourceEntity.getSourceClient() != null) {
        profileFundingEntity.setClientSourceId(sourceEntity.getSourceClient().getId());
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(orcid);
    profileFundingEntity.setProfile(profile);
    setIncomingWorkPrivacy(profileFundingEntity, profile);
    DisplayIndexCalculatorHelper.setDisplayIndexOnNewEntity(profileFundingEntity, isApiRequest);
    profileFundingDao.persist(profileFundingEntity);
    profileFundingDao.flush();
    if (isApiRequest) {
        notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, createItem(profileFundingEntity));
    }
    return jpaJaxbFundingAdapter.toFunding(profileFundingEntity);
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with Funding

use of org.orcid.jaxb.model.record_rc3.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)

Aggregations

Funding (org.orcid.jaxb.model.record_v2.Funding)82 Test (org.junit.Test)71 ClientResponse (com.sun.jersey.api.client.ClientResponse)28 ArrayList (java.util.ArrayList)17 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)16 Response (javax.ws.rs.core.Response)15 Url (org.orcid.jaxb.model.common_v2.Url)15 DBUnitTest (org.orcid.test.DBUnitTest)15 Title (org.orcid.jaxb.model.common_v2.Title)11 Work (org.orcid.jaxb.model.record_v2.Work)10 List (java.util.List)9 FundingTitle (org.orcid.jaxb.model.record_v2.FundingTitle)9 ResearcherUrl (org.orcid.jaxb.model.record_v2.ResearcherUrl)9 Funding (org.orcid.jaxb.model.record_rc1.Funding)8 ExternalIDs (org.orcid.jaxb.model.record_v2.ExternalIDs)8 WorkTitle (org.orcid.jaxb.model.record_v2.WorkTitle)8 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)6 Reader (java.io.Reader)6 BaseTest (org.orcid.core.BaseTest)6