Search in sources :

Example 6 with IseException

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

the class OwnerResource method importManifestAsync.

/**
 * Initiates an asynchronous manifest import for the given organization. The details of
 * the started job can be obtained via the {@link JobResource}.
 *
 * This will bring in any products, content, and subscriptions that were assigned to
 * the distributor who generated the manifest.
 *
 * @return a JobDetail object representing the newly started {@link ImportJob}.
 * @httpcode 400
 * @httpcode 404
 * @httpcode 500
 * @httpcode 200
 * @httpcode 409
 */
@POST
@Path("{owner_key}/imports/async")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(notes = "Initiates an asynchronous manifest import 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 Asynchronously")
@ApiResponses({ @ApiResponse(code = 400, message = ""), @ApiResponse(code = 404, message = "Owner not found"), @ApiResponse(code = 500, message = ""), @ApiResponse(code = 409, message = "") })
public JobDetail importManifestAsync(@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);
        String archivePath = fileData.getData().getAbsolutePath();
        log.info("Running async import of archive {} for owner {}", archivePath, owner.getDisplayName());
        return manifestManager.importManifestAsync(owner, fileData.getData(), fileData.getUploadedFilename(), overrides);
    } catch (IOException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error reading export archive"), e);
    } catch (ManifestFileServiceException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw new IseException(i18n.tr("Error storing uploaded archive for asynchronous processing."), e);
    } catch (CandlepinException e) {
        manifestManager.recordImportFailure(owner, e, fileData.getUploadedFilename());
        throw e;
    }
}
Also used : ConflictOverrides(org.candlepin.sync.ConflictOverrides) CandlepinException(org.candlepin.common.exceptions.CandlepinException) Owner(org.candlepin.model.Owner) IseException(org.candlepin.common.exceptions.IseException) IOException(java.io.IOException) ManifestFileServiceException(org.candlepin.sync.file.ManifestFileServiceException) 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 7 with IseException

use of org.candlepin.common.exceptions.IseException 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 8 with IseException

use of org.candlepin.common.exceptions.IseException 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 9 with IseException

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

the class CrlResource method unrevoke.

@ApiOperation(notes = "Deletes a Certificate from the Revocation List", value = "unrevoke")
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public void unrevoke(@QueryParam("serial") String[] serialIds) throws CRLException, IOException {
    String filePath = getCrlFilePath();
    File crlFile = new File(filePath);
    try {
        List<BigInteger> serials = new LinkedList<>();
        for (CertificateSerial serial : certificateSerialCurator.listBySerialIds(serialIds)) {
            serials.add(serial.getSerial());
        }
        if (serials.size() > 0) {
            this.crlFileUtil.updateCRLFile(crlFile, null, serials);
        }
    } catch (IOException e) {
        throw new IseException(e.getMessage(), e);
    }
}
Also used : IseException(org.candlepin.common.exceptions.IseException) BigInteger(java.math.BigInteger) CertificateSerial(org.candlepin.model.CertificateSerial) IOException(java.io.IOException) File(java.io.File) LinkedList(java.util.LinkedList) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with IseException

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

the class EventFactory method complianceCreated.

public Event complianceCreated(Consumer consumer, ComplianceStatus compliance) {
    Map<String, Object> eventData = new HashMap<>();
    eventData.put("status", compliance.getStatus());
    List<Map<String, String>> reasons = new ArrayList<>(compliance.getReasons().size());
    for (ComplianceReason reason : compliance.getReasons()) {
        reasons.add(ImmutableMap.of("productName", reason.getAttributes().get(ComplianceReason.Attributes.MARKETING_NAME), "message", reason.getMessage()));
    }
    eventData.put("reasons", reasons);
    try {
        String eventDataJson = mapper.writeValueAsString(eventData);
        // is concerned only with the consumer UUID field.
        return new Event(Event.Type.CREATED, Event.Target.COMPLIANCE, consumer.getName(), principalProvider.get(), consumer.getOwnerId(), consumer.getUuid(), consumer.getUuid(), eventDataJson, null, null);
    } catch (JsonProcessingException e) {
        log.error("Error while building JSON for compliance.created event.", e);
        throw new IseException("Error while building JSON for compliance.created event.");
    }
}
Also used : IseException(org.candlepin.common.exceptions.IseException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ComplianceReason(org.candlepin.policy.js.compliance.ComplianceReason)

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