use of com.xrtb.bidder.SelectedCreative in project XRTB by benmfaul.
the class Stroer method buildNewBidResponse.
@Override
public BidResponse buildNewBidResponse(Impression imp, List<SelectedCreative> multi, int xtime) throws Exception {
String avr = null;
String avn = null;
BidResponse response = new BidResponse(this, imp, multi, xtime);
StringBuilder sb = response.getResponseBuffer();
for (int i = 0; i < multi.size(); i++) {
SelectedCreative x = multi.get(i);
Creative c = x.getCreative();
if (c.extensions == null || c.extensions.size() == 0)
throw new Exception(x.getCampaign().adId + "/" + c.impid + " is missing required extensions for Stroer SSP");
avr = c.extensions.get("avr");
avn = c.extensions.get("avn");
if (avr == null || avn == null)
throw new Exception(x.getCampaign().adId + "/" + c.impid + " is missing required avn or avr extension for Stroer SSP");
String rets = getExtension(avr, avn);
int index = sb.indexOf("\"crid");
if (index < 0)
throw new Exception("Could not insert extension, response missing a crid");
sb.insert(index, rets);
}
return response;
}
use of com.xrtb.bidder.SelectedCreative in project XRTB by benmfaul.
the class TestCampaignProcessor method testNoCampaigns.
/**
* Test the situation where no campaigns are loaded in the system.
* @throws Exception when the bid JSON file fails to load or has a JSON error in it.
*/
@Test
public void testNoCampaigns() throws Exception {
InputStream is = Configuration.getInputStream("SampleBids/nexage.txt");
BidRequest request = new BidRequest(is);
AbortableCountDownLatch latch = new AbortableCountDownLatch(1, 1);
CountDownLatch flag = new CountDownLatch(1);
CampaignProcessor proc = new CampaignProcessor(null, request, flag, latch);
flag.countDown();
proc.run();
SelectedCreative resp = proc.getSelectedCreative();
// flag.countDown(); // back when proc was a thread
try {
latch.await();
fail("This latch should have aborted");
} catch (Exception e) {
}
assertNull(resp);
}
use of com.xrtb.bidder.SelectedCreative 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.bidder.SelectedCreative in project XRTB by benmfaul.
the class Creative method process.
/**
* Process the bid request against this creative.
*
* @param br
* BidRequest. Returns true if the creative matches.
* @param errorString
* StringBuilder. The string to hold any campaign failure
* messages
* @return boolean. Returns true of this campaign matches the bid request,
* ie eligible to bid
*/
public SelectedCreative process(BidRequest br, Map<String, String> capSpecs, String adId, StringBuilder errorString, Probe probe) {
int n = br.getImpressions();
StringBuilder sb = new StringBuilder();
Impression imp;
if (br.checkNonStandard(this, errorString) != true) {
return null;
}
for (int i = 0; i < n; i++) {
imp = br.getImpression(i);
SelectedCreative cr = xproc(br, adId, imp, capSpecs, errorString, probe);
if (cr != null) {
if (isCapped(br, capSpecs)) {
sb.append("This creative is capped for " + capSpecification);
if (errorString != null) {
probe.process(br.getExchange(), adId, impid, sb);
errorString.append(sb);
}
return null;
}
cr.setImpression(imp);
return cr;
}
}
return null;
}
use of com.xrtb.bidder.SelectedCreative in project XRTB by benmfaul.
the class Creative method xproc.
public SelectedCreative xproc(BidRequest br, String adId, Impression imp, Map<String, String> capSpecs, StringBuilder errorString, Probe probe) {
List<Deal> newDeals = null;
String dealId = null;
double xprice = price;
String impid = this.impid;
StringBuilder sb;
if (br.checkNonStandard(this, errorString) != true) {
return null;
}
if (price == 0 && (deals == null || deals.size() == 0)) {
sb = new StringBuilder(Probe.DEAL_PRICE_ERROR);
probe.process(br.getExchange(), adId, impid, sb);
if (errorString != null) {
errorString.append(Probe.DEAL_PRICE_ERROR);
}
return null;
}
if (imp.deals != null) {
probe.process(br.getExchange(), adId, impid, Probe.PRIVATE_AUCTION_LIMITED);
if ((deals == null || deals.size() == 0) && price == 0) {
if (errorString != null)
errorString.append(Probe.PRIVATE_AUCTION_LIMITED);
return null;
}
if (deals != null && deals.size() > 0) {
/**
* Ok, find a deal!
*/
newDeals = new ArrayList<Deal>(deals);
newDeals.retainAll(imp.deals);
if (newDeals.size() != 0) {
dealId = newDeals.get(0).id;
xprice = newDeals.get(0).price;
Deal brDeal = imp.getDeal(dealId);
if (brDeal == null && price == 0) {
probe.process(br.getExchange(), adId, impid, Probe.PRIVATE_AUCTION_LIMITED);
if (errorString != null)
errorString.append(Probe.NO_WINNING_DEAL_FOUND);
return null;
}
imp.bidFloor = new Double(brDeal.price);
} else if (price == 0 || imp.privateAuction == 1) {
probe.process(br.getExchange(), adId, impid, Probe.NO_APPLIC_DEAL);
if (errorString != null)
errorString.append(Probe.NO_APPLIC_DEAL);
return null;
}
} else {
if (imp.privateAuction == 1) {
probe.process(br.getExchange(), adId, impid, Probe.PRIVATE_AUCTION_LIMITED);
if (errorString != null)
errorString.append(Probe.PRIVATE_AUCTION_LIMITED);
return null;
}
}
} else {
if (price == 0) {
probe.process(br.getExchange(), adId, impid, Probe.NO_WINNING_DEAL_FOUND);
if (errorString != null)
errorString.append(Probe.NO_WINNING_DEAL_FOUND);
return null;
}
}
if (imp.bidFloor != null) {
if (xprice < 0) {
xprice = Math.abs(xprice) * imp.bidFloor;
}
if (imp.bidFloor > xprice) {
probe.process(br.getExchange(), adId, impid, Probe.BID_FLOOR);
if (errorString != null) {
errorString.append(Probe.BID_FLOOR);
return null;
}
}
} else {
if (xprice < 0)
// A fake bid price if no bid floor
xprice = .01;
}
if (isVideo() && imp.video == null) {
probe.process(br.getExchange(), adId, impid, Probe.BID_CREAT_IS_VIDEO);
if (errorString != null)
errorString.append(Probe.BID_CREAT_IS_VIDEO);
return null;
}
if (isNative() && imp.nativePart == null) {
probe.process(br.getExchange(), adId, impid, Probe.BID_CREAT_IS_NATIVE);
if (errorString != null)
errorString.append(Probe.BID_CREAT_IS_NATIVE);
return null;
}
if ((isVideo() == false && isNative() == false) != (imp.nativePart == null && imp.video == null)) {
probe.process(br.getExchange(), adId, impid, Probe.BID_CREAT_IS_BANNER);
if (errorString != null)
errorString.append(Probe.BID_CREAT_IS_BANNER);
return null;
}
if (isNative()) {
if (imp.nativePart.layout != 0) {
if (imp.nativePart.layout != nativead.nativeAdType) {
probe.process(br.getExchange(), adId, impid, Probe.BID_CREAT_IS_BANNER);
if (errorString != null)
errorString.append(Probe.NATIVE_LAYOUT);
return null;
}
}
if (imp.nativePart.title != null) {
if (imp.nativePart.title.required == 1 && nativead.title == null) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_TITLE);
if (errorString != null)
errorString.append(Probe.NATIVE_TITLE);
return null;
}
if (nativead.title.title.text.length() > imp.nativePart.title.len) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_TITLE_LEN);
if (errorString != null)
errorString.append(Probe.NATIVE_TITLE_LEN);
return null;
}
}
if (imp.nativePart.img != null && nativead.img != null) {
if (imp.nativePart.img.required == 1 && nativead.img == null) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_WANTS_IMAGE);
if (errorString != null)
errorString.append(Probe.NATIVE_WANTS_IMAGE);
return null;
}
if (nativead.img.img.w != imp.nativePart.img.w) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_IMAGEW_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_IMAGEW_MISMATCH);
return null;
}
if (nativead.img.img.h != imp.nativePart.img.h) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_IMAGEH_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_IMAGEH_MISMATCH);
return null;
}
}
if (imp.nativePart.video != null) {
if (imp.nativePart.video.required == 1 || nativead.video == null) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_WANTS_VIDEO);
if (errorString != null)
errorString.append(Probe.NATIVE_WANTS_VIDEO);
return null;
}
if (nativead.video.video.duration < imp.nativePart.video.minduration) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_AD_TOO_SHORT);
if (errorString != null)
errorString.append(Probe.NATIVE_AD_TOO_SHORT);
return null;
}
if (nativead.video.video.duration > imp.nativePart.video.maxduration) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_AD_TOO_LONG);
if (errorString != null)
errorString.append(Probe.NATIVE_AD_TOO_LONG);
return null;
}
if (imp.nativePart.video.linearity != null && imp.nativePart.video.linearity.equals(nativead.video.video.linearity) == false) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_LINEAR_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_LINEAR_MISMATCH);
return null;
}
if (imp.nativePart.video.protocols.size() > 0) {
if (imp.nativePart.video.protocols.contains(nativead.video.video.protocol)) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_AD_PROTOCOL_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_AD_PROTOCOL_MISMATCH);
return null;
}
}
}
for (Data datum : imp.nativePart.data) {
Integer val = datum.type;
Entity e = nativead.dataMap.get(val);
if (datum.required == 1 && e == null) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_AD_PROTOCOL_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_AD_DATUM_MISMATCH);
return null;
}
if (e != null) {
if (e.value.length() > datum.len) {
probe.process(br.getExchange(), adId, impid, Probe.NATIVE_AD_PROTOCOL_MISMATCH);
if (errorString != null)
errorString.append(Probe.NATIVE_AD_DATUM_MISMATCH);
return null;
}
}
}
return new SelectedCreative(this, dealId, xprice, impid);
// return true;
}
if (imp.nativePart == null) {
if (imp.w == null || imp.h == null) {
// we will match any size if it doesn't match...
if (imp.instl != null && imp.instl.intValue() == 1) {
Node n = findAttribute("imp.0.instl");
if (n != null) {
if (n.intValue() == 0) {
probe.process(br.getExchange(), adId, impid, Probe.WH_INTERSTITIAL);
if (errorString != null) {
errorString.append(Probe.WH_INTERSTITIAL);
return null;
}
}
} else {
if (errorString != null) {
errorString.append(Probe.WH_INTERSTITIAL);
return null;
}
}
} else if (errorString != null) {
//errorString.append("No width or height specified\n");
//return null;
// ok, let it go.
}
} else {
if (dimensions == null || dimensions.size() == 0) {
strW = Integer.toString(imp.w);
strH = Integer.toString(imp.h);
} else {
Dimension d = dimensions.getBestFit(imp.w, imp.h);
if (d == null) {
probe.process(br.getExchange(), adId, impid, Probe.WH_MATCH);
if (errorString != null)
errorString.append(Probe.WH_MATCH);
return null;
}
}
}
}
/**
* Video
*
*/
if (imp.video != null) {
if (imp.video.linearity != -1 && this.videoLinearity != null) {
if (imp.video.linearity != this.videoLinearity) {
probe.process(br.getExchange(), adId, impid, Probe.VIDEO_LINEARITY);
if (errorString != null)
errorString.append(Probe.VIDEO_LINEARITY);
return null;
}
}
if (imp.video.minduration != -1) {
if (this.videoDuration != null) {
if (!(this.videoDuration.intValue() >= imp.video.minduration)) {
probe.process(br.getExchange(), adId, impid, Probe.VIDEO_TOO_SHORT);
if (errorString != null)
errorString.append(Probe.VIDEO_TOO_SHORT);
return null;
}
}
}
if (imp.video.maxduration != -1) {
if (this.videoDuration != null) {
if (!(this.videoDuration.intValue() <= imp.video.maxduration)) {
probe.process(br.getExchange(), adId, impid, Probe.VIDEO_TOO_LONG);
if (errorString != null)
errorString.append(Probe.VIDEO_TOO_LONG);
return null;
}
}
}
if (imp.video.protocol.size() != 0) {
if (this.videoProtocol != null) {
if (imp.video.protocol.contains(this.videoProtocol) == false) {
probe.process(br.getExchange(), adId, impid, Probe.VIDEO_PROTOCOL);
if (errorString != null)
errorString.append(Probe.VIDEO_PROTOCOL);
return null;
}
}
}
if (imp.video.mimeTypes.size() != 0) {
if (this.videoMimeType != null) {
if (imp.video.mimeTypes.contains(this.videoMimeType) == false) {
probe.process(br.getExchange(), adId, impid, Probe.VIDEO_MIME);
if (errorString != null)
errorString.append(Probe.VIDEO_MIME);
return null;
}
}
}
}
Node n = null;
/**
* Attributes that are specific to the creative (additional to the
* campaign
*/
try {
for (int i = 0; i < attributes.size(); i++) {
n = attributes.get(i);
if (n.test(br) == false) {
if (errorString != null)
errorString.append("CREATIVE MISMATCH: ");
if (errorString != null) {
if (n.operator == Node.OR)
errorString.append("OR failed on all branches\n");
else
errorString.append(n.hierarchy);
}
sb = new StringBuilder(Probe.CREATIVE_MISMATCH);
sb.append(n.hierarchy);
probe.process(br.getExchange(), adId, impid, sb);
return null;
}
}
} catch (Exception error) {
// error.printStackTrace();
if (errorString != null) {
errorString.append("Internal error in bid request: " + n.hierarchy + " is missing, ");
errorString.append(error.toString());
errorString.append("\n");
}
return null;
}
return new SelectedCreative(this, dealId, xprice, impid);
}
Aggregations