use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class OwnerProductResource method addBatchContent.
@ApiOperation(notes = "Adds one or more Content entities to a Product", value = "addBatchContent")
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("/{product_id}/batch_content")
@Transactional
public ProductDTO addBatchContent(@PathParam("owner_key") String ownerKey, @PathParam("product_id") String productId, @ApiParam(name = "contentMap", required = true) Map<String, Boolean> contentMap) {
Owner owner = this.getOwnerByKey(ownerKey);
Product product = this.fetchProduct(owner, productId);
Collection<ProductContent> productContent = new LinkedList<>();
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 (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);
}
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 ProductImporterTest method testNewProductCreated.
@Test
public void testNewProductCreated() throws Exception {
ProductDTO product = new ProductDTO();
product.setId("test-id");
product.setName("test-name");
product.setAttribute("attr1", "val1");
product.setAttribute("attr2", "val2");
product.setMultiplier(1L);
Set<String> dependentProdIDs = new HashSet<>();
dependentProdIDs.add("g23gh23h2");
dependentProdIDs.add("353g823h");
product.setDependentProductIds(dependentProdIDs);
String json = getJsonForProduct(product);
Reader reader = new StringReader(json);
ProductDTO created = importer.createObject(mapper, reader, owner);
assertEquals(product, created);
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class ProductImporterTest method testVendorSetToUnknown.
@Test
public void testVendorSetToUnknown() throws Exception {
Product product = TestUtil.createProduct();
addNoVendorContentTo(product);
String json = getJsonForProduct(product);
Reader reader = new StringReader(json);
ProductDTO created = importer.createObject(mapper, reader, owner);
ContentDTO c = created.getProductContent().iterator().next().getContent();
assertEquals("unknown", c.getVendor());
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class TestUtil method createProductDTO.
public static ProductDTO createProductDTO(String id, String name) {
ProductDTO dto = new ProductDTO();
dto.setId(id);
dto.setName(name);
return dto;
}
use of org.candlepin.dto.manifest.v1.ProductDTO in project candlepin by candlepin.
the class ProductManagerTest method testAddContentToSharedProduct.
@Test
@Parameters({ "false", "true" })
public void testAddContentToSharedProduct(boolean regenCerts) {
Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1");
Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2");
Product product = this.createProduct("p1", "prod1", owner1);
Content content = this.createContent("c1", "content1", owner1);
this.ownerProductCurator.mapProductToOwners(product, owner1, owner2);
ProductDTO pdto = this.modelTranslator.translate(product, ProductDTO.class);
ContentDTO cdto = this.modelTranslator.translate(content, ContentDTO.class);
pdto.addContent(cdto, true);
Product output = this.productManager.updateProduct(pdto, owner1, regenCerts);
assertNotEquals(product, output);
assertFalse(product.hasContent(content.getId()));
assertTrue(output.hasContent(content.getId()));
assertFalse(this.ownerProductCurator.isProductMappedToOwner(product, owner1));
assertTrue(this.ownerProductCurator.isProductMappedToOwner(product, owner2));
assertTrue(this.ownerProductCurator.isProductMappedToOwner(output, owner1));
assertFalse(this.ownerProductCurator.isProductMappedToOwner(output, owner2));
if (regenCerts) {
verify(this.mockEntCertGenerator, times(1)).regenerateCertificatesOf(eq(Arrays.asList(owner1)), anyCollectionOf(Product.class), anyBoolean());
} else {
verifyZeroInteractions(this.mockEntCertGenerator);
}
}
Aggregations