/** * Rename a category. * * @param originalPath The full path to the category. * @param newName The new name (just the name, not the path). */ public void renameCategory(String originalPath, String newName) { try { Node node = loadCategory(originalPath).getNode(); String sourcePath = node.getPath(); String destPath = node.getParent().getPath() + "/" + newName; this.session.move(sourcePath, destPath); save(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * Rename a category. * * @param originalPath The full path to the category. * @param newName The new name (just the name, not the path). */ public void renameCategory(String originalPath, String newName) { try { Node node = loadCategory(originalPath).getNode(); String sourcePath = node.getPath(); String destPath = node.getParent().getPath() + "/" + newName; this.session.move(sourcePath, destPath); save(); } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * This will retrieve a list of RuleItem objects - that are allocated to the * provided category. Only the latest versions of each RuleItem will be * returned (you will have to delve into the assets deepest darkest history * yourself... mahahahaha). * <p/> * Pass in startRow of 0 to start at zero, numRowsToReturn can be set to -1 * should you want it all. * * @param filter an AssetItem filter */ public AssetItemPageResult findAssetsByCategory(String categoryTag, boolean seekArchivedAsset, int skip, int numRowsToReturn, RepositoryFilter filter) throws RulesRepositoryException { CategoryItem item = this.loadCategory(categoryTag); try { return loadLinkedAssets(seekArchivedAsset, skip, numRowsToReturn, item.getNode(), filter); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
/** * This method sets the categories in one hit, making the * ASSUMPTION that the categories were previously set up ! * (via CategoryItem of course !). */ public void updateCategoryList(String[] categories) { this.checkIsUpdateable(); try { Value[] newCats = new Value[categories.length]; for ( int i = 0; i < categories.length; i++ ) { CategoryItem item = this.rulesRepository.loadCategory( categories[i] ); newCats[i] = this.node.getSession().getValueFactory().createValue( item.getNode() ); } updateCategories( newCats ); } catch ( RepositoryException e ) { throw new RulesRepositoryException(e); } }
/** * This method sets the categories in one hit, making the * ASSUMPTION that the categories were previously set up ! * (via CategoryItem of course !). */ public void updateCategoryList(String[] categories) { this.checkIsUpdateable(); try { Value[] newCats = new Value[categories.length]; for ( int i = 0; i < categories.length; i++ ) { CategoryItem item = this.rulesRepository.loadCategory( categories[i] ); newCats[i] = this.node.getSession().getValueFactory().createValue( item.getNode() ); } updateCategories( newCats ); } catch ( RepositoryException e ) { throw new RulesRepositoryException(e); } }
@Test public void testTagItem() throws Exception { final CategoryItem root = getRepo().loadCategory("/"); root.addCategory("TestTag", "nothing to see"); CategoryItem tagItem1 = getRepo().loadCategory("TestTag"); assertNotNull(tagItem1); assertEquals("TestTag", tagItem1.getName()); CategoryItem tagItem2 = getRepo().loadCategory("TestTag"); assertNotNull(tagItem2); assertEquals("TestTag", tagItem2.getName()); assertEquals(tagItem1, tagItem2); List originalCats = getRepo().loadCategory("/").getChildTags(); // listCategoryNames(); assertTrue(originalCats.size() > 0); CategoryItem rootCat = (CategoryItem)originalCats.get(0); assertNotNull(rootCat.getName()); assertNotNull(rootCat.getFullPath()); root.addCategory("FootestTagItem", "nothing"); List cats = root.getChildTags(); assertEquals(originalCats.size() + 1, cats.size()); boolean found = false; for (Iterator iter = cats.iterator(); iter.hasNext();) { CategoryItem element = (CategoryItem)iter.next(); if (element.getName().equals("FootestTagItem")) { found = true; break; } } assertTrue(found); }
@Test public void testUpdateCategories() { getRepo().loadCategory( "/" ).addCategory( "testUpdateCategoriesOnAsset", "la" ); getRepo().loadCategory( "/" ).addCategory( "testUpdateCategoriesOnAsset2", "la" ); AssetItem item = getRepo().loadDefaultModule().addAsset( "testUpdateCategoriesOnAsset", "huhuhu" ); String[] cats = new String[] {"testUpdateCategoriesOnAsset", "testUpdateCategoriesOnAsset2"}; item.updateCategoryList( cats ); item.checkin( "aaa" ); item = getRepo().loadDefaultModule().loadAsset( "testUpdateCategoriesOnAsset" ); assertEquals(2, item.getCategories().size()); for ( Iterator iter = item.getCategories().iterator(); iter.hasNext(); ) { CategoryItem cat = (CategoryItem) iter.next(); assertTrue(cat.getName().startsWith( "testUpdateCategoriesOnAsset" )); } }
@Test public void testGetTags() { AssetItem ruleItem1 = getDefaultPackage().addAsset("testGetTags", "test content"); List tags = ruleItem1.getCategories(); assertNotNull(tags); assertEquals(0, tags.size()); getRepo().loadCategory( "/" ).addCategory( "testGetTagsTestTag", "description" ); ruleItem1.addCategory("testGetTagsTestTag"); tags = ruleItem1.getCategories(); assertEquals(1, tags.size()); assertEquals("testGetTagsTestTag", ((CategoryItem)tags.get(0)).getName()); }
@Test public void testRemoveTag() { AssetItem ruleItem1 = getDefaultPackage().addAsset("testRemoveTag", "test content"); getRepo().loadCategory( "/" ).addCategory( "TestRemoveCategory", "description" ); ruleItem1.addCategory("TestRemoveCategory"); List tags = ruleItem1.getCategories(); assertEquals(1, tags.size()); ruleItem1.removeCategory("TestRemoveCategory"); tags = ruleItem1.getCategories(); assertEquals(0, tags.size()); getRepo().loadCategory( "/" ).addCategory( "TestRemoveCategory2", "description" ); getRepo().loadCategory( "/" ).addCategory( "TestRemoveCategory3", "description" ); ruleItem1.addCategory("TestRemoveCategory2"); ruleItem1.addCategory("TestRemoveCategory3"); ruleItem1.removeCategory("TestRemoveCategory2"); tags = ruleItem1.getCategories(); assertEquals(1, tags.size()); assertEquals("TestRemoveCategory3", ((CategoryItem)tags.get(0)).getName()); }
@Test public void testRemoveCategoryLinkedWithArchived() { RulesRepository repo = getRepo(); repo.loadCategory("/").addCategory("testRemoveCategoryWithArchivedCat", "a"); AssetItem as = repo.loadDefaultModule().addAsset("testRemoveCategoryWithArchivedAsset", "a", "testRemoveCategoryWithArchivedCat", "drl"); as.checkin("a"); as.archiveItem(true); repo.loadCategory("testRemoveCategoryWithArchivedCat").remove(); repo.save(); as.remove(); } /**
@Test public void testRemoveCategoryUneeded() { RulesRepository repo = getRepo(); repo.loadCategory("/").addCategory("testRemoveCat", "a"); AssetItem as = repo.loadDefaultModule().addAsset("testRemoveCategory", "a", "testRemoveCat", "drl"); as.checkin("a"); as.updateCategoryList(new String[] {}); as.checkin("a"); as = repo.loadDefaultModule().loadAsset("testRemoveCategory"); assertEquals(0, as.getCategories().size()); repo.loadCategory("testRemoveCat").remove(); repo.save(); }
@Test public void testCreateCateories() throws Exception { RulesRepository repo = getRepo(); // load the root CategoryItem root = repo.loadCategory("/"); CategoryItem item = root.addCategory("testCreateCategories", "this is a top level one"); assertEquals("testCreateCategories", item.getName()); assertEquals("testCreateCategories", item.getFullPath()); item = repo.loadCategory("testCreateCategories"); assertEquals("testCreateCategories", item.getName()); item.remove(); repo.save(); try { repo.loadCategory("testCreateCategories"); fail("this should not exist"); } catch (RulesRepositoryException e) { assertNotNull(e.getCause()); } }
@Test public void testUpdateCategoriesForShareableAsset() { getRepo().loadCategory("/").addCategory("testUpdateCategoriesForShareableAssetTag1", "la"); getRepo().loadCategory("/").addCategory("testUpdateCategoriesForShareableAssetTag2", "la"); AssetItem asset = getRepo().loadGlobalArea().addAsset("testUpdateCategoriesForShareableAsset", "desc"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); String[] cats = new String[] {"testUpdateCategoriesForShareableAssetTag1", "testUpdateCategoriesForShareableAssetTag2"}; linkedAsset.updateCategoryList(cats); linkedAsset.checkin("aaa"); asset = getRepo().loadGlobalArea().loadAsset("testUpdateCategoriesForShareableAsset"); assertEquals(2, asset.getCategories().size()); for (Iterator iter = asset.getCategories().iterator(); iter.hasNext();) { CategoryItem cat = (CategoryItem)iter.next(); assertTrue(cat.getName().startsWith("testUpdateCategoriesForShareableAssetTag")); } }
@Test public void testFindRulesByCategory() throws Exception { getRepo().loadCategory( "/" ).addCategory( "testFindRulesByCat", "yeah" ); AssetItem as1 = getDefaultPackage().addAsset( "testFindRulesByCategory1", "ya", "testFindRulesByCat", "drl" ); getDefaultPackage().addAsset( "testFindRulesByCategory2", "ya", "testFindRulesByCat", AssetItem.DEFAULT_CONTENT_FORMAT ).checkin( "version0" ); as1.checkin( "version0" ); assertEquals("drl", as1.getFormat()); List rules = getRepo().findAssetsByCategory( "testFindRulesByCat", 0, -1 ).assets; assertEquals(2, rules.size()); for ( Iterator iter = rules.iterator(); iter.hasNext(); ) { AssetItem element = (AssetItem) iter.next(); assertTrue(element.getName().startsWith( "testFindRulesByCategory" )); } try { getRepo().loadCategory( "testFindRulesByCat" ).remove(); fail("should not be able to remove"); } catch (RulesRepositoryException e) { //assertTrue(e.getCause() instanceof ReferentialIntegrityException); assertNotNull(e.getMessage()); } }
@Test public void testGetChildTags() { final CategoryItem root = getRepo().loadCategory("/"); root.addCategory("TestTag", "nothing to see"); CategoryItem tagItem1 = getRepo().loadCategory("TestTag"); assertNotNull(tagItem1); assertEquals("TestTag", tagItem1.getName()); List childTags = tagItem1.getChildTags(); assertNotNull(childTags); assertEquals(0, childTags.size()); tagItem1.addCategory("TestChildTag1", "description"); childTags = tagItem1.getChildTags(); assertNotNull(childTags); assertEquals(1, childTags.size()); assertEquals("TestChildTag1", ((CategoryItem)childTags.get(0)).getName()); tagItem1.addCategory("AnotherChild", "ignore me"); childTags = tagItem1.getChildTags(); assertNotNull(childTags); assertEquals(2, childTags.size()); }
@Test public void testRemoveTagForShareableAsset() { getRepo().loadCategory("/").addCategory("testRemoveTagForShareableAssetTag1", "la"); getRepo().loadCategory("/").addCategory("testRemoveTagForShareableAssetTag2", "description"); getRepo().loadCategory("/").addCategory("testRemoveTagForShareableAssetTag3", "description"); AssetItem asset = getRepo().loadGlobalArea().addAsset("testRemoveTagForShareableAsset", "desc"); AssetItem linkedAsset = getDefaultPackage().addAssetImportedFromGlobalArea(asset.getName()); getRepo().loadCategory("testRemoveTagForShareableAssetTag2").remove(); fail("should not be able to remove"); } catch (RulesRepositoryException e) {
@Test public void testGetChildTag() { CategoryItem root = getRepo().loadCategory("/"); CategoryItem tagItem1 = root.addCategory("testGetChildTag", "yeah"); assertNotNull(tagItem1); assertEquals("testGetChildTag", tagItem1.getName()); // test that child is added if not already in existence List childTags = tagItem1.getChildTags(); assertNotNull(childTags); assertEquals(0, childTags.size()); CategoryItem childTagItem1 = tagItem1.addCategory("TestChildTag1", "woo"); assertNotNull(childTagItem1); assertEquals("TestChildTag1", childTagItem1.getName()); // test that if already there, it is returned CategoryItem childTagItem2 = getRepo().loadCategory("testGetChildTag/TestChildTag1"); assertNotNull(childTagItem2); assertEquals("TestChildTag1", childTagItem2.getName()); assertEquals(childTagItem1, childTagItem2); }
@Test public void testGetTag() { RulesRepository rulesRepository = getRepo(); CategoryItem root = rulesRepository.loadCategory( "/" ); CategoryItem tagItem1 = root.addCategory( "testGetTag", "ho" ); assertNotNull( tagItem1 ); assertEquals( "testGetTag", tagItem1.getName() ); assertEquals( "testGetTag", tagItem1.getFullPath() ); CategoryItem tagItem2 = rulesRepository.loadCategory( "testGetTag" ); assertNotNull( tagItem2 ); assertEquals( "testGetTag", tagItem2.getName() ); assertEquals( tagItem1, tagItem2 ); //now test getting a tag down in the tag hierarchy CategoryItem tagItem3 = tagItem2.addCategory( "TestChildTag1", "ka" ); assertNotNull( tagItem3 ); assertEquals( "TestChildTag1", tagItem3.getName() ); assertEquals( "testGetTag/TestChildTag1", tagItem3.getFullPath() ); }
@Test public void testFindArchivedAssetsByCategory() { getRepo().loadCategory( "/" ).addCategory( "testFindRulesByCatArchive", "yeah" ); AssetItem as1 = getDefaultPackage().addAsset( "testFindRulesByCategoryArch", "ya", "testFindRulesByCatArchive", "drl" ); getDefaultPackage().addAsset( "testFindRulesByCategoryArch2", "ya", "testFindRulesByCatArchive", AssetItem.DEFAULT_CONTENT_FORMAT ).checkin( "version0" ); as1.archiveItem( true ); as1.checkin( "version0" ); assertEquals( "drl", as1.getFormat() ); List rules = getRepo().findAssetsByCategory( "testFindRulesByCatArchive", 0, -1 ).assets; assertEquals( 1, rules.size() ); List rules1 = getRepo().findAssetsByCategory( "testFindRulesByCatArchive", true, 0, -1 ).assets; assertEquals( 2, rules1.size() ); }
@Test public void testGetFullPath() { CategoryItem root = getRepo().loadCategory("/"); CategoryItem tagItem1 = root.addCategory("testGetFullPath", "foo"); assertNotNull(tagItem1); assertEquals("testGetFullPath", tagItem1.getFullPath()); CategoryItem childTagItem1 = tagItem1.addCategory("TestChildTag1", "foo"); assertNotNull(childTagItem1); assertEquals("testGetFullPath/TestChildTag1", childTagItem1.getFullPath()); CategoryItem childTagItem2 = childTagItem1.addCategory("TestChildTag2", "wee"); assertNotNull(childTagItem2); assertEquals("testGetFullPath/TestChildTag1/TestChildTag2", childTagItem2.getFullPath()); }