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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations