Search in sources :

Example 1 with CdnCertificate

use of org.candlepin.model.CdnCertificate in project candlepin by candlepin.

the class CdnResource method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO.
 * This method will not set the ID field.
 *
 * @param entity
 *  The entity instance to populate
 *
 * @param dto
 *  The DTO containing the data with which to populate the entity
 *
 * @throws IllegalArgumentException
 *  if either entity or dto are null
 */
private void populateEntity(Cdn entity, CdnDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the Cdn model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the Cdn dto is null");
    }
    if (dto.getName() != null) {
        entity.setName(dto.getName());
    }
    if (dto.getUrl() != null) {
        entity.setUrl(dto.getUrl());
    }
    if (dto.getCertificate() != null) {
        CertificateDTO certDTO = dto.getCertificate();
        CdnCertificate cdnCert;
        if (certDTO.getKey() != null && certDTO.getCert() != null) {
            cdnCert = new CdnCertificate();
            cdnCert.setCert(certDTO.getCert());
            cdnCert.setKey(certDTO.getKey());
            if (certDTO.getSerial() != null) {
                CertificateSerialDTO certSerialDTO = certDTO.getSerial();
                CertificateSerial certSerial = new CertificateSerial();
                certSerial.setExpiration(certSerialDTO.getExpiration());
                if (certSerialDTO.getSerial() != null) {
                    certSerial.setSerial(certSerialDTO.getSerial().longValue());
                }
                if (certSerialDTO.isCollected() != null) {
                    certSerial.setCollected(certSerialDTO.isCollected());
                }
                if (certSerialDTO.isRevoked() != null) {
                    certSerial.setRevoked(certSerialDTO.isRevoked());
                }
                cdnCert.setSerial(certSerial);
            }
            entity.setCertificate(cdnCert);
        } else {
            throw new BadRequestException(i18n.tr("cdn certificate has null key or cert."));
        }
    }
}
Also used : CertificateDTO(org.candlepin.dto.api.v1.CertificateDTO) CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CertificateSerial(org.candlepin.model.CertificateSerial) BadRequestException(org.candlepin.common.exceptions.BadRequestException)

Example 2 with CdnCertificate

use of org.candlepin.model.CdnCertificate in project candlepin by candlepin.

the class CdnManager method updateCdn.

/**
 * Updates the specified {@link Cdn}.
 *
 * @param cdn the {@link Cdn} to update.
 */
@Transactional
public void updateCdn(Cdn cdn) {
    CdnCertificate cert = cdn.getCertificate();
    if (cert != null && cert.getSerial() != null) {
        // No need to flush here since updating the Cdn will.
        certSerialCurator.saveOrUpdateAll(Arrays.asList(cert.getSerial()), false, false);
    }
    cdnCurator.update(cdn);
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate) Transactional(com.google.inject.persist.Transactional)

Example 3 with CdnCertificate

use of org.candlepin.model.CdnCertificate in project candlepin by candlepin.

the class CdnManagerTest method createCdn.

private Cdn createCdn(String label) {
    CertificateSerial serial = certSerialCurator.create(new CertificateSerial(new Date()));
    CdnCertificate cert = new CdnCertificate();
    cert.setKey("key");
    cert.setCert("cert");
    cert.setSerial(serial);
    Cdn cdn = new Cdn(label, "Test CDN", "test.url", cert);
    manager.createCdn(cdn);
    return cdn;
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Cdn(org.candlepin.model.Cdn) Date(java.util.Date)

Example 4 with CdnCertificate

use of org.candlepin.model.CdnCertificate in project candlepin by candlepin.

the class CdnTranslatorTest method initSourceObject.

@Override
protected Cdn initSourceObject() {
    Cdn source = new Cdn();
    source.setName("cdn-name");
    source.setId("cdn-id");
    source.setUrl("cdn-url");
    source.setLabel("cdn-label");
    CdnCertificate cdnCert = new CdnCertificate();
    cdnCert.setId("cdn-cert-id");
    cdnCert.setKey("cdn-cert-key");
    cdnCert.setCert("cdn-cert-cert");
    CertificateSerial serial = new CertificateSerial();
    serial.setRevoked(false);
    serial.setCollected(false);
    serial.setExpiration(new Date());
    serial.setSerial(5L);
    serial.setId(1L);
    cdnCert.setSerial(serial);
    source.setCertificate(cdnCert);
    return source;
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate) CertificateSerial(org.candlepin.model.CertificateSerial) Cdn(org.candlepin.model.Cdn) Date(java.util.Date)

Example 5 with CdnCertificate

use of org.candlepin.model.CdnCertificate in project candlepin by candlepin.

the class CdnTranslator method populate.

/**
 * {@inheritDoc}
 */
@Override
public CdnDTO populate(ModelTranslator modelTranslator, Cdn source, CdnDTO dest) {
    dest = super.populate(modelTranslator, source, dest);
    dest.setId(source.getId()).setName(source.getName()).setLabel(source.getLabel()).setUrl(source.getUrl());
    // Process nested objects if we have a model translator to use to the translation...
    if (modelTranslator != null) {
        CdnCertificate cndCert = source.getCertificate();
        dest.setCertificate(cndCert != null ? modelTranslator.translate(cndCert, CertificateDTO.class) : null);
    }
    return dest;
}
Also used : CdnCertificate(org.candlepin.model.CdnCertificate)

Aggregations

CdnCertificate (org.candlepin.model.CdnCertificate)5 CertificateSerial (org.candlepin.model.CertificateSerial)3 Date (java.util.Date)2 Cdn (org.candlepin.model.Cdn)2 Transactional (com.google.inject.persist.Transactional)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)1 CertificateSerialDTO (org.candlepin.dto.api.v1.CertificateSerialDTO)1