use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerResource method logNewConsumerDebugInfo.
private void logNewConsumerDebugInfo(Consumer consumer, List<ActivationKey> keys, ConsumerType type) {
if (log.isDebugEnabled()) {
log.debug("Got consumerTypeLabel of: {}", type.getLabel());
if (consumer.getFacts() != null) {
log.debug("incoming facts:");
for (String key : consumer.getFacts().keySet()) {
log.debug(" {} = {}", key, consumer.getFact(key));
}
}
log.debug("Activation keys:");
for (ActivationKey activationKey : keys) {
log.debug(" {}", activationKey.getName());
}
}
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class OwnerResource method createActivationKey.
/**
* Creates an Activation Key for the Owner
*
* @param ownerKey id of the owner whose keys are sought.
* @return an Activation Key object
* @httpcode 400
* @httpcode 404
* @httpcode 200
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("{owner_key}/activation_keys")
@ApiOperation(notes = "Creates an Activation Key for the Owner", value = "Create Activation Key")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 400, message = "Invalid activation key") })
public ActivationKeyDTO createActivationKey(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @ApiParam(name = "activation_key", required = true) ActivationKeyDTO dto) {
if (StringUtils.isBlank(dto.getName())) {
throw new BadRequestException(i18n.tr("Must provide a name for activation key."));
}
String testName = dto.getName().replace("-", "0").replace("_", "0");
if (!testName.matches("[a-zA-Z0-9]*")) {
throw new BadRequestException(i18n.tr("The activation key name \"{0}\" must be alphanumeric or " + "include the characters \"-\" or \"_\"", dto.getName()));
}
if (dto.getContentOverrides() != null) {
contentOverrideValidator.validateDTOs(dto.getContentOverrides());
}
Owner owner = findOwnerByKey(ownerKey);
if (activationKeyCurator.lookupForOwner(dto.getName(), owner) != null) {
throw new BadRequestException(i18n.tr("The activation key name \"{0}\" is already in use for owner {1}", dto.getName(), ownerKey));
}
serviceLevelValidator.validate(owner.getId(), dto.getServiceLevel());
ActivationKey key = new ActivationKey();
this.populateEntity(key, dto);
key.setOwner(owner);
ActivationKey newKey = activationKeyCurator.create(key);
sink.emitActivationKeyCreated(newKey);
return translator.translate(newKey, ActivationKeyDTO.class);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class OwnerResource method ownerActivationKeys.
/**
* Retrieves a list of Activation Keys for an Owner
*
* @param ownerKey id of the owner whose keys are sought.
* @return a list of Activation Key objects
* @httpcode 404
* @httpcode 200
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{owner_key}/activation_keys")
@ApiOperation(notes = "Retrieves a list of Activation Keys for an Owner", value = "Owner Activation Keys")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public CandlepinQuery<ActivationKeyDTO> ownerActivationKeys(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("name") String keyName) {
Owner owner = findOwnerByKey(ownerKey);
CandlepinQuery<ActivationKey> keys = this.activationKeyCurator.listByOwner(owner, keyName);
return translator.translateQuery(keys, ActivationKeyDTO.class);
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ConsumerBindUtil method handleActivationKeys.
public void handleActivationKeys(Consumer consumer, List<ActivationKey> keys, boolean autoattachDisabledForOwner) throws AutobindDisabledForOwnerException {
// Process activation keys.
boolean listSuccess = false;
for (ActivationKey key : keys) {
boolean keySuccess = true;
handleActivationKeyOverrides(consumer, key.getContentOverrides());
handleActivationKeyRelease(consumer, key.getReleaseVer());
keySuccess &= handleActivationKeyServiceLevel(consumer, key.getServiceLevel(), key.getOwner());
if (key.isAutoAttach() != null && key.isAutoAttach()) {
if (autoattachDisabledForOwner) {
log.warn("Auto-attach is disabled for owner. Skipping auto-attach for consumer/key: {}/{}", consumer.getUuid(), key.getName());
} else {
handleActivationKeyAutoBind(consumer, key);
}
} else {
keySuccess &= handleActivationKeyPools(consumer, key);
}
listSuccess |= keySuccess;
}
if (!listSuccess) {
throw new BadRequestException(i18n.tr("None of the subscriptions on the activation key were available for attaching."));
}
}
use of org.candlepin.model.activationkeys.ActivationKey in project candlepin by candlepin.
the class ActivationKeyResource method updateActivationKey.
@ApiOperation(notes = "Updates an Activation Key", value = "Update Activation Key")
@ApiResponses({ @ApiResponse(code = 400, message = "") })
@PUT
@Path("{activation_key_id}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public ActivationKeyDTO updateActivationKey(@PathParam("activation_key_id") @Verify(ActivationKey.class) String activationKeyId, @ApiParam(name = "update", required = true) ActivationKeyDTO update) {
ActivationKey toUpdate = activationKeyCurator.verifyAndLookupKey(activationKeyId);
if (update.getName() != null) {
toUpdate.setName(update.getName());
}
String serviceLevel = update.getServiceLevel();
if (serviceLevel != null) {
serviceLevelValidator.validate(toUpdate.getOwner().getId(), serviceLevel);
toUpdate.setServiceLevel(serviceLevel);
}
if (update.getReleaseVersion() != null) {
toUpdate.setReleaseVer(new Release(update.getReleaseVersion()));
}
if (update.getDescription() != null) {
toUpdate.setDescription(update.getDescription());
}
if (update.isAutoAttach() != null) {
toUpdate.setAutoAttach(update.isAutoAttach());
}
toUpdate = activationKeyCurator.merge(toUpdate);
return this.translator.translate(toUpdate, ActivationKeyDTO.class);
}
Aggregations