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());
}
}
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);
}
}
Aggregations