Search in sources :

Example 11 with Node

use of com.xrtb.common.Node in project XRTB by benmfaul.

the class BidRequest method compile.

/**
	 * Take the union of all campaign attributes and place them into the static
	 * mapp. This way the JSON is queried once and the query becomes the key,
	 * and the JSON value becomes the map value. With multiple campaigns it is
	 * important to not be traversing the JSON tree for each campaign.
	 * 
	 * The compiled attributes are stored in mapp. In setup, the compiled list
	 * of key/values is then put in the 'database' object for the bidrequest.
	 */
public static synchronized void compile() throws Exception {
    RTB4FREE = false;
    /**
		 * Stop the bidder, if it is running
		 */
    stopBidder();
    keys.clear();
    mapp.clear();
    List<Campaign> list = Configuration.getInstance().campaignsList;
    for (int i = 0; i < list.size(); i++) {
        Campaign c = list.get(i);
        Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compiling for domain: : " + c.adomain));
        for (int j = 0; j < c.attributes.size(); j++) {
            Node node = c.attributes.get(j);
            if (mapp.containsKey(keys) == false) {
                Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compile unit: " + c.adomain + ":" + node.hierarchy) + ", values: " + node.bidRequestValues);
                if (node.hierarchy.equals("") == false) {
                    keys.add(node.hierarchy);
                    mapp.put(node.hierarchy, node.bidRequestValues);
                } else {
                    if (node.operator != Node.OR) {
                        startBidder();
                        throw new Exception("Malformed OR processing in campaign " + c.adId);
                    }
                    List<Node> nodes = (List<Node>) node.value;
                    for (int nc = 0; nc < nodes.size(); nc++) {
                        Object x = nodes.get(nc);
                        Node n = null;
                        if (x instanceof LinkedHashMap) {
                            Map map = (Map) x;
                            n = new Node(map);
                        } else
                            n = (Node) x;
                        n.setValues();
                        if (mapp.get(n.hierarchy) == null) {
                            keys.add(n.hierarchy);
                            mapp.put(n.hierarchy, n.bidRequestValues);
                        }
                    }
                }
            }
        }
        for (Creative creative : c.creatives) {
            // Handle creative specific
            // attributes
            Controller.getInstance().sendLog(5, "BidRequest:compile", "Compiling creatives for: " + c.adomain + ":" + creative.impid);
            for (Node node : creative.attributes) {
                if (mapp.containsKey(keys) == false) {
                    Controller.getInstance().sendLog(5, "BidRequest:compile", ("Compile unit: " + c.adomain + ":" + creative.impid + ":" + node.hierarchy) + ", values: " + node.bidRequestValues);
                    if (mapp.get(node.hierarchy) == null) {
                        keys.add(node.hierarchy);
                        mapp.put(node.hierarchy, node.bidRequestValues);
                    }
                }
            }
            // Now frequency caps */
            if (creative.capSpecification != null) {
                String spec = creative.capSpecification;
                if (mapp.containsKey(spec) == false) {
                    addMap(spec);
                }
            }
        }
    }
    compileBuiltIns();
    /**
		 * Restart the bidder
		 */
    startBidder();
}
Also used : Campaign(com.xrtb.common.Campaign) Creative(com.xrtb.common.Creative) SelectedCreative(com.xrtb.bidder.SelectedCreative) IntNode(com.fasterxml.jackson.databind.node.IntNode) Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) DoubleNode(com.fasterxml.jackson.databind.node.DoubleNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with Node

use of com.xrtb.common.Node in project XRTB by benmfaul.

the class TestNode method testMember.

@Test
public void testMember() throws Exception {
    ArrayList ilist = new ArrayList();
    ilist.clear();
    ilist.add(1);
    ilist.add(2);
    ilist.add(3);
    Node node = new Node("aoo-test", "member test", Node.MEMBER, 1);
    boolean test = node.testInternal(ilist);
    assertTrue(test);
    node = new Node("aoo-test", "member test", Node.NOT_MEMBER, 1);
    test = node.testInternal(ilist);
    assertFalse(test);
    ilist.clear();
    ilist.add("one");
    ilist.add("two");
    ilist.add("three");
    node = new Node("aoo-test", "member test", Node.MEMBER, "two");
    test = node.testInternal(ilist);
    assertTrue(test);
    node = new Node("aoo-test", "member test", Node.NOT_MEMBER, "two");
    test = node.testInternal(ilist);
    assertFalse(test);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 13 with Node

use of com.xrtb.common.Node in project XRTB by benmfaul.

the class TestNode method getIntAndDoubleValue.

@Test
public void getIntAndDoubleValue() throws Exception {
    Node node = new Node("intTest", "user.yob", "EQUALS", 1961);
    Integer ix = node.intValue();
    assertEquals(ix.intValue(), 1961);
    Double dx = node.doubleValue();
    assertTrue(dx.doubleValue() == 1961.0);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 14 with Node

use of com.xrtb.common.Node in project XRTB by benmfaul.

the class TestNode method testNavMap.

@Test
public void testNavMap() throws Exception {
    String content = new String(Files.readAllBytes(Paths.get("SampleBids/nexage.txt")));
    String test = content.replace("166.137.138.18", "45.33.224.0");
    BidRequest br = new BidRequest(new StringBuilder(test));
    assertNotNull(br);
    String op = "MEMBER";
    Node node = new Node("navmap", "device.ip", "MEMBER", "@CIDR");
    boolean b = node.test(br);
    assertTrue(b);
    test = content.replace("166.137.138.18", "45.33.239.255");
    br = new BidRequest(new StringBuilder(test));
    b = node.test(br);
    assertTrue(b);
    test = content.replace("166.137.138.18", "166.55.255.255");
    br = new BidRequest(new StringBuilder(test));
    b = node.test(br);
    assertFalse(b);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Example 15 with Node

use of com.xrtb.common.Node in project XRTB by benmfaul.

the class TestNode method testQueryMap.

@Test
public void testQueryMap() throws Exception {
    BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/atomx.txt"));
    br.setExchange("atomx");
    assertNotNull(br);
    List ilist = new ArrayList();
    ilist.add("builtin");
    ilist.add("test");
    ilist.add("EQUALS");
    ilist.add(1);
    Node node = new Node("query", "site.publisher.id", Node.QUERY, ilist);
    boolean b = node.test(br);
    assertTrue(b);
}
Also used : Node(com.xrtb.common.Node) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BidRequest(com.xrtb.pojo.BidRequest) Test(org.junit.Test)

Aggregations

Node (com.xrtb.common.Node)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 Test (org.junit.Test)12 BidRequest (com.xrtb.pojo.BidRequest)10 ArrayList (java.util.ArrayList)10 List (java.util.List)7 Campaign (com.xrtb.common.Campaign)5 Creative (com.xrtb.common.Creative)3 User (com.xrtb.db.User)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 SelectedCreative (com.xrtb.bidder.SelectedCreative)1 BidResponse (com.xrtb.pojo.BidResponse)1 Impression (com.xrtb.pojo.Impression)1