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));
}
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;
}
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));
}
}
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);
}
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);
}
Aggregations