/** The root node of the repository */ public static Node getRootNode(RulesRepository repo) throws RepositoryException { Session session = repo.getSession(); Node rootNode = session.getRootNode(); return rootNode.getNode(RulesRepository.RULES_REPOSITORY_NAME); }
/** The root node of the repository */ public static Node getRootNode(RulesRepository repo) throws RepositoryException { Session session = repo.getSession(); Node rootNode = session.getRootNode(); return rootNode.getNode(RulesRepository.RULES_REPOSITORY_NAME); }
public boolean needsMigration(RulesRepository repo) throws RepositoryException { Node root = repo.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME); return !root.hasNode("drools.package.migrated"); }
public boolean needsMigration(RulesRepository repo) throws RepositoryException { Node root = repo.getSession().getRootNode().getNode(RulesRepository.RULES_REPOSITORY_NAME); return !root.hasNode("drools.package.migrated"); }
private String getCurrentUserName() { return this.rulesRepository.getSession().getUserID(); } }
private String getCurrentUserName() { return this.rulesRepository.getSession().getUserID(); } }
public void removeWorkspace(String workspace) { try { Node schemaNode = addNodeIfNew(this.session.getRootNode().getNode(RULES_REPOSITORY_NAME), SCHEMA_AREA, "nt:folder"); Node workspaceAreaNode = addNodeIfNew(schemaNode, WORKSPACE_AREA, "nt:folder"); Node workspaceNode = workspaceAreaNode.getNode(workspace); workspaceNode.remove(); this.getSession().save(); } catch (Exception e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * Use the current sessions userName to get to the info node. */ public UserInfo(RulesRepository repo) throws RulesRepositoryException { try { init(repo, repo.getSession().getUserID()); } catch (RepositoryException e) { log.error("Unable to init UserInfo", e); throw new RulesRepositoryException(e); } }
/** * Use the current sessions userName to get to the info node. */ public UserInfo(RulesRepository repo) throws RulesRepositoryException { try { init(repo, repo.getSession().getUserID()); } catch (RepositoryException e) { log.error("Unable to init UserInfo", e); throw new RulesRepositoryException(e); } }
public void removeWorkspace(String workspace) { try { Node schemaNode = addNodeIfNew(this.session.getRootNode().getNode(RULES_REPOSITORY_NAME), SCHEMA_AREA, "nt:folder"); Node workspaceAreaNode = addNodeIfNew(schemaNode, WORKSPACE_AREA, "nt:folder"); Node workspaceNode = workspaceAreaNode.getNode(workspace); workspaceNode.remove(); this.getSession().save(); } catch (Exception e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * This will create a child category under this one */ public CategoryItem addCategory(String name, String description) { try { String nodePath = NodeUtils.makeJSR170ComplaintName(name); Node child = this.node.addNode(nodePath, CategoryItem.TAG_NODE_TYPE_NAME); this.rulesRepository.getSession().save(); return new CategoryItem(this.rulesRepository, child); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RulesRepositoryException(e); } } }
/** * This will create a child category under this one */ public CategoryItem addCategory(String name, String description) { try { String nodePath = NodeUtils.makeJSR170ComplaintName(name); Node child = this.node.addNode(nodePath, CategoryItem.TAG_NODE_TYPE_NAME); this.rulesRepository.getSession().save(); return new CategoryItem(this.rulesRepository, child); } catch (Exception e) { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RulesRepositoryException(e); } } }
/** * Gets StateItem object corresponding to the state property of this object's node * * @return a StateItem object corresponding to the state property of this object's node, or null * if the state property is not set * @throws RulesRepositoryException */ public StateItem getState() throws RulesRepositoryException { try { Node content = getVersionContentNode(); Property stateProperty = content.getProperty( STATE_PROPERTY_NAME ); Node stateNode = this.rulesRepository.getSession().getNodeByIdentifier( stateProperty.getString() ); return new StateItem( this.rulesRepository, stateNode ); } catch ( PathNotFoundException e ) { //not set return null; } catch ( Exception e ) { log.error( "Caught exception", e ); throw new RulesRepositoryException( e ); } }
private void findAndPrintNodeName(Node node) throws ValueFormatException, PathNotFoundException, RepositoryException { String UUID = node.getProperty("jcr:baseVersion").getString(); Node nodeFound = getRepo().getSession().getNodeByUUID(UUID); System.out.println("Node:" + nodeFound.getName()); }
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."); } }
@Test public void testSimpleImportExport() throws PathNotFoundException, IOException, RepositoryException { RulesRepository repo = getRepo(); byte[] repository_backup; ByteArrayOutputStream bout = new ByteArrayOutputStream(); Session session = getRepo().getSession(); session.refresh( false ); session.exportSystemView( "/" + "drools:repository", bout, false, false ); repository_backup = bout.toByteArray(); repo.importRulesRepositoryFromStream(new ByteArrayInputStream( repository_backup)); }
@Test public void testDefaultPackage() throws Exception { RulesRepository repo = getRepo(); Iterator it = repo.listModules(); boolean foundDefault = false; while ( it.hasNext() ) { ModuleItem item = (ModuleItem) it.next(); if ( item.getName().equals( RulesRepository.DEFAULT_PACKAGE ) ) { foundDefault = true; } } assertTrue( foundDefault ); ModuleItem def = repo.loadDefaultModule(); assertNotNull( def ); assertEquals( RulesRepository.DEFAULT_PACKAGE, def.getName() ); String userId = repo.getSession().getUserID(); assertNotNull( userId ); assertFalse( userId.equals( "" ) ); MigrateDroolsPackage mig = new MigrateDroolsPackage(); assertFalse( mig.needsMigration( repo ) ); assertTrue( repo.initialized ); }
@Test public void testSaveAndCheckinDescriptionAndTitle() throws Exception { AssetItem ruleItem1 = getRepo().loadDefaultModule().addAsset("testGetDescription", ""); ruleItem1.checkin( "version0" ); //it should be "" to begin with assertEquals("", ruleItem1.getDescription()); ruleItem1.updateDescription("test description"); assertEquals("test description", ruleItem1.getDescription()); assertTrue(getRepo().getSession().hasPendingChanges()); ruleItem1.updateTitle( "This is a title" ); assertTrue(getRepo().getSession().hasPendingChanges()); ruleItem1.checkin( "ya" ); //we can save without a checkin getRepo().getSession().save(); assertFalse(getRepo().getSession().hasPendingChanges()); try { ruleItem1.getPrecedingVersion().updateTitle( "baaad" ); fail("should not be able to do this"); } catch (RulesRepositoryException e) { assertNotNull(e.getMessage()); } }
@Test public void testShareableNodesWithQuery() throws Exception { RulesRepository repo = getRepo(); AssetItem item = repo.loadGlobalArea().addAsset("testShareableNodesWithQueryOriginal", "desc"); item.updateFormat("xyz"); item.getNode().addMixin("mix:shareable"); ModuleItem source = repo.createModule("testShareableNodesWithQueryPackage", "desc"); repo.save(); AssetItemIterator it = repo.loadGlobalArea().queryAssets( "drools:format='xyz'" ); List list = iteratorToList( it ); assertEquals(1, list.size()); assertTrue(list.get( 0 ) instanceof AssetItem); source.checkout(); Session session = repo.getSession(); Workspace workspace = session.getWorkspace(); String path = "/drools:repository/drools:package_area/testShareableNodesWithQueryPackage/assets/testShareableNodesWithQueryShared"; workspace.clone(workspace.getName(), item.getNode().getPath(), path, false); repo.save(); AssetItem originalItem = repo.loadGlobalArea().loadAsset("testShareableNodesWithQueryOriginal"); AssetItem sharedItem = repo.loadModule("testShareableNodesWithQueryPackage").loadAsset("testShareableNodesWithQueryShared"); assertTrue( originalItem.getFormat().equals("xyz")); assertTrue( sharedItem.getFormat().equals("xyz")); it = repo.loadGlobalArea().queryAssets( "drools:format='xyz'" ); list = iteratorToList( it ); assertEquals(1, list.size()); assertTrue(list.get( 0 ) instanceof AssetItem); }
@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(); }