Package org.drools.rule

Examples of org.drools.rule.ConsequenceMetaData$Statement


      // Set the line item to get LICAs by.
      Long lineItemId = Long.parseLong("INSERT_LINE_ITEM_ID_HERE");

      // Create statement text to select active LICAs for a given line item.
      String statementText = "WHERE lineItemId = :lineItemId and status = :status LIMIT 500";
      Statement filterStatement =
          new StatementBuilder("").putValue("lineItemId", lineItemId).putValue("status",
              LineItemCreativeAssociationStatus.ACTIVE.toString()).toStatement();

      // Set defaults for page and offset.
      LineItemCreativeAssociationPage page = new LineItemCreativeAssociationPage();
      int offset = 0;
      List<Long> creativeIds = new ArrayList<Long>();

      do {
        // Create a statement to page through active LICAs.
        filterStatement.setQuery(statementText + " OFFSET " + offset);

        // Get LICAs by statement.
        page = licaService.getLineItemCreativeAssociationsByStatement(filterStatement);

        if (page.getResults() != null) {
          int i = page.getStartIndex();
          for (LineItemCreativeAssociation lica : page.getResults()) {
            System.out.println(i + ") LICA with line item ID \"" + lica.getLineItemId()
                + "\", creative ID \"" + lica.getCreativeId() + "\", and status \""
                + lica.getStatus() + "\" will be deactivated.");
            creativeIds.add(lica.getCreativeId());
            i++;
          }
        }

        offset += 500;
      } while (offset < page.getTotalResultSetSize());

      System.out.println("Number of LICAs to be deactivated: " + creativeIds.size());

      if (creativeIds.size() > 0) {
        // Modify statement for action.
        filterStatement.setQuery("WHERE lineItemId = :lineItemId and creativeId IN ("
            + StringUtils.join(creativeIds, ",") + ")");

        // Create action.
        DeactivateLineItemCreativeAssociations action =
            new DeactivateLineItemCreativeAssociations();
View Full Code Here


      ActivityGroupServiceInterface activityGroupService =
          user.getService(DfpService.V201311.ACTIVITY_GROUP_SERVICE);

      // Set defaults for page and filterStatement.
      ActivityGroupPage page = new ActivityGroupPage();
      Statement filterStatement = new Statement();
      int offset = 0;

      do {
        // Create a statement to get all activity groups.
        filterStatement.setQuery("LIMIT 500 OFFSET " + offset);

        // Get activity groups by statement.
        page = activityGroupService.getActivityGroupsByStatement(filterStatement);

        if (page.getResults() != null) {
View Full Code Here

    public void testModify() {
        String rule1 = "modify( $a ) { setA( 20 ), setB( $bb ) }";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());
        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment.getType());
        assertEquals("org.drools.A", statment.getFactClassName());

        assertEquals(2, statment.getFields().size());
        ConsequenceMetaData.Field field1 = statment.getFields().get(0);
View Full Code Here

    public void testModify2() {
        String rule1 = "modify( $a ) { setC( $bc ) };\n modify( $b ) { c = \"Hello\" };";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(2, consequenceMetaData.getStatements().size());

        ConsequenceMetaData.Statement statment1 = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment1.getType());
        assertEquals("org.drools.A", statment1.getFactClassName());
        assertEquals(1, statment1.getFields().size());
        ConsequenceMetaData.Field field1 = statment1.getFields().get(0);
        assertEquals("c", field1.getName());
        assertEquals("$bc", field1.getValue());
        assertFalse(field1.isLiteral());

        ConsequenceMetaData.Statement statment2 = consequenceMetaData.getStatements().get(1);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment2.getType());
        assertEquals("org.drools.integrationtests.RuleMetadataTest$B", statment2.getFactClassName());
        assertEquals(1, statment2.getFields().size());
        ConsequenceMetaData.Field field2 = statment2.getFields().get(0);
        assertEquals("c", field2.getName());
View Full Code Here

    public void testRetract() {
        String rule1 = "retract( $b );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());

        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.RETRACT, statment.getType());
        assertEquals("org.drools.integrationtests.RuleMetadataTest$B", statment.getFactClassName());
    }
View Full Code Here

    public void testRetractWithFunction() {
        String rule1 = "retract( getA($a) );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());

        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.RETRACT, statment.getType());
        assertEquals("org.drools.A", statment.getFactClassName());
    }
View Full Code Here

    public void testUpdate() {
        String rule1 = "$a.setA( 20 );\n $a.setB( $bb );\n update( $a );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());
        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment.getType());
        assertEquals("org.drools.A", statment.getFactClassName());

        assertEquals(2, statment.getFields().size());
        ConsequenceMetaData.Field field1 = statment.getFields().get(0);
View Full Code Here

    public void testUpdate2() {
        String rule1 = "$a.setC( $bc );\n $b.c = \"Hello\";\n update( $a );\n update( $b );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(2, consequenceMetaData.getStatements().size());

        ConsequenceMetaData.Statement statment1 = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment1.getType());
        assertEquals("org.drools.A", statment1.getFactClassName());
        assertEquals(1, statment1.getFields().size());
        ConsequenceMetaData.Field field1 = statment1.getFields().get(0);
        assertEquals("c", field1.getName());
        assertEquals("$bc", field1.getValue());
        assertFalse(field1.isLiteral());

        ConsequenceMetaData.Statement statment2 = consequenceMetaData.getStatements().get(1);
        assertEquals(ConsequenceMetaData.Statement.Type.MODIFY, statment2.getType());
        assertEquals("org.drools.integrationtests.RuleMetadataTest$B", statment2.getFactClassName());
        assertEquals(1, statment2.getFields().size());
        ConsequenceMetaData.Field field2 = statment2.getFields().get(0);
        assertEquals("c", field2.getName());
View Full Code Here

    public void testInsert() {
        String rule1 = "insert( new A(1, $bb, \"3\") );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());
        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.INSERT, statment.getType());
        assertEquals("org.drools.A", statment.getFactClassName());

        assertEquals(3, statment.getFields().size());
        ConsequenceMetaData.Field field1 = statment.getFields().get(0);
View Full Code Here

    public void testInsert2() {
        String rule1 = "insert( new B(1, $ab) );";
        KnowledgeBase kbase = getKnowledgeBase(rule1);
        Rule rule = getRule(kbase, "R0");

        ConsequenceMetaData consequenceMetaData = rule.getConsequenceMetaData();
        assertEquals(1, consequenceMetaData.getStatements().size());
        ConsequenceMetaData.Statement statment = consequenceMetaData.getStatements().get(0);
        assertEquals(ConsequenceMetaData.Statement.Type.INSERT, statment.getType());
        assertEquals("org.drools.integrationtests.RuleMetadataTest$B", statment.getFactClassName());
    }
View Full Code Here

TOP

Related Classes of org.drools.rule.ConsequenceMetaData$Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.