Search in sources :

Example 16 with IseException

use of org.candlepin.common.exceptions.IseException in project candlepin by candlepin.

the class ImportJob method toExecute.

@Override
public void toExecute(JobExecutionContext context) throws JobExecutionException {
    JobDataMap map = context.getMergedJobDataMap();
    String ownerKey = (String) map.get(JobStatus.TARGET_ID);
    ConflictOverrides overrides = new ConflictOverrides((String[]) map.get(CONFLICT_OVERRIDES));
    String storedFileId = (String) map.get(STORED_FILE_ID);
    String uploadedFileName = (String) map.get(UPLOADED_FILE_NAME);
    Throwable caught = null;
    Owner targetOwner = null;
    try {
        targetOwner = ownerCurator.lookupByKey(ownerKey);
        if (targetOwner == null) {
            throw new NotFoundException(String.format("Owner %s was not found.", ownerKey));
        }
        ImportRecord importRecord = manifestManager.importStoredManifest(targetOwner, storedFileId, overrides, uploadedFileName);
        context.setResult(importRecord);
    }// info about the exception that was thrown (CandlepinException).
     catch (SyncDataFormatException e) {
        caught = new BadRequestException(e.getMessage(), e);
    } catch (ImporterException e) {
        caught = new IseException(e.getMessage(), e);
    } catch (Exception e) {
        caught = e;
    }
    if (caught != null) {
        log.error("ImportJob encountered a problem.", caught);
        manifestManager.recordImportFailure(targetOwner, caught, uploadedFileName);
        context.setResult(caught.getMessage());
        // If an exception was thrown, the importer's transaction was rolled
        // back. We want to make sure that the file gets deleted so that it
        // doesn't take up disk space. It may be possible that the file was
        // already deleted, but we attempt it anyway.
        manifestManager.deleteStoredManifest(storedFileId);
        throw new JobExecutionException(caught.getMessage(), caught, false);
    }
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) JobDataMap(org.quartz.JobDataMap) Owner(org.candlepin.model.Owner) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) NotFoundException(org.candlepin.common.exceptions.NotFoundException) ImportRecord(org.candlepin.model.ImportRecord) NotFoundException(org.candlepin.common.exceptions.NotFoundException) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ImporterException(org.candlepin.sync.ImporterException) JobExecutionException(org.quartz.JobExecutionException) IseException(org.candlepin.common.exceptions.IseException) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Aggregations

IseException (org.candlepin.common.exceptions.IseException)16 IOException (java.io.IOException)7 ApiOperation (io.swagger.annotations.ApiOperation)6 File (java.io.File)6 Produces (javax.ws.rs.Produces)6 BadRequestException (org.candlepin.common.exceptions.BadRequestException)5 ApiResponses (io.swagger.annotations.ApiResponses)4 Path (javax.ws.rs.Path)4 Consumer (org.candlepin.model.Consumer)4 Owner (org.candlepin.model.Owner)4 ConflictOverrides (org.candlepin.sync.ConflictOverrides)4 ImporterException (org.candlepin.sync.ImporterException)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)3 Verify (org.candlepin.auth.Verify)3 CandlepinException (org.candlepin.common.exceptions.CandlepinException)3 ExportCreationException (org.candlepin.sync.ExportCreationException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2