/** Maps between AdX's {@link CreativeFormat} and OpenRTB's mime types for banners. */
public class BannerMimeMapper {
  private static ImmutableMap<String, CreativeFormat> openrtbToDc =
      ImmutableMap.<String, CreativeFormat>builder()
          .put("application/javascript", CreativeFormat.HTML_CREATIVE)
          .put("image/gif", CreativeFormat.IMAGE_CREATIVE)
          .put("image/jpeg", CreativeFormat.IMAGE_CREATIVE)
          .put("image/png", CreativeFormat.IMAGE_CREATIVE)
          .put("text/css", CreativeFormat.HTML_CREATIVE)
          .put("text/html", CreativeFormat.HTML_CREATIVE)
          .put("video/x-flv", CreativeFormat.FLASH_CREATIVE)
          .build();
  private static ImmutableSet<String>[] dcToOpenrtb =
      MapperUtil.multimapEnumToSets(
          ImmutableMultimap.<CreativeFormat, String>builder()
              .putAll(CreativeFormat.FLASH_CREATIVE, "video/x-flv")
              .putAll(
                  CreativeFormat.HTML_CREATIVE, "text/html", "text/css", "application/javascript")
              .putAll(CreativeFormat.IMAGE_CREATIVE, "image/gif", "image/jpeg", "image/png")
              .build());

  public static ImmutableSet<String> toOpenRtb(CreativeFormat dc) {
    return MapperUtil.get(dcToOpenrtb, dc);
  }

  public static Set<String> toOpenRtb(
      Collection<CreativeFormat> dcList, @Nullable Set<String> openrtbSet) {
    Set<String> ret = openrtbSet == null ? new LinkedHashSet<String>() : openrtbSet;
    for (CreativeFormat dc : dcList) {
      ret.addAll(toOpenRtb(dc));
    }
    return ret;
  }

  @Nullable
  public static CreativeFormat toDoubleClick(String openrtb) {
    return openrtbToDc.get(openrtb);
  }

  public static EnumSet<CreativeFormat> toDoubleClick(
      Collection<String> openrtbList, @Nullable EnumSet<CreativeFormat> dcSet) {
    EnumSet<CreativeFormat> ret = dcSet == null ? EnumSet.noneOf(CreativeFormat.class) : dcSet;
    for (String openrtb : openrtbList) {
      CreativeFormat dc = toDoubleClick(openrtb);
      if (dc != null) {
        ret.add(dc);
      }
    }
    return ret;
  }
}
Beispiel #2
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private final void parseMappings(
      JsonNode mappings,
      VisualStyle style,
      VisualLexicon lexicon,
      MappingFactoryManager factoryManager) {

    for (final JsonNode mapping : mappings) {
      final String type = mapping.get(MAPPING_TYPE).textValue();
      final String column = mapping.get(MAPPING_COLUMN).textValue();
      final String colType = mapping.get(MAPPING_COLUMN_TYPE).textValue();
      final String vpName = mapping.get(MAPPING_VP).textValue();

      final VisualProperty vp = getVisualProperty(vpName, lexicon);
      final Class<?> columnType = MapperUtil.getColumnClass(colType);
      if (vp == null || columnType == null) {
        continue;
      }

      VisualMappingFunction newMapping = null;
      if (type.equals(MAPPING_DISCRETE)) {
        final VisualMappingFunctionFactory factory =
            factoryManager.getFactory(DiscreteMapping.class);
        newMapping =
            parseDiscrete(column, columnType, vp, factory, mapping.get(MAPPING_DISCRETE_MAP));
      } else if (type.equals(MAPPING_CONTINUOUS)) {
        final VisualMappingFunctionFactory factory =
            factoryManager.getFactory(ContinuousMapping.class);
        newMapping = parseContinuous(column, columnType, vp, factory, mapping);
      } else if (type.equals(MAPPING_PASSTHROUGH)) {
        final VisualMappingFunctionFactory factory =
            factoryManager.getFactory(PassthroughMapping.class);
        newMapping = parsePassthrough(column, columnType, vp, factory);
      }

      if (newMapping != null) {
        if (style.getVisualMappingFunction(vp) != null) {
          style.removeVisualMappingFunction(vp);
        }
        style.addVisualMappingFunction(newMapping);
      }
    }
  }
 public static ImmutableSet<String> toOpenRtb(CreativeFormat dc) {
   return MapperUtil.get(dcToOpenrtb, dc);
 }