Search in sources :

Example 6 with ProfileFundingEntity

use of org.orcid.persistence.jpa.entities.ProfileFundingEntity in project ORCID-Source by ORCID.

the class ProfileFundingManagerImpl method checkSourceAndDelete.

/**
     * Deletes a given funding, if and only if, the client that requested the delete is the source of the funding
     * @param orcid
     *          the funding owner
     * @param fundingId
     *          The funding id                 
     * @return true if the funding was deleted, false otherwise
     * */
@Override
@Transactional
public boolean checkSourceAndDelete(String orcid, Long fundingId) {
    ProfileFundingEntity pfe = profileFundingDao.getProfileFunding(orcid, fundingId);
    orcidSecurityManager.checkSource(pfe);
    Item item = createItem(pfe);
    boolean result = profileFundingDao.removeProfileFunding(orcid, fundingId);
    notificationManager.sendAmendEmail(orcid, AmendedSection.FUNDING, item);
    return result;
}
Also used : Item(org.orcid.jaxb.model.notification.permission_v2.Item) ProfileFundingEntity(org.orcid.persistence.jpa.entities.ProfileFundingEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with ProfileFundingEntity

use of org.orcid.persistence.jpa.entities.ProfileFundingEntity 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 8 with ProfileFundingEntity

use of org.orcid.persistence.jpa.entities.ProfileFundingEntity 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 9 with ProfileFundingEntity

use of org.orcid.persistence.jpa.entities.ProfileFundingEntity in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method testAddMultipleModifiesIndexingStatus.

@Test
public void testAddMultipleModifiesIndexingStatus() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding f1 = getFunding("F1");
    f1 = profileFundingManager.createFunding(claimedOrcid, f1, true);
    Funding f2 = getFunding("F2");
    f2 = profileFundingManager.createFunding(claimedOrcid, f2, true);
    Funding f3 = getFunding("F3");
    f3 = profileFundingManager.createFunding(claimedOrcid, f3, true);
    ProfileFundingEntity entity1 = profileFundingDao.find(f1.getPutCode());
    ProfileFundingEntity entity2 = profileFundingDao.find(f2.getPutCode());
    ProfileFundingEntity entity3 = profileFundingDao.find(f3.getPutCode());
    assertNotNull(entity1.getDisplayIndex());
    assertNotNull(entity2.getDisplayIndex());
    assertNotNull(entity3.getDisplayIndex());
    assertEquals(Long.valueOf(0), entity3.getDisplayIndex());
    //Rollback all changes
    profileFundingDao.remove(entity1.getId());
    profileFundingDao.remove(entity2.getId());
    profileFundingDao.remove(entity3.getId());
}
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 10 with ProfileFundingEntity

use of org.orcid.persistence.jpa.entities.ProfileFundingEntity in project ORCID-Source by ORCID.

the class ProfileFundingManagerTest method displayIndexIsSetTo_1_FromUI.

@Test
public void displayIndexIsSetTo_1_FromUI() {
    when(sourceManager.retrieveSourceEntity()).thenReturn(new SourceEntity(new ClientDetailsEntity(CLIENT_1_ID)));
    Funding f1 = getFunding("fromUI-1");
    f1 = profileFundingManager.createFunding(claimedOrcid, f1, false);
    ProfileFundingEntity f = profileFundingDao.find(f1.getPutCode());
    assertNotNull(f);
    assertEquals(Long.valueOf(1), 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)

Aggregations

ProfileFundingEntity (org.orcid.persistence.jpa.entities.ProfileFundingEntity)26 Test (org.junit.Test)9 Funding (org.orcid.jaxb.model.record_v2.Funding)8 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)5 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)5 Transactional (org.springframework.transaction.annotation.Transactional)5 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)4 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 BaseTest (org.orcid.core.BaseTest)3 ClientDetailsEntity (org.orcid.persistence.jpa.entities.ClientDetailsEntity)3 EmailEntity (org.orcid.persistence.jpa.entities.EmailEntity)3 ExternalIdentifierEntity (org.orcid.persistence.jpa.entities.ExternalIdentifierEntity)3 OrgAffiliationRelationEntity (org.orcid.persistence.jpa.entities.OrgAffiliationRelationEntity)3 OtherNameEntity (org.orcid.persistence.jpa.entities.OtherNameEntity)3 ProfileKeywordEntity (org.orcid.persistence.jpa.entities.ProfileKeywordEntity)3 ResearcherUrlEntity (org.orcid.persistence.jpa.entities.ResearcherUrlEntity)3 BigDecimal (java.math.BigDecimal)2 TreeSet (java.util.TreeSet)2 Funding (org.orcid.jaxb.model.message.Funding)2