use of org.candlepin.sync.ExportCreationException in project candlepin by candlepin.
the class ConsumerResource method exportCertificates.
@ApiOperation(notes = "Retrieves a Compressed File of Entitlement Certificates", value = "exportCertificates")
@ApiResponses({ @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@GET
@Produces("application/zip")
@Path("/{consumer_uuid}/certificates")
public File exportCertificates(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert export", consumer);
return null;
}
revokeOnGuestMigration(consumer);
Set<Long> serialSet = this.extractSerials(serials);
// empty
if (serialSet.isEmpty()) {
serialSet = null;
}
File archive;
try {
archive = manifestManager.generateEntitlementArchive(consumer, serialSet);
response.addHeader("Content-Disposition", "attachment; filename=" + archive.getName());
return archive;
} catch (ExportCreationException e) {
throw new IseException(i18n.tr("Unable to create entitlement certificate archive"), e);
}
}
use of org.candlepin.sync.ExportCreationException in project candlepin by candlepin.
the class ManifestManager method generateAndStoreManifest.
/**
* Generates a manifest for the specifed consumer and stores the resulting file via the
* {@link ManifestFileService}.
*
* @param consumerUuid the target consumer's UUID.
* @param cdnLabel the CDN label to store in the meta file.
* @param webUrl the URL pointing to the manifest's originating web application.
* @param apiUrl the API URL pointing to the manifest's originating candlepin API.
* @param extensionData data to be passed to the {@link ExportExtensionAdapter} when creating
* a new export of the target consumer.
* @return an {@link ExportResult} containing the details of the stored file.
* @throws ExportCreationException if there are any issues generating the manifest.
*/
public ExportResult generateAndStoreManifest(String consumerUuid, String cdnLabel, String webUrl, String apiUrl, Map<String, String> extensionData) throws ExportCreationException {
Consumer consumer = validateConsumerForExport(consumerUuid, cdnLabel);
File export = null;
try {
poolManager.regenerateDirtyEntitlements(entitlementCurator.listByConsumer(consumer));
export = exporter.getFullExport(consumer, cdnLabel, webUrl, apiUrl, extensionData);
ManifestFile manifestFile = storeExport(export, consumer);
sink.queueEvent(eventFactory.exportCreated(consumer));
return new ExportResult(consumer.getUuid(), manifestFile.getId());
} catch (ManifestFileServiceException e) {
throw new ExportCreationException("Unable to create export archive", e);
} finally {
// We no longer need the export work directory since the archive has been saved in the DB.
if (export != null) {
File workDir = export.getParentFile();
try {
FileUtils.deleteDirectory(workDir);
} catch (IOException ioe) {
// It'll get cleaned up by the ManifestCleanerJob if it couldn't
// be deleted for some reason.
}
}
}
}
use of org.candlepin.sync.ExportCreationException in project candlepin by candlepin.
the class ConsumerResource method exportData.
/**
* Retrieves a compressed file representation of a Consumer (manifest).
*
* @deprecated use GET /consumers/:consumer_uuid/export/async
* @param response
* @param consumerUuid
* @param cdnLabel
* @param webAppPrefix
* @param apiUrl
* @return the generated file archive.
*/
@Deprecated
@ApiOperation(notes = "Retrieves a Compressed File representation of a Consumer (manifest).", value = "Consumer Export (manifest)", response = File.class)
@ApiResponses({ @ApiResponse(code = 403, message = ""), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 404, message = "") })
@Produces("application/zip")
@GET
@Path("{consumer_uuid}/export")
public File exportData(@Context HttpServletResponse response, @PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("cdn_label") String cdnLabel, @QueryParam("webapp_prefix") String webAppPrefix, @QueryParam("api_url") String apiUrl, @QueryParam("ext") @CandlepinParam(type = KeyValueParameter.class) @ApiParam(value = "Key/Value pairs to be passed to the extension adapter when generating a manifest", required = false, example = "ext=version:1.2.3&ext=extension_key:EXT1") List<KeyValueParameter> extensionArgs) {
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
throw new BadRequestException(i18n.tr("Can not export manifest of a share consumer"));
}
try {
File archive = manifestManager.generateManifest(consumerUuid, cdnLabel, webAppPrefix, apiUrl, getExtensionParamMap(extensionArgs));
response.addHeader("Content-Disposition", "attachment; filename=" + archive.getName());
return archive;
} catch (ExportCreationException e) {
throw new IseException(i18n.tr("Unable to create export archive"), e);
}
}
Aggregations