-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9cde7e0
commit 5486c12
Showing
6 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/main/java/ch/zhaw/gpi/twitterreview/delegates/GetUserInformationDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/ch/zhaw/gpi/twitterreview/resources/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
src/main/java/ch/zhaw/gpi/twitterreview/services/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters