Skip to content

Commit

Permalink
java delegate service classes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sourabhparsekar committed Jun 24, 2021
1 parent 7cb97d1 commit 6b15427
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 158 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Out of the [BMPN 2.0 Implementations](https://docs.camunda.org/manual/7.15/refer
- If the minimum ingredients are available then we put everything in pan, give it a stir, close it with a lid and keep it over heat. (Use your preference there).
- If you smell it nice then open the lid and check if it's cooked.
- If you get busy with something else and you forget to check it, then after 15 minutes cooking timer will expire, and you have to order online as noodles have burnt.
- Luckily, if you see that it's cooked well, then you can eat it. Else.. Sorry, but your efforts are wasted, and you need to order online.
- With that we reach end of our non-intuitive flow to cook instant noodles. By the way, that's how I cook instant noodles, and they turn out good most of the time.
- Luckily, if you see that it's cooked well, then you can eat it. Else.. Sorry, but your efforts are wasted, and you need to order online. Enjoy cooking!!

With that we reach end of our non-intuitive flow to cook my instant noodles. By the way, that's how I cook instant noodles, and they turn out good most of the times.

## Code Configuration

Expand Down

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/com/noodles/util/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
public class Constants {

public static final String INGREDIENTS_AVAILABLE = "IngredientsAvailable";
public static final String IS_IT_COOKING = "IsItCooking";
public static final String DID_WE_EAT_NOODLES = "DidWeEat";
public static String ORDER_ONLINE = "OrderOnline";

public static final String NOODLES = "noodles";
public static final String WATER = "water";
public static final String PAN_SPATULA = "pan_and_spatula";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.noodles.services.workflow.delegates;
package com.noodles.workflow.delegates;

import com.noodles.util.Constants;
import com.noodles.util.WorkflowLogger;
Expand All @@ -11,6 +11,7 @@
@Service("CheckIngredients")
public class CheckIngredients implements JavaDelegate {

public static final String CHECK_INGREDIENTS = "Check Ingredients";
private final Logger logger = LoggerFactory.getLogger(this.getClass());

/**
Expand All @@ -21,7 +22,7 @@ public class CheckIngredients implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {

WorkflowLogger.info(logger, "Check Ingredients", "Check ingredients to make veg masala noodles");
WorkflowLogger.info(logger, CHECK_INGREDIENTS, "Check ingredients to make veg masala noodles");

boolean ingredientsAvailable;

Expand All @@ -35,10 +36,10 @@ public void execute(DelegateExecution execution) {

if (instantNoodles && water && panSpatula) {
ingredientsAvailable = true;
WorkflowLogger.info(logger, "Check Ingredients", "we can make veg masala noodles");
WorkflowLogger.info(logger, CHECK_INGREDIENTS, "we can make veg masala noodles");
} else {
ingredientsAvailable = false;
WorkflowLogger.error(logger, "Check Ingredients", "we cannot make veg masala noodles as required ingredient is missing. Instant Noodles, Water, Pan and Spatula are required.");
WorkflowLogger.error(logger, CHECK_INGREDIENTS, "we cannot make veg masala noodles as required ingredient is missing. Instant Noodles, Water, Pan and Spatula are required.");
}

execution.setVariable(Constants.INGREDIENTS_AVAILABLE, ingredientsAvailable);
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/noodles/workflow/delegates/LetUsCook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.noodles.workflow.delegates;

import com.noodles.util.Constants;
import com.noodles.util.WorkflowLogger;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.StringJoiner;

@Service("LetsCook")
public class LetUsCook implements JavaDelegate {

public static final String STEP = "STEP ";
private final Logger logger = LoggerFactory.getLogger(this.getClass());

/**
* This will be used to fetch ingredients and begin to cook following the recipe
*
* @param execution : Process Variables will be retrieved from DelegateExecution
*/
@Override
public void execute(DelegateExecution execution) {

WorkflowLogger.info(logger, "Prepare Noodles", "Follow below to make veg masala noodles");

WorkflowLogger.info(logger, STEP + 1, "Take a deep-bottomed pan over medium flame and add water in it and bring it to a boil.");

StringJoiner vegetables = new StringJoiner(", ");
if (execution.hasVariable(Constants.ONION) && (boolean) execution.getVariable(Constants.ONION)) vegetables.add(Constants.ONION);
if (execution.hasVariable(Constants.TOMATO) && (boolean) execution.getVariable(Constants.TOMATO)) vegetables.add(Constants.TOMATO);
if (execution.hasVariable(Constants.CARROT) && (boolean) execution.getVariable(Constants.CARROT)) vegetables.add(Constants.CARROT);
if (execution.hasVariable(Constants.CAPSICUM) && (boolean) execution.getVariable(Constants.CAPSICUM)) vegetables.add(Constants.CAPSICUM);

if (vegetables.length() < 4)
WorkflowLogger.info(logger, STEP + 2, "While the water boils, take a chopping board and chop " + vegetables);
else
WorkflowLogger.info(logger, STEP + 2, "While the water starts to boil, check if you received IMs on your mobile.");

WorkflowLogger.info(logger, STEP + 3, "Once the water boils, add chopped vegetables, add 1 packet of instant noodles and stir it.");

WorkflowLogger.info(logger, STEP + 4, "Add the taste-maker to it and give it another stir");

if (execution.hasVariable(Constants.CHEESE) && (boolean) execution.getVariable(Constants.CHEESE))
WorkflowLogger.info(logger, STEP + 5, "Add grated cheese and close the lid");
else
WorkflowLogger.info(logger, STEP + 5, "Close the lid");

WorkflowLogger.info(logger, "Cooking in Process", "You can play with your mobile as it cooks for sometime...");

execution.setVariable(Constants.IS_IT_COOKING, true);
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/noodles/workflow/delegates/LetUsEat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.noodles.workflow.delegates;

import com.noodles.util.Constants;
import com.noodles.util.WorkflowLogger;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service("LetUsEat")
public class LetUsEat implements JavaDelegate {

public static final String EAT_NOODLES = "Eat Noodles";
private final Logger logger = LoggerFactory.getLogger(this.getClass());

/**
* We will eat what we cooked if it was not burnt
* @param execution : Process Variables will be retrieved from DelegateExecution
*/
@Override
public void execute(DelegateExecution execution) {

WorkflowLogger.info(logger, EAT_NOODLES, "Veg masala noodles is ready. Let's eat... But first serve it..");

WorkflowLogger.info(logger, EAT_NOODLES, "Transfer to a serving bowl and sprinkle a pinch of chaat masala or oregano over the noodles to make it even more flavorful.");

if (execution.hasVariable(Constants.CHEESE) && (boolean) execution.getVariable(Constants.CHEESE))
WorkflowLogger.info(logger, EAT_NOODLES, "Add grated cheese over it. ");

WorkflowLogger.info(logger, EAT_NOODLES, "Serve it hot to enjoy!! ");

execution.setVariable(Constants.DID_WE_EAT_NOODLES, true);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.noodles.services.workflow.delegates;
package com.noodles.workflow.delegates;

import com.noodles.util.Constants;
import com.noodles.util.WorkflowLogger;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
Expand All @@ -18,5 +20,10 @@ public class OrderOnline implements JavaDelegate {
@Override
public void execute(DelegateExecution execution) {

WorkflowLogger.info(logger, "Order Online", "Veg masala noodles was no success.. Let's order online...");
execution.setVariable(Constants.DID_WE_EAT_NOODLES, false);

WorkflowLogger.info(logger, "Order Online", "Ordering is not part of this flow yet... Try your local apps...");
execution.setVariable(Constants.ORDER_ONLINE, true);
}
}
78 changes: 27 additions & 51 deletions src/main/resources/cook_noodles_process.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,18 @@
</bpmn:eventBasedGateway>
<bpmn:intermediateCatchEvent id="IsReady" name="It&#39;s cooked">
<bpmn:incoming>Flow_0qr7wg5</bpmn:incoming>
<bpmn:outgoing>Flow_1gn37vq</bpmn:outgoing>
<bpmn:outgoing>Flow_10hgq98</bpmn:outgoing>
<bpmn:messageEventDefinition id="MessageEventDefinition_18kx14u" messageRef="Message_1fwm5d8" />
</bpmn:intermediateCatchEvent>
<bpmn:sequenceFlow id="Flow_0qr7wg5" sourceRef="IsItReady" targetRef="IsReady" />
<bpmn:intermediateCatchEvent id="Event_0y9m0tm" name="I forgot">
<bpmn:intermediateCatchEvent id="Event_0y9m0tm" name="I forgot to check">
<bpmn:incoming>Flow_1jrxoop</bpmn:incoming>
<bpmn:outgoing>Flow_1vpwn8t</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_0xoeq63">
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT5M</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:intermediateCatchEvent>
<bpmn:sequenceFlow id="Flow_1jrxoop" sourceRef="IsItReady" targetRef="Event_0y9m0tm" />
<bpmn:exclusiveGateway id="CanWeEat" name="Is it eatable?" default="Flow_1bpca4z">
<bpmn:incoming>Flow_1gn37vq</bpmn:incoming>
<bpmn:outgoing>Flow_13u92su</bpmn:outgoing>
<bpmn:outgoing>Flow_1bpca4z</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="Flow_1gn37vq" sourceRef="IsReady" targetRef="CanWeEat" />
<bpmn:sequenceFlow id="Flow_13u92su" name="Yes" sourceRef="CanWeEat" targetRef="LetUsEat" />
<bpmn:sequenceFlow id="Flow_1bpca4z" name="No" sourceRef="CanWeEat" targetRef="OrderOnline" />
<bpmn:endEvent id="End_Process">
<bpmn:incoming>Flow_07qsy0u</bpmn:incoming>
<bpmn:incoming>Flow_1ks0pq6</bpmn:incoming>
Expand All @@ -71,15 +63,15 @@
<bpmn:outgoing>Flow_1i8b4u8</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:serviceTask id="OrderOnline" name="Order Online" camunda:delegateExpression="#{OrderOnline}">
<bpmn:incoming>Flow_1bpca4z</bpmn:incoming>
<bpmn:incoming>Flow_1vpwn8t</bpmn:incoming>
<bpmn:incoming>Flow_18j0lcs</bpmn:incoming>
<bpmn:outgoing>Flow_1ks0pq6</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:serviceTask id="LetUsEat" name="Let&#39;s eat" camunda:delegateExpression="#{LetUsEat}">
<bpmn:incoming>Flow_13u92su</bpmn:incoming>
<bpmn:incoming>Flow_10hgq98</bpmn:incoming>
<bpmn:outgoing>Flow_07qsy0u</bpmn:outgoing>
</bpmn:serviceTask>
<bpmn:sequenceFlow id="Flow_10hgq98" sourceRef="IsReady" targetRef="LetUsEat" />
</bpmn:process>
<bpmn:message id="Message_1fwm5d8" name="Something Cooked" />
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
Expand All @@ -90,37 +82,23 @@
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1ks0pq6_di" bpmnElement="Flow_1ks0pq6">
<di:waypoint x="850" y="300" />
<di:waypoint x="922" y="300" />
<di:waypoint x="886" y="300" />
<di:waypoint x="886" y="240" />
<di:waypoint x="922" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_07qsy0u_di" bpmnElement="Flow_07qsy0u">
<di:waypoint x="940" y="230" />
<di:waypoint x="940" y="282" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1bpca4z_di" bpmnElement="Flow_1bpca4z">
<di:waypoint x="800" y="215" />
<di:waypoint x="800" y="260" />
<bpmndi:BPMNLabel>
<dc:Bounds x="808" y="235" width="15" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_13u92su_di" bpmnElement="Flow_13u92su">
<di:waypoint x="825" y="190" />
<di:waypoint x="890" y="190" />
<bpmndi:BPMNLabel>
<dc:Bounds x="849" y="172" width="18" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1gn37vq_di" bpmnElement="Flow_1gn37vq">
<di:waypoint x="718" y="190" />
<di:waypoint x="775" y="190" />
<di:waypoint x="850" y="190" />
<di:waypoint x="886" y="190" />
<di:waypoint x="886" y="240" />
<di:waypoint x="922" y="240" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1jrxoop_di" bpmnElement="Flow_1jrxoop">
<di:waypoint x="600" y="215" />
<di:waypoint x="600" y="282" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0qr7wg5_di" bpmnElement="Flow_0qr7wg5">
<di:waypoint x="625" y="190" />
<di:waypoint x="682" y="190" />
<di:waypoint x="662" y="190" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1i8b4u8_di" bpmnElement="Flow_1i8b4u8">
<di:waypoint x="520" y="190" />
Expand Down Expand Up @@ -150,6 +128,10 @@
<di:waypoint x="210" y="118" />
<di:waypoint x="210" y="150" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_10hgq98_di" bpmnElement="Flow_10hgq98">
<di:waypoint x="698" y="190" />
<di:waypoint x="750" y="190" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_0mmbodz_di" bpmnElement="Start_Process">
<dc:Bounds x="192" y="82" width="36" height="36" />
<bpmndi:BPMNLabel>
Expand All @@ -168,27 +150,12 @@
<dc:Bounds x="576" y="135" width="49" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1fbxlcz_di" bpmnElement="IsReady">
<dc:Bounds x="682" y="172" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="675" y="215" width="53" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_0y9m0tm_di" bpmnElement="Event_0y9m0tm">
<dc:Bounds x="582" y="282" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="582" y="325" width="36" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Gateway_0ks8q6r_di" bpmnElement="CanWeEat" isMarkerVisible="true">
<dc:Bounds x="775" y="165" width="50" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="771" y="135" width="63" height="14" />
<dc:Bounds x="561" y="325" width="79" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1hlu0bs_di" bpmnElement="End_Process">
<dc:Bounds x="922" y="282" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_00z3y4d_di" bpmnElement="CheckIngredients">
<dc:Bounds x="160" y="150" width="100" height="80" />
</bpmndi:BPMNShape>
Expand All @@ -199,7 +166,16 @@
<dc:Bounds x="750" y="260" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_15y7q4x_di" bpmnElement="LetUsEat">
<dc:Bounds x="890" y="150" width="100" height="80" />
<dc:Bounds x="750" y="150" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1hlu0bs_di" bpmnElement="End_Process">
<dc:Bounds x="922" y="222" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1fbxlcz_di" bpmnElement="IsReady">
<dc:Bounds x="662" y="172" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="655" y="215" width="53" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
Expand Down
Binary file modified src/main/resources/cook_noodles_process.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

Loading

0 comments on commit 6b15427

Please sign in to comment.