Search in sources :

Example 51 with Owner

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);
}
Also used : Owner(org.candlepin.model.Owner) ConsumerDTO(org.candlepin.dto.manifest.v1.ConsumerDTO) OwnerDTO(org.candlepin.dto.manifest.v1.OwnerDTO) CertificateSerial(org.candlepin.model.CertificateSerial) UpstreamConsumer(org.candlepin.model.UpstreamConsumer) ConsumerTypeDTO(org.candlepin.dto.manifest.v1.ConsumerTypeDTO) IdentityCertificate(org.candlepin.model.IdentityCertificate) Test(org.junit.Test)

Example 52 with 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);
}
Also used : ContentDTO(org.candlepin.dto.api.v1.ContentDTO) Owner(org.candlepin.model.Owner) ProductContent(org.candlepin.model.ProductContent) Content(org.candlepin.model.Content) Product(org.candlepin.model.Product) ProductContent(org.candlepin.model.ProductContent) LinkedList(java.util.LinkedList) ProductDTO(org.candlepin.dto.api.v1.ProductDTO) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Transactional(com.google.inject.persist.Transactional)

Example 53 with Owner

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;
}
Also used : Owner(org.candlepin.model.Owner) SubscriptionsCertificate(org.candlepin.model.SubscriptionsCertificate) Product(org.candlepin.model.Product) Entitlement(org.candlepin.model.Entitlement) Branding(org.candlepin.model.Branding)

Example 54 with Owner

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;
}
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 55 with Owner

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

Aggregations

Owner (org.candlepin.model.Owner)405 Test (org.junit.Test)254 Product (org.candlepin.model.Product)153 Consumer (org.candlepin.model.Consumer)127 Pool (org.candlepin.model.Pool)79 Date (java.util.Date)72 ConsumerInstalledProduct (org.candlepin.model.ConsumerInstalledProduct)71 ArrayList (java.util.ArrayList)58 Produces (javax.ws.rs.Produces)52 ConsumerType (org.candlepin.model.ConsumerType)52 ApiOperation (io.swagger.annotations.ApiOperation)50 HashSet (java.util.HashSet)44 Entitlement (org.candlepin.model.Entitlement)44 Path (javax.ws.rs.Path)42 HashMap (java.util.HashMap)41 ApiResponses (io.swagger.annotations.ApiResponses)40 Content (org.candlepin.model.Content)39 BadRequestException (org.candlepin.common.exceptions.BadRequestException)37 Subscription (org.candlepin.model.dto.Subscription)32 List (java.util.List)29