use of org.folio.rest.exception.InputValidationException in project mod-kb-ebsco-java by folio-org.
the class EholdingsPackagesImpl method deleteEholdingsPackagesByPackageId.
@Override
@HandleValidationErrors
public void deleteEholdingsPackagesByPackageId(String packageId, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
PackageId parsedPackageId = parsePackageId(packageId);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getPackagesService().retrievePackage(parsedPackageId).thenCompose(packageData -> {
if (BooleanUtils.isNotTrue(packageData.getIsCustom())) {
throw new InputValidationException(INVALID_PACKAGE_TITLE, INVALID_PACKAGE_DETAILS);
}
return context.getPackagesService().deletePackage(parsedPackageId).thenCompose(aVoid -> deleteAssignedResources(parsedPackageId, context));
})).execute();
}
use of org.folio.rest.exception.InputValidationException in project mod-kb-ebsco-java by folio-org.
the class EholdingsResourcesImpl method deleteEholdingsResourcesByResourceId.
@Override
@HandleValidationErrors
public void deleteEholdingsResourcesByResourceId(String resourceId, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
ResourceId parsedResourceId = parseResourceId(resourceId);
templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getResourcesService().retrieveResource(parsedResourceId).thenCompose(title -> {
if (BooleanUtils.isNotTrue(title.getCustomerResourcesList().get(0).getIsPackageCustom())) {
throw new InputValidationException(RESOURCE_CANNOT_BE_DELETED_TITLE, RESOURCE_CANNOT_BE_DELETED_DETAIL);
}
return context.getResourcesService().deleteResource(parsedResourceId);
}).thenCompose(o -> deleteAssignedResources(resourceId, context))).execute();
}
use of org.folio.rest.exception.InputValidationException in project mod-kb-ebsco-java by folio-org.
the class AssignedUsersBodyValidator method validate.
/**
* Provides validation for the data attributes
*
* @throws ValidationException if validation fails
*/
public void validate(AssignedUser data) {
if (Objects.isNull(data) || Objects.isNull(data.getAttributes())) {
throw new InputValidationException(INVALID_POST_BODY, "");
}
AssignedUserDataAttributes attributes = data.getAttributes();
ValidatorUtil.checkIsNotBlank("userName", attributes.getUserName());
ValidatorUtil.checkMaxLength("userName", attributes.getUserName(), 200);
ValidatorUtil.checkIsNotBlank("lastName", attributes.getLastName());
ValidatorUtil.checkMaxLength("lastName", attributes.getLastName(), 200);
ValidatorUtil.checkIsNotBlank("patronGroup", attributes.getPatronGroup());
ValidatorUtil.checkMaxLength("patronGroup", attributes.getPatronGroup(), 200);
if (!Objects.isNull(attributes.getFirstName())) {
ValidatorUtil.checkIsNotBlank("firstName", attributes.getFirstName());
ValidatorUtil.checkMaxLength("firstName", attributes.getFirstName(), 200);
}
}
use of org.folio.rest.exception.InputValidationException in project mod-kb-ebsco-java by folio-org.
the class PackageTagsPutBodyValidator method validate.
public void validate(PackageTagsPutRequest request) {
if (request == null || request.getData() == null || request.getData().getAttributes() == null) {
throw new InputValidationException(INVALID_REQUEST_BODY_TITLE, INVALID_REQUEST_BODY_DETAILS);
}
PackageTagsDataAttributes attributes = request.getData().getAttributes();
ValidatorUtil.checkIsNotBlank("name", attributes.getName());
ValidatorUtil.checkMaxLength("name", attributes.getName(), 200);
ValidatorUtil.checkIsNotNull("contentType", attributes.getContentType());
ValidatorUtil.checkIsNotNull("tags", attributes.getTags());
}
use of org.folio.rest.exception.InputValidationException in project mod-kb-ebsco-java by folio-org.
the class UCAuthServiceImpl method validate.
private CompletableFuture<Void> validate(DbUCCredentials credentials) {
CompletableFuture<Void> validationFuture = new CompletableFuture<>();
requestToken(credentials).handle((ucAuthToken, throwable) -> {
if (throwable != null) {
Throwable resultException = throwable.getCause();
if (resultException instanceof UcAuthenticationException) {
resultException = new InputValidationException(INVALID_UC_CREDENTIALS_MESSAGE, null);
}
validationFuture.completeExceptionally(resultException);
} else {
validationFuture.complete(null);
}
return null;
});
return validationFuture;
}
Aggregations