Search in sources :

Example 1 with Certificate

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;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Pool(org.candlepin.model.Pool) Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Example 2 with Certificate

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);
    }
}
Also used : Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Example 3 with Certificate

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;
}
Also used : EntitlementCertificate(org.candlepin.model.EntitlementCertificate) GeneralSecurityException(java.security.GeneralSecurityException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedList(java.util.LinkedList) CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) DeletedConsumer(org.candlepin.model.DeletedConsumer) Consumer(org.candlepin.model.Consumer) BadRequestException(org.candlepin.common.exceptions.BadRequestException) ConsumerType(org.candlepin.model.ConsumerType) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) IdentityCertificate(org.candlepin.model.IdentityCertificate) Certificate(org.candlepin.model.Certificate) ContentAccessCertificate(org.candlepin.model.ContentAccessCertificate) Path(javax.ws.rs.Path) UpdateConsumerCheckIn(org.candlepin.auth.UpdateConsumerCheckIn) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with Certificate

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);
    }
}
Also used : Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Example 5 with Certificate

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;
}
Also used : Owner(org.candlepin.model.Owner) Consumer(org.candlepin.model.Consumer) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) Pool(org.candlepin.model.Pool) Certificate(org.candlepin.model.Certificate) EntitlementCertificate(org.candlepin.model.EntitlementCertificate)

Aggregations

Certificate (org.candlepin.model.Certificate)5 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)5 Consumer (org.candlepin.model.Consumer)3 Owner (org.candlepin.model.Owner)2 Pool (org.candlepin.model.Pool)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 UpdateConsumerCheckIn (org.candlepin.auth.UpdateConsumerCheckIn)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)1 ConsumerType (org.candlepin.model.ConsumerType)1 ContentAccessCertificate (org.candlepin.model.ContentAccessCertificate)1 DeletedConsumer (org.candlepin.model.DeletedConsumer)1