Search in sources :

Example 1 with Amount

use of org.orcid.jaxb.model.v3.dev1.common.Amount in project ORCID-Source by ORCID.

the class ActivityValidator method validateFunding.

public void validateFunding(Funding funding, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    FundingTitle title = funding.getTitle();
    if (title == null || title.getTitle() == null || StringUtils.isEmpty(title.getTitle().getContent())) {
        throw new ActivityTitleValidationException();
    }
    // translated title language code
    if (title != null && title.getTranslatedTitle() != null && !PojoUtil.isEmpty(title.getTranslatedTitle().getContent())) {
        // If translated title language code is null or invalid
        if (PojoUtil.isEmpty(title.getTranslatedTitle().getLanguageCode()) || !Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(title.getTranslatedTitle().getLanguageCode()::equals)) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
            params.put("type", "translated title -> language code");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
    }
    if (isApiRequest) {
        if (funding.getExternalIdentifiers() == null || funding.getExternalIdentifiers().getExternalIdentifier() == null || funding.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
            throw new ActivityIdentifierValidationException();
        }
    }
    if (funding.getAmount() != null) {
        Amount amount = funding.getAmount();
        if (PojoUtil.isEmpty(amount.getCurrencyCode()) && !PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify a currency code");
        } else if (!PojoUtil.isEmpty(amount.getCurrencyCode()) && PojoUtil.isEmpty(amount.getContent())) {
            throw new OrcidValidationException("Please specify an amount or remove the amount tag");
        }
    }
    if (funding.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    if (isApiRequest) {
        validateDisambiguatedOrg(funding);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = funding.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    externalIDValidator.validateFunding(funding.getExternalIdentifiers());
}
Also used : ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) Amount(org.orcid.jaxb.model.v3.dev1.common.Amount) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 2 with Amount

use of org.orcid.jaxb.model.v3.dev1.common.Amount in project ORCID-Source by ORCID.

the class FundingForm method toFunding.

public Funding toFunding() {
    Funding result = new Funding();
    Amount orcidAmount = new Amount();
    if (!PojoUtil.isEmpty(amount))
        orcidAmount.setContent(amount.getValue());
    if (!PojoUtil.isEmpty(currencyCode))
        orcidAmount.setCurrencyCode(currencyCode.getValue());
    result.setAmount(orcidAmount);
    if (!PojoUtil.isEmpty(description))
        result.setDescription(description.getValue());
    if (!PojoUtil.isEmpty(startDate))
        result.setStartDate(new FuzzyDate(startDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(endDate))
        result.setEndDate(new FuzzyDate(endDate.toFuzzyDate()));
    if (!PojoUtil.isEmpty(putCode))
        result.setPutCode(Long.valueOf(putCode.getValue()));
    if (fundingTitle != null) {
        result.setTitle(fundingTitle.toFundingTitle());
    }
    if (!PojoUtil.isEmpty(fundingType))
        result.setType(FundingType.fromValue(fundingType.getValue()));
    if (organizationDefinedFundingSubType != null && !PojoUtil.isEmpty(organizationDefinedFundingSubType.getSubtype()))
        result.setOrganizationDefinedType(new OrganizationDefinedFundingSubType(organizationDefinedFundingSubType.getSubtype().getValue()));
    if (!PojoUtil.isEmpty(url))
        result.setUrl(new Url(url.getValue()));
    else
        result.setUrl(new Url());
    if (visibility != null)
        result.setVisibility(org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(visibility.getVisibility().value()));
    // Set Organization
    Organization organization = new Organization();
    if (!PojoUtil.isEmpty(fundingName))
        organization.setName(fundingName.getValue());
    OrganizationAddress organizationAddress = new OrganizationAddress();
    organization.setAddress(organizationAddress);
    if (!PojoUtil.isEmpty(city))
        organizationAddress.setCity(city.getValue());
    if (!PojoUtil.isEmpty(region)) {
        organizationAddress.setRegion(region.getValue());
    }
    if (!PojoUtil.isEmpty(country)) {
        organizationAddress.setCountry(Iso3166Country.fromValue(country.getValue()));
    }
    if (!PojoUtil.isEmpty(disambiguatedFundingSourceId)) {
        organization.setDisambiguatedOrganization(new DisambiguatedOrganization());
        organization.getDisambiguatedOrganization().setDisambiguatedOrganizationIdentifier(disambiguatedFundingSourceId.getValue());
        organization.getDisambiguatedOrganization().setDisambiguationSource(disambiguationSource.getValue());
    }
    result.setOrganization(organization);
    // Set contributors
    if (contributors != null && !contributors.isEmpty()) {
        FundingContributors fContributors = new FundingContributors();
        for (Contributor contributor : contributors) {
            if (!PojoUtil.isEmtpy(contributor))
                fContributors.getContributor().add(contributor.toFundingContributor());
        }
        result.setContributors(fContributors);
    }
    // Set external identifiers
    if (externalIdentifiers != null && !externalIdentifiers.isEmpty()) {
        ExternalIDs fExternalIdentifiers = new ExternalIDs();
        for (FundingExternalIdentifierForm fExternalIdentifier : externalIdentifiers) {
            if (!PojoUtil.isEmtpy(fExternalIdentifier))
                fExternalIdentifiers.getExternalIdentifier().add(fExternalIdentifier.toFundingExternalIdentifier());
        }
        result.setExternalIdentifiers(fExternalIdentifiers);
    }
    return result;
}
Also used : Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) DisambiguatedOrganization(org.orcid.jaxb.model.v3.dev1.common.DisambiguatedOrganization) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) Amount(org.orcid.jaxb.model.v3.dev1.common.Amount) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) FuzzyDate(org.orcid.jaxb.model.v3.dev1.common.FuzzyDate) FundingContributors(org.orcid.jaxb.model.v3.dev1.record.FundingContributors) FundingContributor(org.orcid.jaxb.model.v3.dev1.record.FundingContributor) Url(org.orcid.jaxb.model.v3.dev1.common.Url) OrganizationDefinedFundingSubType(org.orcid.jaxb.model.v3.dev1.common.OrganizationDefinedFundingSubType)

Example 3 with Amount

use of org.orcid.jaxb.model.v3.dev1.common.Amount 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 4 with Amount

use of org.orcid.jaxb.model.v3.dev1.common.Amount 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 5 with Amount

use of org.orcid.jaxb.model.v3.dev1.common.Amount 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

Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)8 Amount (org.orcid.jaxb.model.v3.dev1.common.Amount)4 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 FundingTitle (org.orcid.jaxb.model.v3.dev1.record.FundingTitle)3 FundingForm (org.orcid.pojo.ajaxForm.FundingForm)3 HashMap (java.util.HashMap)2 FuzzyDate (org.orcid.jaxb.model.v3.dev1.common.FuzzyDate)2 OrganizationDefinedFundingSubType (org.orcid.jaxb.model.v3.dev1.common.OrganizationDefinedFundingSubType)2 Title (org.orcid.jaxb.model.v3.dev1.common.Title)2 Url (org.orcid.jaxb.model.v3.dev1.common.Url)2 FundingContributor (org.orcid.jaxb.model.v3.dev1.record.FundingContributor)2 FundingContributors (org.orcid.jaxb.model.v3.dev1.record.FundingContributors)2 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 Date (java.util.Date)1 List (java.util.List)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1