Search in sources :

Example 76 with Visibility

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

the class PublicAPISecurityManagerV3Test method getEmailsElement.

private Emails getEmailsElement(Visibility... vs) {
    Emails elements = new Emails();
    for (Visibility v : vs) {
        Email element = new Email();
        element.setVisibility(v);
        if (elements.getEmails() == null) {
            elements.setEmails(new ArrayList<Email>());
        }
        elements.getEmails().add(element);
    }
    return elements;
}
Also used : Email(org.orcid.jaxb.model.v3.dev1.record.Email) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) Emails(org.orcid.jaxb.model.v3.dev1.record.Emails)

Example 77 with Visibility

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

the class ActivityValidator method validateAffiliation.

public void validateAffiliation(Affiliation affiliation, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (affiliation.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 = affiliation.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    if (affiliation.getStartDate() == null) {
        throw new OrcidValidationException("Education start date is required");
    }
    if (isApiRequest) {
        validateDisambiguatedOrg(affiliation);
    }
}
Also used : HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString)

Example 78 with Visibility

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

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

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

the class ManageProfileController method setBiographyFormJson.

@RequestMapping(value = "/biographyForm.json", method = RequestMethod.POST)
@ResponseBody
public BiographyForm setBiographyFormJson(@RequestBody BiographyForm bf) {
    bf.setErrors(new ArrayList<String>());
    if (bf.getBiography() != null) {
        validateBiography(bf.getBiography());
        // Validate visibility is not null
        validateVisibility(bf);
        copyErrors(bf.getBiography(), bf);
        copyErrors(bf.getVisibility(), bf);
        if (bf.getErrors().size() > 0)
            return bf;
        Biography bio = new Biography();
        if (bf.getBiography() != null) {
            bio.setContent(bf.getBiography().getValue());
        }
        if (bf.getVisibility() != null && bf.getVisibility().getVisibility() != null) {
            org.orcid.jaxb.model.v3.dev1.common.Visibility v = org.orcid.jaxb.model.v3.dev1.common.Visibility.fromValue(bf.getVisibility().getVisibility().value());
            bio.setVisibility(v);
        }
        String orcid = getCurrentUserOrcid();
        if (biographyManager.exists(orcid)) {
            biographyManager.updateBiography(orcid, bio);
        } else {
            biographyManager.createBiography(orcid, bio);
        }
    }
    return bf;
}
Also used : Biography(org.orcid.jaxb.model.v3.dev1.record.Biography) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Visibility (org.orcid.jaxb.model.v3.dev1.common.Visibility)44 ClientResponse (com.sun.jersey.api.client.ClientResponse)17 Test (org.junit.Test)17 ExternalID (org.orcid.jaxb.model.v3.dev1.record.ExternalID)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Url (org.orcid.jaxb.model.v3.dev1.common.Url)11 OrcidError (org.orcid.jaxb.model.v3.dev1.error.OrcidError)11 ExternalIDs (org.orcid.jaxb.model.v3.dev1.record.ExternalIDs)11 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)11 HashMap (java.util.HashMap)10 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)10 Name (org.orcid.jaxb.model.v3.dev1.record.Name)7 OtherName (org.orcid.jaxb.model.v3.dev1.record.OtherName)7 Organization (org.orcid.jaxb.model.v3.dev1.common.Organization)6 Biography (org.orcid.jaxb.model.v3.dev1.record.Biography)6 Work (org.orcid.jaxb.model.v3.dev1.record.Work)6 EducationSummary (org.orcid.jaxb.model.v3.dev1.record.summary.EducationSummary)6 Date (java.util.Date)5 OrcidDuplicatedElementException (org.orcid.core.exception.OrcidDuplicatedElementException)5