Package org.candlepin.common.exceptions

Examples of org.candlepin.common.exceptions.BadRequestException


        }
        try {
            d = DatatypeConverter.parseDateTime(activeOn).getTime();
        }
        catch (IllegalArgumentException e) {
            throw new BadRequestException(
                "Invalid date, must use ISO 8601 format");
        }
        return d;
    }
View Full Code Here


    @Produces(MediaType.APPLICATION_JSON)
    public Cdn create(Cdn cdn,
        @Context Principal principal) {
        Cdn existing = curator.lookupByLabel(cdn.getLabel());
        if (existing != null) {
            throw new BadRequestException(
                i18n.tr("A CDN with the label {0}" +
                        "already exists", cdn.getLabel()));
        }
        return curator.create(cdn);
    }
View Full Code Here

    private Pool findPool(String poolId) {
        Pool pool = poolManager.find(poolId);

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

    private Product confirmProduct(String prodId) {
        Product prod = productAdapter.getProductById(prodId);

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

                                 StringUtils.isEmpty(uuid) &&
                                 StringUtils.isEmpty(principalName);

        // make sure we only specified one
        if (allParamsEmpty || !ensureOnlyOne(ownerKey, uuid, principalName)) {
            throw new BadRequestException(i18n.tr("You must specify exactly " +
                "one of owner key, unit UUID, or principal name."));
        }

        List<JobStatus> statuses = null;
        if (!StringUtils.isEmpty(ownerKey)) {
View Full Code Here

    @Path("/{job_id}")
    @Produces(MediaType.APPLICATION_JSON)
    public JobStatus cancel(@PathParam("job_id") String jobId) {
        JobStatus j = curator.find(jobId);
        if (j.getState().equals(JobState.CANCELED)) {
            throw new BadRequestException(i18n.tr("job already canceled"));
        }
        if (j.isDone()) {
            throw new BadRequestException(i18n.tr("cannot cancel a job that " +
                "is in a finished state"));
        }
        return curator.cancel(jobId);
    }
View Full Code Here

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    public Owner createOwner(Owner owner) {
        Owner parent = owner.getParentOwner();
        if (parent != null && ownerCurator.find(parent.getId()) == null) {
            throw new BadRequestException(i18n.tr(
                "Could not create the Owner: {0}. Parent {1} does not exist.",
                owner, parent));
        }
        Owner toReturn = ownerCurator.create(owner);
        sink.emitOwnerCreated(owner);

        log.info("Created owner: " + owner);
        if (toReturn != null) {
            return toReturn;
        }

        throw new BadRequestException(i18n.tr(
            "Could not create the Owner: {0}", owner));
    }
View Full Code Here

        Owner owner = findOwner(ownerKey);
        activationKey.setOwner(owner);

        if (StringUtils.isBlank(activationKey.getName())) {
            throw new BadRequestException(
                i18n.tr("Must provide a name for activation key."));
        }

        String testName = activationKey.getName().replace("-", "0")
                          .replace("_", "0");
        if (!testName.matches("[a-zA-Z0-9]*")) {
            throw new BadRequestException(
                i18n.tr("The activation key name ''{0}'' must be alphanumeric or " +
                    "include the characters '-' or '_'", activationKey.getName()));
        }

        if (activationKeyCurator.lookupForOwner(activationKey.getName(), owner) != null) {
            throw new BadRequestException(
                i18n.tr("The activation key name ''{0}'' is already in use for owner {1}",
                    activationKey.getName(), ownerKey));
        }

        if (activationKey.getContentOverrides() != null) {
View Full Code Here

        acceptedLevels.add(Level.WARN.toString());
        acceptedLevels.add(Level.ERROR.toString());
        acceptedLevels.add(Level.OFF.toString());

        if (!acceptedLevels.contains(level)) {
            throw new BadRequestException(i18n.tr("{0} is not a valid log level", level));
        }

        owner.setLogLevel(level);
        ownerCurator.merge(owner);
        return owner;
View Full Code Here

                throw new NotFoundException(i18n.tr("Unit: {0} not found",
                    consumerUuid));
            }

            if (!c.getOwner().getId().equals(owner.getId())) {
                throw new BadRequestException(
                    "Consumer specified does not belong to owner on path");
            }

            if (!principal.canAccess(c, SubResource.NONE, Access.READ_ONLY)) {
                throw new ForbiddenException(i18n.tr("User {0} cannot access consumer {1}",
                    principal.getPrincipalName(), c.getUuid()));
            }
        }

        ActivationKey key = null;
        if (activationKeyName != null) {
            key = activationKeyCurator.lookupForOwner(activationKeyName, owner);
            if (key == null) {
                throw new BadRequestException(
                    i18n.tr("ActivationKey with id {0} could not be found.",
                        activationKeyName));
            }
        }
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.