Skip to content

Commit

Permalink
Kapitel 9
Browse files Browse the repository at this point in the history
  • Loading branch information
scepbjoern committed Nov 21, 2018
1 parent 9cde7e0 commit 5486c12
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.zhaw.gpi.twitterreview.delegates;

import ch.zhaw.gpi.twitterreview.resources.User;
import ch.zhaw.gpi.twitterreview.services.UserService;
import javax.inject.Named;
import org.camunda.bpm.engine.delegate.BpmnError;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Autowired;

/**
*
* @author scep
*/
@Named(value = "getUserInformationAdapter")
public class GetUserInformationDelegate implements JavaDelegate {

@Autowired
private UserService userService;

@Override
public void execute(DelegateExecution execution) throws Exception {
String anfrageStellenderBenutzer = (String) execution.getVariable("anfrageStellenderBenutzer");

User user = userService.getUser(anfrageStellenderBenutzer);

if(user == null){
throw new BpmnError("UserNotFound", "Kein Benutzer " + anfrageStellenderBenutzer + " gefunden");
}

execution.setVariable("firstName", user.getFirstName());
execution.setVariable("email", user.geteMail());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class NotifyEmployeeDelegate implements JavaDelegate {
public void execute(DelegateExecution de) throws Exception {
// Prozessvariablen auslesen
String email = (String) de.getVariable("email");
String firstName = (String) de.getVariable("firstName");
String tweetContent = (String) de.getVariable("tweetContent");
String checkResult = (String) de.getVariable("checkResult");
String checkResultComment = (String) de.getVariable("checkResultComment");
Expand All @@ -50,7 +51,7 @@ public void execute(DelegateExecution de) throws Exception {
}

// Mail-Text zusammenbauen
String mailBody = "Hallo Mitarbeiter\n\n" + "Du hast folgenden Text zum " +
String mailBody = "Hallo " + firstName + "\n\n" + "Du hast folgenden Text zum " +
"Veröffentlichen als Tweet vorgeschlagen:\n" + tweetContent + "\n\n" +
mailHauptteil + "\n\n" + "Deine Kommunikationsabteilung";

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/ch/zhaw/gpi/twitterreview/resources/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ch.zhaw.gpi.twitterreview.resources;

/**
*
* @author scep
*/
public class User {
private String firstName;
private String eMail;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String geteMail() {
return eMail;
}

public void seteMail(String eMail) {
this.eMail = eMail;
}


}
38 changes: 38 additions & 0 deletions src/main/java/ch/zhaw/gpi/twitterreview/services/UserService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ch.zhaw.gpi.twitterreview.services;

import ch.zhaw.gpi.twitterreview.resources.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

/**
*
* @author scep
*/
@Component
public class UserService {

private final RestTemplate restTemplate;

@Value(value = "${userservice.endpoint}")
private String userServiceEndpoint;

public UserService(){
restTemplate = new RestTemplate();
}

public User getUser(String userName){
try{
User user = restTemplate.getForObject(userServiceEndpoint + "/users/{userName}", User.class, userName);
return user;
} catch(HttpClientErrorException httpClientErrorException){
if(httpClientErrorException.getStatusCode() == HttpStatus.NOT_FOUND){
return null;
} else {
throw httpClientErrorException;
}
}
}
}
4 changes: 3 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@ spring.mail.port=587
spring.mail.username=${mailUser}
spring.mail.password=${mailPass}
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.enable=true

userservice.endpoint=http://localhost:8070/userapi/v1
27 changes: 12 additions & 15 deletions src/main/resources/twitter-review.bpmn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?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_1lvz53z" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="1.16.2">
<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_1lvz53z" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="2.0.3">
<bpmn:collaboration id="Collaboration_1y44tdo">
<bpmn:participant id="Participant_18e1752" name="Verarbeitung von Tweet-Anfragen" processRef="VerarbeitungVonTweetAnfragen" />
</bpmn:collaboration>
Expand All @@ -19,16 +19,15 @@
<bpmn:flowNodeRef>ExclusiveGateway_0fj9kmh</bpmn:flowNodeRef>
<bpmn:flowNodeRef>TweetAnfrageBehandelt</bpmn:flowNodeRef>
<bpmn:flowNodeRef>Pruefergebnis</bpmn:flowNodeRef>
<bpmn:flowNodeRef>MitarbeiterKuerzelExtrahieren</bpmn:flowNodeRef>
<bpmn:flowNodeRef>TweetSenden</bpmn:flowNodeRef>
<bpmn:flowNodeRef>MitarbeiterBenachrichtigen</bpmn:flowNodeRef>
<bpmn:flowNodeRef>BenutzerInformationenAuslesen</bpmn:flowNodeRef>
</bpmn:lane>
</bpmn:laneSet>
<bpmn:sequenceFlow id="SequenceFlow_1vqcip2" sourceRef="TweetAnfrageEingereicht" targetRef="MitarbeiterKuerzelExtrahieren" />
<bpmn:sequenceFlow id="SequenceFlow_1vqcip2" sourceRef="TweetAnfrageEingereicht" targetRef="BenutzerInformationenAuslesen" />
<bpmn:startEvent id="TweetAnfrageEingereicht" name="Tweet-Anfrage&#10;eingereicht" camunda:initiator="anfrageStellenderBenutzer">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="email" label="E-Mail" type="string" />
<camunda:formField id="tweetContent" label="Zu veröffentlichender Text" type="string" />
</camunda:formData>
</bpmn:extensionElements>
Expand Down Expand Up @@ -58,7 +57,7 @@
<bpmn:userTask id="TweetAnfragePruefen" name="Tweet-Anfrage prüfen" camunda:candidateGroups="kommunikationsabteilung">
<bpmn:extensionElements>
<camunda:formData>
<camunda:formField id="alias" label="Kürzel" type="string" />
<camunda:formField id="firstName" label="Vorname des Mitarbeiters" type="string" />
<camunda:formField id="tweetContent" label="Zu veröffentlichender Text" type="string" />
<camunda:formField id="checkResult" label="Hinweise für Mitarbeiter zum Prüfergebnis" type="enum">
<camunda:value id="accepted" name="Genehmigt" />
Expand Down Expand Up @@ -94,13 +93,7 @@
<bpmn:sequenceFlow id="SequenceFlow_13w0jnd" sourceRef="TweetSenden" targetRef="ExclusiveGateway_0fj9kmh" />
<bpmn:sequenceFlow id="SequenceFlow_0akgqts" sourceRef="ExclusiveGateway_0fj9kmh" targetRef="MitarbeiterBenachrichtigen" />
<bpmn:sequenceFlow id="SequenceFlow_0wkf2cr" sourceRef="MitarbeiterBenachrichtigen" targetRef="TweetAnfrageBehandelt" />
<bpmn:sequenceFlow id="SequenceFlow_1n14gt1" sourceRef="MitarbeiterKuerzelExtrahieren" targetRef="ExclusiveGateway_1qa6x80" />
<bpmn:scriptTask id="MitarbeiterKuerzelExtrahieren" name="Mitarbeiter-Kürzel extrahieren" scriptFormat="JavaScript">
<bpmn:incoming>SequenceFlow_1vqcip2</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1n14gt1</bpmn:outgoing>
<bpmn:script>emailAdress = execution.getVariable("email");
execution.setVariable("alias", emailAdress.substring(0,4));</bpmn:script>
</bpmn:scriptTask>
<bpmn:sequenceFlow id="SequenceFlow_1n14gt1" sourceRef="BenutzerInformationenAuslesen" targetRef="ExclusiveGateway_1qa6x80" />
<bpmn:serviceTask id="TweetSenden" name="Tweet senden" camunda:asyncBefore="true" camunda:delegateExpression="#{sendTweetAdapter}">
<bpmn:extensionElements>
<camunda:properties>
Expand Down Expand Up @@ -138,6 +131,10 @@ execution.setVariable("alias", emailAdress.substring(0,4));</bpmn:script>
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT10S</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:serviceTask id="BenutzerInformationenAuslesen" name="Benutzer-Informationen auslesen" camunda:delegateExpression="#{getUserInformationAdapter}">
<bpmn:incoming>SequenceFlow_1vqcip2</bpmn:incoming>
<bpmn:outgoing>SequenceFlow_1n14gt1</bpmn:outgoing>
</bpmn:serviceTask>
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Collaboration_1y44tdo">
Expand Down Expand Up @@ -246,9 +243,6 @@ execution.setVariable("alias", emailAdress.substring(0,4));</bpmn:script>
<di:waypoint x="255" y="212" />
<di:waypoint x="272" y="212" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ScriptTask_0oeqqmr_di" bpmnElement="MitarbeiterKuerzelExtrahieren">
<dc:Bounds x="139" y="311" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="ServiceTask_1fbdslq_di" bpmnElement="TweetSenden">
<dc:Bounds x="612" y="418" width="100" height="80" />
</bpmndi:BPMNShape>
Expand Down Expand Up @@ -280,6 +274,9 @@ execution.setVariable("alias", emailAdress.substring(0,4));</bpmn:script>
<di:waypoint x="826" y="314" />
<di:waypoint x="795" y="340" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="ServiceTask_16550au_di" bpmnElement="BenutzerInformationenAuslesen">
<dc:Bounds x="139" y="311" width="100" height="80" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>

0 comments on commit 5486c12

Please sign in to comment.