Search in sources :

Example 1 with InputValidationException

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();
}
Also used : RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) Filter(org.folio.rest.model.filter.Filter) TagRepository(org.folio.repository.tag.TagRepository) PackageParametersValidator(org.folio.holdingsiq.service.validator.PackageParametersValidator) TitleCollectionResult(org.folio.rmapi.result.TitleCollectionResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ExceptionMappers.error400NotFoundMapper(org.folio.rest.util.ExceptionMappers.error400NotFoundMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) PackagePut(org.folio.holdingsiq.model.PackagePut) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) AccessType(org.folio.rest.jaxrs.model.AccessType) JSONAPI(org.folio.rest.util.RestConstants.JSONAPI) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) Collectors.toMap(java.util.stream.Collectors.toMap) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) EholdingsPackages(org.folio.rest.jaxrs.resource.EholdingsPackages) ListUtils.parseByComma(org.folio.common.ListUtils.parseByComma) PackagePutBodyValidator(org.folio.rest.validator.PackagePutBodyValidator) Map(java.util.Map) Package(org.folio.rest.jaxrs.model.Package) ResourceCollection(org.folio.rest.jaxrs.model.ResourceCollection) IdParser.packageIdToString(org.folio.rest.util.IdParser.packageIdToString) PackageTagsItem(org.folio.rest.jaxrs.model.PackageTagsItem) OkapiData(org.folio.holdingsiq.model.OkapiData) VertxCache(org.folio.cache.VertxCache) PackageBulkFetchCollection(org.folio.rest.jaxrs.model.PackageBulkFetchCollection) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) Future(io.vertx.core.Future) NotFoundException(javax.ws.rs.NotFoundException) PackageCollection(org.folio.rest.jaxrs.model.PackageCollection) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Response(javax.ws.rs.core.Response) PackageResult(org.folio.rmapi.result.PackageResult) ErrorUtil(org.folio.rest.util.ErrorUtil) PackagePostRequest(org.folio.rest.jaxrs.model.PackagePostRequest) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) VendorIdCacheKey(org.folio.config.cache.VendorIdCacheKey) UserKbCredentialsService(org.folio.service.kbcredentials.UserKbCredentialsService) RecordKey(org.folio.repository.RecordKey) FilteredEntitiesLoader(org.folio.service.loader.FilteredEntitiesLoader) PackageTagsDataAttributes(org.folio.rest.jaxrs.model.PackageTagsDataAttributes) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) Tags(org.folio.rest.jaxrs.model.Tags) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) CustomPackagePutBodyValidator(org.folio.rest.validator.CustomPackagePutBodyValidator) Function(java.util.function.Function) DbPackage(org.folio.repository.packages.DbPackage) PackageRequestConverter(org.folio.rest.converter.packages.PackageRequestConverter) InputValidationException(org.folio.rest.exception.InputValidationException) SpringContextUtil(org.folio.spring.SpringContextUtil) ArrayList(java.util.ArrayList) PackagePutRequest(org.folio.rest.jaxrs.model.PackagePutRequest) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PackageTagsPutBodyValidator(org.folio.rest.validator.PackageTagsPutBodyValidator) PackagePostBulkFetchRequest(org.folio.rest.jaxrs.model.PackagePostBulkFetchRequest) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) Converter(org.springframework.core.convert.converter.Converter) ExceptionMappers.error422InputValidationMapper(org.folio.rest.util.ExceptionMappers.error422InputValidationMapper) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) ErrorHandler(org.folio.rest.util.ErrorHandler) Titles(org.folio.holdingsiq.model.Titles) PackagesPostBodyValidator(org.folio.rest.validator.PackagesPostBodyValidator) DbTag(org.folio.repository.tag.DbTag) Validate(org.folio.rest.annotations.Validate) PackageTagsPutRequest(org.folio.rest.jaxrs.model.PackageTagsPutRequest) PackageRepository(org.folio.repository.packages.PackageRepository) CustomerResources(org.folio.holdingsiq.model.CustomerResources) ConverterConsts(org.folio.rest.converter.common.ConverterConsts) TAGS_TYPE(org.folio.rest.util.RestConstants.TAGS_TYPE) TitleResult(org.folio.rmapi.result.TitleResult) PackageTags(org.folio.rest.jaxrs.model.PackageTags) Handler(io.vertx.core.Handler) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) PackagePost(org.folio.holdingsiq.model.PackagePost) PackageId(org.folio.holdingsiq.model.PackageId) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) InputValidationException(org.folio.rest.exception.InputValidationException) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 2 with InputValidationException

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();
}
Also used : RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) ResourcePostBulkFetchRequest(org.folio.rest.jaxrs.model.ResourcePostBulkFetchRequest) TagRepository(org.folio.repository.tag.TagRepository) ExceptionMappers.error400NotFoundMapper(org.folio.rest.util.ExceptionMappers.error400NotFoundMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) AccessType(org.folio.rest.jaxrs.model.AccessType) JSONAPI(org.folio.rest.util.RestConstants.JSONAPI) RowSetUtils(org.folio.db.RowSetUtils) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) ResourcePostValidator(org.folio.rest.validator.ResourcePostValidator) ListUtils.parseByComma(org.folio.common.ListUtils.parseByComma) Map(java.util.Map) TitlesHoldingsIQService(org.folio.holdingsiq.service.TitlesHoldingsIQService) PackagesHoldingsIQService(org.folio.holdingsiq.service.PackagesHoldingsIQService) EholdingsResources(org.folio.rest.jaxrs.resource.EholdingsResources) OkapiData(org.folio.holdingsiq.model.OkapiData) ResourceTagsPutBodyValidator(org.folio.rest.validator.ResourceTagsPutBodyValidator) DbResource(org.folio.repository.resources.DbResource) IdParser.parseTitleId(org.folio.rest.util.IdParser.parseTitleId) UUID(java.util.UUID) Future(io.vertx.core.Future) FilterQuery(org.folio.holdingsiq.model.FilterQuery) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) CompletionStage(java.util.concurrent.CompletionStage) Response(javax.ws.rs.core.Response) ResourceBulkFetchCollection(org.folio.rest.jaxrs.model.ResourceBulkFetchCollection) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) CONTENT_TYPE(org.apache.http.protocol.HTTP.CONTENT_TYPE) SC_NOT_FOUND(org.apache.http.HttpStatus.SC_NOT_FOUND) UserKbCredentialsService(org.folio.service.kbcredentials.UserKbCredentialsService) RecordKey(org.folio.repository.RecordKey) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceTagsPutRequest(org.folio.rest.jaxrs.model.ResourceTagsPutRequest) ResourceRequestConverter(org.folio.rest.converter.resources.ResourceRequestConverter) Sort(org.folio.holdingsiq.model.Sort) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Function(java.util.function.Function) InputValidationException(org.folio.rest.exception.InputValidationException) SpringContextUtil(org.folio.spring.SpringContextUtil) ErrorUtil.createError(org.folio.rest.util.ErrorUtil.createError) ResourceSelectedPayload(org.folio.holdingsiq.model.ResourceSelectedPayload) ResourcePostRequest(org.folio.rest.jaxrs.model.ResourcePostRequest) ResourceTags(org.folio.rest.jaxrs.model.ResourceTags) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ResourceRepository(org.folio.repository.resources.ResourceRepository) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) IdParser.resourceIdToString(org.folio.rest.util.IdParser.resourceIdToString) JSON_API_TYPE(org.folio.rest.util.RestConstants.JSON_API_TYPE) Resource(org.folio.rest.jaxrs.model.Resource) ResourceTagsItem(org.folio.rest.jaxrs.model.ResourceTagsItem) IdParser(org.folio.rest.util.IdParser) ResourcePostDataAttributes(org.folio.rest.jaxrs.model.ResourcePostDataAttributes) ExceptionMappers.error422InputValidationMapper(org.folio.rest.util.ExceptionMappers.error422InputValidationMapper) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) ErrorHandler(org.folio.rest.util.ErrorHandler) ObjectsForPostResourceResult(org.folio.rmapi.result.ObjectsForPostResourceResult) CustomerResources(org.folio.holdingsiq.model.CustomerResources) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) TAGS_TYPE(org.folio.rest.util.RestConstants.TAGS_TYPE) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Handler(io.vertx.core.Handler) ResourceTagsDataAttributes(org.folio.rest.jaxrs.model.ResourceTagsDataAttributes) ResourcePutBodyValidator(org.folio.rest.validator.ResourcePutBodyValidator) ResourceResult(org.folio.rmapi.result.ResourceResult) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceId(org.folio.holdingsiq.model.ResourceId) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) InputValidationException(org.folio.rest.exception.InputValidationException) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 3 with InputValidationException

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);
    }
}
Also used : InputValidationException(org.folio.rest.exception.InputValidationException) AssignedUserDataAttributes(org.folio.rest.jaxrs.model.AssignedUserDataAttributes)

Example 4 with InputValidationException

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());
}
Also used : InputValidationException(org.folio.rest.exception.InputValidationException) PackageTagsDataAttributes(org.folio.rest.jaxrs.model.PackageTagsDataAttributes)

Example 5 with InputValidationException

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) InputValidationException(org.folio.rest.exception.InputValidationException)

Aggregations

InputValidationException (org.folio.rest.exception.InputValidationException)12 CompletableFuture (java.util.concurrent.CompletableFuture)3 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CompletionStage (java.util.concurrent.CompletionStage)2 Function (java.util.function.Function)2 NotFoundException (javax.ws.rs.NotFoundException)2 Response (javax.ws.rs.core.Response)2 BooleanUtils (org.apache.commons.lang3.BooleanUtils)2 ListUtils.parseByComma (org.folio.common.ListUtils.parseByComma)2 CustomerResources (org.folio.holdingsiq.model.CustomerResources)2 OkapiData (org.folio.holdingsiq.model.OkapiData)2 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)2 PackageId (org.folio.holdingsiq.model.PackageId)2