use of org.candlepin.common.exceptions.ConflictException in project candlepin by candlepin.
the class OwnerResource method deleteOwner.
/**
* Removes an Owner
*
* @httpcode 404
* @httpcode 200
*/
@DELETE
@Path("/{owner_key}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(notes = "Removes an Owner", value = "Delete Owner")
@ApiResponses({ @ApiResponse(code = 404, message = "Owner not found") })
public void deleteOwner(@PathParam("owner_key") String ownerKey, @QueryParam("revoke") @DefaultValue("true") boolean revoke, @QueryParam("force") @DefaultValue("false") boolean force) {
Owner owner = findOwnerByKey(ownerKey);
Event event = eventFactory.ownerDeleted(owner);
if (!force && consumerCurator.doesShareConsumerExist(owner)) {
throw new BadRequestException(i18n.tr("owner \"{0}\" cannot be deleted while there is a share consumer. " + "You may use \"force\" to bypass.", owner.getKey()));
}
try {
ownerManager.cleanupAndDelete(owner, revoke);
} catch (PersistenceException e) {
if (e.getCause() instanceof ConstraintViolationException) {
throw new ConflictException(e.getMessage(), e);
} else {
throw e;
}
}
sink.queueEvent(event);
}
use of org.candlepin.common.exceptions.ConflictException in project candlepin by candlepin.
the class RuntimeExceptionMapperTest method candlepinExceptionWithChildNotCandleping.
@Test
public void candlepinExceptionWithChildNotCandleping() {
CandlepinException ce = mock(CandlepinException.class);
when(ce.httpReturnCode()).thenReturn(Status.CONFLICT);
when(ce.message()).thenReturn(new ExceptionMessage().setDisplayMessage("you screwed up"));
when(req.getHeader(HttpHeaderNames.ACCEPT)).thenReturn("application/json");
when(ce.getCause()).thenReturn(new ConflictException("you screwed up"));
Response r = rem.toResponse(ce);
assertNotNull(r);
assertEquals(Status.CONFLICT.getStatusCode(), r.getStatus());
verifyMessage(r, "you screwed up");
}
use of org.candlepin.common.exceptions.ConflictException in project candlepin by candlepin.
the class EnvironmentResource method promoteContent.
@ApiOperation(notes = "Promotes a Content into an Environment. This call accepts multiple " + "content sets to promote at once, after which all affected certificates for consumers" + " in the environment will be regenerated. Consumers registered to this environment " + "will now receive this content in their entitlement certificates. Because the" + " certificate regeneraiton can be quite time consuming, this is done as an " + "asynchronous job. The content will be promoted and immediately available for new " + "entitlements, but existing entitlements could take some time to be regenerated and " + "sent down to clients as they check in.", value = "promoteContent")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{env_id}/content")
public JobDetail promoteContent(@PathParam("env_id") @Verify(Environment.class) String envId, @ApiParam(name = "contentToPromote", required = true) List<org.candlepin.model.dto.EnvironmentContent> contentToPromote, @QueryParam("lazy_regen") @DefaultValue("true") Boolean lazyRegen) {
Environment env = lookupEnvironment(envId);
// there be a problem with the request.
for (org.candlepin.model.dto.EnvironmentContent promoteMe : contentToPromote) {
log.debug("EnvironmentContent to promote: {}:{}", promoteMe.getEnvironmentId(), promoteMe.getContentId());
EnvironmentContent existing = this.envContentCurator.lookupByEnvironmentAndContent(env, promoteMe.getContentId());
if (existing != null) {
throw new ConflictException(i18n.tr("The content with id {0} has already been promoted in this environment.", promoteMe.getContentId()));
}
}
Set<String> contentIds = new HashSet<>();
try {
contentIds = batchCreate(contentToPromote, env);
clearContentAccessCerts(env);
} catch (PersistenceException pe) {
if (rdbmsExceptionTranslator.isConstraintViolationDuplicateEntry(pe)) {
log.info("Concurrent content promotion will cause this request to fail.", pe);
throw new ConflictException(i18n.tr("Some of the content is already associated with Environment: {0}", contentToPromote));
} else {
throw pe;
}
}
JobDataMap map = new JobDataMap();
map.put(RegenEnvEntitlementCertsJob.ENV, env);
map.put(RegenEnvEntitlementCertsJob.CONTENT, contentIds);
map.put(RegenEnvEntitlementCertsJob.LAZY_REGEN, lazyRegen);
JobDetail detail = newJob(RegenEnvEntitlementCertsJob.class).withIdentity("regen_entitlement_cert_of_env" + Util.generateUUID()).usingJobData(map).build();
return detail;
}
Aggregations