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