Search in sources :

Example 1 with OrcidValidationException

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

the class NotificationValidationManagerImpl method validateNotificationPermission.

@Override
public void validateNotificationPermission(NotificationPermission notification) {
    AuthorizationUrl authorizationUrl = notification.getAuthorizationUrl();
    String uriString = authorizationUrl.getUri();
    if (StringUtils.isNotBlank(uriString)) {
        try {
            new URI(uriString);
        } catch (URISyntaxException e) {
            throw new OrcidValidationException("Bad authorization uri", e);
        }
    }
    externalIDValidator.validateNotificationItems(notification.getItems());
}
Also used : AuthorizationUrl(org.orcid.jaxb.model.notification.permission_v2.AuthorizationUrl) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 2 with OrcidValidationException

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

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

the class ValidationManagerImpl method checkMessage.

private void checkMessage(OrcidMessage orcidMessage) {
    OrcidProfile orcidProfile = orcidMessage != null ? orcidMessage.getOrcidProfile() : null;
    if (orcidProfile == null) {
        if (requireOrcidProfile) {
            throw new OrcidValidationException("There must be an orcid-profile element");
        }
    } else {
        checkBio(orcidProfile.getOrcidBio());
        checkActivities(orcidProfile.getOrcidActivities());
    }
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) OrcidValidationException(org.orcid.core.exception.OrcidValidationException)

Example 4 with OrcidValidationException

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

the class ActivityValidatorTest method validateFunding_invalidCurrencyCodeTest.

@Test
public void validateFunding_invalidCurrencyCodeTest() {
    try {
        Funding funding = getFunding();
        funding.getAmount().setCurrencyCode(null);
        activityValidator.validateFunding(funding, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
    try {
        Funding funding = getFunding();
        funding.getAmount().setContent(null);
        activityValidator.validateFunding(funding, null, true, true, Visibility.PUBLIC);
        fail();
    } catch (OrcidValidationException e) {
    }
}
Also used : Funding(org.orcid.jaxb.model.record_v2.Funding) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) Test(org.junit.Test)

Example 5 with OrcidValidationException

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

the class T2OrcidApiServiceVersionedDelegatorTest method testCreateProfileWithInvalidHistoryElements.

@Test
public void testCreateProfileWithInvalidHistoryElements() {
    OrcidMessage orcidMessage = createStubOrcidMessage();
    orcidMessage.setMessageVersion("1.2");
    //Claimed should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setClaimed(new Claimed(false));
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Claimed status should not be specified when creating a profile"));
    }
    //Creation method should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setCreationMethod(CreationMethod.API);
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Creation method should not be specified when creating a profile"));
    }
    //Completion date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setCompletionDate(new CompletionDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Completion date should not be specified when creating a profile"));
    }
    //Submission date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setSubmissionDate(new SubmissionDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Submission date should not be specified when creating a profile"));
    }
    //Last modified date should be null
    try {
        OrcidHistory history = new OrcidHistory();
        history.setLastModifiedDate(new LastModifiedDate());
        orcidMessage.getOrcidProfile().setOrcidHistory(history);
        t2OrcidApiServiceDelegatorLatest.createProfile(mockedUriInfo, orcidMessage);
    } catch (OrcidValidationException obe) {
        assertTrue(obe.getMessage().contains("Last modified date should not be specified when creating a profile"));
    }
}
Also used : LastModifiedDate(org.orcid.jaxb.model.message.LastModifiedDate) OrcidHistory(org.orcid.jaxb.model.message.OrcidHistory) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) OrcidValidationException(org.orcid.core.exception.OrcidValidationException) SubmissionDate(org.orcid.jaxb.model.message.SubmissionDate) CompletionDate(org.orcid.jaxb.model.message.CompletionDate) Claimed(org.orcid.jaxb.model.message.Claimed) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

OrcidValidationException (org.orcid.core.exception.OrcidValidationException)11 Test (org.junit.Test)5 InvalidPutCodeException (org.orcid.core.exception.InvalidPutCodeException)4 HashMap (java.util.HashMap)3 ActivityTypeValidationException (org.orcid.core.exception.ActivityTypeValidationException)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 ActivityIdentifierValidationException (org.orcid.core.exception.ActivityIdentifierValidationException)2 ActivityTitleValidationException (org.orcid.core.exception.ActivityTitleValidationException)2 Amount (org.orcid.jaxb.model.common_v2.Amount)2 Day (org.orcid.jaxb.model.common_v2.Day)2 Month (org.orcid.jaxb.model.common_v2.Month)2 PublicationDate (org.orcid.jaxb.model.common_v2.PublicationDate)2 Visibility (org.orcid.jaxb.model.common_v2.Visibility)2 Year (org.orcid.jaxb.model.common_v2.Year)2 GroupIdRecord (org.orcid.jaxb.model.groupid_v2.GroupIdRecord)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 Work (org.orcid.jaxb.model.record_v2.Work)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1