Search in sources :

Example 1 with ActivityTypeValidationException

use of org.orcid.core.exception.ActivityTypeValidationException in project ORCID-Source by ORCID.

the class ActivityValidator method validatePeerReview.

public void validatePeerReview(PeerReview peerReview, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (peerReview.getExternalIdentifiers() == null || peerReview.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
        throw new ActivityIdentifierValidationException();
    }
    if (peerReview.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("clientName", sourceEntity.getSourceName());
        throw new InvalidPutCodeException(params);
    }
    if (peerReview.getType() == null) {
        Map<String, String> params = new HashMap<String, String>();
        String peerReviewTypes = Arrays.stream(PeerReviewType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
        params.put("type", "peer review type");
        params.put("values", peerReviewTypes);
        throw new ActivityTypeValidationException();
    }
    externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
    if (peerReview.getSubjectExternalIdentifier() != null) {
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = peerReview.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
}
Also used : FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) Arrays(java.util.Arrays) Year(org.orcid.jaxb.model.common_v2.Year) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) WorkTitle(org.orcid.jaxb.model.record_v2.WorkTitle) OrcidStringUtils(org.orcid.utils.OrcidStringUtils) ActivityTitleValidationException(org.orcid.core.exception.ActivityTitleValidationException) OrcidDuplicatedActivityException(org.orcid.core.exception.OrcidDuplicatedActivityException) Contributor(org.orcid.jaxb.model.common_v2.Contributor) ContributorOrcid(org.orcid.jaxb.model.common_v2.ContributorOrcid) Amount(org.orcid.jaxb.model.common_v2.Amount) PojoUtil(org.orcid.pojo.ajaxForm.PojoUtil) HashMap(java.util.HashMap) GroupIdRecord(org.orcid.jaxb.model.groupid_v2.GroupIdRecord) StringUtils(org.apache.commons.lang3.StringUtils) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Day(org.orcid.jaxb.model.common_v2.Day) Matcher(java.util.regex.Matcher) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Source(org.orcid.jaxb.model.common_v2.Source) Map(java.util.Map) VisibilityMismatchException(org.orcid.core.exception.VisibilityMismatchException) CitationType(org.orcid.jaxb.model.record_v2.CitationType) Employment(org.orcid.jaxb.model.record_v2.Employment) Funding(org.orcid.jaxb.model.record_v2.Funding) SourceEntity(org.orcid.persistence.jpa.entities.SourceEntity) PublicationDate(org.orcid.jaxb.model.common_v2.PublicationDate) Resource(javax.annotation.Resource) Month(org.orcid.jaxb.model.common_v2.Month) Collectors(java.util.stream.Collectors) WorkContributors(org.orcid.jaxb.model.record_v2.WorkContributors) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException) WorkType(org.orcid.jaxb.model.record_v2.WorkType) Iso3166Country(org.orcid.jaxb.model.common_v2.Iso3166Country) Visibility(org.orcid.jaxb.model.common_v2.Visibility) Relationship(org.orcid.jaxb.model.record_v2.Relationship) Work(org.orcid.jaxb.model.record_v2.Work) ExternalID(org.orcid.jaxb.model.record_v2.ExternalID) Pattern(java.util.regex.Pattern) PeerReview(org.orcid.jaxb.model.record_v2.PeerReview) SiteConstants(org.orcid.persistence.constants.SiteConstants) Education(org.orcid.jaxb.model.record_v2.Education) ExternalIDs(org.orcid.jaxb.model.record_v2.ExternalIDs) PeerReviewType(org.orcid.jaxb.model.record_v2.PeerReviewType) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 2 with ActivityTypeValidationException

use of org.orcid.core.exception.ActivityTypeValidationException 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 3 with ActivityTypeValidationException

use of org.orcid.core.exception.ActivityTypeValidationException in project ORCID-Source by ORCID.

the class ActivityValidator method validatePeerReview.

public void validatePeerReview(PeerReview peerReview, SourceEntity sourceEntity, boolean createFlag, boolean isApiRequest, Visibility originalVisibility) {
    if (peerReview.getExternalIdentifiers() == null || peerReview.getExternalIdentifiers().getExternalIdentifier().isEmpty()) {
        throw new ActivityIdentifierValidationException();
    }
    if (peerReview.getPutCode() != null && createFlag) {
        Map<String, String> params = new HashMap<String, String>();
        params.put("clientName", sourceEntity.getSourceName());
        throw new InvalidPutCodeException(params);
    }
    if (peerReview.getType() == null) {
        Map<String, String> params = new HashMap<String, String>();
        String peerReviewTypes = Arrays.stream(PeerReviewType.values()).map(element -> element.value()).collect(Collectors.joining(", "));
        params.put("type", "peer review type");
        params.put("values", peerReviewTypes);
        throw new ActivityTypeValidationException();
    }
    externalIDValidator.validateWorkOrPeerReview(peerReview.getExternalIdentifiers());
    if (peerReview.getSubjectExternalIdentifier() != null) {
        externalIDValidator.validateWorkOrPeerReview(peerReview.getSubjectExternalIdentifier());
    }
    // Check that we are not changing the visibility
    if (isApiRequest && !createFlag) {
        Visibility updatedVisibility = peerReview.getVisibility();
        validateVisibilityDoesntChange(updatedVisibility, originalVisibility);
    }
    if (isApiRequest) {
        validateDisambiguatedOrg(peerReview);
    }
}
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) HashMap(java.util.HashMap) InvalidPutCodeException(org.orcid.core.exception.InvalidPutCodeException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.v3.dev1.common.Visibility) TransientNonEmptyString(org.orcid.jaxb.model.v3.dev1.common.TransientNonEmptyString) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 4 with ActivityTypeValidationException

use of org.orcid.core.exception.ActivityTypeValidationException 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);
    }
    // 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.common_v2.Amount) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Visibility(org.orcid.jaxb.model.common_v2.Visibility) FundingTitle(org.orcid.jaxb.model.record_v2.FundingTitle) ActivityIdentifierValidationException(org.orcid.core.exception.ActivityIdentifierValidationException)

Example 5 with ActivityTypeValidationException

use of org.orcid.core.exception.ActivityTypeValidationException in project ORCID-Source by ORCID.

the class ActivityValidatorTest method validateWork_invalidPublicationDateTest.

@Test
public void validateWork_invalidPublicationDateTest() {
    try {
        Work work = getWork();
        work.getPublicationDate().getYear().setValue("invalid");
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (ActivityTypeValidationException e) {
    }
    try {
        Work work = getWork();
        work.getPublicationDate().getMonth().setValue("invalid");
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (ActivityTypeValidationException e) {
    }
    try {
        Work work = getWork();
        work.getPublicationDate().getDay().setValue("invalid");
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (ActivityTypeValidationException e) {
    }
    try {
        Work work = getWork();
        work.setPublicationDate(new PublicationDate(null, new Month(1), new Day(1)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Work work = getWork();
        work.setPublicationDate(new PublicationDate(new Year(2017), null, new Day(1)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Work work = getWork();
        work.setPublicationDate(new PublicationDate(null, null, new Day(1)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Work work = getWork();
        // Invalid 2 digits year
        work.setPublicationDate(new PublicationDate(new Year(25), new Month(1), new Day(1)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Work work = getWork();
        // Invalid 3 digits month
        work.setPublicationDate(new PublicationDate(new Year(2017), new Month(100), new Day(1)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Work work = getWork();
        // Invalid 3 digits day
        work.setPublicationDate(new PublicationDate(new Year(2017), new Month(1), new Day(100)));
        activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    Work work = getWork();
    work.setPublicationDate(new PublicationDate(new Year(2017), new Month(1), null));
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
    work = getWork();
    work.setPublicationDate(new PublicationDate(new Year(2017), null, null));
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
    work = getWork();
    activityValidator.validateWork(work, null, true, true, Visibility.PUBLIC);
}
Also used : Month(org.orcid.jaxb.model.v3.dev1.common.Month) PublicationDate(org.orcid.jaxb.model.v3.dev1.common.PublicationDate) Year(org.orcid.jaxb.model.v3.dev1.common.Year) Work(org.orcid.jaxb.model.v3.dev1.record.Work) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) ActivityTypeValidationException(org.orcid.core.exception.ActivityTypeValidationException) Day(org.orcid.jaxb.model.v3.dev1.common.Day) Test(org.junit.Test)

Aggregations

ActivityTypeValidationException (org.orcid.core.exception.ActivityTypeValidationException)8 OrcidValidationException (org.orcid.core.exception.OrcidValidationException)8 HashMap (java.util.HashMap)6 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)6 ActivityTitleValidationException (org.orcid.core.exception.ActivityTitleValidationException)6 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)6 Arrays (java.util.Arrays)4 Map (java.util.Map)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4 Collectors (java.util.stream.Collectors)4 Resource (javax.annotation.Resource)4 StringUtils (org.apache.commons.lang3.StringUtils)4 OrcidDuplicatedActivityException (org.orcid.core.exception.OrcidDuplicatedActivityException)4 VisibilityMismatchException (org.orcid.core.exception.VisibilityMismatchException)4 SiteConstants (org.orcid.persistence.constants.SiteConstants)4 SourceEntity (org.orcid.persistence.jpa.entities.SourceEntity)4 PojoUtil (org.orcid.pojo.ajaxForm.PojoUtil)4 OrcidStringUtils (org.orcid.utils.OrcidStringUtils)4 Amount (org.orcid.jaxb.model.common_v2.Amount)3