Search in sources :

Example 21 with NotFoundException

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();
}
Also used : SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) 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 22 with NotFoundException

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);
}
Also used : NotFoundException(org.candlepin.common.exceptions.NotFoundException) 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 23 with NotFoundException

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));
    }
}
Also used : Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) Entitlement(org.candlepin.model.Entitlement) 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)

Example 24 with NotFoundException

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));
}
Also used : Event(org.candlepin.audit.Event) NotFoundException(org.candlepin.common.exceptions.NotFoundException) LinkedList(java.util.LinkedList) 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 25 with NotFoundException

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);
}
Also used : NotFoundException(org.candlepin.common.exceptions.NotFoundException) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

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