private ContentKey storeSimpleContent(String title) { ContentEntity content = factory.createContent("MyCategory", "en", "testuser", "0", new Date()); ContentVersionEntity version = factory.createContentVersion("0", "testuser"); ContentTypeConfig contentTypeConfig = ContentTypeConfigParser.parse(ContentHandlerName.CUSTOM, createSimpleContentTypeConfig()); CustomContentData contentData = new CustomContentData(contentTypeConfig); TextDataEntryConfig titleConfig = new TextDataEntryConfig("myTitle", true, title, "contentdata/mytitle"); contentData.add(new TextDataEntry(titleConfig, "relatedconfig")); version.setContentData(contentData); UserEntity runningUser = fixture.findUserByName("testuser"); CreateContentCommand createContentCommand = new CreateContentCommand(); createContentCommand.setCreator(runningUser); createContentCommand.populateCommandWithContentValues(content); createContentCommand.populateCommandWithContentVersionValues(version); createContentCommand.setBinaryDatas(new ArrayList<BinaryDataAndBinary>()); createContentCommand.setUseCommandsBinaryDataToAdd(true); ContentKey contentKey = contentService.createContent(createContentCommand); hibernateTemplate.flush(); hibernateTemplate.clear(); return contentKey; }
public int createFileContent(CreateFileContentParams params) { validateCreateFileContentParams(params); CategoryEntity category = categoryDao.findByKey(new CategoryKey(params.categoryKey)); UserEntity runningUser = securityService.getImpersonatedPortalUser(); LegacyFileContentData contentdata = (LegacyFileContentData) fileContentResolver.resolveContentdata(params.fileContentData); List<BinaryDataAndBinary> binaryDataEntries = new ArrayList<BinaryDataAndBinary>(); binaryDataEntries.add( BinaryDataAndBinary.convertFromFileBinaryInput(params.fileContentData.binary)); CreateContentCommand createCommand = new CreateContentCommand(); createCommand.setAccessRightsStrategy( CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY); createCommand.setCreator(runningUser); createCommand.setStatus(ContentStatus.get(params.status)); createCommand.setPriority(0); createCommand.setCategory(category); createCommand.setLanguage(category.getUnitExcludeDeleted().getLanguage()); createCommand.setAvailableFrom(params.publishFrom); createCommand.setAvailableTo(params.publishTo); createCommand.setContentData(contentdata); createCommand.setContentName( new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle())); createCommand.setBinaryDatas(binaryDataEntries); createCommand.setUseCommandsBinaryDataToAdd(true); if (params.siteKey != null) { createCommand.setSiteKey(new SiteKey(params.siteKey)); } ContentKey contentKey = contentService.createContent(createCommand); return contentKey.toInt(); }
public void unassignContent(UnassignContentParams params) { final UserEntity unassigner = securityService.getImpersonatedPortalUser(); UnassignContentCommand command = new UnassignContentCommand(); command.setContentKey(new ContentKey(params.contentKey)); command.setUnassigner(unassigner.getKey()); contentService.unassignContent(command); }
public int generateLowResImages(final GenerateLowResImagesParams params) { final UserEntity modifier = securityService.getImpersonatedPortalUser(); GenerateLowResImagesCommand generateCommand = new GenerateLowResImagesCommand(); generateCommand.setCategoryKeys(params.categoryKeys); generateCommand.setImageSize(params.imageSize); generateCommand.setModifier(modifier); return contentService.generateLowResImages(generateCommand); }
public void snapshotContent(SnapshotContentParams params) { final UserEntity modifier = securityService.getImpersonatedPortalUser(); SnapshotContentCommand snapshotCommand = new SnapshotContentCommand(); snapshotCommand.setSnapshotComment(params.snapshotComment); snapshotCommand.setSnapshotterKey(modifier.getKey()); snapshotCommand.setContentKey(new ContentKey(params.contentKey)); snapshotCommand.setClearCommentInDraft(params.clearCommentInDraft); contentService.snapshotContent(snapshotCommand); }
private void createUpdateContentWithBinary() { UserEntity runningUser = fixture.findUserByName("testuser"); // prepare: save a new content ContentEntity content = new ContentEntity(); content.setPriority(0); content.setAvailableFrom(null); content.setAvailableTo(null); content.setCategory(fixture.findCategoryByName("MyCategory")); content.setLanguage(fixture.findLanguageByCode("en")); content.setName("testcontentwithbinary"); ContentVersionEntity version = new ContentVersionEntity(); version.setContent(content); version.setModifiedBy(runningUser); version.setStatus(com.enonic.cms.core.content.ContentStatus.DRAFT); version.setContent(content); CustomContentData contentData = new CustomContentData( fixture.findContentTypeByName("MyContentType").getContentTypeConfig()); TextDataEntryConfig titleConfig = (TextDataEntryConfig) contentData.getContentTypeConfig().getForm().getInputConfig("myTitle"); TextDataEntryConfig updateFieldConfig = (TextDataEntryConfig) contentData.getContentTypeConfig().getForm().getInputConfig("fieldToUpdate"); BinaryDataEntryConfig binaryConfig = (BinaryDataEntryConfig) contentData.getContentTypeConfig().getForm().getInputConfig("myBinaryfile"); contentData.add(new TextDataEntry(titleConfig, "testitle")); contentData.add(new TextDataEntry(updateFieldConfig, "foobar")); contentData.add(new BinaryDataEntry(binaryConfig, "%0")); version.setContentData(contentData); version.setTitle(contentData.getTitle()); CreateContentCommand createContentCommand = new CreateContentCommand(); createContentCommand.setCreator(runningUser); createContentCommand.populateCommandWithContentValues(content); createContentCommand.populateCommandWithContentVersionValues(version); List<BinaryDataAndBinary> binaryDatas = new ArrayList<BinaryDataAndBinary>(); binaryDatas.add(factory.createBinaryDataAndBinary("dummyBinary", dummyBinary)); createContentCommand.setBinaryDatas(binaryDatas); createContentCommand.setUseCommandsBinaryDataToAdd(true); contentWithBinaryKey = contentService.createContent(createContentCommand); fixture.flushAndClearHibernateSession(); }
public int createContent(CreateContentParams params) throws ClientException { final CategoryEntity category = validateCreateContentParams(params); final CreateContentCommand command = new CreateContentCommand(); command.setPriority(0); command.setAvailableFrom(params.publishFrom); command.setAvailableTo(params.publishTo); command.setCategory(category); command.setLanguage(category.getUnitExcludeDeleted().getLanguage()); command.setStatus(ContentStatus.get(params.status)); command.setChangeComment(params.changeComment); // content data final ContentTypeEntity contentType = category.getContentType(); if (contentType == null) { throw new IllegalArgumentException( "Unable to create content in category " + category.getKey() + ". Category has no contenttype set."); } final ContentDataResolver customContentResolver = new ContentDataResolver(); final CustomContentData contentdata = customContentResolver.resolveContentdata(params.contentData, contentType); command.setContentData(contentdata); command.setContentName( new PrettyPathNameCreator(transliterate).generatePrettyPathName(contentdata.getTitle())); final List<BinaryDataAndBinary> binaryDatas = BinaryDataAndBinary.convertFromBinaryInputs(params.contentData.getBinaryInputs()); command.setBinaryDatas(binaryDatas); command.setUseCommandsBinaryDataToAdd(true); command.setAccessRightsStrategy( CreateContentCommand.AccessRightsStrategy.INHERIT_FROM_CATEGORY); command.setCreator(securityService.getImpersonatedPortalUser()); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } return contentService.createContent(command).toInt(); }
public void moveContent(MoveContentParams params) { validateMoveContentParams(params); ContentEntity content = contentDao.findByKey(new ContentKey(params.contentKey)); if (content == null) { throw new IllegalArgumentException("No content for given contentKey: " + params.contentKey); } CategoryEntity category = categoryDao.findByKey(new CategoryKey(params.categoryKey)); if (category == null) { throw new IllegalArgumentException( "No category for given categoryKey: " + params.categoryKey); } contentService.moveContent(securityService.getImpersonatedPortalUser(), content, category); }
public void assignContent(AssignContentParams params) { final UserEntity assigner = securityService.getImpersonatedPortalUser(); final UserParser userParser = new UserParser( securityService, userStoreService, userDao, new UserStoreParser(userStoreDao)); final UserEntity assignee = userParser.parseUser(params.assignee); final ContentKey contentToAssignOn = new ContentKey(params.contentKey); AssignContentCommand command = new AssignContentCommand(); command.setContentKey(contentToAssignOn); command.setAssignerKey(assigner.getKey()); command.setAssigneeKey(assignee.getKey()); command.setAssignmentDueDate(params.assignmentDueDate); command.setAssignmentDescription(params.assignmentDescription); contentService.assignContent(command); }
private void createUpdateContent() { UserEntity runningUser = fixture.findUserByName("testuser"); // prepare: save a new content ContentEntity content = new ContentEntity(); content.setPriority(0); content.setAvailableFrom(new Date()); content.setAvailableTo(null); content.setCategory(fixture.findCategoryByName("MyCategory")); content.setLanguage(fixture.findLanguageByCode("en")); content.setName("testcontent"); ContentVersionEntity version = new ContentVersionEntity(); version.setContent(content); version.setModifiedBy(runningUser); version.setStatus(com.enonic.cms.core.content.ContentStatus.APPROVED); version.setContent(content); CustomContentData contentData = new CustomContentData( fixture.findContentTypeByName("MyContentType").getContentTypeConfig()); TextDataEntryConfig titleConfig = (TextDataEntryConfig) contentData.getContentTypeConfig().getForm().getInputConfig("myTitle"); TextDataEntryConfig updateFieldConfig = (TextDataEntryConfig) contentData.getContentTypeConfig().getForm().getInputConfig("fieldToUpdate"); contentData.add(new TextDataEntry(titleConfig, "testitle")); contentData.add(new TextDataEntry(updateFieldConfig, "foobar")); version.setContentData(contentData); version.setTitle(contentData.getTitle()); CreateContentCommand createContentCommand = new CreateContentCommand(); createContentCommand.setCreator(runningUser); createContentCommand.setAccessRightsStrategy(AccessRightsStrategy.USE_GIVEN); createContentCommand.populateCommandWithContentValues(content); createContentCommand.populateCommandWithContentVersionValues(version); updateContentKey = contentService.createContent(createContentCommand); fixture.flushAndClearHibernateSession(); }
public void deleteContent(DeleteContentParams params) { UserEntity runningUser = securityService.getImpersonatedPortalUser(); ContentEntity content = contentDao.findByKey(new ContentKey(params.contentKey)); if (content != null && !content.isDeleted()) { ContentLocationSpecification contentLocationSpecification = new ContentLocationSpecification(); contentLocationSpecification.setIncludeInactiveLocationsInSection(false); ContentLocations contentLocations = content.getLocations(contentLocationSpecification); contentService.deleteContent( runningUser, content, params.siteKey != null ? new SiteKey(params.siteKey) : null); for (ContentLocation contentLocation : contentLocations.getAllLocations()) { PageCache pageCache = pageCacheService.getPageCacheService(contentLocation.getSiteKey()); pageCache.removeEntriesByMenuItem(contentLocation.getMenuItemKey()); } } }
@Test public void testUpdateContentDoNotChangeAssignment() { // exercise: updateContent AssignContentCommand assignContentCommand = new AssignContentCommand(); assignContentCommand.setAssignerKey(fixture.findUserByName("testuser").getKey()); assignContentCommand.setAssigneeKey(fixture.findUserByName("testuser").getKey()); assignContentCommand.setAssignmentDescription("test assignment"); assignContentCommand.setAssignmentDueDate(new DateTime(2010, 6, 6, 10, 0, 0, 0).toDate()); assignContentCommand.setContentKey(contentWithBinaryKey); contentService.assignContent(assignContentCommand); ContentDataInput newContentData = new ContentDataInput("MyContentType"); newContentData.add(new TextInput("myTitle", "changedtitle")); newContentData.add(new BinaryInput("myBinaryfile", dummyBinary, "dummyBinary")); UserEntity runningUser = fixture.findUserByName("testuser"); PortalSecurityHolder.setImpersonatedUser(runningUser.getKey()); UpdateContentParams params = new UpdateContentParams(); params.contentKey = contentWithBinaryKey.toInt(); params.contentData = newContentData; params.publishFrom = new Date(); params.publishTo = null; params.createNewVersion = false; params.status = ContentStatus.STATUS_DRAFT; int contentVersionKey = internalClient.updateContent(params); fixture.flushAndClearHibernateSession(); ContentVersionEntity actualVersion = contentVersionDao.findByKey(new ContentVersionKey(contentVersionKey)); ContentEntity persistedContent = contentDao.findByKey(actualVersion.getContent().getKey()); assertEquals(runningUser, persistedContent.getAssignee()); assertEquals(runningUser, persistedContent.getAssigner()); assertEquals("test assignment", persistedContent.getAssignmentDescription()); assertEquals( new DateTime(2010, 6, 6, 10, 0, 0, 0).toDate(), persistedContent.getAssignmentDueDate()); }
public int updateFileContent(UpdateFileContentParams params) { validateUpdateFileContentParams(params); ContentVersionKey contentVersionKey = resolveContentVersionKey( params.createNewVersion, params.contentKey, params.contentVersionKey); UpdateContentCommand command; if (params.createNewVersion) { command = UpdateContentCommand.storeNewVersionEvenIfUnchanged(contentVersionKey); } else { command = UpdateContentCommand.updateExistingVersion2(contentVersionKey); } command.setContentKey(new ContentKey(params.contentKey)); command.setSyncRelatedContent(false); command.setSyncAccessRights(false); command.setModifier(securityService.getImpersonatedPortalUser()); command.setAvailableFrom(params.publishFrom); command.setAvailableTo(params.publishTo); command.setStatus(ContentStatus.get(params.status)); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } LegacyFileContentData newContentData; List<BinaryDataAndBinary> binariesToAdd = null; List<BinaryDataKey> binariesToRemove = null; if (params.fileContentData != null) { newContentData = (LegacyFileContentData) fileContentResolver.resolveContentdata(params.fileContentData); command.setContentData(newContentData); if (!params.createNewVersion) { // only delete previous binaries if we are overwriting current version ContentVersionEntity persistedVersion = contentVersionDao.findByKey(contentVersionKey); LegacyFileContentData previousContentData = (LegacyFileContentData) persistedVersion.getContentData(); binariesToRemove = previousContentData.getRemovedBinaries(newContentData); } // Find new binaries binariesToAdd = newContentData.getBinaryDataAndBinaryList(); } else { // only update the meta data in this case.. } command.setUpdateAsMainVersion(params.setAsCurrentVersion); command.setUseCommandsBinaryDataToAdd(true); command.setBinaryDataToAdd(binariesToAdd); command.setUseCommandsBinaryDataToRemove(true); command.setBinaryDataToRemove(binariesToRemove); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } UpdateContentResult updateContentResult = contentService.updateContent(command); if (updateContentResult.isAnyChangesMade()) { new PageCacheInvalidatorForContent(pageCacheService) .invalidateForContent(updateContentResult.getTargetedVersion()); } return updateContentResult.getTargetedVersionKey().toInt(); }
public int updateContent(UpdateContentParams params) { validateUpdateContentParams(params); final ContentVersionKey contentVersionKey = resolveContentVersionKey( params.createNewVersion, params.contentKey, params.contentVersionKey); UpdateContentCommand command; if (params.createNewVersion) { command = UpdateContentCommand.storeNewVersionEvenIfUnchanged(contentVersionKey); } else { command = UpdateContentCommand.updateExistingVersion2(contentVersionKey); } command.setContentName(params.name); command.setSyncRelatedContent(true); command.setSyncAccessRights(false); command.setModifier(securityService.getImpersonatedPortalUser()); command.setUpdateAsMainVersion(params.setAsCurrentVersion); command.setContentKey(new ContentKey(params.contentKey)); command.setAvailableFrom(params.publishFrom); command.setAvailableTo(params.publishTo); command.setStatus(ContentStatus.get(params.status)); command.setUseCommandsBinaryDataToRemove(true); command.setUseCommandsBinaryDataToAdd(true); command.setChangeComment(params.changeComment); if (params.siteKey != null) { command.setSiteKey(new SiteKey(params.siteKey)); } if (params.contentData != null) { final ContentTypeEntity contentType = resolveContentType(params.contentKey); final ContentDataResolver customContentResolver = new ContentDataResolver(); final CustomContentData newContentData = customContentResolver.resolveContentdata(params.contentData, contentType); command.setContentData(newContentData); if (!params.createNewVersion) { // only delete previous binaries if we are overwriting current version final ContentVersionEntity persistedVersion = contentVersionDao.findByKey(contentVersionKey); final CustomContentData persistedContentData = (CustomContentData) persistedVersion.getContentData(); final List<BinaryDataEntry> deletedBinaries = persistedContentData.getRemovedBinaryDataEntries(newContentData); command.setBinaryDataToRemove(BinaryDataEntry.createBinaryDataKeyList(deletedBinaries)); command.setUseCommandsBinaryDataToRemove(true); } // Find new binaries final List<BinaryDataEntry> binaryEntries = newContentData.getBinaryDataEntryList(); command.setBinaryDataToAdd(BinaryDataAndBinary.convert(binaryEntries)); command.setUseCommandsBinaryDataToAdd(true); } else { // only update the meta data in this case.. } if (params.updateStrategy == ContentDataInputUpdateStrategy.REPLACE_NEW) { command.setUpdateStrategy(UpdateStrategy.MODIFY); } final UpdateContentResult updateContentResult = contentService.updateContent(command); if (updateContentResult.isAnyChangesMade()) { new PageCacheInvalidatorForContent(pageCacheService) .invalidateForContent(updateContentResult.getTargetedVersion()); } return updateContentResult.getTargetedVersionKey().toInt(); }
@Test public void testUpdateCurrentVersion() { ContentKey relatedContentKey1 = storeSimpleContent("rel1"); ContentKey relatedContentKey2 = storeSimpleContent("rel2"); ContentKey relatedContentKey3 = storeSimpleContent("rel3"); ContentKey relatedContentKey4 = storeSimpleContent("rel4"); ContentKey relatedContentKey5 = storeSimpleContent("rel5"); ContentEntity content = factory.createContent("MyCategory", "en", "testuser", "0", new Date()); ContentVersionEntity version = factory.createContentVersion("0", "testuser"); ContentTypeConfig contentTypeConfig = ContentTypeConfigParser.parse(ContentHandlerName.CUSTOM, configEl); CustomContentData contentData = new CustomContentData(contentTypeConfig); TextDataEntryConfig titleConfig = new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle"); contentData.add(new TextDataEntry(titleConfig, "test title")); RelatedContentDataEntryConfig multipleRelatedContentsConfig = (RelatedContentDataEntryConfig) contentTypeConfig.getInputConfig("myMultipleRelatedContent"); contentData.add( new RelatedContentsDataEntry(multipleRelatedContentsConfig) .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey1)) .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey2))); RelatedContentDataEntryConfig soleRelatedConfig = (RelatedContentDataEntryConfig) contentTypeConfig.getInputConfig("mySoleRelatedContent"); contentData.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey3)); version.setContentData(contentData); UserEntity runningUser = fixture.findUserByName("testuser"); CreateContentCommand createContentCommand = new CreateContentCommand(); createContentCommand.setCreator(runningUser); createContentCommand.populateCommandWithContentValues(content); createContentCommand.populateCommandWithContentVersionValues(version); createContentCommand.setBinaryDatas(new ArrayList<BinaryDataAndBinary>()); createContentCommand.setUseCommandsBinaryDataToAdd(true); ContentKey contentKey = contentService.createContent(createContentCommand); hibernateTemplate.flush(); hibernateTemplate.clear(); ContentEntity persistedContent = contentDao.findByKey(contentKey); assertNotNull(persistedContent); ContentVersionEntity persistedVersion = persistedContent.getMainVersion(); assertNotNull(persistedVersion); assertEquals(3, persistedVersion.getRelatedChildren(true).size()); ContentEntity changedContent = factory.createContent("MyCategory", "en", "testuser", "0", new Date()); changedContent.setKey(contentKey); ContentVersionEntity changedVersion = factory.createContentVersion("0", "testuser"); changedVersion.setKey(persistedVersion.getKey()); CustomContentData changedCD = new CustomContentData(contentTypeConfig); TextDataEntryConfig changedTitleConfig = new TextDataEntryConfig("myTitle", true, "Tittel", "contentdata/mytitle"); changedCD.add(new TextDataEntry(changedTitleConfig, "changed title")); changedCD.add( new RelatedContentsDataEntry(multipleRelatedContentsConfig) .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey3)) .add(new RelatedContentDataEntry(multipleRelatedContentsConfig, relatedContentKey5))); changedCD.add(new RelatedContentDataEntry(soleRelatedConfig, relatedContentKey4)); changedVersion.setContentData(changedCD); UpdateContentCommand updateContentCommand = UpdateContentCommand.updateExistingVersion2(persistedVersion.getKey()); updateContentCommand.setModifier(runningUser); updateContentCommand.setUpdateAsMainVersion(false); updateContentCommand.populateContentValuesFromContent(persistedContent); updateContentCommand.populateContentVersionValuesFromContentVersion(changedVersion); contentService.updateContent(updateContentCommand); hibernateTemplate.flush(); hibernateTemplate.clear(); ContentEntity contentAfterUpdate = contentDao.findByKey(contentKey); ContentVersionEntity versionAfterUpdate = contentVersionDao.findByKey(persistedVersion.getKey()); Document contentDataXmlAfterUpdate = versionAfterUpdate.getContentDataAsJDomDocument(); AssertTool.assertXPathEquals( "/contentdata/mysolerelatedcontent/@key", contentDataXmlAfterUpdate, relatedContentKey4.toString()); AssertTool.assertXPathEquals( "/contentdata/myrelatedcontents/content[1]/@key", contentDataXmlAfterUpdate, relatedContentKey3.toString()); AssertTool.assertXPathEquals( "/contentdata/myrelatedcontents/content[2]/@key", contentDataXmlAfterUpdate, relatedContentKey5.toString()); assertEquals(3, versionAfterUpdate.getRelatedChildren(true).size()); }
@Test public void common_content_related_to_between_two_content_is_listed_both_contents_relatedcontentkeys() { // setup: create same content in two different categories ContentKey commonChildContentKey = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Common child"), "content-creator")); ContentKey contentA = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Content A", commonChildContentKey), "content-creator")); ContentKey contentB = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Content B", commonChildContentKey), "content-creator")); fixture.flushIndexTransaction(); // setup: verify that 2 content is created assertEquals(3, fixture.countAllContent()); // exercise DataSourceContext context = new DataSourceContext(); context.setUser(fixture.findUserByName("content-querier")); String query = "title STARTS WITH 'Content '"; String orderBy = "@title asc"; int index = 0; int count = 10; boolean includeData = true; int childrenLevel = 1; int parentLevel = 0; XMLDocument xmlDocResult = dataSourceService.getContentByQuery( context, query, orderBy, index, count, includeData, childrenLevel, parentLevel, null); // verify Document jdomDocResult = xmlDocResult.getAsJDOMDocument(); System.out.println(JDOMUtil.prettyPrintDocument(jdomDocResult)); AssertTool.assertSingleXPathValueEquals("/contents/@totalcount", jdomDocResult, "2"); AssertTool.assertXPathEquals( "/contents/content/@key", jdomDocResult, contentA.toString(), contentB.toString()); AssertTool.assertXPathEquals( "/contents/content[ title = 'Content A']/relatedcontentkeys/relatedcontentkey/@key", jdomDocResult, commonChildContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[ title = 'Content B']/relatedcontentkeys/relatedcontentkey/@key", jdomDocResult, commonChildContentKey.toString()); AssertTool.assertSingleXPathValueEquals("/contents/relatedcontents/@count", jdomDocResult, "1"); AssertTool.assertSingleXPathValueEquals( "/contents/relatedcontents/content/@key", jdomDocResult, commonChildContentKey.toString()); }
@Test public void content_queried_with_both_related_child_and_parent_having_related_content_existing_as_the_queried_content_is_still_listed_as_related_content() { // setup: create same content in two different categories ContentKey grandChildContentKey = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Grand child"), "content-creator")); ContentKey sonContentKey = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Son", grandChildContentKey), "content-creator")); ContentKey daughterContentKey = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Daughter"), "content-creator")); ContentKey fatherContentKey = contentService.createContent( createCreateContentCommand( "MyCategory", createMyRelatedContentData("Father", sonContentKey, daughterContentKey), "content-creator")); fixture.flushIndexTransaction(); // setup: verify that the content was created assertEquals(4, fixture.countAllContent()); // exercise DataSourceContext context = new DataSourceContext(); context.setUser(fixture.findUserByName("content-querier")); String query = "categorykey = " + fixture.findCategoryByName("MyCategory").getKey(); String orderyBy = "@key desc"; int index = 0; int count = 10; boolean includeData = true; int childrenLevel = 10; int parentLevel = 10; XMLDocument xmlDocResult = dataSourceService.getContentByQuery( context, query, orderyBy, index, count, includeData, childrenLevel, parentLevel, null); // verify Document jdomDocResult = xmlDocResult.getAsJDOMDocument(); AssertTool.assertSingleXPathValueEquals("/contents/@totalcount", jdomDocResult, "4"); AssertTool.assertXPathEquals( "/contents/content/@key", jdomDocResult, fatherContentKey.toString(), daughterContentKey.toString(), sonContentKey.toString(), grandChildContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[title = 'Father']/relatedcontentkeys/relatedcontentkey [@level = 1]/@key", jdomDocResult, sonContentKey.toString(), daughterContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[title = 'Daughter']/relatedcontentkeys/relatedcontentkey[@level = -1]/@key", jdomDocResult, fatherContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[title = 'Son']/relatedcontentkeys/relatedcontentkey[@level = -1]/@key", jdomDocResult, fatherContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[title = 'Son']/relatedcontentkeys/relatedcontentkey[@level = 1]/@key", jdomDocResult, grandChildContentKey.toString()); AssertTool.assertXPathEquals( "/contents/content[title = 'Grand child']/relatedcontentkeys/relatedcontentkey[@level = -1]/@key", jdomDocResult, sonContentKey.toString()); AssertTool.assertSingleXPathValueEquals("/contents/relatedcontents/@count", jdomDocResult, "4"); AssertTool.assertXPathEquals( "/contents/relatedcontents/content/@key", jdomDocResult, grandChildContentKey.toString(), sonContentKey.toString(), daughterContentKey.toString(), fatherContentKey.toString()); }