use of com.xrtb.common.Campaign in project XRTB by benmfaul.
the class CampaignSelector method add.
/**
* Adds a campaign to the list of usable campaigns.
*
* @param campaign
* . A new campaign to add.
*/
public void add(Campaign campaign) throws Exception {
boolean state = RTBServer.stopped;
Thread.sleep(100);
RTBServer.stopped = true;
for (int i = 0; i < config.campaignsList.size(); i++) {
Campaign camp = config.campaignsList.get(i);
if (camp.owner.equals(campaign.owner) && camp.adId.equals(campaign.adId)) {
config.campaignsList.remove(i);
config.campaignsList.add(campaign);
RTBServer.stopped = state;
return;
}
}
RTBServer.stopped = state;
config.campaignsList.add(campaign);
}
use of com.xrtb.common.Campaign in project XRTB by benmfaul.
the class WebCampaign method startCampaign.
/**
* Starts the campaign from the web portal
*
* @param cmd
* Map. The JSON command structure from the web user.
* @return String. The JSON string of all the running campaigns in this
* bidder.
*/
public String startCampaign(Map cmd) throws Exception {
Map response = new HashMap();
try {
String id = getString(cmd.get("id"));
String name = (String) cmd.get("username");
id = id.replaceAll("\"", "");
Campaign c = db.getCampaign(name, id);
Controller.getInstance().addCampaign(c);
response.put("error", false);
AddCampaign command = new AddCampaign(null, name, id);
command.to = "*";
command.from = Configuration.getInstance().instanceName;
Controller.getInstance().sendLog(3, "WebAccess-Start-Campaign", "Campaign start: " + id);
} catch (Exception error) {
response.put("message", "failed: " + error.toString());
response.put("error", true);
}
response.put("running", Configuration.getInstance().getLoadedCampaignNames());
return getString(response);
}
use of com.xrtb.common.Campaign in project XRTB by benmfaul.
the class DbTools method deleteCampaign.
/**
* Remove a campaign by ad id.
*
* @param adId
* String. The ad id.
* @throws Exception
* if the adid does not exist.
*/
public void deleteCampaign(String adId) throws Exception {
Set set = map.keySet();
Iterator<String> it = set.iterator();
while (it.hasNext()) {
String key = it.next();
User u = map.get(key);
for (int i = 0; i < u.campaigns.size(); i++) {
Campaign c = u.campaigns.get(i);
if (c.adId.equals(adId)) {
u.campaigns.remove(i);
dbo.put(u);
return;
}
}
}
throw new Exception("No such campaign");
}
use of com.xrtb.common.Campaign in project XRTB by benmfaul.
the class TestCampaignProcessor method testOneMatching.
/**
* Load a campaign and then use the bidder's campaign processor to make a bid response.
* @throws Exception if the config file or the sample bid file fails to load, or they contain JSON errors.
*/
// @Test
public void testOneMatching() throws Exception {
InputStream is = Configuration.getInputStream("SampleBids/nexage.txt");
BidRequest request = new BidRequest(is);
Configuration cf = Configuration.getInstance();
cf.clear();
cf.initialize("Campaigns/payday.json");
Campaign c = cf.campaignsList.get(0);
AbortableCountDownLatch latch = new AbortableCountDownLatch(1, 1);
CountDownLatch flag = new CountDownLatch(1);
CampaignProcessor proc = new CampaignProcessor(c, request, flag, latch);
flag.countDown();
latch.await();
SelectedCreative resp = proc.getSelectedCreative();
assertNotNull(resp);
assertTrue(resp.getCreative().dimensions.get(0).getLeftX() == 320);
}
use of com.xrtb.common.Campaign in project XRTB by benmfaul.
the class TestDatabase method rawCampaign.
/**
* Test making a campaign from a raw json file.
* @throws Exception if the values obejct is not recognized.
*/
@Test
public void rawCampaign() throws Exception {
String content = new String(Files.readAllBytes(Paths.get("stub.json")));
Campaign c = new Campaign(content);
assertTrue(c.adomain.equals("originator.com"));
assertTrue(c.creatives.size() == 0);
}
Aggregations