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