コード例 #1
0
  private void setAdditionalInfo(
      final StateChangeContext stateChangeContext, final long difference) {
    if (difference == 0L) {
      return;
    }
    final Entity stateChangeEntity = stateChangeContext.getStateChangeEntity();
    final StateChangeEntityDescriber describer = stateChangeContext.getDescriber();
    final OrderState orderState =
        (OrderState) stateChangeContext.getStateEnumValue(describer.getTargetStateFieldName());

    String additionalInfoKey = null;
    if (OrderState.IN_PROGRESS.equals(orderState)) {
      if (difference < 0L) {
        additionalInfoKey = "orders.order.stateChange.additionalInfo.startTooEarly";
      } else {
        additionalInfoKey = "orders.order.stateChange.additionalInfo.startTooLate";
      }
    } else if (OrderState.COMPLETED.equals(orderState)) {
      if (difference < 0L) {
        additionalInfoKey = "orders.order.stateChange.additionalInfo.endTooEarly";
      } else {
        additionalInfoKey = "orders.order.stateChange.additionalInfo.endTooLate";
      }
    } else {
      return;
    }

    final String differenceAsString =
        TimeConverterService.convertTimeToString(String.valueOf(Math.abs(difference)));
    final String additionalInfo =
        translationService.translate(
            additionalInfoKey, LocaleContextHolder.getLocale(), differenceAsString);
    stateChangeEntity.setField(OrderStateChangeFields.ADDITIONAL_INFO, additionalInfo);
    stateChangeContext.save();
  }
コード例 #2
0
  public void closeOrder(final StateChangeContext stateChangeContext) {
    final Entity productionTracking = stateChangeContext.getOwner();
    final Entity order = productionTracking.getBelongsToField(ORDER);

    if (!orderClosingHelper.orderShouldBeClosed(productionTracking)) {
      return;
    }
    if (order.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderIsAlreadyClosed", StateMessageType.INFO, false);
      return;
    }
    final StateChangeContext orderStateChangeContext =
        stateChangeContextBuilder.build(
            orderStateChangeAspect.getChangeEntityDescriber(),
            order,
            OrderState.COMPLETED.getStringValue());
    orderStateChangeAspect.changeState(orderStateChangeContext);
    Entity orderFromDB = order.getDataDefinition().get(orderStateChangeContext.getOwner().getId());
    if (orderFromDB.getStringField(STATE).equals(COMPLETED.getStringValue())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderClosed", StateMessageType.INFO, false);
    } else if (StateChangeStatus.PAUSED.equals(orderStateChangeContext.getStatus())) {
      stateChangeContext.addMessage(
          "productionCounting.order.orderWillBeClosedAfterExtSync", StateMessageType.INFO, false);
    } else {
      stateChangeContext.addMessage(
          "productionCounting.order.orderCannotBeClosed", StateMessageType.FAILURE, false);

      List<ErrorMessage> errors = Lists.newArrayList();

      if (!orderFromDB.getErrors().isEmpty()) {
        errors.addAll(order.getErrors().values());
      }
      if (!orderFromDB.getGlobalErrors().isEmpty()) {
        errors.addAll(order.getGlobalErrors());
      }

      if (!errors.isEmpty()) {
        StringBuilder errorMessages = new StringBuilder();

        for (ErrorMessage errorMessage : errors) {
          String translatedErrorMessage =
              translationService.translate(
                  errorMessage.getMessage(), Locale.getDefault(), errorMessage.getVars());
          errorMessages.append(translatedErrorMessage);
          errorMessages.append(", ");
        }

        stateChangeContext.addValidationError(
            "orders.order.orderStates.error", errorMessages.toString());
      }
    }
  }