/** {@inheritDoc} */
  @Override
  @Nullable
  public String apply(@Nullable final ProfileRequestContext input) {
    if (input == null) {
      return null;
    }

    final SpringRequestContext springRequestContext =
        input.getSubcontext(SpringRequestContext.class, false);
    if (springRequestContext == null) {
      return null;
    }

    final RequestContext requestContext = springRequestContext.getRequestContext();
    if (requestContext == null) {
      return null;
    }

    final FlowExecutionContext flowExecutionContext = requestContext.getFlowExecutionContext();
    if (flowExecutionContext == null) {
      return null;
    }

    if (!flowExecutionContext.isActive()) {
      return null;
    }

    final FlowDefinition flowDefinition = requestContext.getActiveFlow();

    final String flowId = flowDefinition.getId();
    log.debug("Current flow id is '{}'", flowId);
    return flowId;
  }
  @Override
  public void paused(RequestContext context) {

    if (isPersistenceContext(context.getActiveFlow())) {

      final EntityManager em =
          getEntityManager(context.getFlowExecutionContext().getActiveSession());

      /*
       * we were not be able to determine if entityManager has opened
       * connections, then the commit statement is always executed when
       * flow is paused
       */

      transactionTemplate.execute(
          new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {
              /*
               * Commit using the same connection retrieved by hibernate
               * lazy load,if exists, otherwise another connection will be
               * requested from pool
               */
              em.joinTransaction();
            }
          });
    }

    super.paused(context);
  }
 private String getFlowExecutionKey() {
   RequestContext requestContext = RequestContextHolder.getRequestContext();
   return requestContext.getFlowExecutionContext().getKey().toString();
 }