Package org.candlepin.common.exceptions

Examples of org.candlepin.common.exceptions.BadRequestException


            @PathParam("guest_id") String guestId,
            GuestId updated) {

        // I'm not sure this can happen
        if (guestId == null || guestId.isEmpty()) {
            throw new BadRequestException(
                i18n.tr("Please supply a valid guest id"));
        }

        if (updated == null) {
            // If they're not sending attributes, we can get the guestId from the url
            updated = new GuestId(guestId);
        }

        // Allow the id to be left out in this case, we can use the path param
        if (updated.getGuestId() == null) {
            updated.setGuestId(guestId);
        }

        // If the guest uuids do not match, something is wrong
        if (!guestId.equalsIgnoreCase(updated.getGuestId())) {
            throw new BadRequestException(
                i18n.tr("Guest ID in json \"{0}\" does not match path guest ID \"{1}\"",
                    updated.getGuestId(), guestId));
        }

        Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
View Full Code Here


     * Creates a user principal for a given username
     */
    protected Principal createPrincipal(String username) {
        User user = userServiceAdapter.findByLogin(username);
        if (user == null) {
            throw new BadRequestException("user " + username + " not found");
        }

        if (user.isSuperAdmin()) {
            return new UserPrincipal(username, null, true);
        }
View Full Code Here

        }
        catch (OAuthException e) {
            log.debug("OAuth Error", e);
            String message = i18n.tr("OAuth error encountered. Internal message is: {0}",
                e.getMessage());
            throw new BadRequestException(message);
        }
        catch (URISyntaxException e) {
            throw new IseException(e.getMessage(), e);
        }
        catch (IOException e) {
View Full Code Here

        Page<List<Entitlement>> p;
        if (consumerUuid != null) {

            Consumer consumer = consumerCurator.findByUuid(consumerUuid);
            if (consumer == null) {
                throw new BadRequestException(
                    i18n.tr("Unit with ID ''{0}'' could not be found.", consumerUuid));
            }

            p = entitlementCurator.listByConsumer(consumer, pageRequest);
        }
View Full Code Here

        @PathParam("entitlement_id") @Verify(Entitlement.class) String id,
        Entitlement update) {

        // Check that quantity param was set and is not 0:
        if (update.getQuantity() <= 0) {
            throw new BadRequestException(
                i18n.tr("Quantity value must be greater than 0."));
        }

        // Verify entitlement exists:
        Entitlement entitlement = entitlementCurator.find(id);
View Full Code Here

            if (quantity > 0 && quantity <= entitlement.getQuantity()) {
                Consumer sourceConsumer = entitlement.getConsumer();
                Consumer destinationConsumer = consumerCurator.verifyAndLookupConsumer(
                        uuid);
                if (!sourceConsumer.getType().isManifest()) {
                    throw new BadRequestException(i18n.tr(
                        "Entitlement migration is not permissible for units of type ''{0}''",
                        sourceConsumer.getType().getLabel()));
                }
                if (!destinationConsumer.getType().isManifest()) {
                    throw new BadRequestException(i18n.tr(
                        "Entitlement migration is not permissible for units of type ''{0}''",
                        destinationConsumer.getType().getLabel()));
                }
                if (!sourceConsumer.getOwner().getKey().equals(destinationConsumer.getOwner().getKey())) {
                    throw new BadRequestException(i18n.tr(
                        "Source and destination units must belong to the same organization"));
                }
                // test to ensure destination can use the pool
                ValidationResult result = enforcer.preEntitlement(destinationConsumer,
                        entitlement.getPool(), 0, CallerType.BIND);
                if (!result.isSuccessful()) {
                    throw new BadRequestException(i18n.tr(
                        "The entitlement cannot be utilized by the destination unit: ") +
                        messageTranslator.poolErrorToMessage(entitlement.getPool(),
                            result.getErrors().get(0)));
                }
                if (quantity.intValue() == entitlement.getQuantity()) {
                    unbind(id);
                }
                else {
                    entitler.adjustEntitlementQuantity(sourceConsumer, entitlement,
                            entitlement.getQuantity() - quantity);
                }
                Pool pool = entitlement.getPool();
                entitlements.addAll(entitler.bindByPool(pool.getId(), destinationConsumer,
                        quantity));

                // Trigger events:
                entitler.sendEvents(entitlements);

            }
            else {
                throw new BadRequestException(i18n.tr(
                    "The quantity specified must be greater than zero " +
                    "and less than or equal to the total for this entitlement"));
            }
        }
        else {
View Full Code Here

                    p.setPage(readInteger(page));
                    p.setPerPage(readInteger(perPage));
                }
            }
            catch (NumberFormatException nfe) {
                throw new BadRequestException(i18n.tr("offset and limit parameters" +
                    " must be positive integers"), nfe);
            }
        }

        ResteasyProviderFactory.pushContext(PageRequest.class, p);
View Full Code Here

        }
        else if ("descending".equalsIgnoreCase(order) || "desc".equalsIgnoreCase(order)) {
            return Order.DESCENDING;
        }

        throw new BadRequestException(i18n.tr("the order parameter must be either" +
                " 'ascending' or 'descending'"));
    }
View Full Code Here

TOP

Related Classes of org.candlepin.common.exceptions.BadRequestException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.