Search in sources :

Example 6 with BadRequestException

use of org.jboss.resteasy.spi.BadRequestException in project candlepin by candlepin.

the class HealEntireOrgJob method toExecute.

@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
    try {
        // NOTE: ownerId is actually the owner key here.
        JobDataMap map = ctx.getMergedJobDataMap();
        String ownerId = (String) map.get("ownerId");
        Owner owner = ownerCurator.lookupByKey(ownerId);
        if (owner.isAutobindDisabled()) {
            throw new BadRequestException(i18n.tr("Auto-attach is disabled for owner {0}.", owner.getKey()));
        }
        Date entitleDate = (Date) map.get("entitle_date");
        for (String uuid : ownerCurator.getConsumerUuids(owner).list()) {
            // of looking up the non or partially compliant products to bind.
            try {
                Consumer consumer = consumerCurator.getConsumer(uuid);
                healSingleConsumer(consumer, owner, entitleDate);
            }// Perhaps add something to surface errors later
             catch (Exception e) {
                log.debug("Healing failed for UUID \"{}\" with message: {}", uuid, e.getMessage());
            }
        }
    } catch (Exception e) {
        log.error("EntitlerJob encountered a problem.", e);
        ctx.setResult(e.getMessage());
        throw new JobExecutionException(e.getMessage(), e, false);
    }
}
Also used : JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) JobExecutionException(org.quartz.JobExecutionException) Consumer(org.candlepin.model.Consumer) BadRequestException(org.jboss.resteasy.spi.BadRequestException) Date(java.util.Date) BadRequestException(org.jboss.resteasy.spi.BadRequestException) JobExecutionException(org.quartz.JobExecutionException) AutobindDisabledForOwnerException(org.candlepin.controller.AutobindDisabledForOwnerException)

Aggregations

BadRequestException (org.jboss.resteasy.spi.BadRequestException)6 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Owner (org.candlepin.model.Owner)2 Role (org.candlepin.model.Role)2 Date (java.util.Date)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 AutobindDisabledForOwnerException (org.candlepin.controller.AutobindDisabledForOwnerException)1 Consumer (org.candlepin.model.Consumer)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1