use of org.orcid.jaxb.model.v3.dev1.record.summary.Fundings in project ORCID-Source by ORCID.
the class GetMyDataControllerTest method testDownload.
@Test
public void testDownload() throws JAXBException, IOException {
SecurityContextHolder.getContext().setAuthentication(getAuthentication());
MockHttpServletResponse response = new MockHttpServletResponse();
getMyDataController.getMyData(response);
byte[] content = response.getContentAsByteArray();
ByteArrayInputStream is = new ByteArrayInputStream(content);
ZipInputStream zip = new ZipInputStream(is);
ZipEntry zipEntry = zip.getNextEntry();
JAXBContext jaxbContext1 = JAXBContext.newInstance(Person.class, Distinction.class, Education.class, Employment.class, InvitedPosition.class, Membership.class, Qualification.class, Service.class, Funding.class, PeerReview.class, Work.class);
Unmarshaller u = jaxbContext1.createUnmarshaller();
boolean personFound = false;
boolean distinctionFound = false;
boolean educationFound = false;
boolean employmentFound = false;
boolean invitedPositionFound = false;
boolean membershipFound = false;
boolean qualificationFound = false;
boolean serviceFound = false;
boolean fundingFound = false;
boolean peerReviewFound = false;
boolean workFound = false;
while (zipEntry != null) {
String fileName = zipEntry.getName();
byte[] buffer = new byte[1024];
ByteArrayOutputStream out = new ByteArrayOutputStream();
int len;
while ((len = zip.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
if (fileName.equals("person.xml")) {
Person x = (Person) u.unmarshal(in);
assertNotNull(x);
assertEquals("Biography", x.getBiography().getContent());
assertEquals(Visibility.LIMITED, x.getBiography().getVisibility());
personFound = true;
} else if (fileName.startsWith("affiliations/distinctions")) {
assertEquals("affiliations/distinctions/1.xml", fileName);
Distinction x = (Distinction) u.unmarshal(in);
assertNotNull(x);
assertEquals("distinction", x.getDepartmentName());
assertEquals(Long.valueOf(1), x.getPutCode());
validateOrg(x);
distinctionFound = true;
} else if (fileName.startsWith("affiliations/educations")) {
assertEquals("affiliations/educations/2.xml", fileName);
Education x = (Education) u.unmarshal(in);
assertNotNull(x);
assertEquals("education", x.getDepartmentName());
assertEquals(Long.valueOf(2), x.getPutCode());
validateOrg(x);
educationFound = true;
} else if (fileName.startsWith("affiliations/employments")) {
assertEquals("affiliations/employments/3.xml", fileName);
Employment x = (Employment) u.unmarshal(in);
assertNotNull(x);
assertEquals("employment", x.getDepartmentName());
assertEquals(Long.valueOf(3), x.getPutCode());
validateOrg(x);
employmentFound = true;
} else if (fileName.startsWith("affiliations/invited_positions")) {
assertEquals("affiliations/invited_positions/4.xml", fileName);
InvitedPosition x = (InvitedPosition) u.unmarshal(in);
assertNotNull(x);
assertEquals("invited position", x.getDepartmentName());
assertEquals(Long.valueOf(4), x.getPutCode());
validateOrg(x);
invitedPositionFound = true;
} else if (fileName.startsWith("affiliations/memberships")) {
assertEquals("affiliations/memberships/5.xml", fileName);
Membership x = (Membership) u.unmarshal(in);
assertNotNull(x);
assertEquals("membership", x.getDepartmentName());
assertEquals(Long.valueOf(5), x.getPutCode());
validateOrg(x);
membershipFound = true;
} else if (fileName.startsWith("affiliations/qualifications")) {
assertEquals("affiliations/qualifications/6.xml", fileName);
Qualification x = (Qualification) u.unmarshal(in);
assertNotNull(x);
assertEquals("qualification", x.getDepartmentName());
assertEquals(Long.valueOf(6), x.getPutCode());
validateOrg(x);
qualificationFound = true;
} else if (fileName.startsWith("affiliations/services")) {
assertEquals("affiliations/services/7.xml", fileName);
Service x = (Service) u.unmarshal(in);
assertNotNull(x);
assertEquals("service", x.getDepartmentName());
assertEquals(Long.valueOf(7), x.getPutCode());
validateOrg(x);
serviceFound = true;
} else if (fileName.startsWith("fundings")) {
assertEquals("fundings/1.xml", fileName);
Funding x = (Funding) u.unmarshal(in);
assertNotNull(x);
assertEquals("title", x.getTitle().getTitle().getContent());
assertEquals("1000", x.getAmount().getContent());
assertEquals("$", x.getAmount().getCurrencyCode());
assertEquals(Long.valueOf(1), x.getPutCode());
validateOrg(x);
fundingFound = true;
} else if (fileName.startsWith("peer_reviews")) {
assertEquals("peer_reviews/1.xml", fileName);
PeerReview x = (PeerReview) u.unmarshal(in);
assertNotNull(x);
validateOrg(x);
assertEquals(Long.valueOf(1), x.getPutCode());
peerReviewFound = true;
} else if (fileName.startsWith("works")) {
assertEquals("works/1.xml", fileName);
Work x = (Work) u.unmarshal(in);
assertNotNull(x);
assertEquals(Long.valueOf(1), x.getPutCode());
workFound = true;
}
zipEntry = zip.getNextEntry();
}
assertTrue(personFound);
assertTrue(distinctionFound);
assertTrue(educationFound);
assertTrue(employmentFound);
assertTrue(invitedPositionFound);
assertTrue(membershipFound);
assertTrue(qualificationFound);
assertTrue(serviceFound);
assertTrue(fundingFound);
assertTrue(peerReviewFound);
assertTrue(workFound);
zip.closeEntry();
zip.close();
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.Fundings in project ORCID-Source by ORCID.
the class OrcidInfo method getFundingsJson.
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/fundings.json")
@ResponseBody
public List<FundingForm> getFundingsJson(HttpServletRequest request, @PathVariable("orcid") String orcid, @RequestParam(value = "fundingIds") String fundingIdsStr) {
Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
List<FundingForm> fundings = new ArrayList<FundingForm>();
Map<Long, Funding> fundingMap = activityManager.fundingMap(orcid);
String[] fundingIds = fundingIdsStr.split(",");
for (String id : fundingIds) {
Funding funding = fundingMap.get(Long.valueOf(id));
validateVisibility(funding.getVisibility());
sourceUtils.setSourceName(funding);
FundingForm form = FundingForm.valueOf(funding);
// Set type name
if (funding.getType() != null) {
form.setFundingTypeForDisplay(getMessage(buildInternationalizationKey(org.orcid.jaxb.model.message.FundingType.class, funding.getType().value())));
}
// Set translated title language name
if (!(funding.getTitle().getTranslatedTitle() == null) && !StringUtils.isEmpty(funding.getTitle().getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(funding.getTitle().getTranslatedTitle().getLanguageCode());
form.getFundingTitle().getTranslatedTitle().setLanguageName(languageName);
}
// Set formatted amount
if (funding.getAmount() != null && StringUtils.isNotBlank(funding.getAmount().getContent())) {
BigDecimal bigDecimal = new BigDecimal(funding.getAmount().getContent());
String formattedAmount = formatAmountString(bigDecimal);
form.setAmount(Text.valueOf(formattedAmount));
}
// Set country name
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
fundings.add(form);
}
return fundings;
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.Fundings in project ORCID-Source by ORCID.
the class FundingsController method createFundingIdList.
/**
* Create a funding id list and sorts a map associated with the list in in
* the session
*/
private List<String> createFundingIdList(HttpServletRequest request) {
Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
String orcid = getEffectiveUserOrcid();
List<Funding> fundings = profileFundingManager.getFundingList(orcid);
HashMap<String, FundingForm> fundingsMap = new HashMap<String, FundingForm>();
List<String> fundingIds = new ArrayList<String>();
if (fundings != null) {
for (Funding funding : fundings) {
try {
FundingForm form = FundingForm.valueOf(funding);
if (funding.getType() != null) {
form.setFundingTypeForDisplay(getMessage(buildInternationalizationKey(org.orcid.jaxb.model.message.FundingType.class, funding.getType().value())));
}
// Set translated title language name
if (!(funding.getTitle().getTranslatedTitle() == null) && !StringUtils.isEmpty(funding.getTitle().getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(funding.getTitle().getTranslatedTitle().getLanguageCode());
form.getFundingTitle().getTranslatedTitle().setLanguageName(languageName);
}
// Set the formatted amount
if (funding.getAmount() != null && StringUtils.isNotBlank(funding.getAmount().getContent())) {
BigDecimal bigDecimal = new BigDecimal(funding.getAmount().getContent());
String formattedAmount = formatAmountString(bigDecimal);
form.setAmount(Text.valueOf(formattedAmount));
}
if (form.getContributors() != null) {
for (Contributor contributor : form.getContributors()) {
if (!PojoUtil.isEmpty(contributor.getOrcid())) {
String contributorOrcid = contributor.getOrcid().getValue();
if (profileEntityManager.orcidExists(contributorOrcid)) {
// contributor is an ORCID user - visibility of user's name in record must be taken into account
ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
String publicContributorCreditName = cacheManager.getPublicCreditName(profileEntity);
contributor.setCreditName(Text.valueOf(publicContributorCreditName));
}
}
}
}
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
String putCode = String.valueOf(funding.getPutCode());
fundingsMap.put(putCode, form);
fundingIds.add(putCode);
} catch (Exception e) {
LOGGER.error("Failed to parse as Funding. Put code" + funding.getPutCode(), e);
}
}
request.getSession().setAttribute(GRANT_MAP, fundingsMap);
}
return fundingIds;
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.Fundings in project ORCID-Source by ORCID.
the class FundingsController method getFundingJson.
/**
* List fundings associated with a profile
*/
@RequestMapping(value = "/getFunding.json", method = RequestMethod.GET)
@ResponseBody
public FundingForm getFundingJson(@RequestParam(value = "fundingId") Long fundingId) {
if (fundingId == null)
return null;
Map<String, String> languages = lm.buildLanguageMap(getUserLocale(), false);
Funding funding = profileFundingManager.getFunding(getEffectiveUserOrcid(), fundingId);
FundingForm form = FundingForm.valueOf(funding);
if (funding.getType() != null) {
form.setFundingTypeForDisplay(getMessage(buildInternationalizationKey(org.orcid.jaxb.model.message.FundingType.class, funding.getType().value())));
}
// Set translated title language name
if (!(funding.getTitle().getTranslatedTitle() == null) && !StringUtils.isEmpty(funding.getTitle().getTranslatedTitle().getLanguageCode())) {
String languageName = languages.get(funding.getTitle().getTranslatedTitle().getLanguageCode());
form.getFundingTitle().getTranslatedTitle().setLanguageName(languageName);
}
// Set the formatted amount
if (funding.getAmount() != null && StringUtils.isNotBlank(funding.getAmount().getContent())) {
BigDecimal bigDecimal = new BigDecimal(funding.getAmount().getContent());
String formattedAmount = formatAmountString(bigDecimal);
form.setAmount(Text.valueOf(formattedAmount));
}
form.setCountryForDisplay(getMessage(buildInternationalizationKey(CountryIsoEntity.class, funding.getOrganization().getAddress().getCountry().name())));
return form;
}
use of org.orcid.jaxb.model.v3.dev1.record.summary.Fundings in project ORCID-Source by ORCID.
the class OrcidSecurityManager_ActivitiesSummaryTest method testActivitiesSummary_When_SomePrivate_NoSource_ReadLimitedToken.
@Test
public void testActivitiesSummary_When_SomePrivate_NoSource_ReadLimitedToken() {
SecurityContextTestUtils.setUpSecurityContext(ORCID_1, CLIENT_1, ScopePathType.ACTIVITIES_READ_LIMITED);
DistinctionSummary d1 = createDistinctionSummary(Visibility.PUBLIC, CLIENT_2);
DistinctionSummary d2 = createDistinctionSummary(Visibility.PRIVATE, CLIENT_2);
DistinctionSummary d3 = createDistinctionSummary(Visibility.PRIVATE, CLIENT_2);
EducationSummary e1 = createEducationSummary(Visibility.PUBLIC, CLIENT_2);
EducationSummary e2 = createEducationSummary(Visibility.PRIVATE, CLIENT_2);
EducationSummary e3 = createEducationSummary(Visibility.PRIVATE, CLIENT_2);
EmploymentSummary em1 = createEmploymentSummary(Visibility.PUBLIC, CLIENT_2);
EmploymentSummary em2 = createEmploymentSummary(Visibility.PRIVATE, CLIENT_2);
EmploymentSummary em3 = createEmploymentSummary(Visibility.PRIVATE, CLIENT_2);
InvitedPositionSummary i1 = createInvitedPositionSummary(Visibility.PUBLIC, CLIENT_2);
InvitedPositionSummary i2 = createInvitedPositionSummary(Visibility.PRIVATE, CLIENT_2);
InvitedPositionSummary i3 = createInvitedPositionSummary(Visibility.PRIVATE, CLIENT_2);
MembershipSummary m1 = createMembershipSummary(Visibility.PUBLIC, CLIENT_2);
MembershipSummary m2 = createMembershipSummary(Visibility.PRIVATE, CLIENT_2);
MembershipSummary m3 = createMembershipSummary(Visibility.PRIVATE, CLIENT_2);
QualificationSummary q1 = createQualificationSummary(Visibility.PUBLIC, CLIENT_2);
QualificationSummary q2 = createQualificationSummary(Visibility.PRIVATE, CLIENT_2);
QualificationSummary q3 = createQualificationSummary(Visibility.PRIVATE, CLIENT_2);
ServiceSummary s1 = createServiceSummary(Visibility.PUBLIC, CLIENT_2);
ServiceSummary s2 = createServiceSummary(Visibility.PRIVATE, CLIENT_2);
ServiceSummary s3 = createServiceSummary(Visibility.PRIVATE, CLIENT_2);
FundingSummary f1 = createFundingSummary(Visibility.PUBLIC, CLIENT_2, EXTID_1);
FundingSummary f2 = createFundingSummary(Visibility.PRIVATE, CLIENT_2, EXTID_2);
FundingSummary f3 = createFundingSummary(Visibility.PRIVATE, CLIENT_2, EXTID_3);
PeerReviewSummary p1 = createPeerReviewSummary(Visibility.PUBLIC, CLIENT_2, EXTID_1);
PeerReviewSummary p2 = createPeerReviewSummary(Visibility.PRIVATE, CLIENT_2, EXTID_2);
PeerReviewSummary p3 = createPeerReviewSummary(Visibility.PRIVATE, CLIENT_2, EXTID_3);
WorkSummary w1 = createWorkSummary(Visibility.PUBLIC, CLIENT_2, EXTID_1);
WorkSummary w2 = createWorkSummary(Visibility.PRIVATE, CLIENT_2, EXTID_2);
WorkSummary w3 = createWorkSummary(Visibility.PRIVATE, CLIENT_2, EXTID_3);
ActivitiesSummary as = new ActivitiesSummary();
as.setEducations(createEducations(e1, e2, e3));
as.setEmployments(createEmployments(em1, em2, em3));
as.setFundings(createFundings(f1, f2, f3));
as.setPeerReviews(createPeerReviews(p1, p2, p3));
as.setWorks(createWorks(w1, w2, w3));
as.setDistinctions(createDistinctions(d1, d2, d3));
as.setInvitedPositions(createInvitedPositions(i1, i2, i3));
as.setMemberships(createMemberships(m1, m2, m3));
as.setQualifications(createQualifications(q1, q2, q3));
as.setServices(createServices(s1, s2, s3));
orcidSecurityManager.checkAndFilter(ORCID_1, as);
assertNotNull(as);
// Check distinctions
assertEquals(1, as.getDistinctions().getSummaries().size());
assertTrue(as.getDistinctions().getSummaries().contains(d1));
assertFalse(as.getDistinctions().getSummaries().contains(d2));
assertFalse(as.getDistinctions().getSummaries().contains(d3));
// Check invited positions
assertEquals(1, as.getInvitedPositions().getSummaries().size());
assertTrue(as.getInvitedPositions().getSummaries().contains(i1));
assertFalse(as.getInvitedPositions().getSummaries().contains(i2));
assertFalse(as.getInvitedPositions().getSummaries().contains(i3));
// Check memberships
assertEquals(1, as.getMemberships().getSummaries().size());
assertTrue(as.getMemberships().getSummaries().contains(m1));
assertFalse(as.getMemberships().getSummaries().contains(m2));
assertFalse(as.getMemberships().getSummaries().contains(m3));
// Check qualifications
assertEquals(1, as.getQualifications().getSummaries().size());
assertTrue(as.getQualifications().getSummaries().contains(q1));
assertFalse(as.getQualifications().getSummaries().contains(q2));
assertFalse(as.getQualifications().getSummaries().contains(q3));
// Check services
assertEquals(1, as.getServices().getSummaries().size());
assertTrue(as.getServices().getSummaries().contains(s1));
assertFalse(as.getServices().getSummaries().contains(s2));
assertFalse(as.getServices().getSummaries().contains(s3));
// Check educations
assertEquals(1, as.getEducations().getSummaries().size());
assertTrue(as.getEducations().getSummaries().contains(e1));
assertFalse(as.getEducations().getSummaries().contains(e2));
assertFalse(as.getEducations().getSummaries().contains(e3));
// Check employments
assertEquals(1, as.getEmployments().getSummaries().size());
assertTrue(as.getEmployments().getSummaries().contains(em1));
assertFalse(as.getEmployments().getSummaries().contains(em2));
assertFalse(as.getEmployments().getSummaries().contains(em3));
// Check fundings
assertEquals(1, as.getFundings().getFundingGroup().size());
assertEquals(1, as.getFundings().getFundingGroup().get(0).getActivities().size());
assertTrue(as.getFundings().getFundingGroup().get(0).getActivities().contains(f1));
assertFalse(as.getFundings().getFundingGroup().get(0).getActivities().contains(f2));
assertFalse(as.getFundings().getFundingGroup().get(0).getActivities().contains(f3));
assertEquals(2, as.getFundings().getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertTrue(as.getFundings().getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_1)));
assertFalse(as.getFundings().getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_2)));
assertFalse(as.getFundings().getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_3)));
assertTrue(as.getFundings().getFundingGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_SHARED)));
// Check peer reviews
assertEquals(1, as.getPeerReviews().getPeerReviewGroup().size());
assertEquals(1, as.getPeerReviews().getPeerReviewGroup().get(0).getActivities().size());
assertTrue(as.getPeerReviews().getPeerReviewGroup().get(0).getActivities().contains(p1));
assertFalse(as.getPeerReviews().getPeerReviewGroup().get(0).getActivities().contains(p2));
assertFalse(as.getPeerReviews().getPeerReviewGroup().get(0).getActivities().contains(p3));
assertEquals(1, as.getPeerReviews().getPeerReviewGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertTrue(as.getPeerReviews().getPeerReviewGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_SHARED, "peer-review")));
// Check works
assertEquals(1, as.getWorks().getWorkGroup().size());
assertEquals(1, as.getWorks().getWorkGroup().get(0).getActivities().size());
assertTrue(as.getWorks().getWorkGroup().get(0).getActivities().contains(w1));
assertFalse(as.getWorks().getWorkGroup().get(0).getActivities().contains(w2));
assertFalse(as.getWorks().getWorkGroup().get(0).getActivities().contains(w3));
assertEquals(2, as.getWorks().getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().size());
assertTrue(as.getWorks().getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_1)));
assertFalse(as.getWorks().getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_2)));
assertFalse(as.getWorks().getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_3)));
assertTrue(as.getWorks().getWorkGroup().get(0).getIdentifiers().getExternalIdentifier().contains(getExtId(EXTID_SHARED)));
}
Aggregations