ContentManager { public Content createContent(ContentDTO dto, Owner owner) { if (dto == null) { throw new IllegalArgumentException("dto is null"); } if (dto.getId() == null || dto.getType() == null || dto.getLabel() == null || dto.getName() == null || dto.getVendor() == null) { throw new IllegalArgumentException("dto is incomplete"); } if (this.ownerContentCurator.contentExists(owner, dto.getId())) { throw new IllegalStateException("content has already been created: " + dto.getId()); } Content entity = new Content(dto.getId()); this.applyContentChanges(entity, dto); log.debug("Creating new content for org: {}, {}", entity, owner); List<Content> alternateVersions = this.ownerContentCurator.getContentByVersions( owner, Collections.<String, Integer>singletonMap(entity.getId(), entity.getEntityVersion())) .list(); log.debug("Checking {} alternate content versions", alternateVersions.size()); for (Content alt : alternateVersions) { if (alt.equals(entity)) { this.ownerContentCurator.mapContentToOwner(alt, owner); return alt; } } entity = this.contentCurator.create(entity); this.ownerContentCurator.mapContentToOwner(entity, owner); return entity; } @Inject  ContentManager(
        ContentCurator contentCurator, EntitlementCertificateGenerator entitlementCertGenerator,
        OwnerContentCurator ownerContentCurator, ProductCurator productCurator,
        ProductManager productManager, ModelTranslator modelTranslator); Content createContent(ContentDTO dto, Owner owner); Content updateContent(ContentData update, Owner owner, boolean regenerateEntitlementCerts); @Transactional Content updateContent(ContentDTO update, Owner owner, boolean regenerateEntitlementCerts); @SuppressWarnings("checkstyle:methodlength") @Transactional @Traceable ImportResult<Content> importContent(@TraceableParam("owner") Owner owner,
        Map<String, ? extends ContentInfo> contentData, Set<String> importedProductIds); @Transactional void removeContent(Owner owner, Content entity, boolean regenerateEntitlementCerts); void removeContent(Owner owner, Collection<Content> content, boolean regenerateEntitlementCerts); void removeAllContent(Owner owner, boolean regenerateEntitlementCerts); void removeContentByUuids(Owner owner, Collection<String> contentUuids,
        boolean regenerateEntitlementCerts); static boolean isChangedBy(Content entity, ContentDTO dto); static boolean isChangedBy(Content entity, ContentInfo dto);  }
@Test public void testCreateContent() { Owner owner = this.createOwner("test-owner", "Test Owner"); ContentDTO dto = TestUtil.createContentDTO("c1", "content-1"); dto.setLabel("test-label"); dto.setType("test-test"); dto.setVendor("test-vendor"); assertNull(this.ownerContentCurator.getContentById(owner, dto.getId())); Content output = this.contentManager.createContent(dto, owner); assertEquals(output, this.ownerContentCurator.getContentById(owner, dto.getId())); }
@Test public void testCreateContentThatAlreadyExists() { Owner owner = this.createOwner("test-owner", "Test Owner"); ContentDTO dto = TestUtil.createContentDTO("c1", "content-1"); dto.setLabel("test-label"); dto.setType("test-test"); dto.setVendor("test-vendor"); Content output = this.contentManager.createContent(dto, owner); assertNotNull(output); assertEquals(output, this.ownerContentCurator.getContentById(owner, dto.getId())); assertThrows(IllegalStateException.class, () -> this.contentManager.createContent(dto, owner)); }
@Test public void testCreateContentMergeWithExisting() { Owner owner1 = this.createOwner("test-owner-1", "Test Owner 1"); Owner owner2 = this.createOwner("test-owner-2", "Test Owner 2"); Content content1 = TestUtil.createContent("c1", "content-1"); Content content2 = this.createContent("c1", "content-1", owner2); ContentDTO cdto = this.modelTranslator.translate(content1, ContentDTO.class); Content output = this.contentManager.createContent(cdto, owner1); assertEquals(content2.getUuid(), output.getUuid()); assertEquals(content2, output); assertTrue(this.ownerContentCurator.isContentMappedToOwner(output, owner1)); assertTrue(this.ownerContentCurator.isContentMappedToOwner(output, owner2)); }