use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class Api12MembersTest method activitiesReadLimitedTest.
@Test
public void activitiesReadLimitedTest() throws InterruptedException, JSONException {
changeDefaultUserVisibility(org.orcid.jaxb.model.common_v2.Visibility.PUBLIC);
String clientId = getClient1ClientId();
String clientRedirectUri = getClient1RedirectUri();
String clientSecret = getClient1ClientSecret();
String userId = getUser1OrcidId();
String password = getUser1Password();
String workTitle = "Work " + System.currentTimeMillis();
String fundingTitle = "Funding " + System.currentTimeMillis();
String orgName = "Org_" + System.currentTimeMillis();
String accessToken = getAccessToken(userId, password, Arrays.asList("/read-limited", "/activities/update"), clientId, clientSecret, clientRedirectUri, true);
Long workPutCode = null;
Api12Helper.addWork(userId, accessToken, workTitle, t2OAuthClient_1_2);
Long fundingPutCode = null;
Api12Helper.addFunding(userId, accessToken, fundingTitle, t2OAuthClient_1_2);
Long affiliationPutCode = null;
Api12Helper.addAffiliation(userId, accessToken, orgName, t2OAuthClient_1_2);
ClientResponse worksResponse = t2OAuthClient_1_2.viewWorksDetailsXml(userId, accessToken);
assertNotNull(worksResponse);
assertEquals(200, worksResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", worksResponse.getType().toString());
OrcidMessage orcidMessageWithNewWork = worksResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewWork);
assertNotNull(orcidMessageWithNewWork.getOrcidProfile());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks());
assertNotNull(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork());
assertTrue(orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork().size() > 0);
boolean workFound = false;
for (OrcidWork work : orcidMessageWithNewWork.getOrcidProfile().getOrcidActivities().getOrcidWorks().getOrcidWork()) {
if (workTitle.equals(work.getWorkTitle().getTitle().getContent())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, work.getVisibility());
assertNotNull(work.getPutCode());
workPutCode = Long.valueOf(work.getPutCode());
workFound = true;
}
}
assertTrue(workFound);
ClientResponse fundingResponse = t2OAuthClient_1_2.viewFundingDetailsXml(userId, accessToken);
assertNotNull(fundingResponse);
assertEquals(200, fundingResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", fundingResponse.getType().toString());
OrcidMessage orcidMessageWithNewFunding = fundingResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewFunding);
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings());
assertNotNull(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings());
assertTrue(orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings().size() > 0);
boolean fundingFound = false;
for (Funding funding : orcidMessageWithNewFunding.getOrcidProfile().getOrcidActivities().getFundings().getFundings()) {
if (fundingTitle.equals(funding.getTitle().getTitle().getContent())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, funding.getVisibility());
assertNotNull(funding.getPutCode());
fundingPutCode = Long.valueOf(funding.getPutCode());
fundingFound = true;
}
}
assertTrue(fundingFound);
ClientResponse affiliationResponse = t2OAuthClient_1_2.viewAffiliationDetailsXml(userId, accessToken);
assertNotNull(affiliationResponse);
assertEquals(200, affiliationResponse.getStatus());
assertEquals("application/vnd.orcid+xml; charset=UTF-8; qs=5", affiliationResponse.getType().toString());
OrcidMessage orcidMessageWithNewAffiliation = affiliationResponse.getEntity(OrcidMessage.class);
assertNotNull(orcidMessageWithNewAffiliation);
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations());
assertNotNull(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation());
assertTrue(orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation().size() > 0);
boolean affiliationFound = false;
for (Affiliation affiliation : orcidMessageWithNewAffiliation.getOrcidProfile().getOrcidActivities().getAffiliations().getAffiliation()) {
if (orgName.equals(affiliation.getOrganization().getName())) {
// Default user visibility should be public
assertEquals(Visibility.PUBLIC, affiliation.getVisibility());
assertNotNull(affiliation.getPutCode());
affiliationPutCode = Long.valueOf(affiliation.getPutCode());
affiliationFound = true;
}
}
assertTrue(affiliationFound);
// Delete work
ClientResponse deleteResponse = memberV2ApiClient.deleteWorkXml(this.getUser1OrcidId(), workPutCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
// Delete funding
deleteResponse = memberV2ApiClient.deleteFundingXml(this.getUser1OrcidId(), fundingPutCode, accessToken);
assertEquals(Response.Status.NO_CONTENT.getStatusCode(), deleteResponse.getStatus());
// Delete affiliation
deleteResponse = memberV2ApiClient.deleteEducationXml(this.getUser1OrcidId(), affiliationPutCode, 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 Api12Helper method addFunding.
protected static void addFunding(String userOrcid, String token, String title, T2OAuthAPIService<ClientResponse> oauthT2Client) {
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
OrcidProfile orcidProfile = new OrcidProfile();
orcidMessage.setOrcidProfile(orcidProfile);
OrcidActivities orcidActivities = new OrcidActivities();
orcidProfile.setOrcidActivities(orcidActivities);
FundingList fundings = new FundingList();
Funding funding = new Funding();
funding.setVisibility(Visibility.LIMITED);
FundingTitle fundingTitle = new FundingTitle();
fundingTitle.setTitle(new Title(title));
funding.setTitle(fundingTitle);
funding.setType(FundingType.SALARY_AWARD);
Amount amount = new Amount();
amount.setCurrencyCode("CRC");
amount.setContent("1,250,000");
funding.setAmount(amount);
funding.setStartDate(new FuzzyDate(2010, 1, 1));
funding.setEndDate(new FuzzyDate(2013, 1, 1));
funding.setDescription("My Grant description");
funding.setUrl(new Url("http://url.com"));
Organization org = new Organization();
org.setName("Orcid Integration Test Org");
OrganizationAddress add = new OrganizationAddress();
add.setCity("My City");
add.setCountry(Iso3166Country.CR);
org.setAddress(add);
funding.setOrganization(org);
FundingExternalIdentifier extIdentifier = new FundingExternalIdentifier();
extIdentifier.setType(FundingExternalIdentifierType.fromValue("grant_number"));
extIdentifier.setUrl(new Url("http://url.com"));
extIdentifier.setValue("My value");
FundingExternalIdentifiers extIdentifiers = new FundingExternalIdentifiers();
extIdentifiers.getFundingExternalIdentifier().add(extIdentifier);
funding.setFundingExternalIdentifiers(extIdentifiers);
FundingContributors contributors = new FundingContributors();
FundingContributor contributor = new FundingContributor();
contributor.setCreditName(new CreditName("My Credit Name"));
contributor.setContributorEmail(new ContributorEmail("my.email@orcid-integration-test.com"));
FundingContributorAttributes attributes = new FundingContributorAttributes();
attributes.setContributorRole(FundingContributorRole.LEAD);
contributor.setContributorAttributes(attributes);
contributors.getContributor().add(contributor);
funding.setFundingContributors(contributors);
fundings.getFundings().add(funding);
orcidMessage.getOrcidProfile().getOrcidActivities().setFundings(fundings);
ClientResponse clientResponse = oauthT2Client.addFundingXml(userOrcid, orcidMessage, token);
assertEquals(201, clientResponse.getStatus());
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class Jaxb2JpaAdapterImpl method setFundings.
private void setFundings(ProfileEntity profileEntity, FundingList orcidFundings) {
SortedSet<ProfileFundingEntity> existingProfileFundingEntities = profileEntity.getProfileFunding();
if (existingProfileFundingEntities == null) {
existingProfileFundingEntities = new TreeSet<>();
}
// Create a map containing the existing profile funding entities
Map<String, ProfileFundingEntity> existingProfileFundingEntitiesMap = createProfileFundingEntitiesMap(existingProfileFundingEntities);
// A set that will contain the updated profile funding entities that
// comes from the orcidGrant object
SortedSet<ProfileFundingEntity> updatedProfileFundingEntities = new TreeSet<>();
// from the fundingList object
if (orcidFundings != null && orcidFundings.getFundings() != null && !orcidFundings.getFundings().isEmpty()) {
for (Funding orcidFunding : orcidFundings.getFundings()) {
ProfileFundingEntity newProfileGrantEntity = getProfileFundingEntity(orcidFunding, existingProfileFundingEntitiesMap.get(orcidFunding.getPutCode()));
newProfileGrantEntity.setProfile(profileEntity);
updatedProfileFundingEntities.add(newProfileGrantEntity);
}
}
// Create a map containing the profile funding that comes in the
// orcidGrant object and that will be persisted
Map<String, ProfileFundingEntity> updatedProfileGrantEntitiesMap = createProfileFundingEntitiesMap(updatedProfileFundingEntities);
// Remove orphans
for (Iterator<ProfileFundingEntity> iterator = existingProfileFundingEntities.iterator(); iterator.hasNext(); ) {
ProfileFundingEntity existingEntity = iterator.next();
if (!updatedProfileGrantEntitiesMap.containsKey(String.valueOf(existingEntity.getId()))) {
iterator.remove();
}
}
// Add new
for (ProfileFundingEntity updatedEntity : updatedProfileFundingEntities) {
if (updatedEntity.getId() == null) {
existingProfileFundingEntities.add(updatedEntity);
}
}
profileEntity.setProfileFunding(existingProfileFundingEntities);
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class OrcidMessageVersionConverterImplV1_2_rc3ToV1_2_rc4 method downgradeProfile.
private void downgradeProfile(OrcidProfile orcidProfile) {
if (orcidProfile != null) {
if (orcidProfile.getOrcidHistory() != null) {
if (orcidProfile.getOrcidHistory().getVerifiedEmail() != null) {
orcidProfile.getOrcidHistory().setVerifiedEmail(null);
}
if (orcidProfile.getOrcidHistory().getVerifiedPrimaryEmail() != null) {
orcidProfile.getOrcidHistory().setVerifiedPrimaryEmail(null);
}
}
if (orcidProfile.getOrcidInternal() != null) {
// earlier versions of the XSD don't have GroupOrcidIdentifier
if (orcidProfile.getOrcidInternal().getReferredBy() != null) {
orcidProfile.getOrcidInternal().setReferredBy(null);
}
// earlier versions of the XSD don't have
if (orcidProfile.getOrcidInternal().getPreferences() != null && orcidProfile.getOrcidInternal().getPreferences().getDeveloperToolsEnabled() != null) {
orcidProfile.getOrcidInternal().getPreferences().setDeveloperToolsEnabled(null);
}
}
if (orcidProfile.getOrcidInternal() != null) {
if (orcidProfile.getOrcidInternal().getPreferences() != null) {
Preferences prefs = orcidProfile.getOrcidInternal().getPreferences();
if (prefs.getActivitiesVisibilityDefault() != null && prefs.getActivitiesVisibilityDefault().getValue() != null) {
prefs.setWorkVisibilityDefault(new WorkVisibilityDefault(prefs.getActivitiesVisibilityDefault().getValue()));
prefs.setActivitiesVisibilityDefault(null);
}
}
}
//Previews versions doesnt have organization defined funding type
if (orcidProfile.getOrcidActivities() != null) {
OrcidActivities activities = orcidProfile.getOrcidActivities();
if (activities.getFundings() != null) {
FundingList fundingList = activities.getFundings();
for (Funding funding : fundingList.getFundings()) {
funding.setOrganizationDefinedFundingType(null);
}
}
}
}
}
use of org.orcid.jaxb.model.message.Funding in project ORCID-Source by ORCID.
the class OrcidProfileToSolrDocument method convert.
@Deprecated
public OrcidSolrDocument convert(OrcidProfile profile) {
// Check if the profile is locked
if (profile.isLocked()) {
profile.downgradeToOrcidIdentifierOnly();
}
OrcidSolrDocument profileIndexDocument = new OrcidSolrDocument();
profileIndexDocument.setOrcid(profile.getOrcidIdentifier().getPath());
OrcidDeprecated orcidDeprecated = profile.getOrcidDeprecated();
if (orcidDeprecated != null) {
profileIndexDocument.setPrimaryRecord(orcidDeprecated.getPrimaryRecord() != null ? orcidDeprecated.getPrimaryRecord().getOrcidIdentifier().getPath() : null);
}
OrcidBio orcidBio = profile.getOrcidBio();
if (orcidBio != null) {
PersonalDetails personalDetails = orcidBio.getPersonalDetails();
boolean persistPersonalDetails = personalDetails != null;
if (persistPersonalDetails) {
profileIndexDocument.setFamilyName(personalDetails.getFamilyName() != null ? personalDetails.getFamilyName().getContent() : null);
profileIndexDocument.setGivenNames(personalDetails.getGivenNames() != null ? personalDetails.getGivenNames().getContent() : null);
profileIndexDocument.setCreditName(personalDetails.getCreditName() != null ? personalDetails.getCreditName().getContent() : null);
List<OtherName> otherNames = personalDetails.getOtherNames() != null ? personalDetails.getOtherNames().getOtherName() : null;
if (otherNames != null && !otherNames.isEmpty()) {
List<String> names = new ArrayList<String>();
for (OtherName otherName : otherNames) {
names.add(otherName.getContent());
}
profileIndexDocument.setOtherNames(names);
}
}
ContactDetails contactDetails = orcidBio.getContactDetails();
if (contactDetails != null) {
for (Email email : contactDetails.getEmail()) {
profileIndexDocument.addEmailAddress(email.getValue());
}
}
ExternalIdentifiers externalIdentifiers = orcidBio.getExternalIdentifiers();
if (externalIdentifiers != null) {
List<String> extIdOrcids = new ArrayList<String>();
List<String> extIdRefs = new ArrayList<String>();
List<String> extIdOrcidsAndRefs = new ArrayList<String>();
for (ExternalIdentifier externalIdentifier : externalIdentifiers.getExternalIdentifier()) {
Source source = externalIdentifier.getSource();
String sourcePath = null;
if (source != null) {
sourcePath = source.retrieveSourcePath();
if (sourcePath != null) {
extIdOrcids.add(sourcePath);
}
}
ExternalIdReference externalIdReference = externalIdentifier.getExternalIdReference();
if (externalIdReference != null) {
extIdRefs.add(externalIdReference.getContent());
}
if (NullUtils.noneNull(sourcePath, externalIdReference)) {
extIdOrcidsAndRefs.add(sourcePath + "=" + externalIdReference.getContent());
}
}
if (!extIdOrcids.isEmpty()) {
profileIndexDocument.setExternalIdSources(extIdOrcids);
}
if (!extIdRefs.isEmpty()) {
profileIndexDocument.setExternalIdReferences(extIdRefs);
}
if (!extIdOrcidsAndRefs.isEmpty()) {
profileIndexDocument.setExternalIdSourcesAndReferences(extIdOrcidsAndRefs);
}
}
OrcidActivities orcidActivities = profile.getOrcidActivities();
if (orcidActivities != null) {
if (orcidBio != null && orcidBio.getKeywords() != null) {
List<Keyword> keyWords = orcidBio.getKeywords().getKeyword();
if (keyWords != null && keyWords.size() > 0) {
List<String> keywordValues = new ArrayList<String>();
for (Keyword keyword : keyWords) {
keywordValues.add(keyword.getContent());
}
profileIndexDocument.setKeywords(keywordValues);
}
}
}
List<OrcidWork> orcidWorks = profile.retrieveOrcidWorks() != null ? profile.retrieveOrcidWorks().getOrcidWork() : null;
if (orcidWorks != null) {
List<String> workTitles = new ArrayList<String>();
Map<WorkExternalIdentifierType, List<String>> allExternalIdentifiers = new HashMap<WorkExternalIdentifierType, List<String>>();
for (OrcidWork orcidWork : orcidWorks) {
if (orcidWork.getWorkExternalIdentifiers() != null) {
for (WorkExternalIdentifier workExternalIdentifier : orcidWork.getWorkExternalIdentifiers().getWorkExternalIdentifier()) {
/**
* Creates a map that contains all different
* external identifiers for the current work
*/
boolean nullSafeCheckForWorkExternalIdentifier = workExternalIdentifier.getWorkExternalIdentifierId() != null && !StringUtils.isBlank(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
if (nullSafeCheckForWorkExternalIdentifier) {
WorkExternalIdentifierType type = workExternalIdentifier.getWorkExternalIdentifierType();
if (!allExternalIdentifiers.containsKey(type)) {
List<String> content = new ArrayList<String>();
content.add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
allExternalIdentifiers.put(type, content);
} else {
allExternalIdentifiers.get(type).add(workExternalIdentifier.getWorkExternalIdentifierId().getContent());
}
}
}
}
if (orcidWork.getWorkTitle() != null) {
Title workMainTitle = orcidWork.getWorkTitle().getTitle();
Subtitle worksubTitle = orcidWork.getWorkTitle().getSubtitle();
TranslatedTitle translatedTitle = orcidWork.getWorkTitle().getTranslatedTitle();
if (workMainTitle != null && !StringUtils.isBlank(workMainTitle.getContent())) {
workTitles.add(workMainTitle.getContent());
}
if (worksubTitle != null && !StringUtils.isBlank(worksubTitle.getContent())) {
workTitles.add(worksubTitle.getContent());
}
if (translatedTitle != null && !StringUtils.isBlank(translatedTitle.getContent())) {
workTitles.add(translatedTitle.getContent());
}
}
}
profileIndexDocument.setWorkTitles(workTitles);
// Set the list of external identifiers to the document list
addExternalIdentifiersToIndexDocument(profileIndexDocument, allExternalIdentifiers);
}
List<Funding> orcidFundings = profile.retrieveFundings() != null ? profile.retrieveFundings().getFundings() : null;
if (orcidFundings != null) {
List<String> fundingTitle = new ArrayList<String>();
for (Funding orcidFunding : orcidFundings) {
FundingTitle title = orcidFunding.getTitle();
if (title != null) {
if (title.getTitle() != null && !StringUtils.isBlank(title.getTitle().getContent())) {
fundingTitle.add(title.getTitle().getContent());
}
if (title.getTranslatedTitle() != null && StringUtils.isBlank(title.getTranslatedTitle().getContent())) {
fundingTitle.add(title.getTranslatedTitle().getContent());
}
}
}
profileIndexDocument.setFundingTitles(fundingTitle);
}
}
OrcidMessage orcidMessage = new OrcidMessage();
orcidMessage.setMessageVersion(OrcidMessage.DEFAULT_VERSION);
orcidMessage.setOrcidProfile(profile);
OrcidHistory orcidHistory = profile.getOrcidHistory();
if (orcidHistory != null) {
LastModifiedDate lastModifiedDate = orcidHistory.getLastModifiedDate();
if (lastModifiedDate != null) {
profileIndexDocument.setProfileLastModifiedDate(lastModifiedDate.getValue().toGregorianCalendar().getTime());
}
SubmissionDate submissionDate = orcidHistory.getSubmissionDate();
if (submissionDate != null) {
profileIndexDocument.setProfileSubmissionDate(submissionDate.getValue().toGregorianCalendar().getTime());
}
}
return profileIndexDocument;
}
Aggregations