public void setDoNotInstallSample() throws RepositoryException { Node rootNode = this.session.getRootNode().getNode(RULES_REPOSITORY_NAME); if (!rootNode.hasNode(DO_NOT_INSTALL_SAMPLE_NODE)) { rootNode.addNode(DO_NOT_INSTALL_SAMPLE_NODE, "nt:folder"); save(); } }
public void setDoNotInstallSample() throws RepositoryException { Node rootNode = this.session.getRootNode().getNode(RULES_REPOSITORY_NAME); if (!rootNode.hasNode(DO_NOT_INSTALL_SAMPLE_NODE)) { rootNode.addNode(DO_NOT_INSTALL_SAMPLE_NODE, "nt:folder"); save(); } }
public void renameState(String oldName, String newName) { try { StateItem state = loadState(oldName); Node node = state.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); } }
public void renameState(String oldName, String newName) { try { StateItem state = loadState(oldName); Node node = state.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); } }
/** * 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); } }
public void migrate(RulesRepository repo) throws RepositoryException { log.info("AUTO MIGRATION: Performing drools.package migration..."); ModuleIterator pkgs = repo.listModules(); boolean performed = false; while(pkgs.hasNext()) { performed = true; ModuleItem pkg = (ModuleItem) pkgs.next(); migratePackage(pkg); String[] snaps = repo.listModuleSnapshots(pkg.getName()); if (snaps != null) { for (int i = 0; i < snaps.length; i++) { ModuleItem snap = repo.loadModuleSnapshot(pkg.getName(), snaps[i]); migratePackage(snap); } } } if (performed) { repo.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME).addNode("drools.package.migrated", "nt:folder"); repo.save(); log.info("AUTO MIGRATION: drools.package migration completed."); } }
public void migrate(RulesRepository repo) throws RepositoryException { log.info("AUTO MIGRATION: Performing drools.package migration..."); ModuleIterator pkgs = repo.listModules(); boolean performed = false; while(pkgs.hasNext()) { performed = true; ModuleItem pkg = (ModuleItem) pkgs.next(); migratePackage(pkg); String[] snaps = repo.listModuleSnapshots(pkg.getName()); if (snaps != null) { for (int i = 0; i < snaps.length; i++) { ModuleItem snap = repo.loadModuleSnapshot(pkg.getName(), snaps[i]); migratePackage(snap); } } } if (performed) { repo.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME).addNode("drools.package.migrated", "nt:folder"); repo.save(); log.info("AUTO MIGRATION: drools.package migration completed."); } }
public void createUser(String userName) { if (!isValideUserName(userName)) { throw new RulesRepositoryException("Invalide user name"); } if (containsUser(userName)) { throw new RulesRepositoryException("User name [" + userName + "] already exists"); } try { Node permsNode = getUserPermissionNode(userName); permsNode.remove(); //remove this so we get a fresh set permsNode = getUserPermissionNode(userName).addNode("jcr:content", "nt:unstructured"); this.rulesRepository.save(); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
public void createUser(String userName) { if (!isValideUserName(userName)) { throw new RulesRepositoryException("Invalide user name"); } if (containsUser(userName)) { throw new RulesRepositoryException("User name [" + userName + "] already exists"); } try { Node permsNode = getUserPermissionNode(userName); permsNode.remove(); //remove this so we get a fresh set permsNode = getUserPermissionNode(userName).addNode("jcr:content", "nt:unstructured"); this.rulesRepository.save(); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
@Test public void testPackageRemove() throws Exception { RulesRepository repo = getRepo(); ModuleItem p = repo.createModule("removeMe", ""); AssetItem a = p.addAsset("Whee", ""); a.updateContent("yeah"); a.checkin("la"); p.addAsset("Waa", ""); repo.save(); ModuleItem pkgNested = p.createSubModule("NestedGoodness"); assertNotNull(pkgNested); int n = iteratorToList(repo.listModules()).size(); p = repo.loadModule("removeMe"); p.remove(); repo.save(); int n_ = iteratorToList(repo.listModules()).size(); assertEquals(n - 1, n_); }
@Test public void testShareableNodes() throws Exception { RulesRepository repo = getRepo(); AssetItem item = repo.loadDefaultModule().addAsset("testShareableNodeOriginal", "desc"); item.updateContent("la"); item.getNode().addMixin("mix:shareable"); ModuleItem source = repo.createModule("testShareableNodesPackage", "desc"); repo.save(); source.checkout(); Session session = repo.getSession(); Workspace workspace = session.getWorkspace(); String path = "/drools:repository/drools:package_area/testShareableNodesPackage/assets/testShareableNodeShared"; workspace.clone(workspace.getName(), item.getNode().getPath(), path, false); repo.save(); AssetItem originalItem = repo.loadDefaultModule().loadAsset("testShareableNodeOriginal"); AssetItem sharedItem = repo.loadModule("testShareableNodesPackage").loadAsset("testShareableNodeShared"); assertTrue( originalItem.getContent().equals("la")); assertTrue( sharedItem.getContent().equals("la")); originalItem.remove(); }
@Test public void testFindByState() throws Exception { RulesRepository repo = getRepo(); ModuleItem pkg = repo.createModule( "testFindByStatePackage", "heheheh" ); AssetItem asset1 = pkg.addAsset( "asset1", "" ); AssetItem asset2 = pkg.addAsset( "asset2", "" ); repo.createState( "testFindByState" ); repo.save(); asset1.updateState( "testFindByState" ); asset2.updateState( "testFindByState" ); asset1.checkin( "" ); asset2.checkin( "" ); AssetItemPageResult result = repo.findAssetsByState( "testFindByState", true, 0, -1 ); assertEquals( 2, result.assets.size() ); }
@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 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 testMiscProperties() { ModuleItem item = getRepo().createModule( "testHeader", "ya" ); updateHeader( "new header", item ); item.updateExternalURI( "boo" ); getRepo().save(); assertEquals("new header", getHeader(item)); item = getRepo().loadModule("testHeader"); assertEquals("new header", getHeader(item)); assertEquals("boo", item.getExternalURI()); }
@Test public void testRemoveState() { RulesRepository repo = getRepo(); StateItem[] items = repo.listStates(); assertTrue( items.length > 0 ); final String name = "stateThatHasALongNameAndWillBeRenamed"; repo.createState( name ); StateItem[] items2 = repo.listStates(); assertEquals( items.length + 1, items2.length ); repo.loadState( name ).remove(); repo.save(); StateItem[] items3 = repo.listStates(); assertEquals( items2.length -1, items3.length ); try { repo.loadState( name ); fail( "Should never be here. Removed state still exists." ); } catch ( RulesRepositoryException e ) { // Works } } /*
@Test public void testIgnoreState() throws Exception { ModuleItem pack = getRepo().createModule( "package testIgnoreState", "foo" ); getRepo().createState( "x" ); AssetItem rule1 = pack.addAsset( "rule number 1", "yeah man" ); rule1.updateState( "x" ); rule1.checkin( "version0" ); AssetItem rule2 = pack.addAsset( "rule number 2", "no way" ); rule2.updateState( "x" ); rule2.checkin( "version0" ); AssetItem rule3 = pack.addAsset( "rule number 3", "yes way" ); getRepo().createState( "disabled" ); rule3.updateState( "disabled" ); rule3.checkin( "version0" ); getRepo().save(); Iterator result = pack.getAssetsWithStatus( getRepo().getState( "x" ), getRepo().getState( "disabled" ) ); List l = iteratorToList( result ); assertEquals(2, l.size()); }
@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 testPackageCheckinConfig() { ModuleItem item = getRepo().createModule( "testPackageCheckinConfig", "description" ); AssetItem rule = item.addAsset( "testPackageCheckinConfig", "w" ); rule.checkin( "goo" ); assertEquals(1, iteratorToList( item.getAssets() ).size()); updateHeader( "la", item ); item.checkin( "woot" ); updateHeader( "we", item ); item.checkin( "gah" ); // PackageItem pre = (PackageItem) item.getPrecedingVersion(); // assertNotNull(pre); // assertEquals("la", getHeader(pre)); AssetItem rule_ = getRepo().loadAssetByUUID( rule.getUUID() ); assertEquals(rule.getVersionNumber(), rule_.getVersionNumber()); item = getRepo().loadModule( "testPackageCheckinConfig"); long v = item.getVersionNumber(); item.updateCheckinComment( "x" ); getRepo().save(); assertEquals(v, item.getVersionNumber()); }