[rules-users] Creating custom selectors using the "category" property for deploying certain rules in guvnor

Jaroslaw Kijanowski kijanowski at gmail.com
Mon Jul 6 09:17:43 EDT 2009


Have a look at this class:
drools-repository/src/test/java/org/drools/repository/AssetItemTest.java

The doc in the selectors.properties file is talking about properties of 
AssetItem - however, don't take it literally - a rule uses a getter, 
hence it's sufficient to have such a method in the AssetItem class 
instead of a regular field. So if you see a getStateDescription method 
you can use stateDescription - that's at least my understanding.

So looking at AssetItem and VersionableItem I see following candidates 
for a selector:
name
createdDate
versionNumber
creator
lastContributor
checkinComment
categories (java.util.List)
categorySummary (space separated string of categories)
precedingVersion
format
stateDescription
lastModified
dateEffective
dateExpired
description
succeedingVersion
content
title
disabled

Let's get back to your original question (I've answered it already in jira):
Try this out:
package org.drools.guvnor.server.selector

import org.drools.repository.AssetItem
import org.drools.repository.CategoryItem
import org.drools.guvnor.server.selector.Allow


rule 'select all rules assigned to myCategory'
dialect 'mvel'
when
   ai : AssetItem()
   CategoryItem(name == "myCategory") from ai.categories
then
   insert (new Allow( ) );
end


Cheers,
  Jarek

Premkumar Stephen wrote:
> Hi Jaroslaw,
> 
> 
> I voted for https://jira.jboss.org/jira/browse/GUVNOR-109
> and added the following comment:
> <<
> +1 for this request.
> The ability for users to choose among which selectors are available is 
> awesome.
> 
> Here's an extra requirement that I am bringing forward, not sure what 
> the complexity on this is:
> The list will be populated based on user permissions of some kind.
> ie, not all the users can deploy production rules, but all can deploy QA 
> rules, for example.
>  >>
> 
> I have also created https://jira.jboss.org/jira/browse/GUVNOR-392 for 
> including categories as a field for filtering.
> 
> Regarding your tip on using the 'status' field, I was planning for the 
> workaround, though it messes with the actual value of this field which i 
> was planning to use.
> Based on our environment, we might actually use the "author" field as 
> currently there will not be many authors and we are tracking 
> functionality by using categories anyways.
> 
> I have the following questions that are still unanswered:
> 1) I am trying to figure out where the code for "statusDescription" is?
> 2) You have suggested 'categorySummary'  - was wondering where these 
> fields are configured.
> 3) the minimal documentation in selectors.properties tells only about 
> the fields status, lastModified date and author, and ends with etc. 
> Could one of the devs kindly post ALL the fields that could be used?
> 
> Regards,
> Prem
> 
> 
> On Wed, Jul 1, 2009 at 1:03 PM, Jaroslaw Kijanowski 
> <kijanowski at gmail.com <mailto:kijanowski at gmail.com>> wrote:
> 
>     Hi,
>      you may vote for this one ;)
>     https://jira.jboss.org/jira/browse/GUVNOR-109
> 
>     So far I have successfully used 'stateDescription' and 'creator',
>     for sample rules look at this:
>     https://jira.jboss.org/jira/browse/GUVNOR-108
> 
>     Haven't tried to select by category - how about 'categorySummary'?
> 
>     Cheers,
>      Jarek
> 
>     Premkumar Stephen wrote:
> 
>         Hello everyone,
> 
>         I am trying to create a custom selector, based on certain
>         properties such as "categories" (primary property) and others
>         such as status and author.
> 
>         from the examples in selectors.properties, I could not see a way
>         to create using categories. In that file, some of the field
>         described are statusDescription, lastModified, creator, etc
>         I was trying to find the complete list of all fields that could
>         be used to filter the rules.
> 
>         I dug into the code and came across "categoryReference" in
>         VersionableItem.java. Is this the variable that stores the category?
>         Since a rule can have multiple categories, how does this pan
>         out? Is this a Collection?
> 
>         Also, where does the string "statusDescription" get tied in to
>         the status of a rule? This one throws me off, since it is a
>         valid field, but I cannot understand how it is being set.
> 
>         If any of you could share examples where you have done custom
>         selectors either in java or in drl, that would be awesome.
> 
>         Thanks,
>         Prem
> 
> 
>         ------------------------------------------------------------------------
> 
>         _______________________________________________
>         rules-users mailing list
>         rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>         https://lists.jboss.org/mailman/listinfo/rules-users
> 
>     _______________________________________________
>     rules-users mailing list
>     rules-users at lists.jboss.org <mailto:rules-users at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/rules-users
> 
> 



More information about the rules-users mailing list