Search in sources :

Example 1 with SyncDataFormatException

use of org.candlepin.sync.SyncDataFormatException in project candlepin by candlepin.

the class OwnerResource method importManifest.

/**
 * Imports a manifest zip file for the given organization.
 *
 * This will bring in any products, content, and subscriptions that were assigned to
 * the distributor who generated the manifest.
 *
 * @deprecated use GET /owners/:owner_key/imports/async
 *
 * @return a ImportRecord object if the import is successful.
 * @httpcode 400
 * @httpcode 404
 * @httpcode 500
 * @httpcode 200
 * @httpcode 409
 */
@POST
@Path("{owner_key}/imports")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(notes = "Imports a manifest zip file for the given organization. " + "This will bring in any products, content, and subscriptions that were " + "assigned to the distributor who generated the manifest.", value = "Import Manifest")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "") })
@Deprecated
public ImportRecord importManifest(@PathParam("owner_key") @Verify(Owner.class) String ownerKey, @QueryParam("force") String[] overrideConflicts, MultipartInput input) {
    ConflictOverrides overrides = processConflictOverrideParams(overrideConflicts);
    UploadMetadata fileData = new UploadMetadata();
    Owner owner = findOwnerByKey(ownerKey);
    try {
        fileData = getArchiveFromResponse(input);
        return manifestManager.importManifest(owner, fileData.getData(), fileData.getUploadedFilename(), overrides);
    } catch (IOException e) {
        log.error("Reading error during importing", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error reading export archive"), e);
    }// These come back with internationalized messages, so we can transfer:
     catch (SyncDataFormatException e) {
        log.error("Format error of the data in a manifest", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new BadRequestException(e.getMessage(), e);
    } catch (ImporterException e) {
        log.error("Problem with archive", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(e.getMessage(), e);
    }// to pass on the http return code
     catch (CandlepinException e) {
        log.error("Recording import failure", e);
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw e;
    } finally {
        log.info("Import attempt completed for owner {}", owner.getDisplayName());
    }
}
Also used : ImporterException(org.candlepin.sync.ImporterException) ConflictOverrides(org.candlepin.sync.ConflictOverrides) CandlepinException(org.candlepin.common.exceptions.CandlepinException) Owner(org.candlepin.model.Owner) IseException(org.candlepin.common.exceptions.IseException) SyncDataFormatException(org.candlepin.sync.SyncDataFormatException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with SyncDataFormatException

use of org.candlepin.sync.SyncDataFormatException 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

BadRequestException (org.candlepin.common.exceptions.BadRequestException)2 IseException (org.candlepin.common.exceptions.IseException)2 Owner (org.candlepin.model.Owner)2 ConflictOverrides (org.candlepin.sync.ConflictOverrides)2 ImporterException (org.candlepin.sync.ImporterException)2 SyncDataFormatException (org.candlepin.sync.SyncDataFormatException)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 CandlepinException (org.candlepin.common.exceptions.CandlepinException)1 NotFoundException (org.candlepin.common.exceptions.NotFoundException)1 ImportRecord (org.candlepin.model.ImportRecord)1 JobDataMap (org.quartz.JobDataMap)1 JobExecutionException (org.quartz.JobExecutionException)1