// Path: src/main/java/org/expedientframework/workflowlite/core/AbstractAsyncAction.java
// public abstract class AbstractAsyncAction<TContext extends ExecutionContext, TResult> extends AbstractAction<TContext, CompletableFuture<TResult>>
// {
// }
// 
// Path: src/main/java/org/expedientframework/workflowlite/core/DefaultExecutionContext.java
// public class DefaultExecutionContext extends AbstractExecutionContext
// {
//   /**
//    * Default constructor taking in the workflow id. It uses 'source' default name for referring the 
//    * original input object in the Spring Expression Language.
//    * 
//    * @param workflowId The workflow id. This should match the ID in the UML diagram.
//    */
//   public DefaultExecutionContext(final String workflowId)
//   {
//     this(workflowId, "source");
//   }
// 
//   /**
//    * Constructor taking in the workflow id and the source property name.
//    * 
//    * @param workflowId The workflow id. This should match the ID in the UML diagram.
//    * @param sourcePropertyName The name by which the input object should be referred in the 
//    * Spring Expression Languange.
//    */
//   public DefaultExecutionContext(final String workflowId, final String sourcePropertyName)
//   {
//     super(workflowId, sourcePropertyName);
//   }
// }


import org.expedientframework.workflowlite.core.AbstractAsyncAction;
import org.expedientframework.workflowlite.core.DefaultExecutionContext;
import java.util.concurrent.CompletableFuture;
/********************************************************************
 * File Name:    AsyncReverseStringAction.java
 *
 * Date Created: Aug 24, 2017
 *
 * ------------------------------------------------------------------
 * 
 * Copyright @ 2017 ajeydudhe@gmail.com
 *
 *******************************************************************/

package org.expedientframework.workflowlite.core.actions;



  
public class AsyncReverseStringAction extends AbstractAsyncAction<DefaultExecutionContext, String>
{
  protected AsyncReverseStringAction(final String value)
  {
    this.value = value;
  }
  
  @Override
  public CompletableFuture<String> execute(DefaultExecutionContext context)
  {
    final CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
        
        if(this.bThrowException)
        {
          throw new RuntimeException("Dummy exception thrown from " + this.getClass().getSimpleName() + ".");
        } 
        
        return new StringBuilder(this.value).reverse().toString();
      });
    
    if(this.bCancel)
    {
      future.cancel(true);
    }
    
    return future;
  }

  public void setThrowException(boolean bThrowException)
  {
    this.bThrowException = bThrowException;
  }

// Path: src/main/java/org/expedientframework/workflowlite/core/AbstractAsyncAction.java
// public abstract class AbstractAsyncAction<TContext extends ExecutionContext, TResult> extends AbstractAction<TContext, CompletableFuture<TResult>>
// {
// }
// 
// Path: src/main/java/org/expedientframework/workflowlite/core/DefaultExecutionContext.java
// public class DefaultExecutionContext extends AbstractExecutionContext
// {
//   /**
//    * Default constructor taking in the workflow id. It uses 'source' default name for referring the 
//    * original input object in the Spring Expression Language.
//    * 
//    * @param workflowId The workflow id. This should match the ID in the UML diagram.
//    */
//   public DefaultExecutionContext(final String workflowId)
//   {
//     this(workflowId, "source");
//   }
// 
//   /**
//    * Constructor taking in the workflow id and the source property name.
//    * 
//    * @param workflowId The workflow id. This should match the ID in the UML diagram.
//    * @param sourcePropertyName The name by which the input object should be referred in the 
//    * Spring Expression Languange.
//    */
//   public DefaultExecutionContext(final String workflowId, final String sourcePropertyName)
//   {
//     super(workflowId, sourcePropertyName);
//   }
// }


// Path: src/test/java/org/expedientframework/workflowlite/core/actions/AsyncReverseStringAction.java
import org.expedientframework.workflowlite.core.AbstractAsyncAction;
import org.expedientframework.workflowlite.core.DefaultExecutionContext;
import java.util.concurrent.CompletableFuture;

/********************************************************************
 * File Name:    AsyncReverseStringAction.java
 *
 * Date Created: Aug 24, 2017
 *
 * ------------------------------------------------------------------
 * 
 * Copyright @ 2017 ajeydudhe@gmail.com
 *
 *******************************************************************/

package org.expedientframework.workflowlite.core.actions;



  
public class AsyncReverseStringAction extends AbstractAsyncAction<DefaultExecutionContext, String>
{
  protected AsyncReverseStringAction(final String value)
  {
    this.value = value;
  }
  
  @Override
  public CompletableFuture<String> execute(DefaultExecutionContext context)
  {
    final CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
        
        if(this.bThrowException)
        {
          throw new RuntimeException("Dummy exception thrown from " + this.getClass().getSimpleName() + ".");
        } 
        
        return new StringBuilder(this.value).reverse().toString();
      });
    
    if(this.bCancel)
    {
      future.cancel(true);
    }
    
    return future;
  }

  public void setThrowException(boolean bThrowException)
  {
    this.bThrowException = bThrowException;
  }

  public void setCancel(boolean bCancel)