use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class EntitlementResource method getUpstreamCert.
@ApiOperation(notes = "Retrieves a Subscription Certificate. We can't return CdnInfo " + "at this time, but when the time comes this is the implementation we want to start" + " from. It will require changes to thumbslug. will also" + " @Produces(MediaType.APPLICATION_JSON)", value = "getUpstreamCert")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("{dbid}/upstream_cert")
public String getUpstreamCert(@PathParam("dbid") String entitlementId) {
Entitlement ent = entitlementCurator.find(entitlementId);
if (ent == null) {
throw new NotFoundException(i18n.tr("Entitlement with ID \"{0}\" could not be found.", entitlementId));
}
Pool entPool = ent.getPool();
if (!StringUtils.isBlank(entPool.getSourceStackId())) {
/*
* A derived pool originating from a stacked parent pool will have no subscription
* ID as the pool is technically from many subscriptions. (i.e. all the
* entitlements in the stack) In this case we must look up an active entitlement
* in the hosts stack, and use this as our upstream certificate.
*/
log.debug("Entitlement is from a stack derived pool, searching for oldest " + "active entitlements in source stack.");
ent = entitlementCurator.findUpstreamEntitlementForStack(entPool.getSourceStack().getSourceConsumer(), entPool.getSourceStackId());
}
if (ent == null || ent.getPool() == null || ent.getPool().getCertificate() == null) {
throw new NotFoundException(i18n.tr("Unable to find upstream certificate for entitlement: {0}", entitlementId));
}
SubscriptionsCertificate cert = ent.getPool().getCertificate();
return cert.getCert() + cert.getKey();
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class EntitlementResource method getEntitlement.
@ApiOperation(notes = "Retrieves a single Entitlement", value = "getEntitlement")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{entitlement_id}")
public EntitlementDTO getEntitlement(@PathParam("entitlement_id") @Verify(Entitlement.class) String entitlementId) {
Entitlement entitlement = entitlementCurator.find(entitlementId);
if (entitlement == null) {
throw new NotFoundException(i18n.tr("Entitlement with ID \"{0}\" could not be found.", entitlementId));
}
// Impl note:
// If the entitlement is dirty, this performs an in-place update of the entitlement, not a
// generation of a new entitlement object, as the name would imply.
poolManager.regenerateDirtyEntitlements(Arrays.asList(entitlement));
return this.translator.translate(entitlement, EntitlementDTO.class);
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class EntitlementResource method updateEntitlement.
@ApiOperation(notes = "Updates an Entitlement. This only works for the quantity.", value = "updateEntitlement")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{entitlement_id}")
public void updateEntitlement(@PathParam("entitlement_id") @Verify(Entitlement.class) String id, @ApiParam(name = "update", required = true) EntitlementDTO update) {
// Check that quantity param was set and is not 0:
if (update.getQuantity() <= 0) {
throw new BadRequestException(i18n.tr("Quantity value must be greater than 0."));
}
// Verify entitlement exists:
Entitlement entitlement = entitlementCurator.find(id);
if (entitlement != null) {
// make sure that this will be a change
if (!entitlement.getQuantity().equals(update.getQuantity())) {
Consumer consumer = entitlement.getConsumer();
entitler.adjustEntitlementQuantity(consumer, entitlement, update.getQuantity());
}
} else {
throw new NotFoundException(i18n.tr("Entitlement with ID \"{0}\" could not be found.", id));
}
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class EventResource method getEvent.
@ApiOperation(notes = "Retrieves a single Event", value = "getEvent")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{uuid}")
@Produces(MediaType.APPLICATION_JSON)
public EventDTO getEvent(@PathParam("uuid") String uuid) {
Event toReturn = eventCurator.find(uuid);
if (toReturn != null) {
List<Event> events = new LinkedList<>();
events.add(toReturn);
eventAdapter.addMessageText(events);
return this.translator.translate(toReturn, EventDTO.class);
}
throw new NotFoundException(i18n.tr("Event with ID \"{0}\" could not be found.", uuid));
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class ConsumerResourceTest method testRegenerateEntitlementCertificatesWithInvalidConsumerId.
/**
* Basic test. If invalid id is given, should throw
* {@link NotFoundException}
*/
@Test(expected = NotFoundException.class)
public void testRegenerateEntitlementCertificatesWithInvalidConsumerId() {
when(mockConsumerCurator.verifyAndLookupConsumer(any(String.class))).thenThrow(new NotFoundException(""));
ConsumerResource consumerResource = new ConsumerResource(mockConsumerCurator, mockConsumerTypeCurator, null, null, null, null, null, null, i18n, null, null, null, null, null, null, null, null, null, null, null, null, null, null, this.config, null, null, null, consumerBindUtil, null, null, this.factValidator, null, consumerEnricher, migrationProvider, translator);
consumerResource.regenerateEntitlementCertificates("xyz", null, true);
}
Aggregations