コード例 #1
0
 private static void removeLineItemFromOrder(LineItemDomain lineItem, OrderDomain order) {
   if (order.getLineItems().remove(lineItem)) {
     order.setGrossValue(order.getGrossValue() - lineItem.getGrossValue());
     order.setNetValue(order.getNetValue() - lineItem.getNetValue());
     order.setGeneralDiscount(order.getGeneralDiscount() - lineItem.getGeneralDiscount());
   }
 }
コード例 #2
0
 private static void addLineItemIntoOrder(LineItemDomain lineItem, OrderDomain order) {
   if (order.getLineItems().add(lineItem)) {
     order.setGrossValue(order.getGrossValue() + lineItem.getGrossValue());
     order.setNetValue(order.getNetValue() + lineItem.getNetValue());
     order.setGeneralDiscount(order.getGeneralDiscount() + lineItem.getGeneralDiscount());
   }
 }
コード例 #3
0
  public static void removeLineItems(OrderDomain order) throws Exception {
    if (CollectionUtils.isEmpty(order.getLineItems())) {
      return;
    }

    final List<Long> itemsIds = new ArrayList<>(order.getLineItems().size());
    for (LineItemDomain item : order.getLineItems()) {
      itemsIds.add(item.getId());
    }

    final String itemsIdsString = StringUtils.join(itemsIds, ',');

    final Statement stmtFilterByIds =
        new StatementBuilder().where(String.format("id IN (%s)", itemsIdsString)).toStatement();

    final LineItemServiceInterface itemService =
        dfpServiceFactory.newDfpService(LineItemServiceInterface.class);
    itemService.performLineItemAction(new DeleteLineItems(), stmtFilterByIds);

    order.getLineItems().clear();
  }
コード例 #4
0
  public static LineItemDomain createDefaultLineItem(OrderDomain order) throws Exception {
    final String name = "Line item #" + order.getLineItems().size() + 1;
    final String sapProduct = new String[] {"DECOMM", "DLINKP", "DPUBLI"}[random.nextInt(3)];
    final String costType = new String[] {"CPC", "CPM", "CPD"}[random.nextInt(3)];

    final CreativePlaceholder creativePlaceholder = new CreativePlaceholder();
    creativePlaceholder.setSize(new Size(320, 480, false));
    final BaseCustomFieldValue sapProductField = createCustomFieldSapProduct(sapProduct);
    final Calendar tomorrow = Calendar.getInstance();
    final Calendar dayAfterTomorrow = Calendar.getInstance();
    tomorrow.add(Calendar.DAY_OF_MONTH, 1);
    dayAfterTomorrow.add(Calendar.DAY_OF_MONTH, 2);

    LineItem dfpLineItem = new LineItem();
    dfpLineItem.setName(name);
    dfpLineItem.setOrderId(order.getId());
    dfpLineItem.setAllowOverbook(true);
    dfpLineItem.setCreativeRotationType(CreativeRotationType.EVEN);
    dfpLineItem.setCreativePlaceholders(new CreativePlaceholder[] {creativePlaceholder});
    dfpLineItem.setCustomFieldValues(new BaseCustomFieldValue[] {sapProductField});
    dfpLineItem.setTargeting(createDefaultTargeting());
    dfpLineItem.setStartDateTime(toDateTime(tomorrow));
    dfpLineItem.setEndDateTime(toDateTime(dayAfterTomorrow));

    setLineItemsCostValues(dfpLineItem, order.getCurrency(), costType);

    final LineItemServiceInterface itemService =
        dfpServiceFactory.newDfpService(LineItemServiceInterface.class);
    try {
      dfpLineItem = itemService.createLineItem(dfpLineItem);
    } catch (ApiException e) {
      if (e.getFaultString().contains("RangeError.TOO_HIGH @ discount")) {
        dfpLineItem.setDiscount(0D);
        dfpLineItem = itemService.createLineItem(dfpLineItem);
      }
    }

    return createLineItemDomain(dfpLineItem, order, sapProduct);
  }