Search in sources :

Example 1 with CertificateSerialDTO

use of org.candlepin.dto.manifest.v1.CertificateSerialDTO in project candlepin by candlepin.

the class CertificateSerialResourceTest method getSerial.

@Test
public void getSerial() {
    CertificateSerialCurator csc = mock(CertificateSerialCurator.class);
    CertificateSerialResource csr = new CertificateSerialResource(csc, this.modelTranslator);
    CertificateSerial cs = new CertificateSerial(10L);
    when(csc.find(cs.getId())).thenReturn(cs);
    CertificateSerialDTO output = csr.getCertificateSerial(10L);
    assertNotNull(output);
    CertificateSerialDTO dto = this.modelTranslator.translate(cs, CertificateSerialDTO.class);
    assertEquals(dto, output);
}
Also used : CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CertificateSerial(org.candlepin.model.CertificateSerial) CertificateSerialCurator(org.candlepin.model.CertificateSerialCurator) Test(org.junit.Test)

Example 2 with CertificateSerialDTO

use of org.candlepin.dto.manifest.v1.CertificateSerialDTO 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 3 with CertificateSerialDTO

use of org.candlepin.dto.manifest.v1.CertificateSerialDTO in project candlepin by candlepin.

the class CertificateSerialResourceTest method listall.

@Test
public void listall() {
    CandlepinQuery cqmock = new EmptyCandlepinQuery();
    CertificateSerialCurator csc = mock(CertificateSerialCurator.class);
    when(csc.listAll()).thenReturn(cqmock);
    CertificateSerialResource csr = new CertificateSerialResource(csc, this.modelTranslator);
    CandlepinQuery<CertificateSerialDTO> result = csr.getCertificateSerials();
    assertNotNull(result);
    verify(csc, times(1)).listAll();
}
Also used : CertificateSerialDTO(org.candlepin.dto.api.v1.CertificateSerialDTO) CandlepinQuery(org.candlepin.model.CandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) EmptyCandlepinQuery(org.candlepin.model.EmptyCandlepinQuery) CertificateSerialCurator(org.candlepin.model.CertificateSerialCurator) Test(org.junit.Test)

Example 4 with CertificateSerialDTO

use of org.candlepin.dto.manifest.v1.CertificateSerialDTO in project candlepin by candlepin.

the class EntitlementImporter method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO.
 *
 * @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
 */
@SuppressWarnings("checkstyle:methodlength")
private void populateEntity(Entitlement entity, EntitlementDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the entitlement model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the entitlement dto is null");
    }
    if (dto.getId() != null) {
        entity.setId(dto.getId());
    }
    if (dto.getQuantity() != null) {
        entity.setQuantity(dto.getQuantity());
    }
    if (dto.getUpdated() != null) {
        entity.setUpdated(dto.getUpdated());
    }
    if (dto.getCreated() != null) {
        entity.setCreated(dto.getCreated());
    }
    if (dto.getStartDate() != null) {
        entity.setStartDate(dto.getStartDate());
    }
    if (dto.getEndDate() != null) {
        entity.setEndDate(dto.getEndDate());
    }
    if (dto.getPool() != null) {
        PoolDTO poolDTO = dto.getPool();
        Pool poolEntity = new Pool();
        if (poolDTO.getId() != null) {
            poolEntity.setId(poolDTO.getId());
        }
        if (poolDTO.getQuantity() != null) {
            poolEntity.setQuantity(poolDTO.getQuantity());
        }
        if (poolDTO.isActiveSubscription() != null) {
            poolEntity.setActiveSubscription(poolDTO.isActiveSubscription());
        }
        if (poolDTO.isCreatedByShare() != null) {
            poolEntity.setCreatedByShare(poolDTO.isCreatedByShare());
        }
        if (poolDTO.hasSharedAncestor() != null) {
            poolEntity.setHasSharedAncestor(poolDTO.hasSharedAncestor());
        }
        if (poolDTO.getRestrictedToUsername() != null) {
            poolEntity.setRestrictedToUsername(poolDTO.getRestrictedToUsername());
        }
        if (poolDTO.getConsumed() != null) {
            poolEntity.setConsumed(poolDTO.getConsumed());
        }
        if (poolDTO.getExported() != null) {
            poolEntity.setExported(poolDTO.getExported());
        }
        if (poolDTO.getShared() != null) {
            poolEntity.setShared(poolDTO.getShared());
        }
        if (poolDTO.getStackId() != null && poolDTO.getSourceStackId() != null) {
            SourceStack sourceStack = new SourceStack();
            sourceStack.setId(poolDTO.getStackId());
            sourceStack.setSourceStackId(poolDTO.getSourceStackId());
            poolEntity.setSourceStack(sourceStack);
        }
        if (poolDTO.getProductId() != null) {
            poolEntity.setProductId(poolDTO.getProductId());
        }
        if (poolDTO.getDerivedProductId() != null) {
            poolEntity.setDerivedProductId(poolDTO.getDerivedProductId());
        }
        if (poolDTO.getStartDate() != null) {
            poolEntity.setStartDate(poolDTO.getStartDate());
        }
        if (poolDTO.getEndDate() != null) {
            poolEntity.setEndDate(poolDTO.getEndDate());
        }
        if (poolDTO.getCreated() != null) {
            poolEntity.setCreated(poolDTO.getCreated());
        }
        if (poolDTO.getUpdated() != null) {
            poolEntity.setUpdated(poolDTO.getUpdated());
        }
        if (poolDTO.getAccountNumber() != null) {
            poolEntity.setAccountNumber(poolDTO.getAccountNumber());
        }
        if (poolDTO.getOrderNumber() != null) {
            poolEntity.setOrderNumber(poolDTO.getOrderNumber());
        }
        if (poolDTO.getContractNumber() != null) {
            poolEntity.setContractNumber(poolDTO.getContractNumber());
        }
        if (poolDTO.getOwner() != null) {
            Owner ownerEntity = new Owner();
            populateEntity(ownerEntity, poolDTO.getOwner());
            poolEntity.setOwner(ownerEntity);
        }
        if (poolDTO.getUpstreamPoolId() != null) {
            poolEntity.setUpstreamPoolId(poolDTO.getUpstreamPoolId());
        }
        if (poolDTO.getUpstreamConsumerId() != null) {
            poolEntity.setUpstreamConsumerId(poolDTO.getUpstreamConsumerId());
        }
        if (poolDTO.getUpstreamEntitlementId() != null) {
            poolEntity.setUpstreamEntitlementId(poolDTO.getUpstreamEntitlementId());
        }
        if (poolDTO.getSourceEntitlement() != null) {
            EntitlementDTO sourceEntitlementDTO = poolDTO.getSourceEntitlement();
            poolEntity.setSourceEntitlement(findEntitlement(sourceEntitlementDTO.getId()));
        }
        if (poolDTO.getSubscriptionSubKey() != null) {
            poolEntity.setSubscriptionSubKey(poolDTO.getSubscriptionSubKey());
        }
        if (poolDTO.getSubscriptionId() != null) {
            poolEntity.setSubscriptionId(poolDTO.getSubscriptionId());
        }
        if (poolDTO.getAttributes() != null) {
            if (poolDTO.getAttributes().isEmpty()) {
                poolEntity.setAttributes(Collections.emptyMap());
            } else {
                poolEntity.setAttributes(poolDTO.getAttributes());
            }
        }
        if (poolDTO.getCalculatedAttributes() != null) {
            if (poolDTO.getCalculatedAttributes().isEmpty()) {
                poolEntity.setCalculatedAttributes(Collections.emptyMap());
            } else {
                poolEntity.setCalculatedAttributes(poolDTO.getCalculatedAttributes());
            }
        }
        if (poolDTO.getProductAttributes() != null) {
            if (poolDTO.getProductAttributes().isEmpty()) {
                poolEntity.setProductAttributes(Collections.emptyMap());
            } else {
                poolEntity.setProductAttributes(poolDTO.getProductAttributes());
            }
        }
        if (poolDTO.getDerivedProductAttributes() != null) {
            if (poolDTO.getDerivedProductAttributes().isEmpty()) {
                poolEntity.setDerivedProductAttributes(Collections.emptyMap());
            } else {
                poolEntity.setDerivedProductAttributes(poolDTO.getDerivedProductAttributes());
            }
        }
        if (poolDTO.getBranding() != null) {
            if (poolDTO.getBranding().isEmpty()) {
                poolEntity.setBranding(Collections.emptySet());
            } else {
                Set<Branding> branding = new HashSet<>();
                for (BrandingDTO brandingDTO : poolDTO.getBranding()) {
                    if (brandingDTO != null) {
                        Branding brandingEntity = new Branding(brandingDTO.getProductId(), brandingDTO.getType(), brandingDTO.getName());
                        brandingEntity.setId(brandingDTO.getId());
                        brandingEntity.setCreated(brandingDTO.getCreated());
                        brandingEntity.setUpdated(brandingDTO.getUpdated());
                        branding.add(brandingEntity);
                    }
                }
                poolEntity.setBranding(branding);
            }
        }
        if (poolDTO.getProvidedProducts() != null) {
            if (poolDTO.getProvidedProducts().isEmpty()) {
                poolEntity.setProvidedProductDtos(Collections.emptySet());
            } else {
                Set<ProvidedProduct> providedProducts = new HashSet<>();
                for (PoolDTO.ProvidedProductDTO ppDTO : poolDTO.getProvidedProducts()) {
                    if (ppDTO != null) {
                        ProvidedProduct providedProduct = new ProvidedProduct();
                        providedProduct.setProductId(ppDTO.getProductId());
                        providedProduct.setProductName(ppDTO.getProductName());
                        providedProducts.add(providedProduct);
                    }
                }
                poolEntity.setProvidedProductDtos(providedProducts);
            }
        }
        if (poolDTO.getDerivedProvidedProducts() != null) {
            if (poolDTO.getDerivedProvidedProducts().isEmpty()) {
                poolEntity.setDerivedProvidedProductDtos(Collections.emptySet());
            } else {
                Set<ProvidedProduct> derivedProvidedProducts = new HashSet<>();
                for (PoolDTO.ProvidedProductDTO dppDTO : poolDTO.getDerivedProvidedProducts()) {
                    if (dppDTO != null) {
                        ProvidedProduct derivedProvidedProduct = new ProvidedProduct();
                        derivedProvidedProduct.setProductId(dppDTO.getProductId());
                        derivedProvidedProduct.setProductName(dppDTO.getProductName());
                        derivedProvidedProducts.add(derivedProvidedProduct);
                    }
                }
                poolEntity.setDerivedProvidedProductDtos(derivedProvidedProducts);
            }
        }
        entity.setPool(poolEntity);
    }
    if (dto.getCertificates() != null) {
        if (dto.getCertificates().isEmpty()) {
            entity.setCertificates(Collections.emptySet());
        } else {
            Set<EntitlementCertificate> entityCerts = new HashSet<>();
            for (CertificateDTO dtoCert : dto.getCertificates()) {
                if (dtoCert != null) {
                    EntitlementCertificate entityCert = new EntitlementCertificate();
                    entityCert.setId(dtoCert.getId());
                    entityCert.setKey(dtoCert.getKey());
                    entityCert.setCert(dtoCert.getCert());
                    entityCert.setCreated(dtoCert.getCreated());
                    entityCert.setUpdated(dtoCert.getUpdated());
                    if (dtoCert.getSerial() != null) {
                        CertificateSerialDTO dtoSerial = dtoCert.getSerial();
                        CertificateSerial entitySerial = new CertificateSerial();
                        entitySerial.setId(dtoSerial.getId());
                        entitySerial.setCollected(dtoSerial.isCollected());
                        entitySerial.setExpiration(dtoSerial.getExpiration());
                        entitySerial.setRevoked(dtoSerial.isRevoked());
                        entitySerial.setSerial(dtoSerial.getSerial() != null ? dtoSerial.getSerial().longValueExact() : null);
                        entitySerial.setCreated(dtoSerial.getCreated());
                        entitySerial.setUpdated(dtoSerial.getUpdated());
                        entityCert.setSerial(entitySerial);
                    }
                    entityCerts.add(entityCert);
                }
            }
            entity.setCertificates(entityCerts);
        }
    }
}
Also used : Owner(org.candlepin.model.Owner) EntitlementCertificate(org.candlepin.model.EntitlementCertificate) CertificateSerialDTO(org.candlepin.dto.manifest.v1.CertificateSerialDTO) PoolDTO(org.candlepin.dto.manifest.v1.PoolDTO) CertificateSerial(org.candlepin.model.CertificateSerial) Branding(org.candlepin.model.Branding) ProvidedProduct(org.candlepin.model.ProvidedProduct) CertificateDTO(org.candlepin.dto.manifest.v1.CertificateDTO) EntitlementDTO(org.candlepin.dto.manifest.v1.EntitlementDTO) BrandingDTO(org.candlepin.dto.manifest.v1.BrandingDTO) SourceStack(org.candlepin.model.SourceStack) Pool(org.candlepin.model.Pool) HashSet(java.util.HashSet)

Example 5 with CertificateSerialDTO

use of org.candlepin.dto.manifest.v1.CertificateSerialDTO in project candlepin by candlepin.

the class Importer method populateEntity.

/**
 * Populates the specified entity with data from the provided DTO.
 *
 * @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(IdentityCertificate entity, CertificateDTO dto) {
    if (entity == null) {
        throw new IllegalArgumentException("the certificate model entity is null");
    }
    if (dto == null) {
        throw new IllegalArgumentException("the certificate dto is null");
    }
    entity.setId(dto.getId());
    entity.setKey(dto.getKey());
    entity.setCert(dto.getCert());
    entity.setUpdated(dto.getUpdated());
    entity.setCreated(dto.getCreated());
    if (dto.getSerial() != null) {
        CertificateSerialDTO dtoSerial = dto.getSerial();
        CertificateSerial entitySerial = new CertificateSerial();
        entitySerial.setId(dtoSerial.getId());
        entitySerial.setSerial(dtoSerial.getSerial() != null ? dtoSerial.getSerial().longValueExact() : null);
        entitySerial.setCollected(dtoSerial.isCollected());
        entitySerial.setExpiration(dtoSerial.getExpiration());
        entitySerial.setRevoked(dtoSerial.isRevoked());
        entity.setSerial(entitySerial);
    }
}
Also used : CertificateSerialDTO(org.candlepin.dto.manifest.v1.CertificateSerialDTO) CertificateSerial(org.candlepin.model.CertificateSerial)

Aggregations

CertificateSerial (org.candlepin.model.CertificateSerial)5 CertificateSerialDTO (org.candlepin.dto.api.v1.CertificateSerialDTO)4 Test (org.junit.Test)3 CertificateDTO (org.candlepin.dto.api.v1.CertificateDTO)2 CertificateSerialDTO (org.candlepin.dto.manifest.v1.CertificateSerialDTO)2 CertificateSerialCurator (org.candlepin.model.CertificateSerialCurator)2 Calendar (java.util.Calendar)1 HashSet (java.util.HashSet)1 BadRequestException (org.candlepin.common.exceptions.BadRequestException)1 BrandingDTO (org.candlepin.dto.manifest.v1.BrandingDTO)1 CertificateDTO (org.candlepin.dto.manifest.v1.CertificateDTO)1 EntitlementDTO (org.candlepin.dto.manifest.v1.EntitlementDTO)1 PoolDTO (org.candlepin.dto.manifest.v1.PoolDTO)1 Branding (org.candlepin.model.Branding)1 CandlepinQuery (org.candlepin.model.CandlepinQuery)1 CdnCertificate (org.candlepin.model.CdnCertificate)1 EmptyCandlepinQuery (org.candlepin.model.EmptyCandlepinQuery)1 EntitlementCertificate (org.candlepin.model.EntitlementCertificate)1 Owner (org.candlepin.model.Owner)1 Pool (org.candlepin.model.Pool)1