use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class ProductDTOTranslator method populate.
/**
* {@inheritDoc}
*
* <p>Note: the 'locked' field is always set to false and the 'href' field is not translated,
* since these fields are not currently being exported.</p>
*/
@Override
public ProductData populate(ModelTranslator modelTranslator, ProductDTO source, ProductData dest) {
if (source == null) {
throw new IllegalArgumentException("source is null");
}
if (dest == null) {
throw new IllegalArgumentException("dest is null");
}
dest.setCreated(source.getCreated());
dest.setUpdated(source.getUpdated());
dest.setUuid(source.getUuid());
dest.setId(source.getId());
dest.setName(source.getName());
dest.setMultiplier(source.getMultiplier());
dest.setAttributes(source.getAttributes());
dest.setDependentProductIds(source.getDependentProductIds());
// We manually set this to false since it is not included in the exported data.
dest.setLocked(false);
Collection<ProductDTO.ProductContentDTO> productContentDTOs = source.getProductContent();
dest.setProductContent(Collections.emptyList());
if (modelTranslator != null && productContentDTOs != null) {
ObjectTranslator<ContentDTO, ContentData> contentDTOTranslator = modelTranslator.findTranslatorByClass(ContentDTO.class, ContentData.class);
for (ProductDTO.ProductContentDTO pcdto : productContentDTOs) {
if (pcdto != null && pcdto.getContent() != null) {
ContentData contentData = contentDTOTranslator.translate(modelTranslator, pcdto.getContent());
dest.addContent(contentData, pcdto.isEnabled());
}
}
}
return dest;
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class EntitlementImporter method importObject.
public Subscription importObject(ObjectMapper mapper, Reader reader, Owner owner, Map<String, ProductDTO> productsById, String consumerUuid, Meta meta) throws IOException, SyncDataFormatException {
EntitlementDTO entitlementDTO = mapper.readValue(reader, EntitlementDTO.class);
Entitlement entitlement = new Entitlement();
populateEntity(entitlement, entitlementDTO);
Subscription subscription = new Subscription();
log.debug("Building subscription for owner: {}", owner);
log.debug("Using pool from entitlement: {}", entitlement.getPool());
// Now that we no longer store Subscriptions in the on-site database, we need to
// manually give the subscription a downstream ID. Note that this may later be
// overwritten by reconciliation code if it determines this Subscription
// should replace and existing one.
subscription.setId(Util.generateDbUUID());
subscription.setUpstreamPoolId(entitlement.getPool().getId());
subscription.setUpstreamEntitlementId(entitlement.getId());
subscription.setUpstreamConsumerId(consumerUuid);
subscription.setOwner(owner);
subscription.setStartDate(entitlement.getStartDate());
subscription.setEndDate(entitlement.getEndDate());
subscription.setAccountNumber(entitlement.getPool().getAccountNumber());
subscription.setContractNumber(entitlement.getPool().getContractNumber());
subscription.setOrderNumber(entitlement.getPool().getOrderNumber());
subscription.setQuantity(entitlement.getQuantity().longValue());
for (Branding b : entitlement.getPool().getBranding()) {
subscription.getBranding().add(new Branding(b.getProductId(), b.getType(), b.getName()));
}
String cdnLabel = meta.getCdnLabel();
if (!StringUtils.isBlank(cdnLabel)) {
Cdn cdn = cdnCurator.lookupByLabel(cdnLabel);
if (cdn != null) {
subscription.setCdn(cdn);
}
}
ProductDTO productDTO = this.findProduct(productsById, entitlement.getPool().getProductId());
subscription.setProduct(this.translator.translate(productDTO, ProductData.class));
// Add any sub product data to the subscription.
if (entitlement.getPool().getDerivedProductId() != null) {
productDTO = this.findProduct(productsById, entitlement.getPool().getDerivedProductId());
subscription.setDerivedProduct(this.translator.translate(productDTO, ProductData.class));
}
associateProvidedProducts(productsById, entitlement, subscription);
Set<EntitlementCertificate> certs = entitlement.getCertificates();
// subscriptions have one cert
int entcnt = 0;
for (EntitlementCertificate cert : certs) {
++entcnt;
CertificateSerial cs = new CertificateSerial();
cs.setCollected(cert.getSerial().isCollected());
cs.setExpiration(cert.getSerial().getExpiration());
cs.setUpdated(cert.getSerial().getUpdated());
cs.setCreated(cert.getSerial().getCreated());
SubscriptionsCertificate sc = new SubscriptionsCertificate();
sc.setKey(cert.getKey());
sc.setCertAsBytes(cert.getCertAsBytes());
sc.setSerial(cs);
subscription.setCertificate(sc);
}
if (entcnt > 1) {
log.error("More than one entitlement cert found for subscription");
}
return subscription;
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class OwnerProductResource method removeBatchContent.
@ApiOperation(notes = "Adds one or more Content entities to a Product", value = "addBatchContent")
@DELETE
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{product_id}/batch_content")
@Transactional
public ProductDTO removeBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, @ApiParam(name = "content", required = true) List<String> contentIds) {
Owner owner = this.getOwnerByKey(ownerKey);
Product product = this.fetchProduct(owner, productId);
if (product.isLocked()) {
throw new ForbiddenException(i18n.tr("product \"{0}\" is locked", product.getId()));
}
this.productCurator.lock(product);
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 (String contentId : contentIds) {
changed |= pdto.removeContent(contentId);
}
if (changed) {
product = this.productManager.updateProduct(pdto, owner, true);
}
return this.translator.translate(product, ProductDTO.class);
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class OwnerProductResourceTest method testCreateProductWithContent.
@Test
public void testCreateProductWithContent() {
Owner owner = this.createOwner("Example-Corporation");
Content content = this.createContent("content-1", "content-1", owner);
ProductDTO pdto = this.buildTestProductDTO();
ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
pdto.addContent(cdto, true);
assertNull(this.ownerProductCurator.getProductById(owner.getKey(), pdto.getId()));
ProductDTO result = this.ownerProductResource.createProduct(owner.getKey(), pdto);
Product entity = this.ownerProductCurator.getProductById(owner, pdto.getId());
ProductDTO expected = this.modelTranslator.translate(entity, ProductDTO.class);
assertNotNull(result);
assertNotNull(entity);
assertEquals(expected, result);
assertNotNull(result.getProductContent());
assertEquals(1, result.getProductContent().size());
assertEquals(cdto, result.getProductContent().iterator().next().getContent());
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class OwnerProductResourceTest method testCreateProductResource.
@Test
public void testCreateProductResource() {
Owner owner = this.createOwner("Example-Corporation");
ProductDTO pdto = this.buildTestProductDTO();
assertNull(this.ownerProductCurator.getProductById(owner.getKey(), pdto.getId()));
ProductDTO result = this.ownerProductResource.createProduct(owner.getKey(), pdto);
Product entity = this.ownerProductCurator.getProductById(owner, pdto.getId());
ProductDTO expected = this.modelTranslator.translate(entity, ProductDTO.class);
assertNotNull(result);
assertNotNull(entity);
assertEquals(expected, result);
}
Aggregations