use of org.candlepin.model.Owner in project candlepin by candlepin.
the class ConsumerImporterTest method importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced.
@Test
public void importConsumerWithMismatchedUuidShouldNotThrowExceptionIfForced() throws ImporterException {
Owner owner = mock(Owner.class);
OwnerDTO ownerDTO = mock(OwnerDTO.class);
ConsumerDTO consumer = mock(ConsumerDTO.class);
ConsumerTypeDTO type = mock(ConsumerTypeDTO.class);
when(owner.getUpstreamUuid()).thenReturn("another-test-uuid");
when(consumer.getUuid()).thenReturn("test-uuid");
when(consumer.getOwner()).thenReturn(ownerDTO);
when(consumer.getType()).thenReturn(type);
IdentityCertificate idCert = new IdentityCertificate();
idCert.setSerial(new CertificateSerial());
importer.store(owner, consumer, new ConflictOverrides(Importer.Conflict.DISTRIBUTOR_CONFLICT), idCert);
// now verify that the owner has the upstream consumer set
ArgumentCaptor<UpstreamConsumer> arg = ArgumentCaptor.forClass(UpstreamConsumer.class);
verify(owner).setUpstreamConsumer(arg.capture());
assertEquals("test-uuid", arg.getValue().getUuid());
verify(curator).merge(owner);
}
use of org.candlepin.model.Owner in project candlepin by candlepin.
the class HostedTestSubscriptionResource method addBatchContent.
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/owners/{owner_key}/products/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, Map<String, Boolean> contentMap) {
Owner owner = this.getOwnerByKey(ownerKey);
Product product = this.fetchProduct(owner, productId);
Collection<ProductContent> productContent = new LinkedList<>();
ProductDTO pdto = this.translator.translate(product, ProductDTO.class);
// Impl note:
// This is a wholely inefficient way of doing this. When we return to using ID-based linking
// and we're not linking the universe with our model, we can just attach the IDs directly
// without needing all this DTO conversion back and forth.
// Alternatively, we can shut off Hibernate's auto-commit junk and get in the habit of
// calling commit methods as necessary so we don't have to work with DTOs internally.
boolean changed = false;
for (Entry<String, Boolean> entry : contentMap.entrySet()) {
Content content = this.fetchContent(owner, entry.getKey());
boolean enabled = entry.getValue() != null ? entry.getValue() : ProductContent.DEFAULT_ENABLED_STATE;
ContentDTO cdto = this.translator.translate(content, ContentDTO.class);
changed |= pdto.addContent(cdto, enabled);
addContentToUpstreamSubscriptions(product, content, enabled);
}
if (changed) {
product = this.productManager.updateProduct(pdto, owner, true);
}
return this.translator.translate(product, ProductDTO.class);
}
use of org.candlepin.model.Owner in project candlepin by candlepin.
the class PoolTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("checkstyle:methodlength")
public PoolDTO populate(ModelTranslator modelTranslator, Pool source, PoolDTO dest) {
dest = super.populate(modelTranslator, source, dest);
dest.setId(source.getId());
dest.setType(source.getType().toString());
dest.setActiveSubscription(source.getActiveSubscription());
dest.setCreatedByShare(source.isCreatedByShare());
dest.setHasSharedAncestor(source.hasSharedAncestor());
dest.setQuantity(source.getQuantity());
dest.setStartDate(source.getStartDate());
dest.setEndDate(source.getEndDate());
dest.setAttributes(source.getAttributes());
dest.setRestrictedToUsername(source.getRestrictedToUsername());
dest.setContractNumber(source.getContractNumber());
dest.setAccountNumber(source.getAccountNumber());
dest.setOrderNumber(source.getOrderNumber());
dest.setConsumed(source.getConsumed());
dest.setExported(source.getExported());
dest.setShared(source.getShared());
dest.setCalculatedAttributes(source.getCalculatedAttributes());
dest.setUpstreamPoolId(source.getUpstreamPoolId());
dest.setUpstreamEntitlementId(source.getUpstreamEntitlementId());
dest.setUpstreamConsumerId(source.getUpstreamConsumerId());
dest.setProductName(source.getProductName());
dest.setProductId(source.getProductId());
dest.setProductAttributes(source.getProductAttributes());
dest.setStackId(source.getStackId());
dest.setStacked(source.isStacked());
dest.setDevelopmentPool(source.isDevelopmentPool());
dest.setDerivedProductAttributes(source.getDerivedProductAttributes());
dest.setDerivedProductId(source.getDerivedProductId());
dest.setDerivedProductName(source.getDerivedProductName());
dest.setSourceStackId(source.getSourceStackId());
dest.setSubscriptionSubKey(source.getSubscriptionSubKey());
dest.setSubscriptionId(source.getSubscriptionId());
// Process nested objects if we have a model translator to use to the translation...
if (modelTranslator != null) {
Owner owner = source.getOwner();
dest.setOwner(owner != null ? modelTranslator.translate(owner, OwnerDTO.class) : null);
SubscriptionsCertificate subCertificate = source.getCertificate();
dest.setCertificate(subCertificate != null ? modelTranslator.translate(subCertificate, CertificateDTO.class) : null);
Entitlement sourceEntitlement = source.getSourceEntitlement();
dest.setSourceEntitlement(sourceEntitlement != null ? modelTranslator.translate(sourceEntitlement, EntitlementDTO.class) : null);
Set<Branding> branding = source.getBranding();
if (branding != null && !branding.isEmpty()) {
for (Branding brand : branding) {
if (brand != null) {
dest.addBranding(modelTranslator.translate(brand, BrandingDTO.class));
}
}
} else {
dest.setBranding(Collections.<BrandingDTO>emptySet());
}
Set<Product> products = source.getProvidedProducts();
if (products != null && !products.isEmpty()) {
for (Product prod : products) {
if (prod != null) {
dest.addProvidedProduct(new PoolDTO.ProvidedProductDTO(prod.getId(), prod.getName()));
}
}
} else {
dest.setProvidedProducts(Collections.<PoolDTO.ProvidedProductDTO>emptySet());
}
Set<Product> derivedProducts = source.getDerivedProvidedProducts();
if (derivedProducts != null && !derivedProducts.isEmpty()) {
for (Product derivedProd : derivedProducts) {
if (derivedProd != null) {
dest.addDerivedProvidedProduct(new PoolDTO.ProvidedProductDTO(derivedProd.getId(), derivedProd.getName()));
}
}
} else {
dest.setDerivedProvidedProducts(Collections.<PoolDTO.ProvidedProductDTO>emptySet());
}
}
return dest;
}
use of org.candlepin.model.Owner 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.Owner in project candlepin by candlepin.
the class ConsumerTranslator method populate.
/**
* {@inheritDoc}
*/
@Override
public ConsumerDTO populate(ModelTranslator translator, Consumer source, ConsumerDTO dest) {
if (source == null) {
throw new IllegalArgumentException("source is null");
}
if (dest == null) {
throw new IllegalArgumentException("destination is null");
}
dest.setUuid(source.getUuid()).setName(source.getName()).setContentAccessMode(source.getContentAccessMode());
// Process nested objects if we have a ModelTranslator to use to the translation...
if (translator != null) {
if (source.getOwnerId() != null) {
Owner owner = this.ownerCurator.findOwnerById(source.getOwnerId());
dest.setOwner(owner != null ? translator.translate(owner, OwnerDTO.class) : null);
}
// Temporary measure to maintain API compatibility
if (source.getTypeId() != null) {
ConsumerType ctype = this.consumerTypeCurator.getConsumerType(source);
dest.setType(translator.translate(ctype, ConsumerTypeDTO.class));
} else {
dest.setType(null);
}
} else {
dest.setOwner(null);
dest.setType(null);
}
return dest;
}
Aggregations