@Test
  public void testRunFailWithRetry() {
    final TaskModel taskModelMock = mock(TaskModel.class);
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final DefaultSendOrderCancelRequestToDataHubHelper cSVHelperMock =
        mock(DefaultSendOrderCancelRequestToDataHubHelper.class);
    final TaskService paramTaskService = null;
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);

    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);
    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(cSVHelperMock.createAndSendRawItem(orderCancelRecordEntryMock))
        .thenReturn(new DefaultSendToDataHubResult(HttpStatus.FORBIDDEN, ""));
    when(modificationRecordMock.getOrder()).thenReturn(order);

    cut.setModelService(modelService);
    cut.setOrderCancelRequestCSVHelper(cSVHelperMock);
    try {
      cut.run(paramTaskService, taskModelMock);
    } catch (final RetryLaterException e) {
      verify(cSVHelperMock).createAndSendRawItem(orderCancelRecordEntryMock);
      verify(modelService).save(order);
      assertEquals(OrderStatus.CANCELLING, order.getStatus());
      assertEquals(SendOrderCancelRequestAsCSVTaskRunner.DEFAULT_RETRY_DELAY, e.getDelay());
      return;
    }
    fail("RetryLaterException missing");
  }
  @Test
  public void testSetEntryNumbersForNewEntriesHalfAutomatically() {
    final OrderModel order = createNewOrder();

    modelService.save(order);
    final List<AbstractOrderEntryModel> oldEntries = order.getEntries();

    Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber());

    final OrderEntryModel entry1 = createTestOrderEntry(order);
    entry1.setEntryNumber(5);
    final OrderEntryModel entry2 = createTestOrderEntry(order);
    entry2.setEntryNumber(4);
    final OrderEntryModel entry3 = createTestOrderEntry(order);
    final OrderEntryModel entry4 = createTestOrderEntry(order);

    modelService.saveAll(entry1, entry2, entry3, entry4);
    Assert.assertEquals(Integer.valueOf(5), entry1.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(4), entry2.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(6), entry3.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(7), entry4.getEntryNumber());
  }
  @Test
  public void testRunFailWithoutRetry() throws RetryLaterException {
    final TaskModel taskModelMock = mock(TaskModel.class);
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final DefaultSendOrderCancelRequestToDataHubHelper cSVHelperMock =
        mock(DefaultSendOrderCancelRequestToDataHubHelper.class);
    final TaskService paramTaskService = null;
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);

    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);
    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(cSVHelperMock.createAndSendRawItem(orderCancelRecordEntryMock))
        .thenReturn(new DefaultSendToDataHubResult(HttpStatus.FORBIDDEN, ""));
    when(modificationRecordMock.getOrder()).thenReturn(order);
    when(taskModelMock.getRetry()).thenReturn(Integer.valueOf(11));

    cut.setModelService(modelService);
    cut.setOrderCancelRequestCSVHelper(cSVHelperMock);
    cut.run(paramTaskService, taskModelMock);

    verify(cSVHelperMock).createAndSendRawItem(orderCancelRecordEntryMock);
    verify(modelService).save(order);
    assertEquals(OrderStatus.CANCELLING, order.getStatus());
  }
 private void assertEntriesOrder(final OrderModel order) {
   if (!modelService.isNew(order)) {
     Assert.assertEquals(
         "Unexpected product in order entry 1: ",
         product1,
         orderService.getEntryForNumber(order, 0).getProduct());
     Assert.assertEquals(
         "Unexpected product in order entry 2: ",
         product2,
         orderService.getEntryForNumber(order, 1).getProduct());
     Assert.assertEquals(
         "Unexpected product in order entry 3: ",
         product3,
         orderService.getEntryForNumber(order, 2).getProduct());
     Assert.assertEquals(
         "Unexpected product in order entry 4: ",
         product4,
         orderService.getEntryForNumber(order, 3).getProduct());
   }
   Assert.assertEquals(
       "Unexpected product in order entry 1: ", product1, order.getEntries().get(0).getProduct());
   Assert.assertEquals(
       "Unexpected product in order entry 2: ", product2, order.getEntries().get(1).getProduct());
   Assert.assertEquals(
       "Unexpected product in order entry 3: ", product3, order.getEntries().get(2).getProduct());
   Assert.assertEquals(
       "Unexpected product in order entry 4: ", product4, order.getEntries().get(3).getProduct());
 }
  @Before
  public void setUp() throws Exception {
    // Used for MockitoAnnotations annotations
    MockitoAnnotations.initMocks(this);
    action.setModelService(modelService);
    action.setTicketBusinessService(ticketBusinessService);
    BDDMockito.given(modelService.create(CsTicketModel.class)).willReturn(new CsTicketModel());

    authorizationAccepted =
        createPaymentTransactionEntry(
            PaymentTransactionType.AUTHORIZATION, TransactionStatus.ACCEPTED);
    authorizationReview =
        createPaymentTransactionEntry(
            PaymentTransactionType.AUTHORIZATION, TransactionStatus.REVIEW);
    reviewAccepted =
        createPaymentTransactionEntry(
            PaymentTransactionType.REVIEW_DECISION, TransactionStatus.ACCEPTED);
    reviewRejected =
        createPaymentTransactionEntry(
            PaymentTransactionType.REVIEW_DECISION, TransactionStatus.REJECTED);

    process = new OrderProcessModel();
    final OrderModel order = new OrderModel();
    process.setOrder(order);
    final List<PaymentTransactionModel> paymentTransactionList =
        new ArrayList<PaymentTransactionModel>();
    order.setPaymentTransactions(paymentTransactionList);
    final PaymentTransactionModel paymentTransactionModel = new PaymentTransactionModel();
    paymentTransactionList.add(paymentTransactionModel);
    paymentTransactionEntriesList = new ArrayList<PaymentTransactionEntryModel>();
    paymentTransactionModel.setEntries(paymentTransactionEntriesList);
  }
Ejemplo n.º 6
0
 @Override
 public void run() {
   ru.technonikol.ws.orders.Order integrationOrder = null;
   // convert order
   try {
     integrationOrder = convert(order);
   } catch (final ConversionException ex) {
     LOG.error(
         "Error when trying to convert de.hybris.platform.core.model.order.OrderModel to ru.technonikol.ws.orders.Order",
         ex);
     order.setStatus(OrderStatus.SENT_TO_SERVER_ERROR);
     modelService.save(order);
     return;
   }
   // send to service
   try {
     createOrderIntegrationService.ordersCreateRequestOutSyn(integrationOrder);
   } catch (WebServiceException exception) {
     // if service is unavailable
     if (exception.getCause() instanceof ConnectException
         || exception.getCause() instanceof SocketTimeoutException) {
       order.setStatus(OrderStatus.RESEND_TO_SERVER);
       modelService.save(order);
       return;
       // service data processing errors
     } else {
       order.setStatus(OrderStatus.SENT_TO_SERVER_ERROR);
       modelService.save(order);
     }
     return;
   }
   order.setStatus(OrderStatus.SENT_TO_SERVER_OK);
   modelService.save(order);
 }
 private void assertNew(final OrderModel order) {
   Assert.assertTrue(modelService.isNew(order));
   Assert.assertTrue(modelService.isNew(order.getEntries().get(0)));
   Assert.assertTrue(modelService.isNew(order.getEntries().get(1)));
   Assert.assertTrue(modelService.isNew(order.getEntries().get(2)));
   Assert.assertTrue(modelService.isNew(order.getEntries().get(3)));
 }
 protected void addDeliveryStatus(final OrderModel source, final OrderData target) {
   target.setDeliveryStatus(source.getDeliveryStatus());
   if (source.getDeliveryStatus() != null) {
     target.setDeliveryStatusDisplay(
         getTypeService().getEnumerationValue(source.getDeliveryStatus()).getName());
   }
 }
  @Test
  public void shouldStartApprovalProcessAndIgnoreInactiveCreditLimit() throws Exception {
    final String userId = "GC S HH";
    login(userId);

    // Set up credit limit data for test
    final B2BUnitModel unitLoggedIn = b2bUnitService.getUnitForUid("GC Sales Hamburg");
    final B2BCreditLimitModel creditLimitToUse =
        b2bUnitService.getParent(unitLoggedIn).getCreditLimit();
    creditLimitToUse.setActive(Boolean.TRUE);
    creditLimitToUse.setDateRange(B2BPeriodRange.DAY);
    creditLimitToUse.setDatePeriod(null);
    modelService.save(creditLimitToUse);

    // Credit Limit is active, so unit is returned
    final B2BUnitModel unitWithCreditLimit = b2bUnitService.getUnitWithCreditLimit(unitLoggedIn);
    Assert.assertNotNull(unitWithCreditLimit);

    // Update credit limit with past start/end dates as date range
    final B2BCreditLimitModel creditLimit = unitWithCreditLimit.getCreditLimit();
    creditLimit.setActive(Boolean.FALSE);

    modelService.save(creditLimit);

    // Create order which crosses credit limit
    final OrderModel order =
        createOrder(
            this.login("GC S HH"),
            140,
            OrderStatus.CREATED,
            productService.getProductForCode("testProduct0"));
    Assert.assertNotNull(order);

    final B2BApprovalProcessModel b2bApprovalProcessModel =
        getB2BApprovalProcessModelForOrder(order);

    // Process does not stop at waitProcessCreditLimit, so it should continue after waitProcess
    if (this.waitForProcessAction(b2bApprovalProcessModel.getCode(), "waitProcess", 20000)) {
      modelService.refresh(order);
      final Collection<WorkflowActionModel> actions =
          b2bWorkflowIntegrationService.getStartWorkflowActions(order.getWorkflow());
      Assert.assertEquals(1, actions.size());
      b2bWorkflowIntegrationService.approveWorkflowAction(actions.iterator().next());
    }

    // Credit limit is inactive, so unit is null
    final B2BUnitModel unitWithCreditLimitNull =
        b2bUnitService.getUnitWithCreditLimit(order.getUnit());
    Assert.assertNull(unitWithCreditLimitNull);

    // Process finishes and order placed above is approved - Order total is more than credit limit
    // amount, but
    // credit limit is inactive, so its ignored
    this.waitForProcessToEnd(b2bApprovalProcessModel.getCode(), 20000);
    this.modelService.refresh(order);
    this.modelService.refresh(b2bApprovalProcessModel);
    Assert.assertEquals(OrderStatus.APPROVED, order.getStatus());
    Assert.assertEquals(ProcessState.SUCCEEDED, b2bApprovalProcessModel.getProcessState());
  }
 @Override
 protected boolean shouldHandleEvent(final OrderCancelledEvent event) {
   final OrderModel order = event.getProcess().getOrder();
   ServicesUtil.validateParameterNotNullStandardMessage("event.order", order);
   final BaseSiteModel site = order.getSite();
   ServicesUtil.validateParameterNotNullStandardMessage("event.order.site", site);
   return SiteChannel.B2C.equals(site.getChannel());
 }
  @Override
  public Transition executeAction(final OrderProcessModel process) {
    LOG.info("Process: " + process.getCode() + " in step " + getClass());
    ServicesUtil.validateParameterNotNull(process, "Process can not be null");
    ServicesUtil.validateParameterNotNull(process.getOrder(), "Order can not be null");

    final double scoreLimit =
        Double.parseDouble(
            Config.getParameter(
                HybrisTestFulfilmentProcessConstants.EXTENSIONNAME + ".fraud.scoreLimitExternal"));
    final double scoreTolerance =
        Double.parseDouble(
            Config.getParameter(
                HybrisTestFulfilmentProcessConstants.EXTENSIONNAME
                    + ".fraud.scoreToleranceExternal"));

    final OrderModel order = process.getOrder();
    final FraudServiceResponse response =
        getFraudService().recognizeOrderSymptoms(getProviderName(), order);
    final double score = response.getScore();
    if (score < scoreLimit) {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.OK);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.OK, null);
      order.setFraudulent(Boolean.FALSE);
      order.setPotentiallyFraudulent(Boolean.FALSE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.OK;
    } else if (score < scoreLimit + scoreTolerance) {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.CHECK);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.CHECK, fraudReport.getCode());
      order.setFraudulent(Boolean.FALSE);
      order.setPotentiallyFraudulent(Boolean.TRUE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.POTENTIAL;
    } else {
      final FraudReportModel fraudReport =
          createFraudReport(providerName, response, order, FraudStatus.FRAUD);
      final OrderHistoryEntryModel historyEntry =
          createHistoryLog(providerName, order, FraudStatus.FRAUD, fraudReport.getCode());
      order.setFraudulent(Boolean.TRUE);
      order.setPotentiallyFraudulent(Boolean.FALSE);
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      modelService.save(fraudReport);
      modelService.save(historyEntry);
      modelService.save(order);
      return Transition.FRAUD;
    }
  }
  @Test
  public void testExecute() throws RetryLaterException, Exception {

    final OrderProcessModel orderProcess = new OrderProcessModel();
    final OrderModel order = new OrderModel();
    order.setStatus(OrderStatus.CREATED);
    orderProcess.setOrder(order);
    prepareOrderForManualCheck.executeAction(orderProcess);
    Assert.assertEquals(OrderStatus.WAIT_FRAUD_MANUAL_CHECK, orderProcess.getOrder().getStatus());
  }
  @Override
  public List<Map<String, Object>> createRows(final OrderModel order) {
    final Map<String, Object> row = new HashMap<>();

    row.put(OrderCsvColumns.ORDER_ID, order.getCode());
    row.put(OrderCsvColumns.DATE, order.getDate());
    row.put(OrderCsvColumns.ORDER_CURRENCY_ISO_CODE, order.getCurrency().getIsocode());
    final DeliveryModeModel deliveryMode = order.getDeliveryMode();
    row.put(OrderCsvColumns.DELIVERY_MODE, deliveryMode != null ? deliveryMode.getCode() : "");
    row.put(OrderCsvColumns.BASE_STORE, order.getStore().getUid());
    return Arrays.asList(row);
  }
  @Test
  public void shouldStartApprovalProcessAndAssertApprovalFromMerchant() throws Exception {
    login("GC S HH");

    // Set up credit limit data for test
    final B2BUnitModel unitLoggedIn = b2bUnitService.getUnitForUid("GC Sales Hamburg");
    final B2BCreditLimitModel creditLimitToUse =
        b2bUnitService.getParent(unitLoggedIn).getCreditLimit();
    creditLimitToUse.setActive(Boolean.TRUE);
    creditLimitToUse.setDateRange(B2BPeriodRange.DAY);
    creditLimitToUse.setDatePeriod(null);
    modelService.save(creditLimitToUse);

    final OrderModel order =
        createOrder(
            this.login("GC S HH"),
            140,
            OrderStatus.CREATED,
            productService.getProductForCode("testProduct0"));
    Assert.assertNotNull(order);

    final B2BApprovalProcessModel b2bApprovalProcessModel =
        getB2BApprovalProcessModelForOrder(order);

    final B2BUnitModel unitWithCreditLimit = b2bUnitService.getUnitWithCreditLimit(order.getUnit());

    Assert.assertEquals("GC Sales DE", unitWithCreditLimit.getUid());

    if (this.waitForProcessAction(b2bApprovalProcessModel.getCode(), "waitProcess", 20000)) {
      modelService.refresh(order);
      final Collection<WorkflowActionModel> actions =
          b2bWorkflowIntegrationService.getStartWorkflowActions(order.getWorkflow());
      Assert.assertEquals(1, actions.size());
      b2bWorkflowIntegrationService.decideAction(
          actions.iterator().next(), B2BWorkflowIntegrationService.DECISIONCODES.APPROVE.name());
    }

    if (this.waitForProcessAction(
        b2bApprovalProcessModel.getCode(), "waitProcessCreditLimit", 20000)) {
      modelService.refresh(order);
      final Collection<WorkflowActionModel> actions =
          b2bWorkflowIntegrationService.getStartWorkflowActions(order.getWorkflow());
      Assert.assertEquals(1, actions.size());
      this.approveWorkflowAction(actions.iterator().next());
    }

    this.waitForProcessToEnd(b2bApprovalProcessModel.getCode(), 20000);
    this.modelService.refresh(order);
    this.modelService.refresh(b2bApprovalProcessModel);
    Assert.assertEquals(OrderStatus.APPROVED, order.getStatus());
    Assert.assertEquals(ProcessState.SUCCEEDED, b2bApprovalProcessModel.getProcessState());
  }
  private void assertSaved(final OrderModel order) {
    Assert.assertFalse(modelService.isNew(order));
    Assert.assertFalse(modelService.isNew(order.getEntries().get(0)));
    Assert.assertFalse(modelService.isNew(order.getEntries().get(1)));
    Assert.assertFalse(modelService.isNew(order.getEntries().get(2)));
    Assert.assertFalse(modelService.isNew(order.getEntries().get(3)));

    Assert.assertTrue(modelService.isUpToDate(order));
    Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(0)));
    Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(1)));
    Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(2)));
    Assert.assertTrue(modelService.isUpToDate(order.getEntries().get(3)));
  }
Ejemplo n.º 16
0
  protected Transition executeAction(final OrderProcessModel process) {
    ServicesUtil.validateParameterNotNull(process, "Process cannot be null");
    LOG.info("Process: " + process.getCode() + " in step " + getClass().getSimpleName());

    final OrderModel order = process.getOrder();
    ServicesUtil.validateParameterNotNull(order, "Order in process cannot be null");
    ServicesUtil.validateParameterNotNull(
        order.getFraudulent(), "Fraudulent value in order cannot be null");

    final OrderHistoryEntryModel historyLog =
        createHistoryLog("Order Manually checked by CSA - Fraud = " + order.getFraudulent(), order);
    modelService.save(historyLog);

    LOG.info(
        "The fraud condition of the order "
            + order.getCode()
            + " is "
            + order.getFraudulent().booleanValue());
    if (order.getFraudulent().booleanValue()) {
      order.setStatus(OrderStatus.SUSPENDED);
      getModelService().save(order);
      return Transition.NOK;
    } else {
      order.setStatus(OrderStatus.FRAUD_CHECKED);
      getModelService().save(order);
      return Transition.OK;
    }
  }
  @Test
  public void testExecuteActionNOK() throws RetryLaterException, Exception {
    final OrderProcessModel businessProcessModel = new OrderProcessModel();

    final OrderModel order = new OrderModel();
    final PaymentTransactionModel paymentTransaction = new PaymentTransactionModel();
    final PaymentTransactionEntryModel entry = new PaymentTransactionEntryModel();
    entry.setType(PaymentTransactionType.AUTHORIZATION);
    entry.setTransactionStatus(TransactionStatus.REJECTED.name());
    paymentTransaction.setEntries(Arrays.asList(entry));
    businessProcessModel.setOrder(order);
    order.setPaymentTransactions(Arrays.asList(paymentTransaction));
    Assertions.assertThat(checkAuthorizeOrderPayment.executeAction(businessProcessModel))
        .isEqualTo(Transition.NOK);
  }
  @Test
  public void shouldTriggerCreditAlert() throws Exception {
    // Step 1 There should not be any template for Alert
    final EmployeeModel employeeModel = userService.getAdminUser();
    WorkflowTemplateModel workflowTemplateModel = null;
    try {
      workflowTemplateModel =
          workflowTemplateService.getWorkflowTemplateForCode("B2B-Alert-GC Acct Mgr");
    } catch (final UnknownIdentifierException uie) {
      // Do nothing
    }

    Assert.assertNull(workflowTemplateModel);

    /**
     * Create and order between 8000 - 10000 EUR for unit GC Sales DE Alert should be created for GC
     * Sales Rep
     */
    final OrderModel order = createOrder("GC Sales DE Boss", 900, OrderStatus.CREATED);
    Assert.assertNotNull(order);

    // Set up credit limit data for test so that it generates an Alert
    final B2BUnitModel unitLoggedIn = b2bUnitService.getUnitForUid("GC Sales DE");
    final B2BCreditLimitModel creditLimitToUse = unitLoggedIn.getCreditLimit();
    creditLimitToUse.setActive(Boolean.TRUE);
    creditLimitToUse.setDateRange(B2BPeriodRange.DAY);
    creditLimitToUse.setDatePeriod(null);
    creditLimitToUse.setAlertSentDate(null);
    modelService.save(creditLimitToUse);

    final B2BApprovalProcessModel b2bApprovalProcessModel =
        getB2BApprovalProcessModelForOrder(order);

    this.waitForProcessToEnd(b2bApprovalProcessModel.getCode(), 20000);
    this.modelService.refresh(order);
    this.modelService.refresh(b2bApprovalProcessModel);

    // verify that creditCheckAlert was sent - template and workflow should exist for an Alert
    workflowTemplateModel =
        workflowTemplateService.getWorkflowTemplateForCode("B2B-Alert-GC Acct Mgr");
    Assert.assertNotNull(workflowTemplateModel);
    final List<WorkflowModel> workflowModelList =
        newestWorkflowService.getWorkflowsForTemplateAndUser(workflowTemplateModel, employeeModel);
    Assert.assertTrue(CollectionUtils.isNotEmpty(workflowModelList));

    Assert.assertEquals(OrderStatus.APPROVED, order.getStatus());
    Assert.assertEquals(ProcessState.SUCCEEDED, b2bApprovalProcessModel.getProcessState());
  }
 @Override
 protected void onSiteEvent(final OrderCancelledEvent event) {
   final OrderModel orderModel = event.getProcess().getOrder();
   final OrderProcessModel orderProcessModel =
       (OrderProcessModel)
           getBusinessProcessService()
               .createProcess(
                   "sendOrderCancelledEmailProcess-"
                       + orderModel.getCode()
                       + "-"
                       + System.currentTimeMillis(),
                   "sendOrderCancelledEmailProcess");
   orderProcessModel.setOrder(orderModel);
   getModelService().save(orderProcessModel);
   getBusinessProcessService().startProcess(orderProcessModel);
 }
 @Override
 public boolean check(final OrderModel order) {
   if (!order.getCalculated().booleanValue()) {
     // Order must be calculated
     return false;
   }
   if (order.getEntries().isEmpty()) {
     // Order must have some lines
     return false;
   } else if (order.getPaymentInfo() == null) {
     // Order must have some payment info to use in the process
     return false;
   } else {
     // Order delivery options must be valid
     return checkDeliveryOptions(order);
   }
 }
  protected boolean checkDeliveryOptions(final OrderModel order) {
    if (order.getDeliveryMode() == null) {
      // Order must have an overall delivery mode
      return false;
    }

    if (order.getDeliveryAddress() == null) {
      for (final AbstractOrderEntryModel entry : order.getEntries()) {
        if (entry.getDeliveryPointOfService() == null && entry.getDeliveryAddress() == null) {
          // Order and Entry have no delivery address and some entries are not for pickup
          return false;
        }
      }
    }

    return true;
  }
Ejemplo n.º 22
0
 @Override
 protected void onSiteEvent(final OrderPlacedEvent orderPlacedEvent) {
   final OrderModel orderModel = orderPlacedEvent.getProcess().getOrder();
   final OrderProcessModel orderProcessModel =
       (OrderProcessModel)
           getBusinessProcessService()
               .createProcess(
                   "b2bOrderConfirmationEmailProcess"
                       + "-"
                       + orderModel.getCode()
                       + "-"
                       + System.currentTimeMillis(),
                   "b2bOrderConfirmationEmailProcess");
   orderProcessModel.setOrder(orderModel);
   getModelService().save(orderProcessModel);
   getBusinessProcessService().startProcess(orderProcessModel);
 }
  @Test
  public void testManualOrderEntryPositions() {
    final OrderModel newOne = createNewOrder();

    // take out entries
    final List<AbstractOrderEntryModel> entries = newOne.getEntries();
    newOne.setEntries(null);

    modelService.save(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertEquals(Collections.EMPTY_LIST, newOne.getEntries());

    Assert.assertTrue(modelService.isNew(entries.get(0)));
    Assert.assertTrue(modelService.isNew(entries.get(1)));
    Assert.assertTrue(modelService.isNew(entries.get(2)));
    Assert.assertTrue(modelService.isNew(entries.get(3)));

    // now save in reverse order
    AbstractOrderEntryModel entry = entries.get(3);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(3), entry.getEntryNumber());

    entry = entries.get(2);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(2), entry.getEntryNumber());

    entry = entries.get(1);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(1), entry.getEntryNumber());

    entry = entries.get(0);
    modelService.save(entry);
    Assert.assertEquals(Integer.valueOf(0), entry.getEntryNumber());

    modelService.refresh(newOne);

    Assert.assertFalse(modelService.isNew(newOne));
    Assert.assertFalse(modelService.isNew(entries.get(0)));
    Assert.assertFalse(modelService.isNew(entries.get(1)));
    Assert.assertFalse(modelService.isNew(entries.get(2)));
    Assert.assertFalse(modelService.isNew(entries.get(3)));

    assertEntriesOrder(newOne);
  }
  @Test
  public void testSetEntryNumbersForAdditionalEntries() {
    final OrderModel order = createNewOrder();

    modelService.save(order);
    final List<AbstractOrderEntryModel> oldEntries = order.getEntries();

    Assert.assertEquals(Integer.valueOf(0), oldEntries.get(0).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(1), oldEntries.get(1).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(2), oldEntries.get(2).getEntryNumber());
    Assert.assertEquals(Integer.valueOf(3), oldEntries.get(3).getEntryNumber());

    final OrderEntryModel entry1 = createTestOrderEntry(order);
    final OrderEntryModel entry2 = createTestOrderEntry(order);
    modelService.saveAll(entry1, entry2);
    Assert.assertEquals(Integer.valueOf(4), entry1.getEntryNumber());
    Assert.assertEquals(Integer.valueOf(5), entry2.getEntryNumber());
  }
  protected Transition executeAction(final OrderProcessModel process) {
    ServicesUtil.validateParameterNotNull(process, "Process cannot be null");

    final OrderModel order = process.getOrder();
    ServicesUtil.validateParameterNotNull(order, "Order in process cannot be null");
    if (order.getFraudulent() != null) {
      final OrderHistoryEntryModel historyLog =
          createHistoryLog(
              "Order Manually checked by CSA - Fraud = " + order.getFraudulent(), order);
      modelService.save(historyLog);
      if (order.getFraudulent().booleanValue()) {
        order.setStatus(OrderStatus.SUSPENDED);
        getModelService().save(order);
        return Transition.NOK;
      }
      return Transition.OK;
    }
    return Transition.UNDEFINED;
  }
  @Test
  public void testHandleError() {
    final OrderCancelRecordEntryModel orderCancelRecordEntryMock =
        mock(OrderCancelRecordEntryModel.class);
    final OrderModificationRecordModel modificationRecordMock =
        mock(OrderModificationRecordModel.class);
    final OrderModel order = new OrderModel();
    final ModelService modelService = mock(ModelService.class);
    final TaskModel taskModelMock = mock(TaskModel.class);

    when(orderCancelRecordEntryMock.getModificationRecord()).thenReturn(modificationRecordMock);
    when(modificationRecordMock.getOrder()).thenReturn(order);
    when(taskModelMock.getContext()).thenReturn(orderCancelRecordEntryMock);

    cut.setModelService(modelService);
    cut.handleError(null, taskModelMock, null);

    verify(modelService).save(order);
    assertEquals(OrderStatus.CANCELLING, order.getStatus());
  }
  @Override
  public Transition executeAction(final OrderProcessModel process) {
    final OrderModel order = process.getOrder();

    if (order != null) {
      if (order.getPaymentInfo() instanceof InvoicePaymentInfoModel) {
        return Transition.OK;
      } else {
        for (final PaymentTransactionModel transaction : order.getPaymentTransactions()) {
          for (final PaymentTransactionEntryModel entry : transaction.getEntries()) {
            if (entry.getType().equals(PaymentTransactionType.AUTHORIZATION)
                && TransactionStatus.ACCEPTED.name().equals(entry.getTransactionStatus())) {
              order.setStatus(OrderStatus.PAYMENT_AUTHORIZED);
              modelService.save(order);
              return Transition.OK;
            }
          }
        }
      }
    }
    return Transition.NOK;
  }
  @Override
  public void executeAction(final B2BApprovalProcessModel process) throws RetryLaterException {
    OrderModel order = null;
    try {
      order = process.getOrder();
      Assert.notNull(
          order,
          String.format("Order of BusinessProcess %s should have be set for accelerator", process));
      final B2BCustomerModel user = (B2BCustomerModel) order.getUser();
      if (LOG.isDebugEnabled()) {
        LOG.debug(
            String.format(
                "Process for accelerator: %s in step %s order: %s user: %s ",
                process.getCode(), getClass(), order.getUnit(), user.getUid()));
      }
    } catch (final Exception exception) {
      LOG.error(exception.getMessage(), exception);
      this.handleError(order, exception);

      throw new RuntimeException(exception.getMessage(), exception);
    }
  }
 private void displayEntries(final OrderModel order, final String prefix) {
   System.out.println(prefix + "Order@" + System.identityHashCode(order));
   final List<AbstractOrderEntryModel> entries = order.getEntries();
   if (entries != null && !entries.isEmpty()) {
     for (final AbstractOrderEntryModel entry : entries) {
       System.out.println(
           prefix
               + "Entry@"
               + System.identityHashCode(entry)
               + ", Entry.PK="
               + entry.getPk()
               + ", Entry.EntryNumber="
               + entry.getEntryNumber()
               + ", Entry.Product.PK="
               + entry.getProduct().getPk()
               + ", Entry.Product.Code="
               + entry.getProduct().getCode());
     }
   }
 }
  private OrderModel createNewOrder() {
    final OrderModel order = modelService.create(OrderModel.class);

    final UserModel user = userService.getCurrentUser();

    order.setUser(user);

    order.setCurrency(commonI18NService.getBaseCurrency());
    order.setDate(new java.util.Date());
    order.setNet(Boolean.FALSE);

    final OrderEntryModel entry1 = modelService.create(OrderEntryModel.class);
    entry1.setOrder(order);
    entry1.setQuantity(Long.valueOf(1));
    entry1.setUnit(productService.getOrderableUnit(product1));
    entry1.setProduct(product1);
    entry1.setEntryNumber(Integer.valueOf(0));

    final OrderEntryModel entry2 = modelService.create(OrderEntryModel.class);
    entry2.setOrder(order);
    entry2.setQuantity(Long.valueOf(1));
    entry2.setUnit(productService.getOrderableUnit(product2));
    entry2.setProduct(product2);
    entry2.setEntryNumber(Integer.valueOf(1));

    final OrderEntryModel entry3 = modelService.create(OrderEntryModel.class);
    entry3.setOrder(order);
    entry3.setQuantity(Long.valueOf(1));
    entry3.setUnit(productService.getOrderableUnit(product3));
    entry3.setProduct(product3);
    entry3.setEntryNumber(Integer.valueOf(2));

    final OrderEntryModel entry4 = modelService.create(OrderEntryModel.class);
    entry4.setOrder(order);
    entry4.setQuantity(Long.valueOf(1));
    entry4.setUnit(productService.getOrderableUnit(product4));
    entry4.setProduct(product4);
    entry4.setEntryNumber(Integer.valueOf(3));

    order.setEntries((List) Arrays.asList(entry1, entry2, entry3, entry4));

    return order;
  }