OrderDeleteCommandImpl(final Versioned<Order> versioned) { super(versioned, OrderEndpoint.ENDPOINT, OrderExpansionModel.of(), OrderDeleteCommandImpl::new); }
public static OrderExpansionModel<Order> of() { return new OrderExpansionModel<>(); }
public ExpansionPathContainer<T> cart() { return expansionPath("cart"); }
protected CompletionStage<Optional<Order>> findOrderById(final String orderId) { final OrderByIdGet baseRequest = OrderByIdGet.of(orderId).plusExpansionPaths(m -> m.paymentInfo().payments()); final OrderByIdGet orderByIdGet = OrderByIdGetHook.runHook(hooks(), baseRequest); return sphere().execute(orderByIdGet) .thenApplyAsync(nullableOrder -> { if (nullableOrder != null) { OrderLoadedHook.runHook(hooks(), nullableOrder); } return Optional.ofNullable(nullableOrder); }, defaultContext()); }
public SyncInfoExpansionModel<T> syncInfo() { //since it is a set, there is no method with index access return new SyncInfoExpansionModel<>(pathExpression(), "syncInfo[*]"); }
@Test public void referenceExpansion() throws Exception { withOrder(client(), order -> { assertThat(order.getOrderNumber()).isNull(); final String orderNumber = randomString(); final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, SetOrderNumber.of(orderNumber)).plusExpansionPaths(m -> m.cart()); final Order updatedOrder = client().executeBlocking(orderUpdateCommand); assertThat(updatedOrder.getCart().getObj()).isNotNull(); return updatedOrder; }); }
@Test public void importLineItemState() throws Exception { withStandardStates(client(), (State initialState, State nextState) -> withOrder(client(), order -> { final LineItem lineItem = order.getLineItems().get(0); assertThat(lineItem).has(state(initialState)).has(not(state(nextState))); final Set<ItemState> itemStates = asSet(ItemState.of(nextState, 1L), ItemState.of(initialState, lineItem.getQuantity() - 1)); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, ImportLineItemState.of(lineItem, itemStates))); assertThat(updatedOrder.getLineItems().get(0)).has(itemStates(itemStates)); //reference expansion final OrderByIdGet orderByIdGet = OrderByIdGet.of(order).withExpansionPaths(m -> m.lineItems().state().state()); final Order loadedOrder = client().executeBlocking(orderByIdGet); final Reference<State> state = new LinkedList<>(loadedOrder.getLineItems().get(0).getState()).getFirst().getState(); assertThat(state.getObj()).isNotNull(); return updatedOrder; }) ); }
@Test public void updateSyncInfo() throws Exception { withOrderExportChannel(client(), channel -> withOrder(client(), order -> { assertThat(order.getSyncInfo()).isEmpty(); final ZonedDateTime aDateInThePast = ZonedDateTime_IN_PAST; final String externalId = "foo"; final UpdateSyncInfo action = UpdateSyncInfo.of(channel).withExternalId(externalId).withSyncedAt(aDateInThePast); final Order updatedOrder = client().executeBlocking(OrderUpdateCommand.of(order, action)); assertThat(updatedOrder.getSyncInfo()).containsOnly(SyncInfo.of(channel, aDateInThePast, externalId)); //check channel expansion final OrderByIdGet orderByIdGet = OrderByIdGet.of(order).withExpansionPaths(m -> m.syncInfo().channel()); final Order loadedOrder = client().executeBlocking(orderByIdGet); assertThat(new ArrayList<>(loadedOrder.getSyncInfo()).get(0).getChannel().getObj()).isNotNull(); return updatedOrder; }) ); }
@Test public void customerGroupIsExpandeable() throws Exception { CustomerFixtures.withCustomerInGroup(client(), (customer, customerGroup) -> { withOrder(client(), customer, order -> { final OrderQuery orderQuery = OrderQuery.of() .withPredicates(m -> m.id().is(order.getId()).and(m.customerGroup().is(customerGroup))) .withExpansionPaths(m -> m.customerGroup()); final Order queriedOrder = client().executeBlocking(orderQuery).head().get(); assertThat(queriedOrder.getCustomerGroup().getObj().getName()) .overridingErrorMessage("customerGroupIsExpandeable") .isEqualTo(customerGroup.getName()); return order; }); }); }
@Test public void addPayment() { withPayment(client(), payment -> { withOrder(client(), order -> { //add payment final OrderUpdateCommand orderUpdateCommand = OrderUpdateCommand.of(order, AddPayment.of(payment)) .withExpansionPaths(m -> m.paymentInfo().payments()); final Order orderWithPayment = client().executeBlocking(orderUpdateCommand); final Reference<Payment> paymentReference = orderWithPayment.getPaymentInfo().getPayments().get(0); assertThat(paymentReference).isEqualTo(payment.toReference()); assertThat(paymentReference).is(expanded(payment)); //remove payment final Order orderWithoutPayment = client().executeBlocking(OrderUpdateCommand.of(orderWithPayment, RemovePayment.of(payment))); assertThat(orderWithoutPayment.getPaymentInfo()).isNull(); return orderWithoutPayment; }); return payment; }); }
OrderByIdGetImpl(final String id) { super(id, OrderEndpoint.ENDPOINT, OrderExpansionModel.of(), OrderByIdGetImpl::new); }
OrderFromCartCreateCommandImpl(final OrderFromCartDraft draft) { super(draft, OrderEndpoint.ENDPOINT, OrderExpansionModel.of(), OrderFromCartCreateCommandImpl::new); }
OrderFromCartCreateCommandImpl(final OrderFromCartDraft draft) { super(draft, OrderEndpoint.ENDPOINT, OrderExpansionModel.of(), OrderFromCartCreateCommandImpl::new); }
OrderFromCartCreateCommandImpl(final OrderFromCartDraft draft) { super(draft, OrderEndpoint.ENDPOINT, OrderExpansionModel.of(), OrderFromCartCreateCommandImpl::new); }
OrderUpdateCommandImpl(final Versioned<Order> order, final List<? extends UpdateAction<Order>> updateActions) { super(order, updateActions, OrderEndpoint.ENDPOINT, OrderUpdateCommandImpl::new, OrderExpansionModel.of()); }
OrderByOrderNumberGetImpl(final String orderNumber) { super("", buildEndpoint(orderNumber), OrderExpansionModel.of(), OrderByOrderNumberGetImpl::new); }
OrderByOrderNumberGetImpl(final String orderNumber) { super("", buildEndpoint(orderNumber), OrderExpansionModel.of(), OrderByOrderNumberGetImpl::new); }
OrderByIdGetImpl(final String id) { super(id, JsonEndpoint.of(Order.typeReference(), "/orders"), OrderExpansionModel.of(), OrderByIdGetImpl::new); }
OrderDeleteCommandImpl(final Versioned<Order> versioned,final boolean eraseData) { super(versioned,eraseData, JsonEndpoint.of(Order.typeReference(), "/orders"), OrderExpansionModel.of(), OrderDeleteCommandImpl::new); }
OrderUpdateCommandImpl(final Versioned<Order> versioned, final List<? extends UpdateAction<Order>> updateActions) { super(versioned, updateActions, JsonEndpoint.of(Order.typeReference(), "/orders"), OrderUpdateCommandImpl::new, OrderExpansionModel.of()); }