Search in sources :

Example 36 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class OwnerContentResource method updateContent.

@ApiOperation(notes = "Updates a Content", value = "updateContent")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{content_id}")
public ContentDTO updateContent(@PathParam("owner_key") String ownerKey, @PathParam("content_id") String contentId, @ApiParam(name = "content", required = true) ContentDTO content) {
    Owner owner = this.getOwnerByKey(ownerKey);
    Content existing = this.fetchContent(owner, contentId);
    if (existing.isLocked()) {
        throw new ForbiddenException(i18n.tr("content \"{0}\" is locked", existing.getId()));
    }
    existing = this.contentManager.updateContent(content, owner, true);
    ownerManager.refreshOwnerForContentAccess(owner);
    return this.translator.translate(existing, ContentDTO.class);
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Content(org.candlepin.model.Content) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT)

Example 37 with ForbiddenException

use of org.candlepin.common.exceptions.ForbiddenException in project candlepin by candlepin.

the class ConsumerBindUtil method handleActivationKeyAutoBind.

private void handleActivationKeyAutoBind(Consumer consumer, ActivationKey key) throws AutobindDisabledForOwnerException {
    try {
        Set<String> productIds = new HashSet<>();
        List<String> poolIds = new ArrayList<>();
        for (Product akp : key.getProducts()) {
            productIds.add(akp.getId());
        }
        for (ConsumerInstalledProduct cip : consumer.getInstalledProducts()) {
            productIds.add(cip.getProductId());
        }
        for (ActivationKeyPool p : key.getPools()) {
            poolIds.add(p.getPool().getId());
        }
        Owner owner = ownerCurator.findOwnerById(consumer.getOwnerId());
        AutobindData autobindData = AutobindData.create(consumer, owner).forProducts(productIds.toArray(new String[0])).withPools(poolIds);
        List<Entitlement> ents = entitler.bindByProducts(autobindData);
        entitler.sendEvents(ents);
    } catch (ForbiddenException fe) {
        throw fe;
    } catch (CertVersionConflictException cvce) {
        throw cvce;
    } catch (RuntimeException re) {
        log.warn("Unable to attach a subscription for a product that " + "has no pool: " + re.getMessage());
    }
}
Also used : Owner(org.candlepin.model.Owner) ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ArrayList(java.util.ArrayList) Product(org.candlepin.model.Product) ConsumerInstalledProduct(org.candlepin.model.ConsumerInstalledProduct) ActivationKeyPool(org.candlepin.model.activationkeys.ActivationKeyPool) CertVersionConflictException(org.candlepin.version.CertVersionConflictException) AutobindData(org.candlepin.resource.dto.AutobindData) Entitlement(org.candlepin.model.Entitlement) HashSet(java.util.HashSet)

Aggregations

ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)37 Owner (org.candlepin.model.Owner)22 Consumer (org.candlepin.model.Consumer)19 Test (org.junit.Test)15 BadRequestException (org.candlepin.common.exceptions.BadRequestException)13 Product (org.candlepin.model.Product)13 ApiOperation (io.swagger.annotations.ApiOperation)12 Produces (javax.ws.rs.Produces)12 Pool (org.candlepin.model.Pool)12 ArrayList (java.util.ArrayList)11 Path (javax.ws.rs.Path)11 NotFoundException (org.candlepin.common.exceptions.NotFoundException)9 Transactional (com.google.inject.persist.Transactional)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Content (org.candlepin.model.Content)7 HashMap (java.util.HashMap)6 Consumes (javax.ws.rs.Consumes)6 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)6 ActivationKey (org.candlepin.model.activationkeys.ActivationKey)6 DELETE (javax.ws.rs.DELETE)5