Skip to content
Snippets Groups Projects
Commit e71aa8b6 authored by Jonas Blatt's avatar Jonas Blatt :ant:
Browse files

Add rfid API call and second process for product review

parent 24a4a098
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
......@@ -126,5 +126,8 @@
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-jaxb-annotations:2.9.7" level="project" />
<orderEntry type="library" name="Maven: org.camunda.bpm.webapp:camunda-webapp-webjar:7.10.0" level="project" />
<orderEntry type="library" name="Maven: com.h2database:h2:1.4.197" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.6" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.11" level="project" />
</component>
</module>
\ No newline at end of file
......@@ -26,10 +26,24 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
......
......@@ -5,6 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String... args) {
SpringApplication.run(Application.class, args);
}
......
package de.unikoblenz.fgbas.bs.bpm.iot;
import de.unikoblenz.fgbas.bs.bpm.iot.service.RfidProductService;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.util.EntityUtils;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.camunda.bpm.engine.impl.util.json.JSONArray;
import org.camunda.bpm.engine.impl.util.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.http.impl.client.HttpClients;
public class RfidTimerReaderService implements JavaDelegate {
public static final String GET_HTTP_RFID_API = "http://localhost/postserver/rfidtest.json";
private final Logger LOGGER = LoggerFactory.getLogger(RfidTimerReaderService.class);
public void execute(DelegateExecution delegateExecution) throws Exception {
LOGGER.info("Amazing IoT api call....");
Optional<HttpResponse> response = sendHTTPRequest();
if (response.isPresent()) {
String result = EntityUtils.toString(response.get().getEntity());
LOGGER.info("Response: " + result);
JSONArray listOfRfidTags = new JSONArray(result);
for (int i = 0; i < listOfRfidTags.length(); i++) {
JSONObject jo = listOfRfidTags.getJSONObject(i);
String rfidTag = jo.getString("tagId");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = sdf.parse(jo.getString("timeStamp"));
LOGGER.info("Starting product review with rfid tag {" + rfidTag + "}");
// Create new Process
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("rfidTag", rfidTag);
variables.put("product", RfidProductService.getProductByRfidTag(rfidTag));
delegateExecution.getProcessEngineServices().getRuntimeService()
.startProcessInstanceByKey("Process_2", variables);
}
}
}
private Optional<HttpResponse> sendHTTPRequest() {
LOGGER.info("Message send:");
HttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(GET_HTTP_RFID_API);
get.setHeader("content-type", "application/json");
try {
return Optional.of(client.execute(get));
} catch (Exception e) {
return Optional.empty();
}
}
}
package de.unikoblenz.fgbas.bs.bpm.iot;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestService implements JavaDelegate {
private final Logger LOGGER = LoggerFactory.getLogger(TestService.class);
public void execute(DelegateExecution delegateExecution) throws Exception {
LOGGER.info("Amazing IoT api call....");
}
}
package de.unikoblenz.fgbas.bs.bpm.iot.service;
import java.util.HashMap;
import java.util.Map;
public class RfidProductService {
private static Map<String, String> rifdProductMap = new HashMap<>();
static {
rifdProductMap.put("12345678", "Pizza");
rifdProductMap.put("87654321", "Doener");
}
private RfidProductService() {
// Nothing
}
public static String getProductByRfidTag(String tagId) {
return rifdProductMap.getOrDefault(tagId, "No product found");
}
}
......@@ -8,7 +8,7 @@
<bpmn:endEvent id="EndEvent_11c5iyc">
<bpmn:incoming>SequenceFlow_1wfucxl</bpmn:incoming>
</bpmn:endEvent>
<bpmn:serviceTask id="Task_1ls08zd" name="Call IoT and do amazing stuff" camunda:class="de.unikoblenz.fgbas.bs.bpm.iot.TestService">
<bpmn:serviceTask id="Task_1ls08zd" name="Call IoT and do amazing stuff" camunda:class="de.unikoblenz.fgbas.bs.bpm.iot.RfidTimerReaderService">
<bpmn:incoming>SequenceFlow_0nwksx9</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_0cblkjr</bpmn:outgoing>
</bpmn:serviceTask>
......@@ -19,7 +19,7 @@
<bpmn:outgoing>SequenceFlow_0nwksx9</bpmn:outgoing>
</bpmn:exclusiveGateway>
<bpmn:sequenceFlow id="SequenceFlow_0nwksx9" sourceRef="ExclusiveGateway_09r95mp" targetRef="Task_1ls08zd" />
<bpmn:intermediateCatchEvent id="IntermediateThrowEvent_1hvhn31" name="30 sec">
<bpmn:intermediateCatchEvent id="IntermediateThrowEvent_1hvhn31" name="1 min">
<bpmn:incoming>SequenceFlow_0cblkjr</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1xiqxap</bpmn:outgoing>
<bpmn:timerEventDefinition>
......@@ -62,7 +62,7 @@
<bpmndi:BPMNShape id="IntermediateCatchEvent_0j8ya9i_di" bpmnElement="IntermediateThrowEvent_1hvhn31">
<dc:Bounds x="553" y="204" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="555" y="247" width="33" height="14" />
<dc:Bounds x="558" y="247" width="27" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1xiqxap_di" bpmnElement="SequenceFlow_1xiqxap">
......
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_0m41206" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.2.4">
<bpmn:process id="Process_2" isExecutable="true">
<bpmn:startEvent id="StartEvent_1">
<bpmn:outgoing>SequenceFlow_1c5kgwq</bpmn:outgoing>
</bpmn:startEvent>
<bpmn:endEvent id="EndEvent_11c5iyc">
<bpmn:incoming>SequenceFlow_1mmk7vf</bpmn:incoming>
</bpmn:endEvent>
<bpmn:sequenceFlow id="SequenceFlow_1c5kgwq" sourceRef="StartEvent_1" targetRef="Task_1lt29o9" />
<bpmn:sequenceFlow id="SequenceFlow_1mmk7vf" sourceRef="Task_1lt29o9" targetRef="EndEvent_11c5iyc" />
<bpmn:userTask id="Task_1lt29o9" name="Product Review">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="rfidTag" label="Rfid Tag" type="string" />
<camunda:formField id="product" label="Product" type="string" />
<camunda:formField id="productAccept" label="Accept?" type="boolean" defaultValue="false" />
</camunda:formData>
</bpmn:extensionElements>
<bpmn:incoming>SequenceFlow_1c5kgwq</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1mmk7vf</bpmn:outgoing>
</bpmn:userTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_2">
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="118" y="117" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="EndEvent_11c5iyc_di" bpmnElement="EndEvent_11c5iyc">
<dc:Bounds x="397" y="117" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="SequenceFlow_1c5kgwq_di" bpmnElement="SequenceFlow_1c5kgwq">
<di:waypoint x="154" y="135" />
<di:waypoint x="223" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="SequenceFlow_1mmk7vf_di" bpmnElement="SequenceFlow_1mmk7vf">
<di:waypoint x="323" y="135" />
<di:waypoint x="397" y="135" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="UserTask_09tmhqu_di" bpmnElement="Task_1lt29o9">
<dc:Bounds x="223" y="95" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment