Package org.candlepin.common.exceptions

Examples of org.candlepin.common.exceptions.BadRequestException


            String decoded = new String(Base64.decodeBase64(rulesBuffer));
            rules = new Rules(decoded);
        }
        catch (Throwable t) {
            log.error("Exception in rules upload", t);
            throw new BadRequestException(
                i18n.tr("Error decoding the rules. The text should be base 64 encoded"));
        }
        Rules oldRules = rulesCurator.getRules();
        rulesCurator.update(rules);
        sink.emitRulesModified(oldRules, rules);
View Full Code Here


    @Path("/{content_id}")
    public Content getContent(@PathParam("content_id") String contentId) {
        Content content = contentCurator.find(contentId);

        if (content == null) {
            throw new BadRequestException(
                i18n.tr("Content with id {0} could not be found.", contentId));
        }

        return content;
    }
View Full Code Here

            int value = -1;
            try {
                value = Integer.parseInt(attr.getValue());
            }
            catch (NumberFormatException nfe) {
                throw new BadRequestException(i18n.tr(
                    "The attribute ''{0}'' must be an integer value.",
                    attr.getName()));
            }
            if (posIntAttrs != null && posIntAttrs.contains(
                attr.getName()) &&
                value < 0) {
                throw new BadRequestException(i18n.tr(
                    "The attribute ''{0}'' must have a positive value.",
                    attr.getName()));
            }
        }
        else if (longAttrs != null && longAttrs.contains(attr.getName()) ||
            posLongAttrs != null && posLongAttrs.contains(attr.getName())) {
            long value = -1;
            try {
                value = Long.parseLong(attr.getValue());
            }
            catch (NumberFormatException nfe) {
                throw new BadRequestException(i18n.tr(
                    "The attribute ''{0}'' must be a long value.",
                    attr.getName()));
            }
            if (posLongAttrs != null && posLongAttrs.contains(
                attr.getName()) &&
                value <= 0) {
                throw new BadRequestException(i18n.tr(
                    "The attribute ''{0}'' must have a positive value.",
                    attr.getName()));
            }
        }
        else if (boolAttrs != null && boolAttrs.contains(attr.getName())) {
            if (attr.getValue() != null &&
                !"true".equalsIgnoreCase(attr.getValue().trim()) &&
                !"false".equalsIgnoreCase(attr.getValue()) &&
                !"1".equalsIgnoreCase(attr.getValue()) &&
                !"0".equalsIgnoreCase(attr.getValue())) {
                throw new BadRequestException(i18n.tr(
                    "The attribute ''{0}'' must be a boolean value.",
                    attr.getName()));
            }
        }
    }
View Full Code Here

        Integer quantity) {
        Pool pool = poolManager.find(poolId);
        List<Entitlement> entitlementList = new LinkedList<Entitlement>();

        if (pool == null) {
            throw new BadRequestException(i18n.tr(
                "Subscription pool {0} does not exist.", poolId));
        }

        if (log.isDebugEnabled()) {
            log.debug("pool: id[" + pool.getId() + "], consumed[" +
View Full Code Here

    private SubscriptionsCertificate getSubCertWorker(String subscriptionId) {
        Subscription sub = verifyAndFind(subscriptionId);
        SubscriptionsCertificate subCert = sub.getCertificate();
        if (subCert == null) {
            throw new BadRequestException(
                i18n.tr("no certificate for subscription {0}", subscriptionId));
        }
        return subCert;
    }
View Full Code Here

        @QueryParam("email") String email,
        @QueryParam("email_locale") String emailLocale,
        @Context HttpServletResponse response) {

        if (email == null) {
            throw new BadRequestException(i18n.tr(
                    "email is required for notification"));
        }

        if (emailLocale == null) {
            throw new BadRequestException(i18n.tr(
                    "email locale is required for notification"));
        }

        Consumer consumer = consumerCurator.findByUuid(consumerUuid);

        if (consumer == null) {
            throw new BadRequestException(i18n.tr("No such unit: {0}",
                consumerUuid));
        }

        this.subService.activateSubscription(consumer, email, emailLocale);
View Full Code Here

    private Subscription verifyAndFind(String subscriptionId) {
        Subscription subscription = subService.getSubscription(subscriptionId);

        if (subscription == null) {
            throw new BadRequestException(
                i18n.tr("Subscription with id {0} could not be found.", subscriptionId));
        }
        return subscription;
    }
View Full Code Here

            throw new ForbiddenException(i18n.tr("Insufficient permissions"));
        }

        if (!keyStrings.isEmpty()) {
            if (ownerKey == null) {
                throw new BadRequestException(i18n.tr(
                        "Must specify an org to register with activation keys."));
            }
            if (userName != null) {
                throw new BadRequestException(i18n.tr("Cannot specify username with activation keys."));
            }
        }

        Owner owner = setupOwner(principal, ownerKey);
        // Raise an exception if none of the keys specified exist for this owner.
        List<ActivationKey> keys = new ArrayList<ActivationKey>();
        for (String keyString : keyStrings) {
            ActivationKey key = null;
            try {
                key = findKey(keyString, owner);
                keys.add(key);
            }
            catch (NotFoundException e) {
                log.warn(e.getMessage());
            }
        }
        if ((principal instanceof NoAuthPrincipal) && keys.isEmpty()) {
            throw new BadRequestException(i18n.tr(
                    "None of the activation keys specified exist for this org."));
        }

        userName = setUserName(consumer, principal, userName);

        checkConsumerName(consumer);

        ConsumerType type = lookupConsumerType(consumer.getType().getLabel());
        if (type.isType(ConsumerTypeEnum.PERSON)) {
            if (keys.size() > 0) {
                throw new BadRequestException(i18n.tr(
                        "A unit type of 'person' cannot be used with activation keys"));
            }
            if (!isConsumerPersonNameValid(consumer.getName())) {
                throw new BadRequestException(i18n.tr(
                        "System name cannot contain most special characters."));
            }

            verifyPersonConsumer(consumer, type, owner, userName, principal);
        }

        if (type.isType(ConsumerTypeEnum.SYSTEM) &&
            !isConsumerSystemNameValid(consumer.getName())) {

            throw new BadRequestException(i18n.tr("System name cannot contain most special characters."));
        }
        consumer.setOwner(owner);
        consumer.setType(type);
        consumer.setCanActivate(subAdapter.canActivateSubscription(consumer));
        consumer.setAutoheal(true); // this is the default
        if (consumer.getServiceLevel() == null) { consumer.setServiceLevel(""); }

        // If no service level was specified, and the owner has a default set, use it:
        if (consumer.getServiceLevel().equals("") &&
            owner.getDefaultServiceLevel() != null) {
            consumer.setServiceLevel(owner.getDefaultServiceLevel());
        }
        updateCapabilities(consumer, null);

        logNewConsumerDebugInfo(consumer, keys, type);

        if (consumer.getInstalledProducts() != null) {
            for (ConsumerInstalledProduct p : consumer.getInstalledProducts()) {
                p.setConsumer(consumer);
            }
        }
        if (consumer.getGuestIds() != null) {
            for (GuestId g : consumer.getGuestIds()) {
                g.setConsumer(consumer);
            }
        }
        HypervisorId hvsrId = consumer.getHypervisorId();
        if (hvsrId != null && hvsrId.getHypervisorId() != null && !hvsrId.getHypervisorId().isEmpty()) {
            // If a hypervisorId is supplied, make sure the consumer and owner are correct
            hvsrId.setConsumer(consumer);
        }

        consumerBindUtil.validateServiceLevel(owner, consumer.getServiceLevel());

        try {
            consumer = consumerCurator.create(consumer);
            IdentityCertificate idCert = generateIdCert(consumer, false);
            consumer.setIdCert(idCert);

            sink.emitConsumerCreated(consumer);

            if (keys.size() > 0) {
                consumerBindUtil.handleActivationKeys(consumer, keys);
            }

            // Don't allow complianceRules to update entitlementStatus, because we're about to perform
            // an update unconditionally.
            complianceRules.getStatus(consumer, null, false, false);
            consumerCurator.update(consumer);

            log.info("Consumer " + consumer.getUuid() + " created in org " + consumer.getOwner().getKey());

            return consumer;
        }
        catch (CandlepinException ce) {
            // If it is one of ours, rethrow it.
            throw ce;
        }
        catch (Exception e) {
            log.error("Problem creating unit:", e);
            throw new BadRequestException(i18n.tr(
                "Problem creating unit {0}", consumer));
        }
    }
View Full Code Here

    private void checkConsumerName(Consumer consumer) {
        // for now this applies to both types consumer
        if (consumer.getName() != null &&
            consumer.getName().indexOf('#') == 0) {
            // this is a bouncycastle restriction
            throw new BadRequestException(
                i18n.tr("System name cannot begin with # character"));
        }
    }
View Full Code Here

            Consumer existing = consumerCurator.findByUser(user);

            if (existing != null &&
                existing.getType().isType(ConsumerTypeEnum.PERSON)) {
                // TODO: This is not the correct error code for this situation!
                throw new BadRequestException(i18n.tr(
                    "User ''{0}'' has already registered a personal consumer",
                    user.getUsername()));
            }
            consumer.setName(user.getUsername());
        }
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.