Search in sources :

Example 36 with NotFoundException

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

the class PoolResource method getPool.

@ApiOperation(notes = "Retrieves a single Pool", value = "getPool")
@ApiResponses({ @ApiResponse(code = 404, message = "if the pool with the specified id is not found"), @ApiResponse(code = 404, message = "") })
@GET
@Path("/{pool_id}")
@Produces(MediaType.APPLICATION_JSON)
public PoolDTO getPool(@PathParam("pool_id") @Verify(Pool.class) String id, @QueryParam("consumer") String consumerUuid, @ApiParam("Uses ISO 8601 format") @QueryParam("activeon") String activeOn, @Context Principal principal) {
    Pool toReturn = poolManager.find(id);
    Consumer c = null;
    if (consumerUuid != null) {
        c = consumerCurator.findByUuid(consumerUuid);
        if (c == null) {
            throw new NotFoundException(i18n.tr("consumer: {0} not found", consumerUuid));
        }
        if (!principal.canAccess(c, SubResource.NONE, Access.READ_ONLY)) {
            throw new ForbiddenException(i18n.tr("User {0} cannot access consumer {1}", principal.getPrincipalName(), c.getUuid()));
        }
    }
    if (toReturn != null) {
        Date activeOnDate = new Date();
        if (activeOn != null) {
            activeOnDate = ResourceDateParser.parseDateString(activeOn);
        }
        toReturn.setCalculatedAttributes(calculatedAttributesUtil.buildCalculatedAttributes(toReturn, activeOnDate));
        calculatedAttributesUtil.setQuantityAttributes(toReturn, c, activeOnDate);
        return translator.translate(toReturn, PoolDTO.class);
    }
    throw new NotFoundException(i18n.tr("Subscription Pool with ID \"{0}\" could not be found.", id));
}
Also used : ForbiddenException(org.candlepin.common.exceptions.ForbiddenException) Consumer(org.candlepin.model.Consumer) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Pool(org.candlepin.model.Pool) Date(java.util.Date) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 37 with NotFoundException

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

the class PoolResource method getPoolEntitlements.

@ApiOperation(notes = "Retrieve a list of Entitlements for a Pool", value = "getPoolEntitlements")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@GET
@Path("{pool_id}/entitlements")
@Produces(MediaType.APPLICATION_JSON)
public List<EntitlementDTO> getPoolEntitlements(@PathParam("pool_id") @Verify(value = Pool.class, subResource = SubResource.ENTITLEMENTS) String id, @Context Principal principal) {
    Pool pool = poolManager.find(id);
    if (pool == null) {
        throw new NotFoundException(i18n.tr("Subscription Pool with ID \"{0}\" could not be found.", id));
    }
    List<EntitlementDTO> entitlementDTOs = new ArrayList<>();
    for (Entitlement entitlement : pool.getEntitlements()) {
        entitlementDTOs.add(this.translator.translate(entitlement, EntitlementDTO.class));
    }
    return entitlementDTOs;
}
Also used : EntitlementDTO(org.candlepin.dto.api.v1.EntitlementDTO) ArrayList(java.util.ArrayList) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Pool(org.candlepin.model.Pool) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 38 with NotFoundException

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

the class SubscriptionResource method deleteSubscription.

@ApiOperation(notes = "Removes a Subscription", value = "deleteSubscription")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@DELETE
@Path("/{subscription_id}")
@Produces(MediaType.APPLICATION_JSON)
public void deleteSubscription(@PathParam("subscription_id") String subscriptionId) {
    // Lookup pools from subscription ID
    int count = 0;
    for (Pool pool : this.poolManager.getPoolsBySubscriptionId(subscriptionId)) {
        this.poolManager.deletePool(pool);
        ++count;
    }
    if (count == 0) {
        throw new NotFoundException(i18n.tr("A subscription with the ID \"{0}\" could not be found.", subscriptionId));
    }
}
Also used : NotFoundException(org.candlepin.common.exceptions.NotFoundException) Pool(org.candlepin.model.Pool) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 39 with NotFoundException

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

the class ConsumerTypeResource method deleteConsumerType.

@ApiOperation(notes = "Removes a Consumer Type", value = "deleteConsumerType")
@DELETE
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
public void deleteConsumerType(@PathParam("id") String id) {
    ConsumerType type = consumerTypeCurator.find(id);
    if (type == null) {
        throw new NotFoundException(i18n.tr("Unit type with id {0} could not be found.", id));
    }
    consumerTypeCurator.delete(type);
}
Also used : NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerType(org.candlepin.model.ConsumerType) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 40 with NotFoundException

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

the class ConsumerTypeResource method update.

@ApiOperation(notes = "Updates a Consumer Type", value = "update")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@PUT
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public ConsumerTypeDTO update(@ApiParam(name = "consumerType", required = true) ConsumerTypeDTO dto) throws BadRequestException {
    ConsumerType type = consumerTypeCurator.find(dto.getId());
    if (type == null) {
        throw new NotFoundException(i18n.tr("Unit type with label {0} could not be found.", dto.getId()));
    }
    this.populateEntity(type, dto);
    type = consumerTypeCurator.merge(type);
    return this.translator.translate(type, ConsumerTypeDTO.class);
}
Also used : NotFoundException(org.candlepin.common.exceptions.NotFoundException) ConsumerType(org.candlepin.model.ConsumerType) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Aggregations

NotFoundException (org.candlepin.common.exceptions.NotFoundException)44 ApiOperation (io.swagger.annotations.ApiOperation)25 Produces (javax.ws.rs.Produces)25 ApiResponses (io.swagger.annotations.ApiResponses)24 Path (javax.ws.rs.Path)22 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 Consumer (org.candlepin.model.Consumer)12 Owner (org.candlepin.model.Owner)12 DELETE (javax.ws.rs.DELETE)11 GET (javax.ws.rs.GET)10 Entitlement (org.candlepin.model.Entitlement)10 Pool (org.candlepin.model.Pool)9 ArrayList (java.util.ArrayList)7 Transactional (com.google.inject.persist.Transactional)6 Consumes (javax.ws.rs.Consumes)6 ConsumerType (org.candlepin.model.ConsumerType)6 PUT (javax.ws.rs.PUT)5 ForbiddenException (org.candlepin.common.exceptions.ForbiddenException)5 Environment (org.candlepin.model.Environment)5 Test (org.junit.Test)5