Search in sources :

Example 1 with Campaign

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);
}
Also used : Campaign(com.xrtb.common.Campaign)

Example 2 with 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);
}
Also used : AddCampaign(com.xrtb.commands.AddCampaign) Campaign(com.xrtb.common.Campaign) AddCampaign(com.xrtb.commands.AddCampaign) DeleteCampaign(com.xrtb.commands.DeleteCampaign) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with Campaign

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");
}
Also used : Set(java.util.Set) User(com.xrtb.db.User) Campaign(com.xrtb.common.Campaign)

Example 4 with 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);
}
Also used : Campaign(com.xrtb.common.Campaign) Configuration(com.xrtb.common.Configuration) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) InputStream(java.io.InputStream) CampaignProcessor(com.xrtb.bidder.CampaignProcessor) SelectedCreative(com.xrtb.bidder.SelectedCreative) AbortableCountDownLatch(com.xrtb.bidder.AbortableCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) BidRequest(com.xrtb.pojo.BidRequest)

Example 5 with Campaign

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);
}
Also used : Campaign(com.xrtb.common.Campaign) Test(org.junit.Test)

Aggregations

Campaign (com.xrtb.common.Campaign)27 User (com.xrtb.db.User)13 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 Configuration (com.xrtb.common.Configuration)7 List (java.util.List)7 Creative (com.xrtb.common.Creative)6 RTBServer (com.xrtb.bidder.RTBServer)5 Node (com.xrtb.common.Node)5 BidRequest (com.xrtb.pojo.BidRequest)5 DbTools (com.xrtb.tools.DbTools)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 AddCampaign (com.xrtb.commands.AddCampaign)4 DeleteCampaign (com.xrtb.commands.DeleteCampaign)4 SelectedCreative (com.xrtb.bidder.SelectedCreative)3 BidResponse (com.xrtb.pojo.BidResponse)3 HttpPostGet (com.xrtb.common.HttpPostGet)2 Bid (com.xrtb.pojo.Bid)2