public Entity createOrderProductEntity(
     final ParsedOrderItem item, final Entity order, final Map<String, Entity> productEntities) {
   Entity orderProductEntity =
       dataDefinitionService
           .get(
               SfcSimpleConstants.PLUGIN_IDENTIFIER,
               SfcSimpleConstants.MODEL_IMPORTED_ORDER_PRODUCT)
           .create();
   try {
     orderProductEntity.setField(
         FIELD_ORDER_NUMBER, IntegrationParserUtils.parseInteger(item.getField(FIELD_NUMBER)));
     orderProductEntity.setField(
         FIELD_QUANTITY, IntegrationParserUtils.parseBigDecimal(item.getField(FIELD_QUANTITY)));
   } catch (IntegrationParserException e) {
     throw new IllegalStateException(e.getMessage(), e);
   }
   Entity itemProduct = productEntities.get(item.getProductIdentificationCode());
   orderProductEntity.setField("product", itemProduct);
   orderProductEntity.setField("order", order);
   return orderProductEntity;
 }
  public boolean isEqualOrders(final Entity existingOrder, final ParsedOrder order) {
    if (!existingOrder.getField(FIELD_NUMBER).equals(order.getField(FIELD_NUMBER))) {
      return false;
    }
    if (!existingOrder.getField(FIELD_CLIENT_NAME).equals(order.getField(FIELD_CLIENT_NAME))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_CLIENT_ADDRESS)
        .equals(order.getField(FIELD_CLIENT_ADDRESS))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_DRAW_DATE)
        .equals(
            IntegrationParserUtils.parseDateWithoutException(order.getField(FIELD_DRAW_DATE)))) {
      return false;
    }
    if (!existingOrder
        .getField(FIELD_REALIZATION_DATE)
        .equals(
            IntegrationParserUtils.parseDateWithoutException(
                order.getField(FIELD_REALIZATION_DATE)))) {
      return false;
    }

    List<Entity> existingOrderProducts =
        new ArrayList<Entity>(existingOrder.getHasManyField("orderProducts"));
    List<ParsedOrderItem> orderProducts = new ArrayList<ParsedOrderItem>(order.getItems());
    if (existingOrderProducts.size() == orderProducts.size()) {
      Collections.sort(existingOrderProducts, new OrderProductEntityComparator());
      Collections.sort(orderProducts, new ParsedOrderProductComparator());
      for (int i = 0; i < existingOrderProducts.size(); i++) {
        Entity existingOrderProduct = existingOrderProducts.get(i);
        ParsedOrderItem orderProduct = orderProducts.get(i);
        if (!existingOrderProduct
            .getField(FIELD_ORDER_NUMBER)
            .equals(
                IntegrationParserUtils.parseIntegerWithoutException(
                    orderProduct.getField(FIELD_NUMBER)))) {
          return false;
        }
        if (((BigDecimal) existingOrderProduct.getField(FIELD_QUANTITY))
                .compareTo(
                    IntegrationParserUtils.parseBigDecimalWithoutException(
                        orderProduct.getField(FIELD_QUANTITY)))
            != 0) {
          return false;
        }
        if (!existingOrderProduct
            .getBelongsToField("product")
            .getField(FIELD_IDENTIFICATION_CODE)
            .equals(orderProduct.getProductIdentificationCode())) {
          return false;
        }
      }
      return true;
    }

    return false;
  }