public StateItem loadState(String name) throws RulesRepositoryException { try { Node ruleStateNode = this.getAreaNode(STATE_AREA).getNode(name); return new StateItem(this, ruleStateNode); } catch (RepositoryException e) { log.error("Unable to load a status. ", e); throw new RulesRepositoryException("Unable to load a status. ", e); } }
/** Compare this rules state with some other state */ public boolean sameState(StateItem other) { StateItem thisState = getState(); if ( thisState == other ) { return true; } else if ( thisState != null ) { return thisState.equals( other ); } else { return false; } }
/** * Sets this object's rule node's state property to refer to the specified StateItem's node * * @param stateItem the StateItem encapsulating the node to refer to from this object's node's state * property * @throws RulesRepositoryException */ public void updateState(StateItem stateItem) throws RulesRepositoryException { checkIsUpdateable(); try { //now set the state property of the rule checkout(); this.node.setProperty( STATE_PROPERTY_NAME, stateItem.getNode() ); } catch ( Exception e ) { log.error( "Caught exception", e ); throw new RulesRepositoryException( e ); } }
@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 } } /*
/** * Sets this object's rule node's state property to refer to the specified StateItem's node * * @param stateItem the StateItem encapsulating the node to refer to from this object's node's state * property * @throws RulesRepositoryException */ public void updateState(StateItem stateItem) throws RulesRepositoryException { checkIsUpdateable(); try { //now set the state property of the rule checkout(); this.node.setProperty( STATE_PROPERTY_NAME, stateItem.getNode() ); } catch ( Exception e ) { log.error( "Caught exception", e ); throw new RulesRepositoryException( e ); } }
public StateItem loadState(String name) throws RulesRepositoryException { try { Node ruleStateNode = this.getAreaNode(STATE_AREA).getNode(name); return new StateItem(this, ruleStateNode); } catch (RepositoryException e) { log.error("Unable to load a status. ", e); throw new RulesRepositoryException("Unable to load a status. ", 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); } }
/** Compare this rules state with some other state */ public boolean sameState(StateItem other) { StateItem thisState = getState(); if ( thisState == other ) { return true; } else if ( thisState != null ) { return thisState.equals( other ); } else { return false; } }
public String toString() { return "Current status: [" + getName() + "] (" + super.toString() + ")"; }
/** * @return A list of statii in the system. */ public StateItem[] listStates() { List<StateItem> states = new ArrayList<StateItem>(); try { NodeIterator it = this.getAreaNode(STATE_AREA).getNodes(); while (it.hasNext()) { states.add(new StateItem(this, it.nextNode())); } } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } return states.toArray(new StateItem[states.size()]); }
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 int hashCode() { return getName().hashCode(); }
/** * @return A list of statii in the system. */ public StateItem[] listStates() { List<StateItem> states = new ArrayList<StateItem>(); try { NodeIterator it = this.getAreaNode(STATE_AREA).getNodes(); while (it.hasNext()) { states.add(new StateItem(this, it.nextNode())); } } catch (RepositoryException e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } return states.toArray(new StateItem[states.size()]); }
/** * Finds the AssetItem's linked to the requested state. Similar to finding * by category. * * @param filter an AssetItem filter */ public AssetItemPageResult findAssetsByState(String stateName, boolean seekArchivedAsset, int skip, int numRowsToReturn, RepositoryFilter filter) throws RulesRepositoryException { StateItem item = this.getState(stateName); try { return loadLinkedAssets(seekArchivedAsset, skip, numRowsToReturn, item.getNode(), filter); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
public int hashCode() { return getName().hashCode(); }
/** * Create a status node of the given name. */ public StateItem createState(String name) { try { Node folderNode = this.getAreaNode(STATE_AREA); String nodePath = NodeUtils.makeJSR170ComplaintName(name); Node stateNode = RulesRepository.addNodeIfNew(folderNode, nodePath, StateItem.STATE_NODE_TYPE_NAME); log.debug("Created the status [" + name + "] at [" + nodePath + "]"); return new StateItem(this, stateNode); } catch (Exception e) { log.error(e.getMessage(), e); throw new RulesRepositoryException(e); } }
/** * Finds the AssetItem's linked to the requested state. Similar to finding * by category. * * @param filter an AssetItem filter */ public AssetItemPageResult findAssetsByState(String stateName, boolean seekArchivedAsset, int skip, int numRowsToReturn, RepositoryFilter filter) throws RulesRepositoryException { StateItem item = this.getState(stateName); try { return loadLinkedAssets(seekArchivedAsset, skip, numRowsToReturn, item.getNode(), filter); } catch (RepositoryException e) { throw new RulesRepositoryException(e); } }
public String toString() { return "Current status: [" + getName() + "] (" + super.toString() + ")"; }