Finding the approver for an employee (1) Is this a good problem for rules? (2) How you would do it?
by dc tech
(Note: This was cross-posted earlier to the Jess User Group as well)
We wrote code to solve this problem (described later) many years ago, when I
was not aware of rule based approaches. However, I wonder if a rules based
solution might represent a better approach to solve this problem... and if
so, how would one do it?
*BACKGROUND*
We have departments setup in a hierarchical structure (i.e. parent
departments)
An employee can belong to one and only one department.
An employee can be the manager of one or more departments; a manager may
or not belong to that department.
A department can have many employees and many managers.
*PROBLEM*
Find the approver for an employee's expenses.
An approver is a 'higher level' manager relative to employee in the
organizational hierarchy.
Note that since the manager is employee as well, this includes the problem
of finding the manager of a manager.
*RULES*
1. The approver the nearest manager to the employee (traversing up the
department hierarchy)
Typical cases then are:
- for a non-manager employee, the approver is the manager of the employee's
department
- for a manager who manages a single department and belongs to that
department, the approver is the manager of the parent unit
2. The approver for a manager cannot the manager himself or a peer manager
(in the same department).
3. An approver cannot report to the employee
This sometimes happens when the manager is an employee in one department but
manager for a department a few levels up in the hierarchy
3a. An approver cannot be the peer to someone who reports to the manager
*SAMPLE DATA*
A (manager Hillary)
A1 (manager John and Jane )
A11
A12 (manager Mike; employees John and Mike)
A13
A2 (manager Kate)
A21 (manager Jessica, employee Janet)
A22 (manager Erica, employee Jane)
1. Approver for Janet is Jessica
2. Approver for Jessica is Kate
3.Approver for John is Hillary (cannot be Mike, John himself or Jane)
4. Approver for Jane is Erica via A22 (no reporting relationship).
*ALGORITHMIC SOLUTION*
Define the department reporting vector starting from the employee
department
e.g. for (1) it would be A21 -> A2 -> A and
for (3) it would be A12 -> A1 -> A
Then for each, define managers and then employees
(1) : A21( jessica/ janet ) -> A2: ( Kate) -> A( Hillary)
(2): A12 (Mike/ John, Mike) -> A1 (John, Jane) -> A (Hillary)
Then starting from the top (i.e. A), move down looking for the employee (in
manager or employee list)
If the employee is found in the manager list, approver is the manager of
the parent department
If the employee is found in the employee list, the approver is the manager
of this unit (not the parent)
(I may have missed a few rules in the algorithmic solution)
*RULE BASED SOLUTION?*
Is this a good problem for rule bases solution?
I started to model this and will post my solution if I can come up with
something useful but would absolutely welcome your inputs.
13 years, 10 months
Drl to Xml conversion
by ADITYA CHITRE
Hi,
I am trying to convert a drl file to an xml file using drool xml language. In there a way to convert the drool fusion operators (temporal) from the drl file to an xml equivalent? For eg. the time information (3m30s, 4m) in the fusion temporal operator "before[ 3m30s, 4m ]" is being ignored when the xml conversion is done. Is it possible to preserve this time information using xml drool api's?
Regards,
Aditya
13 years, 10 months
Re: [rules-users] Using GlobalArea in Guvnor
by John Peterson
>Message: 7
>Date: Fri, 10 Dec 2010 09:48:21 -0700
>From: "John Peterson" <john.peterson.gv3k(a)statefarm.com>
>Subject: [rules-users] Using GlobalArea in Guvnor
>To: <rules-users(a)lists.jboss.org>
>Message-ID:
>
<D3A6E68928C9104BB815C83F43A36BDF0EF4EA42(a)WPSCV6NH.OPR.STATEFARM.ORG>
>Content-Type: text/plain; charset="US-ASCII"
>
>Hi,
>
>I'm working with Guvnor 5.1.1 and I'm having an issue accessing
>Declarative Models defined in the Global Area in the Packages. Is it
>possible to create a shared model in the Global Area and then write
>rules against them in other packages? It would seem to me that the
>answer would be yes (why else have a "Global" area), but, for some
>reason, it doesn't seem to recognize them.
>
>Here's a scenario:
>
>I declare a DeclarativeModel in GlobalArea:
>
>GenericFact
> id: Integer
> valueOne: Integer
> label: String
>end
>
>I have a package called com.experiment. I'd like to write Business
Rule
>in it using that GenericFact. However, when I click the "+" sign to
add
>a Fact, I see a yellow background over "Note: No model has been
>defined." Is there something that needs to be done to make the
>GlobalArea stuff viewable from the individual packages?
Follow-up from last Friday: I have not been able to figure out this
situation.
It would appear that I am supposed to "import" my model from my Global
Area into my other packages for use, but whenever I create "New
declarative model" or "Upload POJO Model jar" and then select "Import
asset from global area", there's nothing in the drop down for "Asset to
import". I have 2 Model assets in the global area - one a POJO, the
other a Declarative model. Is there something that needs to be done to
make these "visible" to the other packages? I can't find anything in
the documentation about it.
13 years, 10 months
Problems with BigDecimal on LHS
by Jason Mihalick
I searched on the forum before I posted this and looked in JIRA. It appears
that all problems like this with BigDecimal are thought to be resolved.
However, I am having a problem that appears it may be attributed to Drools
using the BigDecimal( double ) constructor when converting decimal numbers
in the rules to a BigDecimal.
If you are able to reproduce this problem, what is the work around? Use an
eval statement?
The rule does not fire in the following test:
package org.test;
import java.math.BigDecimal;
import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatelessKnowledgeSession;
public class BigDTest {
public final static String RULE =
"package mypackage; " +
"import org.test.BigDTest;" +
"rule \"BigDecimal compare problem\" " +
" when " +
" BigDTest( bigDValue == 6.3 ) " +
" then " +
" System.out.println( \"Matched!\" ); " +
" end"
;
private BigDecimal bigDValue = new BigDecimal( "6.3" ) ; // Rule will fire
if this is changed to BigDecimal( 6.3 )
public BigDecimal getBigDValue() {
return bigDValue;
}
public void setBigDValue( BigDecimal bigDValue ) {
this.bigDValue = bigDValue;
}
public static void main( String[] args ) {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add( ResourceFactory.newByteArrayResource( RULE.getBytes() ),
ResourceType.DRL );
if ( kbuilder.hasErrors() ) {
System.err.println( kbuilder.getErrors().toString() );
}
KnowledgeBase kbase = kbuilder.newKnowledgeBase();
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
BigDTest bigDTest = new BigDTest();
ksession.execute( bigDTest );
}
}
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Problems-with-BigDeci...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
Re: [rules-users] Guvnor - archival option
by Rob Fisher
After further review, I discovered that the rule I was trying to create
did indeed exist in the archival section. I deleted it and was able to
then create the rule with the preferred name.
Sorry to send you on a wild goose chase. I'm very new to this. Every
day is a learning experience.
Rob
Message: 3
Date: Mon, 10 Jan 2011 12:03:10 +0800
From: Jervis Liu <jliu(a)redhat.com>
Subject: Re: [rules-users] Guvnor - archival option
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID: <4D2A84FE.8060805(a)redhat.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
On 2011/1/6 22:39, Rob Fisher wrote:
> I'm using version 5.1.1
>
> I can't find any reference to the rule anywhere in the package, yet it
> seems to be seeing it when trying to create a rule with the same name.
>
Hi, I verified guvnor 5.1.1, still can not reproduce the problem you
reported. If you believe you still have this problem, you can send me a
repository dump with detailed instruction on how to reproduce so that I
can take a further look. Thanks.
Cheers,
Jervis
> Rob Fisher
> Systems Analyst, Agency Awards
> Desk 309-735-4136
> Cell 309-660-4957
>
>
> -----Original Message-----
> From: rules-users-bounces(a)lists.jboss.org
> [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Jervis Liu
> Sent: Thursday, January 06, 2011 1:58 AM
> To: Rules Users List
> Subject: Re: [rules-users] Guvnor - archival option
>
> What version of Guvnor are you using? I am not able to reproduce this
> problem on trunk.
>
> Thanks,
> Jervis
>
> Rob Fisher wrote:
>>
>> I archived a rule, then deleted it within Administration\Archive
>> (using the "Delete selected asset" option). However, when trying to
>> create a rule with the same name, I receive the following message:
>> "An
>
>> asset with that name already exists in the chosen package. Please use
>> another name". I do not see the rule under Archive any longer (since
>> it was deleted). It seems, however, to still be recognized within the
>> repository.
>>
>> Anyone know how to solve this?
>>
>> Thanks
>>
>> Rob Fisher**
>>
>> ---------------------------------------------------------------------
>> -
>> --
Rob Fisher
13 years, 10 months
process-designer deserialization error
by AlfredoLatini
Hi,
i have a problem with oryx process-designer and drools guvnor. I have
created a process with process-designer and i saved it. Then i have opened
this file with eclipse and i uploaded this file in guvnor repository.
I have opened the process in drools guvnor and the following exception
occurred:
The server encountered an internal error () that prevented it from
fulfilling this request.</u></p><p>exception
<pre>javax.servlet.ServletException:
http://localhost:8080/designer/bpmn2_0deserialization
org.drools.guvnor.server.GuvnorAPIServlet.service(GuvnorAPIServlet.java:73)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
How can i fix this problem?
My jboss installation runs on port 8580 because 8080 is busy (oracleXE).
Thanks in advance
Alfredo.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/process-designer-dese...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
Not able to achieve NOT & FROM keyword in a brl through Guvnor
by Harshit Bapna
Hello All,
>From the Expert documentation, I am trying to create the rule(below) in
Guvnor
Guvnor Version : 5.1.1
I am not able to build a rule which has 'from' keyword. Is it supported in
Guvnor ?
Also I am not able to achieve the combination of NOT & FROM in a business
rule.
Is it possible ?
------------------------------------------------------------------------------------
package org.drools;
rule "Avoid NPE on wrong syntax"
when
not( Cheese( ( type == "stilton" && price == 10 ) || ( type == "brie"
&& price == 15 ) ) from $cheeseList )
then
System.out.println("OK");
end
------------------------------------------------------------------------------------
13 years, 10 months
XML to DRL
by T-Otte
Hello,
I know that this error has come up a few times in the past, but i wasn't
able to solve my problem.
I am trying to convert documents from the drools xml format to .drl using
drools 5.1.
The error i am getting is:
(null: 5, 76): schema_reference.4: Failed to read schema document
'drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 5, 76): cvc-elt.1: Cannot find the declaration of element 'package'.
(null: 6, 35): schema_reference.4: Failed to read schema document
'drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
...
Multiple of the example xml documents have been tried, but the error is
always the same. I tried to eliminate uneccessary whitespaces since that was
suggested in one of the previous topics about this issue, but so far to no
avail.
Right now i am using the very simple test_ParseGlobal:
<?xml version="1.0" encoding="UTF-8"?>
<package name="com.sample"
xmlns="http://drools.org/drools-5.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0 drools.org/drools-5.0.xsd">
<import name="java.util.HashMap"/>
<import name="org.drools.*"/>
<global identifier="x" type="com.sample.X"/>
<global identifier="yada" type="com.sample.Yada"/>
</package>
My code to do the transformation is:
PackageBuilderConfiguration conf = new PackageBuilderConfiguration();
XmlPackageReader reader = new XmlPackageReader(conf.getSemanticModules());
DrlDumper dumper = new DrlDumper();
FileReader filereader = new FileReader("test_ParseGlobal.xml");
PackageDescr descr = reader.read(filereader);
String test = dumper.dump(descr);
System.out.println(test);
FileWriter writer = new FileWriter(new File("test_ParseGlobal.drl"));
writer.write(dumper.dump(descr));
writer.flush();
writer.close();
Thank you for your help!
Best regards
Tobias
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/XML-to-DRL-tp2236936p...
Sent from the Drools - User mailing list archive at Nabble.com.
13 years, 10 months
LHS Condition not able to achieve through Guvnor GUI.
by Harshit Bapna
Hello All,
I want to create below LHS condition in a Guvnor BRL rule.
(or
not (exists TransactionInfo())
TransactionInfo(action == null || action == "")
)
I am not able to achieve this though Guvnor.
After setting up an OR prefix, then the NOT option isn’t offered in the drop
down so this condition cannot be authored.
Is it possible ? any suggestions.
I want to avoid the two other approaches :
1. breaking this rule into two rules.
2. Writing a drl.
FYI, I did the testing with the DRL and now I am creating a BRL from the
DRL.
--Harshit
13 years, 10 months
CE "not" not working
by Piyush Goel
Hi,
We have a few rules like the ones given below.
rule "4"
salience 0
dialect "mvel"
when
av1 : AttributeValue( str == "Boys" )
exists InventoryAttribute( attribute == "DIVISION" && value == av1 )
av2 : AttributeValue( str == "Blazer" )
exists InventoryAttribute( attribute == "SUBCATEGORY" && value == av2 )
av3 : AttributeValue( str == "Boys Upper" )
not InventoryAttribute( attribute == "CATEGORY" && value == av3 )
then
VoucherSeries fact0 = new VoucherSeries();
fact0.setSeriesCode( "BUPPER1" );
fact0.setPriority(100);
fact0.setRuleName(drools.getRule().getName());
insert(fact0);
end
The CE "not" is never evaluating to true in the above rule. The "not" CE is
working only for very simple conditions like 'not AttributeValue( str ==
"Blazer")' .
Any idea what are we doing wrong ?
Regards,
piyush
13 years, 10 months