Search in sources :

Example 11 with Country

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

the class Utils method getAddress.

public static Address getAddress() {
    Address address = new Address();
    address.setVisibility(Visibility.PUBLIC);
    address.setCountry(new Country(Iso3166Country.ES));
    return address;
}
Also used : Address(org.orcid.jaxb.model.v3.dev1.record.Address) OrganizationAddress(org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress) Country(org.orcid.jaxb.model.v3.dev1.common.Country) Iso3166Country(org.orcid.jaxb.model.v3.dev1.common.Iso3166Country)

Example 12 with Country

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

the class ActivityValidator method validateWork.

public void validateWork(Work work, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    WorkTitle title = work.getWorkTitle();
    if (title == null || title.getTitle() == null || PojoUtil.isEmpty(title.getTitle().getContent())) {
        throw new ActivityTitleValidationException();
    }
    if (work.getCountry() != null) {
        if (work.getCountry().getValue() == null) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(Iso3166Country.values()).map(element -> element.value()).collect(Collectors.joining(", "));
            params.put("type", "country");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
    }
    // translated title language code
    if (title != null && title.getTranslatedTitle() != null) {
        String translatedTitle = title.getTranslatedTitle().getContent();
        String languageCode = title.getTranslatedTitle().getLanguageCode();
        if (PojoUtil.isEmpty(translatedTitle) && !PojoUtil.isEmpty(languageCode)) {
            throw new OrcidValidationException("Please specify a translated title or remove the language code");
        }
        // If translated title language code is null or invalid
        if (!PojoUtil.isEmpty(translatedTitle) && (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 (work.getWorkType() == null) {
        Map<String, String> params = new HashMap<String, String>();
        String values = Arrays.stream(WorkType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
        params.put("type", "work type");
        params.put("values", values);
        throw new ActivityTypeValidationException(params);
    }
    if (!PojoUtil.isEmpty(work.getLanguageCode())) {
        if (!Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).anyMatch(work.getLanguageCode()::equals)) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(SiteConstants.AVAILABLE_ISO_LANGUAGES).collect(Collectors.joining(", "));
            params.put("type", "language code");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
    }
    // publication date
    if (work.getPublicationDate() != null) {
        PublicationDate pd = work.getPublicationDate();
        Year year = pd.getYear();
        Month month = pd.getMonth();
        Day day = pd.getDay();
        if (year != null) {
            try {
                Integer.valueOf(year.getValue());
            } catch (NumberFormatException n) {
                Map<String, String> params = new HashMap<String, String>();
                params.put("type", "publication date -> year");
                params.put("values", "integers");
                throw new ActivityTypeValidationException(params);
            }
            if (year.getValue().length() != 4) {
                throw new OrcidValidationException("Invalid year " + year.getValue() + " please specify a four digits value");
            }
        }
        if (month != null) {
            try {
                Integer.valueOf(month.getValue());
            } catch (NumberFormatException n) {
                Map<String, String> params = new HashMap<String, String>();
                params.put("type", "publication date -> month");
                params.put("values", "integers");
                throw new ActivityTypeValidationException(params);
            }
            if (month.getValue().length() != 2) {
                throw new OrcidValidationException("Invalid month " + month.getValue() + " please specify a two digits value");
            }
        }
        if (day != null) {
            try {
                Integer.valueOf(day.getValue());
            } catch (NumberFormatException n) {
                Map<String, String> params = new HashMap<String, String>();
                params.put("type", "publication date -> day");
                params.put("values", "integers");
                throw new ActivityTypeValidationException(params);
            }
            if (day.getValue().length() != 2) {
                throw new OrcidValidationException("Invalid day " + day.getValue() + " please specify a two digits value");
            }
        }
        // Check the date is valid
        boolean isYearEmpty = (year == null || year.getValue() == null) ? true : false;
        boolean isMonthEmpty = (month == null || month.getValue() == null) ? true : false;
        boolean isDayEmpty = (day == null || day.getValue() == null) ? true : false;
        if (isYearEmpty && (!isMonthEmpty || !isDayEmpty)) {
            throw new OrcidValidationException("Invalid date, please specify a year element");
        } else if (!isYearEmpty && isMonthEmpty && !isDayEmpty) {
            throw new OrcidValidationException("Invalid date, please specify a month element");
        } else if (isYearEmpty && isMonthEmpty && !isDayEmpty) {
            throw new OrcidValidationException("Invalid date, please specify a year and month elements");
        }
    }
    // citation
    if (work.getWorkCitation() != null) {
        String citation = work.getWorkCitation().getCitation();
        CitationType type = work.getWorkCitation().getWorkCitationType();
        if (type == null) {
            Map<String, String> params = new HashMap<String, String>();
            String values = Arrays.stream(CitationType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
            params.put("type", "citation type");
            params.put("values", values);
            throw new ActivityTypeValidationException(params);
        }
        if (PojoUtil.isEmpty(citation)) {
            throw new OrcidValidationException("Please specify a citation or remove the parent tag");
        }
    }
    if (work.getWorkExternalIdentifiers() == null || work.getWorkExternalIdentifiers().getExternalIdentifier() == null || work.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
        throw new ActivityIdentifierValidationException();
    }
    if (work.getWorkContributors() != null) {
        WorkContributors contributors = work.getWorkContributors();
        if (!contributors.getContributor().isEmpty()) {
            for (Contributor contributor : contributors.getContributor()) {
                if (contributor.getContributorOrcid() != null) {
                    ContributorOrcid contributorOrcid = contributor.getContributorOrcid();
                    if (!PojoUtil.isEmpty(contributorOrcid.getUri())) {
                        if (!OrcidStringUtils.isValidOrcid2_1Uri(contributorOrcid.getUri())) {
                            throw new OrcidValidationException("Invalid contributor URI");
                        }
                    }
                    if (!PojoUtil.isEmpty(contributorOrcid.getPath())) {
                        if (!OrcidStringUtils.isValidOrcid(contributorOrcid.getPath())) {
                            throw new OrcidValidationException("Invalid contributor ORCID");
                        }
                    }
                }
                if (contributor.getCreditName() != null) {
                    if (PojoUtil.isEmpty(contributor.getCreditName().getContent())) {
                        throw new OrcidValidationException("Please specify a contributor credit name or remove the empty tag");
                    }
                }
                if (contributor.getContributorEmail() != null) {
                    if (PojoUtil.isEmpty(contributor.getContributorEmail().getValue())) {
                        throw new OrcidValidationException("Please specify a contributor email or remove the empty tag");
                    }
                }
            }
        }
    }
    if (work.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        if (sourceEntity != null) {
            params.put("clientName", sourceEntity.getSourceName());
        }
        throw new InvalidPutCodeException(params);
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = work.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    externalIDValidator.validateWorkOrPeerReview(work.getExternalIdentifiers());
}
Also used : Arrays(java.util.Arrays) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) WorkContributors(org.orcid.jaxb.model.v3.dev1.record.WorkContributors) StringUtils(org.apache.commons.lang3.StringUtils) InvalidOrgException(org.orcid.core.exception.InvalidOrgException) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) Matcher(java.util.regex.Matcher) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Map(java.util.Map) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) Month(org.orcid.jaxb.model.v3.dev1.common.Month) CitationType(org.orcid.jaxb.model.v3.dev1.record.CitationType) PeerReviewType(org.orcid.jaxb.model.v3.dev1.record.PeerReviewType) Affiliation(org.orcid.jaxb.model.v3.dev1.record.Affiliation) Resource(javax.annotation.Resource) NormalizationService(org.orcid.core.utils.v3.identifiers.NormalizationService) ExternalIDs(org.orcid.jaxb.model.v3.dev1.record.ExternalIDs) Amount(org.orcid.jaxb.model.v3.dev1.common.Amount) ContributorOrcid(org.orcid.jaxb.model.v3.dev1.common.ContributorOrcid) Collectors(java.util.stream.Collectors) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) OrganizationHolder(org.orcid.jaxb.model.v3.dev1.common.OrganizationHolder) PeerReview(org.orcid.jaxb.model.v3.dev1.record.PeerReview) Day(org.orcid.jaxb.model.v3.dev1.common.Day) Source(org.orcid.jaxb.model.v3.dev1.common.Source) PublicationDate(org.orcid.jaxb.model.v3.dev1.common.PublicationDate) Pattern(java.util.regex.Pattern) SiteConstants(org.orcid.persistence.constants.SiteConstants) Relationship(org.orcid.jaxb.model.v3.dev1.record.Relationship) Year(org.orcid.jaxb.model.v3.dev1.common.Year) OrcidStringUtils(org.orcid.utils.OrcidStringUtils) ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) PojoUtil(org.orcid.pojo.ajaxForm.PojoUtil) HashMap(java.util.HashMap) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Organization(org.orcid.jaxb.model.v3.dev1.common.Organization) Iso3166Country(org.orcid.jaxb.model.v3.dev1.common.Iso3166Country) WorkType(org.orcid.jaxb.model.v3.dev1.record.WorkType) Funding(org.orcid.jaxb.model.v3.dev1.record.Funding) InvalidDisambiguatedOrgException(org.orcid.core.exception.InvalidDisambiguatedOrgException) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) GroupIdRecord(org.orcid.jaxb.model.v3.dev1.groupid.GroupIdRecord) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) FundingTitle(org.orcid.jaxb.model.v3.dev1.record.FundingTitle) Work(org.orcid.jaxb.model.v3.dev1.record.Work) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) ExternalID(org.orcid.jaxb.model.v3.dev1.record.ExternalID) PublicationDate(org.orcid.jaxb.model.v3.dev1.common.PublicationDate) HashMap(java.util.HashMap) WorkContributors(org.orcid.jaxb.model.v3.dev1.record.WorkContributors) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Contributor(org.orcid.jaxb.model.v3.dev1.common.Contributor) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) Month(org.orcid.jaxb.model.v3.dev1.common.Month) ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) Year(org.orcid.jaxb.model.v3.dev1.common.Year) WorkTitle(org.orcid.jaxb.model.v3.dev1.record.WorkTitle) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) CitationType(org.orcid.jaxb.model.v3.dev1.record.CitationType) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) ContributorOrcid(org.orcid.jaxb.model.v3.dev1.common.ContributorOrcid) Day(org.orcid.jaxb.model.v3.dev1.common.Day) Map(java.util.Map) HashMap(java.util.HashMap)

Example 13 with Country

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

the class ManageProfileController method getProfileCountryJson.

@RequestMapping(value = "/countryForm.json", method = RequestMethod.GET)
@ResponseBody
public AddressesForm getProfileCountryJson(HttpServletRequest request) throws NoSuchRequestHandlingMethodException {
    Addresses addresses = addressManager.getAddresses(getCurrentUserOrcid());
    AddressesForm form = AddressesForm.valueOf(addresses);
    // Set country name
    if (form != null && form.getAddresses() != null) {
        Map<String, String> countries = retrieveIsoCountries();
        for (AddressForm addressForm : form.getAddresses()) {
            addressForm.setCountryName(countries.get(addressForm.getIso2Country().getValue().name()));
        }
    }
    ProfileEntity profile = profileEntityCacheManager.retrieve(getCurrentUserOrcid());
    // Set the default visibility
    if (profile.getActivitiesVisibilityDefault() != null) {
        form.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
    }
    // Return an empty country in case we dont have any
    if (form.getAddresses() == null) {
        form.setAddresses(new ArrayList<AddressForm>());
    }
    if (form.getAddresses().isEmpty()) {
        AddressForm address = new AddressForm();
        address.setDisplayIndex(1L);
        address.setVisibility(org.orcid.pojo.ajaxForm.Visibility.valueOf(profile.getActivitiesVisibilityDefault()));
        form.getAddresses().add(address);
    }
    return form;
}
Also used : Addresses(org.orcid.jaxb.model.v3.dev1.record.Addresses) AddressesForm(org.orcid.pojo.ajaxForm.AddressesForm) AddressForm(org.orcid.pojo.ajaxForm.AddressForm) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with Country

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

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

the class OrcidInfo method getWorkInfo.

/**
 * Returns the work info for a given work id
 *
 * @param workId
 *            The id of the work
 * @return the content of that work
 */
@RequestMapping(value = "/{orcid:(?:\\d{4}-){3,}\\d{3}[\\dX]}/getWorkInfo.json", method = RequestMethod.GET)
@ResponseBody
public WorkForm getWorkInfo(@PathVariable("orcid") String orcid, @RequestParam(value = "workId") Long workId) {
    Map<String, String> languages = lm.buildLanguageMap(localeManager.getLocale(), false);
    if (workId == null)
        return null;
    Work workObj = workManager.getWork(orcid, workId);
    if (workObj != null) {
        validateVisibility(workObj.getVisibility());
        sourceUtils.setSourceName(workObj);
        WorkForm work = WorkForm.valueOf(workObj);
        // Set country name
        if (!PojoUtil.isEmpty(work.getCountryCode())) {
            Text countryName = Text.valueOf(retrieveIsoCountries().get(work.getCountryCode().getValue()));
            work.setCountryName(countryName);
        }
        // Set language name
        if (!PojoUtil.isEmpty(work.getLanguageCode())) {
            Text languageName = Text.valueOf(languages.get(work.getLanguageCode().getValue()));
            work.setLanguageName(languageName);
        }
        // Set translated title language name
        if (work.getTranslatedTitle() != null && !StringUtils.isEmpty(work.getTranslatedTitle().getLanguageCode())) {
            String languageName = languages.get(work.getTranslatedTitle().getLanguageCode());
            work.getTranslatedTitle().setLanguageName(languageName);
        }
        if (work.getContributors() != null) {
            for (Contributor contributor : work.getContributors()) {
                if (!PojoUtil.isEmpty(contributor.getOrcid())) {
                    String contributorOrcid = contributor.getOrcid().getValue();
                    if (profileEntManager.orcidExists(contributorOrcid)) {
                        ProfileEntity profileEntity = profileEntityCacheManager.retrieve(contributorOrcid);
                        String publicContributorCreditName = activityManager.getPublicCreditName(profileEntity);
                        contributor.setCreditName(Text.valueOf(publicContributorCreditName));
                    }
                }
            }
        }
        return work;
    }
    return null;
}
Also used : WorkForm(org.orcid.pojo.ajaxForm.WorkForm) Work(org.orcid.jaxb.model.v3.dev1.record.Work) Contributor(org.orcid.pojo.ajaxForm.Contributor) Text(org.orcid.pojo.ajaxForm.Text) ProfileEntity(org.orcid.persistence.jpa.entities.ProfileEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Iso3166Country (org.orcid.jaxb.model.v3.dev1.common.Iso3166Country)8 Country (org.orcid.jaxb.model.v3.dev1.common.Country)7 Work (org.orcid.jaxb.model.v3.dev1.record.Work)7 Url (org.orcid.jaxb.model.v3.dev1.common.Url)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)5 ContributorOrcid (org.orcid.jaxb.model.v3.dev1.common.ContributorOrcid)4 FuzzyDate (org.orcid.jaxb.model.v3.dev1.common.FuzzyDate)4 PublicationDate (org.orcid.jaxb.model.v3.dev1.common.PublicationDate)4 Title (org.orcid.jaxb.model.v3.dev1.common.Title)4 Address (org.orcid.jaxb.model.v3.dev1.record.Address)4 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)4 Funding (org.orcid.jaxb.model.v3.dev1.record.Funding)4 WorkTitle (org.orcid.jaxb.model.v3.dev1.record.WorkTitle)4 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)4 CreatedDate (org.orcid.jaxb.model.v3.dev1.common.CreatedDate)3 CreditName (org.orcid.jaxb.model.v3.dev1.common.CreditName)3 Day (org.orcid.jaxb.model.v3.dev1.common.Day)3 Month (org.orcid.jaxb.model.v3.dev1.common.Month)3 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)3 OrganizationAddress (org.orcid.jaxb.model.v3.dev1.common.OrganizationAddress)3