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