use of com.xrtb.db.User in project XRTB by benmfaul.
the class TestNode method testSets.
/**
* Test the set operations.
* @throws Exception on configuration file errors.
*/
@Test
public void testSets() throws Exception {
BidRequest br = new BidRequest(Configuration.getInputStream("SampleBids/nexage.txt"));
assertNotNull(br);
String content = new String(Files.readAllBytes(Paths.get("database.json")));
List<User> users = DbTools.mapper.readValue(content, DbTools.mapper.getTypeFactory().constructCollectionType(List.class, User.class));
User u = users.get(0);
List<Campaign> camps = u.campaigns;
assertNotNull(camps);
Campaign c = null;
for (Campaign x : camps) {
if (x.adId.equals("ben:payday")) {
c = x;
break;
}
}
Node n = c.getAttribute("site.domain");
List<String> list = (List) n.value;
list.add("junk.com");
String op = "INTERSECTS";
Node node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
Boolean b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
/**
* Test adding an array of objects
*/
String[] parts = new String[1];
op = "INTERSECTS";
parts[0] = "junk.com";
node = new Node("blacklist-array", "site.domain", op, parts);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
n = new Node("matching-categories", "site.cat", Node.INTERSECTS, parts);
list.add("junk1.com");
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertTrue(b);
list.clear();
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertFalse(b);
op = "NOT_INTERSECTS";
node = new Node("blacklist", "site.domain", op, list);
// true means the constraint is satisfied.
b = node.test(br);
// should be on blacklist and will not bid
assertTrue(b);
op = "MEMBER";
node = new Node("mimes", "imp.0.banner.mimes", op, "image/jpg");
b = node.test(br);
assertTrue(b);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method addUser.
/**
* Add a new user's information.
*
* @param m
* Map. The command parameters.
* @return JSON encoded string of the command return values.
* @throws Exception
* on JSON or cache errors.
*/
private String addUser(Map m) throws Exception {
Map response = new HashMap();
String name = (String) m.get("name");
String pass = (String) m.get("pass");
String directory = (String) m.get("dir");
String phone = (String) m.get("phone");
String email = (String) m.get("email");
String creditcard = (String) m.get("credit");
User u = db.getUser(name);
if (u != null) {
response.put("error", true);
response.put("message", "user already exists");
} else {
u = new User();
u.creditcard = creditcard;
u.password = pass;
u.email = email;
u.directory = directory;
u.phone = phone;
u.email = email;
u.name = name;
u.campaigns = new ArrayList();
db.addUser(u);
response.put("users", makeUsersResponseList());
}
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method multiPart.
public String multiPart(Request baseRequest, HttpServletRequest request, MultipartConfigElement config) throws Exception {
HttpSession session = request.getSession(false);
String user = (String) session.getAttribute("user");
User u = db.getUser(user);
if (u == null)
throw new Exception("No such user");
baseRequest.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, config);
Collection<Part> parts = request.getParts();
for (Part part : parts) {
System.out.println("" + part.getName());
}
Part filePart = request.getPart("file");
InputStream imageStream = filePart.getInputStream();
byte[] resultBuff = new byte[0];
byte[] buff = new byte[1024];
int k = -1;
while ((k = imageStream.read(buff, 0, buff.length)) > -1) {
// temp buffer size
byte[] tbuff = new byte[resultBuff.length + k];
// = bytes already
// read + bytes last
// read
// copy
System.arraycopy(resultBuff, 0, tbuff, 0, resultBuff.length);
// previous
// bytes
// copy
System.arraycopy(buff, 0, tbuff, resultBuff.length, k);
// current
// lot
// call the temp buffer as your result buff
resultBuff = tbuff;
}
System.out.println(resultBuff.length + " bytes read.");
if (k == 0) {
// no file provided
throw new Exception("No file provided");
} else {
byte[] bytes = new byte[1024];
Part namePart = request.getPart("name");
InputStream nameStream = namePart.getInputStream();
int rc = nameStream.read(bytes);
String name = new String(bytes, 0, rc);
FileOutputStream fos = new FileOutputStream(u.directory + "/" + name);
fos.write(resultBuff);
fos.close();
}
Map response = new HashMap();
response.put("images", getFiles(u));
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class WebCampaign method doDeleteCampaign.
/**
* Deletes a campaign from aerospike/cache.
*
* @param m
* Map. The command parameters.
* @return JSON. The JSON encoded return values of the command.
* @throws Exception
* on JSON or cache errors.
*/
private String doDeleteCampaign(Map m) throws Exception {
Map response = new HashMap();
String who = (String) m.get("username");
String id = (String) m.get("campaign");
User u = db.getUser(who);
if (u == null) {
response.put("message", "No user " + who);
return getString(response);
}
Controller.getInstance().sendLog(3, "WebAccess-Delete-Campaign", who + " deleted a campaign " + id);
// delete from bidder
Controller.getInstance().deleteCampaign(who, id);
// delete from
response.put("campaigns", db.deleteCampaign(u, id));
// database
return getString(response);
}
use of com.xrtb.db.User in project XRTB by benmfaul.
the class MyReader method testSetup.
@BeforeClass
public static void testSetup() {
try {
DbTools tools = new DbTools("localhost:3000");
tools.clear();
tools.loadDatabase("database.json");
if (server == null) {
server = new RTBServer("./Campaigns/payday.json");
int wait = 0;
while (!server.isReady() && wait < 10) {
Thread.sleep(1000);
wait++;
}
if (wait == 10) {
fail("Server never started");
}
Thread.sleep(1000);
} else {
Configuration c = Configuration.getInstance();
c.campaignsList.clear();
User u = DataBaseObject.getInstance().get("ben");
for (Campaign camp : u.campaigns) {
c.addCampaign("ben", camp.adId);
}
}
} catch (Exception e) {
e.printStackTrace();
fail(e.toString());
}
}
Aggregations