Search in sources :

Example 1 with Data

use of com.xrtb.nativeads.creative.Data in project XRTB by benmfaul.

the class Impression method doNative.

/**
	 * Handle the native impression
	 */
void doNative() {
    JsonNode node = rnode.get("native");
    if (node != null) {
        JsonNode child = null;
        nativead = true;
        nativePart = new NativePart();
        child = node.path("layout");
        if (child != null) {
            nativePart.layout = child.intValue();
        }
        if (node.path("assets") instanceof MissingNode == false) {
            ArrayNode array = (ArrayNode) node.path("assets");
            for (JsonNode x : array) {
                child = x.path("title");
                if (child instanceof MissingNode == false) {
                    nativePart.title = new Title();
                    nativePart.title.len = child.path("len").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.title.required = x.path("required").intValue();
                    }
                }
                child = x.path("img");
                if (child instanceof MissingNode == false) {
                    nativePart.img = new Img();
                    nativePart.img.w = child.path("w").intValue();
                    nativePart.img.h = child.path("h").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.img.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        if (child.path("mimes") instanceof TextNode) {
                            nativePart.img.mimes.add(child.get("mimes").asText());
                        } else {
                            array = (ArrayNode) child.path("mimes");
                            for (JsonNode nx : array) {
                                nativePart.img.mimes.add(nx.textValue());
                            }
                        }
                    }
                }
                child = x.path("video");
                if (child instanceof MissingNode == false) {
                    nativePart.video = new NativeVideo();
                    nativePart.video.linearity = child.path("linearity").intValue();
                    nativePart.video.minduration = child.path("minduration").intValue();
                    nativePart.video.maxduration = child.path("maxduration").intValue();
                    if (x.path("required") instanceof MissingNode == false) {
                        nativePart.video.required = x.path("required").intValue();
                    }
                    if (child.path("mimes") instanceof MissingNode == false) {
                        array = (ArrayNode) child.path("protocols");
                        for (JsonNode nx : array) {
                            nativePart.video.protocols.add(nx.textValue());
                        }
                    }
                }
                child = x.path("data");
                if (child instanceof MissingNode == false) {
                    Data data = new Data();
                    if (x.path("required") instanceof MissingNode == false) {
                        data.required = x.path("required").intValue();
                    }
                    if (child.path("len") instanceof MissingNode == false) {
                        data.len = child.path("len").intValue();
                    }
                    data.type = child.path("type").intValue();
                    nativePart.data.add(data);
                }
            }
        }
    }
}
Also used : NativeVideo(com.xrtb.nativeads.creative.NativeVideo) Img(com.xrtb.nativeads.creative.Img) Title(com.xrtb.nativeads.creative.Title) JsonNode(com.fasterxml.jackson.databind.JsonNode) MissingNode(com.fasterxml.jackson.databind.node.MissingNode) TextNode(com.fasterxml.jackson.databind.node.TextNode) Data(com.xrtb.nativeads.creative.Data) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 2 with Data

use of com.xrtb.nativeads.creative.Data 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);
}
Also used : Entity(com.xrtb.nativeads.assets.Entity) SelectedCreative(com.xrtb.bidder.SelectedCreative) Data(com.xrtb.nativeads.creative.Data)

Aggregations

Data (com.xrtb.nativeads.creative.Data)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 MissingNode (com.fasterxml.jackson.databind.node.MissingNode)1 TextNode (com.fasterxml.jackson.databind.node.TextNode)1 SelectedCreative (com.xrtb.bidder.SelectedCreative)1 Entity (com.xrtb.nativeads.assets.Entity)1 Img (com.xrtb.nativeads.creative.Img)1 NativeVideo (com.xrtb.nativeads.creative.NativeVideo)1 Title (com.xrtb.nativeads.creative.Title)1