use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method addFundings.
/**
* Adds a new {@link List<org.orcid.jaxb.model.message.FundingList<}
* to the {@link} OrcidProfile} and returns the updated values
*
* @param updatedOrcidProfile
* @return
*/
@Override
@Transactional
public void addFundings(OrcidProfile updatedOrcidProfile) {
String orcid = updatedOrcidProfile.getOrcidIdentifier().getPath();
OrcidProfile existingProfile = retrieveOrcidProfile(orcid);
if (existingProfile == null) {
throw new IllegalArgumentException("No record found for " + orcid);
}
String amenderOrcid = sourceManager.retrieveSourceOrcid();
FundingList existingFundingList = existingProfile.retrieveFundings();
// updates the amount format to the right format according to the
// current locale
setFundingAmountsWithTheCorrectFormat(updatedOrcidProfile);
FundingList updatedFundingList = updatedOrcidProfile.retrieveFundings();
Visibility workVisibilityDefault = existingProfile.getOrcidInternal().getPreferences().getActivitiesVisibilityDefault().getValue();
Boolean claimed = existingProfile.getOrcidHistory().isClaimed();
setFundingPrivacy(updatedFundingList, workVisibilityDefault, claimed == null ? false : claimed);
updatedFundingList = dedupeFundings(updatedFundingList);
addSourceToFundings(updatedFundingList, amenderOrcid);
List<Funding> updatedList = updatedFundingList.getFundings();
checkForAlreadyExistingFundings(existingFundingList, updatedList);
persistAddedFundings(orcid, updatedList);
profileDao.flush();
boolean notificationsEnabled = existingProfile.getOrcidInternal().getPreferences().getNotificationsEnabled();
if (notificationsEnabled) {
notificationManager.sendAmendEmail(existingProfile, AmendedSection.FUNDING);
}
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class OrcidProfileManagerImpl method persistAddedFundings.
private void persistAddedFundings(String orcid, List<Funding> updatedFundingList) {
ProfileEntity profileEntity = profileDao.find(orcid);
for (Funding updatedFunding : updatedFundingList) {
ProfileFundingEntity profileFundingEntity = jaxb2JpaAdapter.getNewProfileFundingEntity(updatedFunding, profileEntity);
// Save the profile grant
profileFundingDao.addProfileFunding(profileFundingEntity);
}
orcidProfileCacheManager.remove(orcid);
}
use of org.orcid.jaxb.model.message.Funding 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);
}
}
}
}
}
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class Api12MembersTest method addFundingTest.
@Test
public void addFundingTest() throws InterruptedException, JSONException {
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String accessToken = getAccessToken(userId, password, Arrays.asList("/funding/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
String fundingTitle = "Funding " + System.currentTimeMillis();
Long putCode = null;
Api12Helper.addFunding(userId, accessToken, fundingTitle, t2OAuthClient_1_2);
ClientResponse response = t2OAuthClient_1_2.viewFundingDetailsXml(userId, accessToken);
assertNotNull(response);
assertEquals(200, response.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", response.getType().toString());
OrcidMessage orcidMessage = response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessage);
assertNotNull(orcidMessage.getOrcidProfile());
assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities().getFundings());
assertNotNull(orcidMessage.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
boolean found = false;
for (Funding funding : orcidMessage.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
if (fundingTitle.equals(funding.getTitle().getTitle().getContent())) {
assertNotNull(funding.getPutCode());
putCode = Long.valueOf(funding.getPutCode());
found = true;
}
}
assertTrue(found);
// Delete it
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class Api12MembersTest method viewOwnPrivateFundingTest.
@Test
public void viewOwnPrivateFundingTest() throws InterruptedException, JSONException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PRIVATE);
String client1Id = getClient1ClientId();
String client1RedirectUri = getClient1RedirectUri();
String client1Secret = getClient1ClientSecret();
String client2Id = getClient2ClientId();
String client2RedirectUri = getClient2RedirectUri();
String client2Secret = getClient2ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String client1AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client1Id, client1Secret, client1RedirectUri, true);
String client2AccessToken = getAccessToken(userId, password, Arrays.asList("/activities/read-limited", "/activities/update"), client2Id, client2Secret, client2RedirectUri, true);
String title1 = "Client 1 - Funding " + System.currentTimeMillis();
String title2 = "Client 2 - Funding " + System.currentTimeMillis();
Api12Helper.addFunding(userId, client1AccessToken, title1, t2OAuthClient_1_2);
Api12Helper.addFunding(userId, client2AccessToken, title2, t2OAuthClient_1_2);
Long putCode1 = 0L;
Long putCode2 = 0L;
// Fetch with client 1 and verify it can only see his private funding
ClientResponse client1Response = t2OAuthClient_1_2.viewFundingDetailsXml(userId, client1AccessToken);
assertNotNull(client1Response);
assertEquals(200, client1Response.getStatus());
OrcidMessage orcidMessageWithNewFunding = client1Response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewFunding);
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
boolean found = false;
for (Funding funding : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
if (title2.equals(funding.getTitle().getTitle().getContent())) {
fail("I found funding for client # 2, which is wrong since it is private");
}
if (title1.equals(funding.getTitle().getTitle().getContent())) {
assertEquals(Visibility.PRIVATE, funding.getVisibility());
putCode1 = Long.valueOf(funding.getPutCode());
found = true;
}
}
assertTrue(found);
// Fetch with client 2 and verify it can only see his private funding
ClientResponse client2Response = t2OAuthClient_1_2.viewFundingDetailsXml(userId, client2AccessToken);
assertNotNull(client2Response);
assertEquals(200, client2Response.getStatus());
orcidMessageWithNewFunding = client2Response.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewFunding);
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
found = false;
for (Funding funding : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
if (title1.equals(funding.getTitle().getTitle().getContent())) {
fail("I found funding for client # 1, which is wrong since it is private");
}
if (title2.equals(funding.getTitle().getTitle().getContent())) {
assertEquals(Visibility.PRIVATE, funding.getVisibility());
putCode2 = Long.valueOf(funding.getPutCode());
found = true;
}
}
assertTrue(found);
// Delete both funding before finishing
ClientResponse deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode1, client1AccessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), putCode2, client2AccessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
}
Aggregations