Skip to content

Commit

Permalink
new_feature_release
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakarora3 committed Jun 19, 2023
1 parent acd4a46 commit 9120715
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 99 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>com.americanexpress.unify.flowret</groupId>
<artifactId>unify-flowret</artifactId>
<version>1.3.7</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<name>unify-flowret</name>
Expand Down Expand Up @@ -75,7 +75,7 @@
<dependency>
<groupId>com.americanexpress.unify.jdocs</groupId>
<artifactId>unify-jdocs</artifactId>
<version>1.3.7</version>
<version>1.4.0</version>
</dependency>

<!-- test dependencies -->
Expand Down
35 changes: 24 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Flowret is available as a jar file in Maven central with the following Maven coo
````pom
<groupId>com.americanexpress.unify.flowret</groupId>
<artifactId>unify-flowret</artifactId>
<version>1.3.7</version>
<version>1.4.0</version>
````

---
Expand Down Expand Up @@ -696,13 +696,12 @@ Flowret will throw an exception in case the case id already exists.
`ProcessVariables processVariables` is a collection of variables that are
made available to steps and routes. The process variables can be updated by steps and routes.

`String journeySlaJson` specifies the SLA Milestones for the process. This is detailed out in the secition
on SLA Milestones later in this document. A null value can be passed in case no SLA milestones are to be used.
`String journeySlaJson` specifies the SLA Milestones for the process. This is detailed out in the secition on SLA
Milestones later in this document. A null value can be passed in case no SLA milestones are to be used.

This methods returns true in case the process was run else false.
This methods throws an exception if the case could not be started.

This method will internally start the process execution and return when
either the process pends or when it finishes.
This method will internally start the process execution and return when either the process pends or when it finishes.

At the time of starting the case, Flowret also writes out a copy of the process definition associated
with the case. This locks the process definition to the case
Expand Down Expand Up @@ -854,8 +853,7 @@ In future versions, a feature may be provided for Flowret to return a list of pe

#### Resume a case

In case a process had been started earlier and had pended, the application can resume the same
by the following call:
In case a process had been started earlier and had pended, the application can resume the same by the following call:

```java
rts.resumeCase(caseId);
Expand All @@ -865,10 +863,25 @@ rts.resumeCase(caseId);

---

#### Reopen a case

A case which has already been finalized can be reopened. In order to do this, there must be a ticket defined in the
definition which tells Flowret where to begin the execution from when reopen is called. This ticket needs to be passed
into the reopen method as below:

```java
rts.reopenCase(String caseId,String ticket,boolean pendBeforeResume,String pendWorkbasket);
rts.reopenCase(String caseId,String ticket,boolean pendBeforeResume,String pendWorkbasket,ProcessVariables pvs);
```

The user can also specify if the case is to be pended in a workbasket after reopen. If this is set to true, the name of
the pend work basket needs to be specified. The user can also provide a list of process variables which will be added /
updated to the already existing process variables.

#### Audit logging

Flowret logs information to the data store (as specified by the Dao) after it executes
each step / route. Each entry comprises of a JSON document with the name as described before:
Flowret logs information to the data store (as specified by the Dao) after it executes each step / route. Each entry
comprises of a JSON document with the name as described before:

Each audit log JSON file contains information of the following:

Expand Down Expand Up @@ -1103,7 +1116,7 @@ An SLA milestone is a definition of an action to be systematically performed som
SLA milestones can be defined at the following levels:

* On case start
* On case reopened (yet to be implemented)
* On case reopened
* On work basket entry
* On work basket exit

Expand Down
88 changes: 22 additions & 66 deletions src/main/java/com/americanexpress/unify/flowret/Rts.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package com.americanexpress.unify.flowret;

import com.americanexpress.unify.base.BaseUtils;
import com.americanexpress.unify.base.ErrorTuple;
import com.americanexpress.unify.base.UnifyException;
import com.americanexpress.unify.jdocs.Document;
import com.americanexpress.unify.jdocs.JDocument;
Expand Down Expand Up @@ -66,22 +65,14 @@ protected void invokeEventHandler(EventType event, ProcessContext pc) {
case ON_PROCESS_COMPLETE:
case ON_PROCESS_PEND:
case ON_PROCESS_REOPEN:
try {
eventHandler.invoke(event, pc);
if ((slad != null) && (slaQm != null)) {
raiseSlaEvent(event, pc);
}
if (event == ON_PROCESS_PEND) {
// set the prev pend work basket
ExecPath ep = pi.getExecPath(pi.getPendExecPath());
ep.setPrevPendWorkBasket(ep.getPendWorkBasket());
}
eventHandler.invoke(event, pc);
if ((slad != null) && (slaQm != null)) {
raiseSlaEvent(event, pc);
}
catch (Exception e) {
// we log an error but we do not stop and the application has generated an error and we are not responsible for that
logger.error("Error encountered while invoking event. Case id -> {}, event type -> {}, error message -> {}", pi.getCaseId(), event.name(), e.getMessage());
logger.error(BaseUtils.getStackTrace(e));
throw new UnifyException(new ErrorTuple("flowret_error", "Exception encountered while invoking event"));
if (event == ON_PROCESS_PEND) {
// set the prev pend work basket
ExecPath ep = pi.getExecPath(pi.getPendExecPath());
ep.setPrevPendWorkBasket(ep.getPendWorkBasket());
}
break;

Expand All @@ -96,7 +87,6 @@ protected void invokeEventHandler(EventType event, ProcessContext pc) {
}
break;
}

}

public boolean isCaseStarted(String caseId) {
Expand Down Expand Up @@ -153,30 +143,14 @@ public ProcessContext startCase(String caseId, String journeyJson, ProcessVariab
pi.setProcessVariable(pv);
}

boolean bContinue = true;
ProcessContext pc = null;
if (hasAlreadyStarted == false) {
logger.info("Case id -> " + pi.getCaseId() + ", successfully created case");

// invoke event handler
pc = ProcessContext.forEvent(EventType.ON_PROCESS_START, this, ".");
try {
invokeEventHandler(EventType.ON_PROCESS_START, pc);
}
catch (Exception e) {
bContinue = false;
pc = null;
logger.info("Case id -> " + pi.getCaseId() + ", aborting as application exception encountered while raising event");
logger.info("Case id -> " + pi.getCaseId() + ", exception details -> " + e.getMessage());
logger.info("Case id -> " + pi.getCaseId() + ", exception stack -> " + e.getStackTrace());
}
}

// start case
if (bContinue == true) {
pc = resumeCase(caseId, false, null);
invokeEventHandler(EventType.ON_PROCESS_START, pc);
}

pc = resumeCase(caseId, false, null);
return pc;
}

Expand Down Expand Up @@ -211,34 +185,21 @@ private ProcessContext resumeCase(String caseId, boolean raiseResumeEvent, Proce
throw new UnifyException("flowret_err_6", pi.getCaseId());
}

boolean bContinue = true;
ProcessContext pc = null;
try {
if (raiseResumeEvent) {
pc = ProcessContext.forEvent(EventType.ON_PROCESS_RESUME, this, pi.getPendExecPath());
invokeEventHandler(EventType.ON_PROCESS_RESUME, pc);
}

if (pi.getTicket().isEmpty() == false) {
pc = ProcessContext.forEvent(EventType.ON_TICKET_RAISED, this, pi.getPendExecPath());
invokeEventHandler(EventType.ON_TICKET_RAISED, pc);
}

}
catch (Exception e) {
bContinue = false;
pc = null;
logger.info("Case id -> " + pi.getCaseId() + ", aborting as application exception encountered while raising event");
logger.info("Case id -> " + pi.getCaseId() + ", exception details -> " + e.getMessage());
logger.info("Case id -> " + pi.getCaseId() + ", exception stack -> " + e.getStackTrace());
if (raiseResumeEvent) {
pc = ProcessContext.forEvent(EventType.ON_PROCESS_RESUME, this, pi.getPendExecPath());
invokeEventHandler(EventType.ON_PROCESS_RESUME, pc);
}

if (bContinue == true) {
// initiate on the current thread
ExecThreadTask task = new ExecThreadTask(this);
pc = task.execute();
if (pi.getTicket().isEmpty() == false) {
pc = ProcessContext.forEvent(EventType.ON_TICKET_RAISED, this, pi.getPendExecPath());
invokeEventHandler(EventType.ON_TICKET_RAISED, pc);
}

// initiate on the current thread
ExecThreadTask task = new ExecThreadTask(this);
pc = task.execute();

return pc;
}

Expand Down Expand Up @@ -307,18 +268,13 @@ public ProcessContext reopenCase(String caseId, String ticket, boolean pendBefor
ProcessContext pc = null;

// invoke event handler
try {
pc = ProcessContext.forEvent(EventType.ON_PROCESS_REOPEN, this, ".");
invokeEventHandler(EventType.ON_PROCESS_REOPEN, pc);
pc = ProcessContext.forEvent(EventType.ON_PROCESS_REOPEN, this, ".");
invokeEventHandler(EventType.ON_PROCESS_REOPEN, pc);

if (pendBeforeResume == true) {
pc = ProcessContext.forEvent(ON_PROCESS_PEND, this, ".");
invokeEventHandler(ON_PROCESS_PEND, pc);
}
catch (Exception e) {
logger.info("Case id -> " + pi.getCaseId() + ", exception encountered while raising event");
logger.info("Case id -> " + pi.getCaseId() + ", exception details -> " + e.getMessage());
logger.info("Case id -> " + pi.getCaseId() + ", exception stack -> " + e.getStackTrace());
}

// resume the case if required
if (pendBeforeResume == false) {
Expand Down
32 changes: 12 additions & 20 deletions src/main/java/com/americanexpress/unify/flowret/Wms.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,34 @@ public void changeWorkBasket(String caseId, String newWb) {
// get pc as per updated pi
ProcessContext pc = ProcessContext.forWms(pd, pi);

boolean isError = false;
try {
// call the work manager on the application
if (wm != null) {
wm.changeWorkBasket(pc, currWb, newWb);
}
}
catch (Exception e) {
isError = true;
logger.error("Error encountered while invoking work manager in the application. Case id -> {}, error message -> {}", pi.getCaseId(), e.getMessage());

// undo the changes
ep.setPrevPendWorkBasket(prevWb);
ep.setPendWorkBasket(currWb);

throw e;
}

if (isError == false) {
try {
// enqueue / dequeue as required
if (currWb.equals(newWb) == false) {
if (currWb.equals(tbcSlaWb) == false) {
if (slaQm != null) {
Utils.dequeueWorkBasketMilestones(pc, currWb, slad, slaQm);
}
}

if (newWb.equals(tbcSlaWb) == false) {
if ((slad != null) && (slaQm != null)) {
Utils.enqueueWorkBasketMilestones(pc, SlaMilestoneSetupOn.work_basket_entry, newWb, slad, slaQm);
}
}
// enqueue / dequeue as required
if (currWb.equals(newWb) == false) {
if (currWb.equals(tbcSlaWb) == false) {
if (slaQm != null) {
Utils.dequeueWorkBasketMilestones(pc, currWb, slad, slaQm);
}
}
catch (Exception e) {
isError = true;
logger.error("Error encountered while invoking sla queue manager in the application. Case id -> {}, error message -> {}", pi.getCaseId(), e.getMessage());

if (newWb.equals(tbcSlaWb) == false) {
if ((slad != null) && (slaQm != null)) {
Utils.enqueueWorkBasketMilestones(pc, SlaMilestoneSetupOn.work_basket_entry, newWb, slad, slaQm);
}
}
}

Expand Down

0 comments on commit 9120715

Please sign in to comment.