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);
}
}
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());
}
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);
}
}
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());
}
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);
}
Aggregations