use of org.candlepin.model.Certificate in project candlepin by candlepin.
the class EntitlementTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public EntitlementDTO populate(ModelTranslator modelTranslator, Entitlement source, EntitlementDTO dest) {
dest = super.populate(modelTranslator, source, dest);
dest.setId(source.getId());
dest.setQuantity(source.getQuantity());
dest.setDeletedFromPool(source.deletedFromPool());
dest.setStartDate(source.getStartDate());
dest.setEndDate(source.getEndDate());
if (modelTranslator != null) {
Owner owner = source.getOwner();
dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
Pool pool = source.getPool();
dest.setPool(pool != null ? modelTranslator.translate(pool, PoolDTO.class) : null);
Consumer consumer = source.getConsumer();
dest.setConsumer(consumer != null ? modelTranslator.translate(consumer, ConsumerDTO.class) : null);
Set<EntitlementCertificate> certs = source.getCertificates();
if (certs != null && !certs.isEmpty()) {
for (Certificate cert : certs) {
if (cert != null) {
dest.addCertificate(modelTranslator.translate(cert, CertificateDTO.class));
}
}
} else {
dest.setCertificates(Collections.emptySet());
}
}
return dest;
}
use of org.candlepin.model.Certificate in project candlepin by candlepin.
the class EntitlementTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Entitlement source, EntitlementDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dest.getId());
assertEquals(source.getQuantity(), dest.getQuantity());
assertEquals(source.deletedFromPool(), dest.isDeletedFromPool());
assertEquals(source.getStartDate(), dest.getStartDate());
assertEquals(source.getEndDate(), dest.getEndDate());
if (childrenGenerated) {
this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
this.poolTranslatorTest.verifyOutput(source.getPool(), dest.getPool(), true);
this.consumerTranslatorTest.verifyOutput(source.getConsumer(), dest.getConsumer(), true);
for (Certificate sourceCertificate : source.getCertificates()) {
for (CertificateDTO certDTO : dest.getCertificates()) {
assertNotNull(certDTO);
assertNotNull(certDTO.getId());
if (certDTO.getId().equals(sourceCertificate.getId())) {
this.certificateTranslatorTest.verifyOutput(sourceCertificate, certDTO, true);
}
}
}
} else {
assertNull(dest.getOwner());
assertNull(dest.getPool());
assertNull(dest.getCertificates());
assertNull(dest.getConsumer());
}
} else {
assertNull(dest);
}
}
use of org.candlepin.model.Certificate in project candlepin by candlepin.
the class ConsumerResource method getEntitlementCertificates.
@ApiOperation(notes = "Retrieves a list of Entitlement Certificates for the Consumer", value = "getEntitlementCertificates")
@ApiResponses({ @ApiResponse(code = 404, message = "") })
@GET
@Path("{consumer_uuid}/certificates")
@Produces(MediaType.APPLICATION_JSON)
@UpdateConsumerCheckIn
public List<CertificateDTO> getEntitlementCertificates(@PathParam("consumer_uuid") @Verify(Consumer.class) String consumerUuid, @QueryParam("serials") String serials) {
log.debug("Getting client certificates for consumer: {}", consumerUuid);
Consumer consumer = consumerCurator.verifyAndLookupConsumer(consumerUuid);
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(consumer);
if (ctype.isType(ConsumerTypeEnum.SHARE)) {
logShareConsumerRequestWarning("cert fetch", consumer);
return new ArrayList<>();
}
revokeOnGuestMigration(consumer);
poolManager.regenerateDirtyEntitlements(consumer);
Set<Long> serialSet = this.extractSerials(serials);
List<CertificateDTO> returnCerts = new LinkedList<>();
List<EntitlementCertificate> allCerts = entCertService.listForConsumer(consumer);
for (EntitlementCertificate cert : allCerts) {
if (serialSet.isEmpty() || serialSet.contains(cert.getSerial().getId())) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
}
// we want to insert the content access cert to this list if appropriate
try {
Certificate cert = contentAccessCertService.getCertificate(consumer);
if (cert != null) {
returnCerts.add(translator.translate(cert, CertificateDTO.class));
}
} catch (IOException ioe) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), ioe);
} catch (GeneralSecurityException gse) {
throw new BadRequestException(i18n.tr("Cannot retrieve content access certificate"), gse);
}
return returnCerts;
}
use of org.candlepin.model.Certificate in project candlepin by candlepin.
the class EntitlementTranslatorTest method verifyOutput.
@Override
protected void verifyOutput(Entitlement source, EntitlementDTO dest, boolean childrenGenerated) {
if (source != null) {
assertEquals(source.getId(), dest.getId());
assertEquals(source.getQuantity(), dest.getQuantity());
assertEquals(source.deletedFromPool(), dest.isDeletedFromPool());
assertEquals(source.getStartDate(), dest.getStartDate());
assertEquals(source.getEndDate(), dest.getEndDate());
if (childrenGenerated) {
this.ownerTranslatorTest.verifyOutput(source.getOwner(), dest.getOwner(), true);
this.poolTranslatorTest.verifyOutput(source.getPool(), dest.getPool(), true);
this.consumerTranslatorTest.verifyOutput(source.getConsumer(), dest.getConsumer(), true);
for (Certificate sourceCertificate : source.getCertificates()) {
for (CertificateDTO certDTO : dest.getCertificates()) {
assertNotNull(certDTO);
assertNotNull(certDTO.getId());
if (certDTO.getId().equals(sourceCertificate.getId())) {
this.certificateTranslatorTest.verifyOutput(sourceCertificate, certDTO, true);
}
}
}
} else {
assertNull(dest.getOwner());
assertNull(dest.getPool());
assertNull(dest.getCertificates());
assertNull(dest.getConsumer());
}
} else {
assertNull(dest);
}
}
use of org.candlepin.model.Certificate in project candlepin by candlepin.
the class EntitlementTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public EntitlementDTO populate(ModelTranslator modelTranslator, Entitlement source, EntitlementDTO dest) {
dest = super.populate(modelTranslator, source, dest);
dest.setId(source.getId());
dest.setQuantity(source.getQuantity());
dest.setDeletedFromPool(source.deletedFromPool());
dest.setStartDate(source.getStartDate());
dest.setEndDate(source.getEndDate());
if (modelTranslator != null) {
Owner owner = source.getOwner();
dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
Pool pool = source.getPool();
dest.setPool(pool != null ? modelTranslator.translate(pool, PoolDTO.class) : null);
Consumer consumer = source.getConsumer();
dest.setConsumer(consumer != null ? modelTranslator.translate(consumer, ConsumerDTO.class) : null);
Set<EntitlementCertificate> certs = source.getCertificates();
if (certs != null && !certs.isEmpty()) {
for (Certificate cert : certs) {
if (cert != null) {
dest.addCertificate(modelTranslator.translate(cert, CertificateDTO.class));
}
}
} else {
dest.setCertificates(Collections.<CertificateDTO>emptySet());
}
}
return dest;
}
Aggregations