use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class UserResourceTest method testUpdateUsersNoLogin.
@Test
public void testUpdateUsersNoLogin() {
try {
User user = new User();
user.setUsername("henri");
user.setPassword("password");
userResource.updateUser("JarJarIsMyCopilot", user);
} catch (NotFoundException e) {
// this is exptected
return;
}
fail("No exception was thrown");
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class JobCurator method cancelNoReturn.
@Transactional
public void cancelNoReturn(String jobId) {
String hql = "update JobStatus j " + "set j.state = :canceled " + "where j.id = :jobid";
Query query = this.currentSession().createQuery(hql).setParameter("jobid", jobId).setInteger("canceled", JobState.CANCELED.ordinal());
int updated = query.executeUpdate();
if (updated == 0) {
throw new NotFoundException("job not found");
}
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class ConsumerResource method validateShareConsumer.
/**
* Ensure that certain fields remain unset when creating a share consumer.
* @param consumer the consumer to validate
* @param principal the principal performing the operation
* @param keys any provided activation keys
* @throws BadRequestException if any validations fail
*/
private void validateShareConsumer(ConsumerDTO consumer, Principal principal, List<ActivationKey> keys) throws BadRequestException {
if (keys.size() > 0) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot be used with activation keys"));
}
if (StringUtils.isNotBlank(consumer.getServiceLevel())) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have a service level"));
}
if (StringUtils.isNotBlank(consumer.getReleaseVersion())) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have a release version"));
}
if (CollectionUtils.isNotEmpty(consumer.getInstalledProducts())) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have installed products"));
}
if (StringUtils.isNotBlank(consumer.getContentAccessMode())) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have a content access mode"));
}
if (consumer.getGuestIds() != null && !consumer.getGuestIds().isEmpty()) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have guest IDs"));
}
if (consumer.getHypervisorId() != null) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot have a hypervisor ID"));
}
if (consumer.getRecipientOwnerKey() == null) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" must specify a recipient org key"));
}
if (consumer.isGuest()) {
throw new BadRequestException(i18n.tr("A unit type of \"share\" cannot be a virtual guest"));
}
String recipient = consumer.getRecipientOwnerKey();
Owner recipientOwner = ownerCurator.lookupByKey(recipient);
if (recipientOwner == null) {
throw new NotFoundException(i18n.tr("owner with key: {0} was not found.", recipient));
}
// Check permissions for current principal on the recipient owner
if (!principal.canAccess(recipientOwner, SubResource.ENTITLEMENTS, Access.CREATE)) {
log.warn("User {} does not have access to create shares to org {}", principal.getPrincipalName(), recipient);
throw new NotFoundException(i18n.tr("owner with key: {0} was not found.", recipient));
}
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class ConsumerResource method checkActivationKeys.
private List<ActivationKey> checkActivationKeys(Principal principal, Owner owner, Set<String> keyStrings) throws BadRequestException {
List<ActivationKey> keys = new ArrayList<>();
for (String keyString : keyStrings) {
ActivationKey key = null;
try {
key = findKey(keyString, owner);
keys.add(key);
} catch (NotFoundException e) {
log.warn(e.getMessage());
}
}
if ((principal instanceof NoAuthPrincipal) && keys.isEmpty()) {
throw new BadRequestException(i18n.tr("None of the activation keys specified exist for this org."));
}
return keys;
}
use of org.candlepin.common.exceptions.NotFoundException in project candlepin by candlepin.
the class ConsumerResource method unbindByPool.
@ApiOperation(notes = "Removes all Entitlements from a Consumer. By Pool Id", value = "unbindByPool")
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 404, message = "") })
@DELETE
@Produces(MediaType.WILDCARD)
@Path("/{consumer_uuid}/entitlements/pool/{pool_id}")
public void unbindByPool(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @PathParam("pool_id") String poolId) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
List<Entitlement> entitlementsToDelete = entitlementCurator.listByConsumerAndPoolId(consumer, poolId);
if (!entitlementsToDelete.isEmpty()) {
for (Entitlement toDelete : entitlementsToDelete) {
poolManager.revokeEntitlement(toDelete);
}
} else {
throw new NotFoundException(i18n.tr("No entitlements for consumer \"{0}\" with pool id \"{1}\"", consumerUuid, poolId));
}
}
Aggregations