Search in sources :

Example 1 with ExportCreationException

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);
    }
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) IseException(org.candlepin.common.exceptions.IseException) ExportCreationException(org.candlepin.sync.ExportCreationException) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with ExportCreationException

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.
            }
        }
    }
}
Also used : Consumer(org.candlepin.model.Consumer) ExportCreationException(org.candlepin.sync.ExportCreationException) IOException(java.io.IOException) ManifestFile(org.candlepin.sync.file.ManifestFile) File(java.io.File) ManifestFile(org.candlepin.sync.file.ManifestFile) ManifestFileServiceException(org.candlepin.sync.file.ManifestFileServiceException) ExportResult(org.candlepin.sync.ExportResult)

Example 3 with ExportCreationException

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);
    }
}
Also used : DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) IseException(org.candlepin.common.exceptions.IseException) ExportCreationException(org.candlepin.sync.ExportCreationException) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

File (java.io.File)3 Consumer (org.candlepin.model.Consumer)3 ExportCreationException (org.candlepin.sync.ExportCreationException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 IseException (org.candlepin.common.exceptions.IseException)2 ConsumerType (org.candlepin.model.ConsumerType)2 DeletedConsumer (org.candlepin.model.DeletedConsumer)2 IOException (java.io.IOException)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 ExportResult (org.candlepin.sync.ExportResult)1 ManifestFile (org.candlepin.sync.file.ManifestFile)1 ManifestFileServiceException (org.candlepin.sync.file.ManifestFileServiceException)1