use of org.orcid.jaxb.model.record_rc1.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());
}
use of org.orcid.jaxb.model.record_rc1.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);
}
use of org.orcid.jaxb.model.record_rc1.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);
}
use of org.orcid.jaxb.model.record_rc1.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());
}
use of org.orcid.jaxb.model.record_rc1.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());
}
Aggregations