From: <jbo...@li...> - 2006-01-21 01:14:06
|
Author: mic...@jb... Date: 2006-01-20 20:13:52 -0500 (Fri, 20 Jan 2006) New Revision: 2160 Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java Log: added user identity stuff Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java 2006-01-21 01:01:13 UTC (rev 2159) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java 2006-01-21 01:13:52 UTC (rev 2160) @@ -95,7 +95,7 @@ * * This will save the rule as it stands, including any changes. */ - public abstract void checkOutRule(RuleDef rule, String userId); + public abstract void checkOutRule(RuleDef rule); /** * This removes the check out flag. @@ -106,7 +106,7 @@ * This can effectively be "overridden" by either just saving the rule, or passing * in the correct username. It is up to client applications to enforce this behaviour. */ - public abstract void checkInRule(RuleDef rule, String userId); + public abstract void checkInRule(RuleDef rule); /** @@ -115,7 +115,7 @@ * * This will save the attachment as it stands, including any changes. */ - public abstract void checkOutAttachment(RuleSetAttachment attachment, String userId); + public abstract void checkOutAttachment(RuleSetAttachment attachment); /** * This removes the check out flag. @@ -126,7 +126,7 @@ * This can effectively be "overridden" by either just saving the rule, or passing * in the correct username. It is up to client applications to enforce this behaviour. */ - public abstract void checkInAttachment(RuleSetAttachment attachment, String userId); + public abstract void checkInAttachment(RuleSetAttachment attachment); Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java 2006-01-21 01:01:13 UTC (rev 2159) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java 2006-01-21 01:13:52 UTC (rev 2160) @@ -166,17 +166,30 @@ return list; } - public void checkOutRule(RuleDef rule, - String userId) { + public void checkOutRule(RuleDef rule) { + + String userId = getUserId(); if (rule.isCheckedOut()) { - throw new RepositoryException("Rule is already checked out to " + userId); + throw new RepositoryException("Rule is already checked out to " + rule.getCheckedOutBy()); } rule.setCheckedOut(true); rule.setCheckedOutBy(userId); session.update(rule); } - public void checkInRule(RuleDef rule, String userId) { + + + private String getUserId() { + if (this.currentUser == null) { + throw new RepositoryException("No current user context was provided to the repository."); + } + String userId = this.currentUser.getName(); + return userId; + } + + public void checkInRule(RuleDef rule) { + String userId = getUserId(); + if (!userId.equals(rule.getCheckedOutBy())) { throw new RepositoryException("Unable to check in the rule, as it is currently checked out by " + rule.getCheckedOutBy()); } @@ -185,10 +198,10 @@ session.update(rule); } - public void checkOutAttachment(RuleSetAttachment attachment, - String userId) { + public void checkOutAttachment(RuleSetAttachment attachment) { + String userId = getUserId(); if (attachment.isCheckedOut()) { - throw new RepositoryException("Rule is already checked out to " + userId); + throw new RepositoryException("Rule is already checked out to " + attachment.getCheckedOutBy()); } attachment.setCheckedOut(true); attachment.setCheckedOutBy(userId); @@ -196,8 +209,8 @@ } - public void checkInAttachment(RuleSetAttachment attachment, - String userId) { + public void checkInAttachment(RuleSetAttachment attachment) { + String userId = getUserId(); if (!userId.equals(attachment.getCheckedOutBy())) { throw new RepositoryException("Unable to check in the attachment, as it is currently checked out by " + attachment.getCheckedOutBy()); } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-21 01:01:13 UTC (rev 2159) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-21 01:13:52 UTC (rev 2160) @@ -83,13 +83,10 @@ /** * Adds a rule to the ruleset. * If the rule has already been saved, then it will be copied for this ruleset. - * (the rulesetname will be prepended to the rule name to keep it unique). * - * ie: rulesetName:originalRuleName - * - * (if you don't like that, then copy() the rule before adding it). + * If a rule is new, obviously there is no copying. * - * If a rule is new, obviously there is no copying, and the name is "as is". + * The owningRuleSetName property is set to the name of this ruleset. * * @return The rule that was just added (which may be a copy). */ Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java 2006-01-21 01:01:13 UTC (rev 2159) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java 2006-01-21 01:13:52 UTC (rev 2160) @@ -1,5 +1,6 @@ package org.drools.repository; +import java.security.Principal; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -188,7 +189,7 @@ assertEquals(2, ruleSet.getAttachments().size()); repo.close(); - repo = RepositoryFactory.getStatefulRepository(); + repo = RepositoryFactory.getRepository(new MockUser("Michael"), false); //now with a new session, lets load up the latest, and add an attachment ruleSet = repo.loadRuleSet("Integration attachments 1", 2); @@ -205,9 +206,9 @@ assertEquals(3, ruleSet.getAttachments().size()); RuleSetAttachment att = (RuleSetAttachment) ruleSet.getAttachments().iterator().next(); - repo.checkOutAttachment(att, "Michael"); + repo.checkOutAttachment(att); assertEquals(true, att.isCheckedOut()); - repo.checkInAttachment(att, "Michael"); + repo.checkInAttachment(att); assertEquals(false, att.isCheckedOut()); repo.close(); @@ -373,4 +374,6 @@ repo.close(); } + + } Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-21 01:01:13 UTC (rev 2159) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-21 01:13:52 UTC (rev 2160) @@ -131,22 +131,28 @@ public void testCheckinOut() { RuleDef rule = new RuleDef("checkin", "some rule"); - RepositoryManager repo = getRepo(); + RepositoryManager repo = RepositoryFactory.getRepository(new MockUser("michael"), false); repo.save(rule); - repo.checkOutRule(rule, "u=Michael.Neale"); + repo.checkOutRule(rule); rule = repo.loadRule("checkin", 1); assertEquals(true, rule.isCheckedOut()); - assertEquals("u=Michael.Neale", rule.getCheckedOutBy()); + assertEquals("michael", rule.getCheckedOutBy()); + repo = RepositoryFactory.getRepository(new MockUser("rohit"), false); + try { - repo.checkInRule(rule, "u=Rohit.Mathur"); + //whoops we cant check it in + repo.checkInRule(rule); } catch (RepositoryException e) { assertNotNull(e.getMessage()); } - repo.checkInRule(rule, "u=Michael.Neale"); + //now we can check it in + repo = RepositoryFactory.getRepository(new MockUser("michael"), false); + + repo.checkInRule(rule); assertEquals(false, rule.isCheckedOut()); } |