RulePoint
- RulePoint 6.2
- All Products
import java.util.ArrayList; import java.util.List; import com.informatica.cep.wrapper.api.ProjectContext; import com.informatica.cep.wrapper.api.RulePointAPI; import com.informatica.cep.wrapper.dao.query.FilterClause; import com.informatica.cep.wrapper.dao.query.OrderBy; import com.informatica.cep.wrapper.dao.query.PaginatedQuery; import com.informatica.cep.wrapper.dao.query.QueryFilter; import com.informatica.cep.wrapper.error.RulePointException; import com.informatica.cep.wrapper.vo.AccessControlListVO; import com.informatica.cep.wrapper.vo.AccessControlListVOImpl; import com.informatica.cep.wrapper.vo.AccessControlVO; import com.informatica.cep.wrapper.vo.AccessControlVOImpl; import com.informatica.cep.wrapper.vo.Permission; import com.informatica.cep.wrapper.vo.RuleVO; import com.informatica.cep.wrapper.vo.RuleVOImpl; /** * A simple application that performs the following steps: * * 1) Login to RulePoint 2) Create a rule 3) Load a list of rules 4) Logout of * RulePoint */ public class HelloRulePoint { private static String projectName = "Default Project"; public static void main(String[] args) { // Construct a new RulePointAPI that will be initialized with a default // configuration that can be overridden by the contents of // config.properties. RulePointAPI api = new RulePointAPI(); ProjectContext context = null; try { // login user=admin, password=admin, locale=en_US api.login("Administrator", "Administrator1", "en_US"); context = api.getProjectContextByName(projectName); // build a rule to create in RulePoint RuleVO rule = new RuleVOImpl(); // generate a unique name for the rule rule.setName("Hello World rule " + System.currentTimeMillis()); rule.setDescription("This is the first RulePoint rule that I have " + "created using Java"); // IMPORTANT NOTE: The following rule references the "RTAM Alert" response. // Therefore, the RTAM Alert response must exist in RulePoint before we attempt to create this rule; otherwise, a RulePointException will be thrown. rule.setDrql("when 1 news then \"RTAM Alert\""); // This access control grants read permission to the user identified by the unique name 'demo'. AccessControlVO demoAccess = new AccessControlVOImpl(); demoAccess.setPermission(Permission.READ); demoAccess.setGranted(true); demoAccess.setPrincipal("demo"); // Build the access control list AccessControlListVO acl = new AccessControlListVOImpl(); List<AccessControlVO> list = new ArrayList<AccessControlVO>(); // list.add(myAccess); list.add(demoAccess); acl.setEntries(list); rule.setACL(acl); // Create the rule RuleVO savedRule =context.createAdvancedRule(rule); // Default ACL will be created for current user. Get the default created ACLs AccessControlListVO currentUserACL = savedRule.getACL(); AccessControlVO accessControlVO = currentUserACL.getEntries().get(0); System.out.println("Current User Principal from default ACL "+accessControlVO.getPrincipal()); System.out.println("Current User Permission from default ACL "+accessControlVO.getPermission()); System.out.println("Rule is Valid ? "+savedRule.isValid()); System.out.println("Deploy State of the Rule is "+savedRule.getDeployState()); System.out.println("Created rule with ID " + savedRule.getId()); // list up to the first 10 rules, sorted by ascending name. int page = 1; int pageSize = 10; QueryFilter filter = new QueryFilter(); FilterClause clause = new FilterClause("name",FilterClause.OPCODE.STARTS_WITH,"Hello"); ArrayList<FilterClause> clauses = new ArrayList<FilterClause>(); clauses.add(clause); filter.setClauses(clauses); // list all users PaginatedQuery query = new PaginatedQuery(page,pageSize); List<OrderBy> orderBy = new ArrayList<OrderBy>(); OrderBy oneO = new OrderBy("name", OrderBy.DIRECTION.ASCENDING); orderBy.add(oneO); System.out.println("Loading rules"); RuleVO[] allRules = api.getProjectContextByName(projectName).getRuleList(query, filter, orderBy); System.out.println("Loaded " + allRules.length + " rule(s)"); for (RuleVO r : allRules) { System.out.println("id=" + r.getId() + " name=" + r.getName() + " description=" + r.getDescription() + " drql=" + r.getDrql()); } } catch (RulePointException ex) { ex.printStackTrace(System.err); } finally{ try { //destroy project context context.destroy(); // logout RulePoint api.logout(); } catch (RulePointException e) { e.printStackTrace(System.err); } } } }