Search in sources :

Example 81 with Funding

use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.

the class ActivitiesGroupGenerator_GroupingFundingsTest method generateFundings.

/**
 * funding-1 -> A, B, C
 * funding-2 -> C, D, E
 * funding-3 -> X, Y, Z
 * funding-4 -> Y, B, 1
 * funding-5 -> M, N, O
 * funding-6 -> O, P, Q
 * funding-7 -> 1, 2, B
 * funding-8 -> No external identifiers
 * funding-9 -> No external identifiers
 */
private Map<String, FundingSummary> generateFundings() {
    Map<String, FundingSummary> result = new HashMap<String, FundingSummary>();
    for (int i = 1; i < 10; i++) {
        String name = "funding-" + i;
        FundingSummary funding = new FundingSummary();
        FundingTitle title = new FundingTitle();
        title.setTitle(new Title(name));
        funding.setTitle(title);
        ExternalIDs fei = new ExternalIDs();
        switch(i) {
            case 1:
                ExternalID f1 = new ExternalID();
                f1.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f1.setValue("A");
                ExternalID f2 = new ExternalID();
                f2.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f2.setValue("B");
                ExternalID f3 = new ExternalID();
                f3.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f3.setValue("C");
                fei.getExternalIdentifier().add(f1);
                fei.getExternalIdentifier().add(f2);
                fei.getExternalIdentifier().add(f3);
                break;
            case 2:
                ExternalID f4 = new ExternalID();
                f4.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f4.setValue("C");
                ExternalID f5 = new ExternalID();
                f5.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f5.setValue("D");
                ExternalID f6 = new ExternalID();
                f6.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f6.setValue("E");
                fei.getExternalIdentifier().add(f4);
                fei.getExternalIdentifier().add(f5);
                fei.getExternalIdentifier().add(f6);
                break;
            case 3:
                ExternalID f7 = new ExternalID();
                f7.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f7.setValue("X");
                ExternalID f8 = new ExternalID();
                f8.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f8.setValue("Y");
                ExternalID f9 = new ExternalID();
                f9.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f9.setValue("Z");
                fei.getExternalIdentifier().add(f7);
                fei.getExternalIdentifier().add(f8);
                fei.getExternalIdentifier().add(f9);
                break;
            case 4:
                ExternalID f10 = new ExternalID();
                f10.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f10.setValue("Y");
                ExternalID f11 = new ExternalID();
                f11.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f11.setValue("B");
                ExternalID f12 = new ExternalID();
                f12.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f12.setValue("1");
                fei.getExternalIdentifier().add(f10);
                fei.getExternalIdentifier().add(f11);
                fei.getExternalIdentifier().add(f12);
                break;
            case 5:
                ExternalID f13 = new ExternalID();
                f13.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f13.setValue("M");
                ExternalID f14 = new ExternalID();
                f14.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f14.setValue("N");
                ExternalID f15 = new ExternalID();
                f15.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f15.setValue("O");
                fei.getExternalIdentifier().add(f13);
                fei.getExternalIdentifier().add(f14);
                fei.getExternalIdentifier().add(f15);
                break;
            case 6:
                ExternalID f16 = new ExternalID();
                f16.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f16.setValue("O");
                ExternalID f17 = new ExternalID();
                f17.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f17.setValue("P");
                ExternalID f18 = new ExternalID();
                f18.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f18.setValue("Q");
                fei.getExternalIdentifier().add(f16);
                fei.getExternalIdentifier().add(f17);
                fei.getExternalIdentifier().add(f18);
                break;
            case 7:
                ExternalID f19 = new ExternalID();
                f19.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f19.setValue("1");
                ExternalID f20 = new ExternalID();
                f20.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f20.setValue("2");
                ExternalID f21 = new ExternalID();
                f21.setType(org.orcid.jaxb.model.message.FundingExternalIdentifierType.GRANT_NUMBER.value());
                f21.setValue("B");
                fei.getExternalIdentifier().add(f19);
                fei.getExternalIdentifier().add(f20);
                fei.getExternalIdentifier().add(f21);
                break;
        }
        funding.setExternalIdentifiers(fei);
        result.put(name, funding);
    }
    return result;
}
Also used : ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) HashMap(java.util.HashMap) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) FundingSummary(org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) Title(org.orcid.jaxb.model.v3.dev1.common.Title) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle)

Example 82 with Funding

use of org.orcid.jaxb.model.v3.dev1.record.Funding in project ORCID-Source by ORCID.

the class GetMyDataControllerTest method before.

@Before
public void before() {
    MockitoAnnotations.initMocks(this);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "batchSize", 50);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "personDetailsManager", mockPersonDetailsManager);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "workEntityCacheManager", mockWorkEntityCacheManager);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "affiliationManagerReadOnly", mockAffiliationManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "profileFundingManagerReadOnly", mockProfileFundingManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "peerReviewManagerReadOnly", mockPeerReviewManagerReadOnly);
    TargetProxyHelper.injectIntoProxy(getMyDataController, "workManagerReadOnly", mockWorkManagerReadOnly);
    when(mockPersonDetailsManager.getPersonDetails(anyString())).thenAnswer(new Answer<Person>() {

        @Override
        public Person answer(InvocationOnMock invocation) throws Throwable {
            Person p = new Person();
            p.setBiography(new Biography("Biography", Visibility.LIMITED));
            Name name = new Name();
            name.setVisibility(Visibility.LIMITED);
            name.setFamilyName(new FamilyName("Family Name"));
            name.setGivenNames(new GivenNames("Given Names"));
            name.setCreditName(new CreditName("Credit Name"));
            p.setName(name);
            return p;
        }
    });
    when(mockAffiliationManagerReadOnly.getAffiliations(anyString())).thenAnswer(new Answer<List<Affiliation>>() {

        @Override
        public List<Affiliation> answer(InvocationOnMock invocation) throws Throwable {
            List<Affiliation> affs = new ArrayList<Affiliation>();
            FuzzyDate startDate = new FuzzyDate(new Year(2018), new Month(1), new Day(1));
            FuzzyDate endDate = new FuzzyDate(new Year(2018), new Month(12), new Day(31));
            Distinction d = new Distinction();
            d.setDepartmentName("distinction");
            d.setEndDate(endDate);
            d.setStartDate(startDate);
            d.setPutCode(1L);
            setOrg(d);
            affs.add(d);
            Education e = new Education();
            e.setDepartmentName("education");
            e.setEndDate(endDate);
            e.setStartDate(startDate);
            e.setPutCode(2L);
            setOrg(e);
            affs.add(e);
            Employment emp = new Employment();
            emp.setDepartmentName("employment");
            emp.setEndDate(endDate);
            emp.setStartDate(startDate);
            emp.setPutCode(3L);
            setOrg(emp);
            affs.add(emp);
            InvitedPosition i = new InvitedPosition();
            i.setDepartmentName("invited position");
            i.setEndDate(endDate);
            i.setStartDate(startDate);
            i.setPutCode(4L);
            setOrg(i);
            affs.add(i);
            Membership m = new Membership();
            m.setDepartmentName("membership");
            m.setEndDate(endDate);
            m.setStartDate(startDate);
            m.setPutCode(5L);
            setOrg(m);
            affs.add(m);
            Qualification q = new Qualification();
            q.setDepartmentName("qualification");
            q.setEndDate(endDate);
            q.setStartDate(startDate);
            q.setPutCode(6L);
            setOrg(q);
            affs.add(q);
            Service s = new Service();
            s.setDepartmentName("service");
            s.setEndDate(endDate);
            s.setStartDate(startDate);
            s.setPutCode(7L);
            setOrg(s);
            affs.add(s);
            return affs;
        }
    });
    when(mockProfileFundingManagerReadOnly.getFundingList(anyString())).thenAnswer(new Answer<List<Funding>>() {

        @Override
        public List<Funding> answer(InvocationOnMock invocation) throws Throwable {
            List<Funding> fundings = new ArrayList<Funding>();
            Funding f = new Funding();
            Amount a = new Amount();
            a.setContent("1000");
            a.setCurrencyCode("$");
            f.setAmount(a);
            FundingTitle t = new FundingTitle();
            t.setTitle(new Title("title"));
            f.setTitle(t);
            setOrg(f);
            f.setPutCode(1L);
            fundings.add(f);
            return fundings;
        }
    });
    when(mockPeerReviewManagerReadOnly.findPeerReviews(anyString())).thenAnswer(new Answer<List<PeerReview>>() {

        @Override
        public List<PeerReview> answer(InvocationOnMock invocation) throws Throwable {
            List<PeerReview> peerReviews = new ArrayList<PeerReview>();
            PeerReview p = new PeerReview();
            setOrg(p);
            p.setPutCode(1L);
            peerReviews.add(p);
            return peerReviews;
        }
    });
    when(mockWorkManagerReadOnly.findWorks(anyString(), any())).thenAnswer(new Answer<List<Work>>() {

        @Override
        public List<Work> answer(InvocationOnMock invocation) throws Throwable {
            List<Work> works = new ArrayList<Work>();
            Work w = new Work();
            WorkTitle t = new WorkTitle();
            t.setTitle(new Title("title"));
            w.setPutCode(1L);
            works.add(w);
            return works;
        }
    });
    when(mockWorkManagerReadOnly.getLastModified(anyString())).thenReturn(0L);
    when(mockWorkEntityCacheManager.retrieveWorkLastModifiedList(anyString(), anyLong())).thenAnswer(new Answer<List<WorkLastModifiedEntity>>() {

        @Override
        public List<WorkLastModifiedEntity> answer(InvocationOnMock invocation) throws Throwable {
            List<WorkLastModifiedEntity> works = new ArrayList<WorkLastModifiedEntity>();
            WorkLastModifiedEntity w = new WorkLastModifiedEntity();
            w.setId(1L);
            w.setOrcid(ORCID);
            w.setLastModified(new Date());
            works.add(w);
            return works;
        }
    });
}
Also used : FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FamilyName(org.orcid.jaxb.model.v3.dev1.record.FamilyName) Name(org.orcid.jaxb.model.v3.dev1.record.Name) Month(org.orcid.jaxb.model.v3.dev1.common.Month) WorkLastModifiedEntity(org.orcid.persistence.jpa.entities.WorkLastModifiedEntity) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) GivenNames(org.orcid.jaxb.model.v3.dev1.record.GivenNames) Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) List(java.util.List) ArrayList(java.util.ArrayList) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation) Amount(org.orcid.jaxb.model.v3.dev1.common.Amount) CreditName(org.orcid.jaxb.model.v3.dev1.common.CreditName) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) Service(org.orcid.jaxb.model.v3.dev1.record.Service) Title(org.orcid.jaxb.model.v3.dev1.common.Title) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) Date(java.util.Date) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) Year(org.orcid.jaxb.model.v3.dev1.common.Year) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) Person(org.orcid.jaxb.model.v3.dev1.record.Person) Day(org.orcid.jaxb.model.v3.dev1.common.Day) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) Before(org.junit.Before)

Example 83 with Funding

use of org.orcid.jaxb.model.v3.dev1.record.Funding 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();
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) InvitedPosition(org.orcid.jaxb.model.v3.dev1.record.InvitedPosition) ZipEntry(java.util.zip.ZipEntry) Service(org.orcid.jaxb.model.v3.dev1.record.Service) JAXBContext(javax.xml.bind.JAXBContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZipInputStream(java.util.zip.ZipInputStream) Qualification(org.orcid.jaxb.model.v3.dev1.record.Qualification) ByteArrayInputStream(java.io.ByteArrayInputStream) Education(org.orcid.jaxb.model.v3.dev1.record.Education) Employment(org.orcid.jaxb.model.v3.dev1.record.Employment) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Membership(org.orcid.jaxb.model.v3.dev1.record.Membership) Unmarshaller(javax.xml.bind.Unmarshaller) Person(org.orcid.jaxb.model.v3.dev1.record.Person) Distinction(org.orcid.jaxb.model.v3.dev1.record.Distinction) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) Test(org.junit.Test)

Example 84 with Funding

use of org.orcid.jaxb.model.v3.dev1.record.Funding 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;
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 85 with Funding

use of org.orcid.jaxb.model.v3.dev1.record.Funding 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;
}
Also used : Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) HashMap(java.util.HashMap) FundingForm(org.orcid.pojo.ajaxForm.FundingForm) ArrayList(java.util.ArrayList) Contributor(org.orcid.pojo.ajaxForm.Contributor) BigDecimal(java.math.BigDecimal) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity)

Aggregations

Test (org.junit.Test)76 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)72 FundingSummary (org.orcid.jaxb.model.v3.dev1.record.summary.FundingSummary)24 Response (javax.ws.rs.core.Response)23 DBUnitTest (org.orcid.test.DBUnitTest)23 ActivitiesSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ActivitiesSummary)20 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)15 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)12 EmploymentSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EmploymentSummary)12 PeerReviewSummary (org.orcid.jaxb.model.v3.dev1.record.summary.PeerReviewSummary)12 WorkSummary (org.orcid.jaxb.model.v3.dev1.record.summary.WorkSummary)12 DistinctionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.DistinctionSummary)10 InvitedPositionSummary (org.orcid.jaxb.model.v3.dev1.record.summary.InvitedPositionSummary)10 MembershipSummary (org.orcid.jaxb.model.v3.dev1.record.summary.MembershipSummary)10 QualificationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.QualificationSummary)10 ServiceSummary (org.orcid.jaxb.model.v3.dev1.record.summary.ServiceSummary)10 Url (org.orcid.jaxb.model.v3.dev1.common.Url)9 FundingContributor (org.orcid.jaxb.model.v3.dev1.record.FundingContributor)9 ArrayList (java.util.ArrayList)8 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)8