Search in sources :

Example 76 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerResource method getComplianceStatus.

@ApiOperation(notes = "Retireves the Compliance Status of a Consumer.", value = "getComplianceStatus")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{consumer_uuid}/compliance")
@Transactional
public ComplianceStatus getComplianceStatus(@PathParam("consumer_uuid") @Verify(Consumer.class) String uuid, @ApiParam("Date to get compliance information for, default is now.") @QueryParam("on_date") String onDate) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(uuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    Date date = ResourceDateParser.parseDateString(onDate);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        logShareConsumerRequestWarning("fetch compliance", consumer);
        return new ComplianceStatus(date);
    }
    return this.complianceRules.getStatus(consumer, date);
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ComplianceStatus(org.candlepin.policy.js.compliance.ComplianceStatus) ConsumerType(org.candlepin.model.ConsumerType) 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) Transactional(com.google.inject.persist.Transactional)

Example 77 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerResource method regenerateEntitlementCertificates.

@ApiOperation(notes = "Regenerates the Entitlement Certificates for a Consumer", value = "regenerateEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@PUT
@Produces(MediaType.WILDCARD)
@Consumes(MediaType.WILDCARD)
@Path("/{consumer_uuid}/certificates")
@UpdateConsumerCheckIn
public void regenerateEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("entitlement") String entitlementId, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        logShareConsumerRequestWarning("cert regen", consumer);
        return;
    }
    if (entitlementId != null) {
        Entitlement e = verifyAndLookupEntitlement(entitlementId);
        poolManager.regenerateCertificatesOf(e, lazyRegen);
    } else {
        poolManager.regenerateCertificatesOf(consumer, lazyRegen);
    }
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) ConsumerType(org.candlepin.model.ConsumerType) Entitlement(org.candlepin.model.Entitlement) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 78 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerResource method getEntitlementCertificates.

@ApiOperation(notes = "Retrieves a list of Entitlement Certificates for the Consumer", value = "getEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates")
@Produces(MediaType.APPLICATION_JSON)
@UpdateConsumerCheckIn
public List<CertificateDTO> getEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
    log.debug("Getting client certificates for consumer: {}", consumerUuid);
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        logShareConsumerRequestWarning("cert fetch", consumer);
        return new ArrayList<>();
    }
    revokeOnGuestMigration(consumer);
    poolManager.regenerateDirtyEntitlements(consumer);
    Set<Long> serialSet = this.extractSerials(serials);
    List<CertificateDTO> returnCerts = new LinkedList<>();
    List<EntitlementCertificate> allCerts = entCertService.listForConsumer(consumer);
    for (EntitlementCertificate cert : allCerts) {
        if (serialSet.isEmpty() || serialSet.contains(cert.getSerial().getId())) {
            returnCerts.add(translator.translate(cert, CertificateDTO.class));
        }
    }
    // we want to insert the content access cert to this list if appropriate
    try {
        Certificate cert = contentAccessCertService.getCertificate(consumer);
        if (cert != null) {
            returnCerts.add(translator.translate(cert, CertificateDTO.class));
        }
    } catch (IOException ioe) {
        throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
    } catch (GeneralSecurityException gse) {
        throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), gse);
    }
    return returnCerts;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedList(java.util.LinkedList) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) IdentityCertificate(org.candlepin.model.IdentityCertificate) Certificate(org.candlepin.model.Certificate) ContentAccessCertificate(org.candlepin.model.ContentAccessCertificate) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 79 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerResource method downloadExistingExport.

/**
 * Downloads an asynchronously generated consumer export file (manifest). If the file
 * was successfully downloaded, it will be deleted.
 *
 * @param response
 * @param consumerUuid the UUID of the target consumer.
 * @param exportId the id of the stored export.
 */
@ApiOperation(notes = "Downloads an asynchronously generated consumer export file (manifest).", value = "Async Consumer Export (manifest) Download", response = File.class)
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces("application/zip")
@Path("{consumer_uuid}/export/{export_id}")
public void downloadExistingExport(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @PathParam("export_id") String exportId) {
    Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE)) {
        throw new BadRequestException(i18n.tr("Can not export manifest of a share consumer"));
    }
    // *******************************************************************************
    // NOTE: If changing the path or parameters of this end point, be sure to update
    // the HREF generation in ConsumerResource.buildAsyncDownloadManifestHref.
    // *******************************************************************************
    // The response for this request is formulated a little different for this
    // file download. In some cases, such as for a hibernate DB file service, we must
    // stream the results from the DB to the client by directly writing to the
    // response output stream.
    // 
    // NOTE: Passing the database input stream to the response builder seems
    // like it would be a correct approach here, but large object streaming
    // can only be done inside a single transaction, so we have to stream it
    // manually.
    // TODO See if there is a way to get RestEasy to do this so we don't have to.
    manifestManager.writeStoredExportToResponse(exportId, consumerUuid, response);
    // On successful manifest read, delete the record. The manifest can only be
    // downloaded once and must then be regenerated.
    manifestManager.deleteStoredManifest(exportId);
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) 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 80 with ConsumerType

use of org.candlepin.model.ConsumerType in project candlepin by candlepin.

the class ConsumerResource method validateBindArguments.

private void validateBindArguments(String poolIdString, Integer quantity, String[] productIds, List<String> fromPools, Date entitleDate, Consumer consumer, boolean async) {
    short parameters = 0;
    ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
    if (ctype.isType(ConsumerTypeEnum.SHARE) && StringUtils.isBlank(poolIdString)) {
        throw new BadRequestException(i18n.tr("Share consumers must be bound to a specific pool"));
    }
    if (poolIdString != null) {
        parameters++;
    }
    if (ArrayUtils.isNotEmpty(productIds) || CollectionUtils.isNotEmpty(fromPools) || entitleDate != null) {
        parameters++;
    }
    if (parameters > 1) {
        throw new BadRequestException(i18n.tr("Cannot bind by multiple parameters."));
    }
    if (poolIdString == null && quantity != null) {
        throw new BadRequestException(i18n.tr("Cannot specify a quantity when auto-binding."));
    }
}
Also used : BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType)

Aggregations

ConsumerType (org.candlepin.model.ConsumerType)169 Consumer (org.candlepin.model.Consumer)92 Test (org.junit.Test)71 Owner (org.candlepin.model.Owner)53 Pool (org.candlepin.model.Pool)47 Entitlement (org.candlepin.model.Entitlement)33 ArrayList (java.util.ArrayList)29 Date (java.util.Date)27 HashMap (java.util.HashMap)24 HashSet (java.util.HashSet)24 ValidationResult (org.candlepin.policy.ValidationResult)22 ApiOperation (io.swagger.annotations.ApiOperation)21 Produces (javax.ws.rs.Produces)21 Before (org.junit.Before)20 ApiResponses (io.swagger.annotations.ApiResponses)19 Path (javax.ws.rs.Path)18 LinkedList (java.util.LinkedList)16 BadRequestException (org.candlepin.common.exceptions.BadRequestException)16 DeletedConsumer (org.candlepin.model.DeletedConsumer)16 Matchers.anyString (org.mockito.Matchers.anyString)16