-
Notifications
You must be signed in to change notification settings - Fork 38
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
Robert Moffat
committed
Sep 14, 2020
1 parent
f9b0f3f
commit 60bad80
Showing
83 changed files
with
5,334 additions
and
9 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Symphony Java Toolkit - FINOS | ||
Copyright 2019 - 2020 Deutsche Bank AG deutsche-[email protected] | ||
Copyright 2019 - 2020 Deutsche Bank AG symphony-practice@list.db.com | ||
|
||
This product includes software developed at the Fintech Open Source Foundation (https://www.finos.org/) and Deutsche Bank AG. |
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 |
---|---|---|
|
@@ -13,13 +13,6 @@ | |
<version>4.59.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<developers> | ||
<developer> | ||
<name>Rob Moffat</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
|
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,69 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>chat-workflow</artifactId> | ||
<name>Chat Workflow</name> | ||
<description>Build Workflows Using Enterprise Chat</description> | ||
|
||
<parent> | ||
<groupId>com.github.deutschebank.symphony</groupId> | ||
<artifactId>symphony-java-client-parent</artifactId> | ||
<version>4.59.1-SNAPSHOT</version> | ||
</parent> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<spring-boot.version>2.2.0.RELEASE</spring-boot.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.deutschebank.symphony</groupId> | ||
<artifactId>symphony-api-spring-boot-starter</artifactId> | ||
<version>4.59.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.deutschebank.symphony</groupId> | ||
<artifactId>symphony-java-client-entity-json</artifactId> | ||
<version>4.59.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.deutschebank.symphony</groupId> | ||
<artifactId>symphony-shared-stream</artifactId> | ||
<version>4.59.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${spring-boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-validation</artifactId> | ||
<version>${spring-boot.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<version>2.0.1.Final</version> | ||
</dependency> | ||
|
||
<!-- allows chat workflow to send attachments --> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-multipart</artifactId> | ||
<scope>provided</scope> | ||
<version>2.28</version> | ||
</dependency> | ||
|
||
<!-- for testing --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
<version>${spring-boot.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
12 changes: 12 additions & 0 deletions
12
...rkflow/src/main/java/com/github/deutschebank/symphony/workflow/AbstractNeedsWorkflow.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,12 @@ | ||
package com.github.deutschebank.symphony.workflow; | ||
|
||
public abstract class AbstractNeedsWorkflow { | ||
|
||
protected Workflow wf; | ||
|
||
public AbstractNeedsWorkflow(Workflow wf) { | ||
this.wf = wf; | ||
} | ||
|
||
|
||
} |
119 changes: 119 additions & 0 deletions
119
chat-workflow/src/main/java/com/github/deutschebank/symphony/workflow/AbstractWorkflow.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,119 @@ | ||
package com.github.deutschebank.symphony.workflow; | ||
|
||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import com.github.deutschebank.symphony.workflow.content.Addressable; | ||
import com.github.deutschebank.symphony.workflow.content.Room; | ||
import com.github.deutschebank.symphony.workflow.content.User; | ||
import com.github.deutschebank.symphony.workflow.history.History; | ||
import com.github.deutschebank.symphony.workflow.room.Rooms; | ||
|
||
/** | ||
* Represents workflows which can use the state of the conversation, and knows which rooms it is in. | ||
* | ||
* @author Rob Moffat | ||
* | ||
*/ | ||
public abstract class AbstractWorkflow implements Workflow { | ||
|
||
protected List<History> historyProviders = new ArrayList<History>();; | ||
protected List<Rooms> roomsProviders = new ArrayList<>(); | ||
private String namespace; | ||
private List<User> admins; | ||
private Rooms rooms; | ||
private History history; | ||
List<Room> keyRooms; | ||
|
||
public AbstractWorkflow(String namespace, List<User> admins, List<Room> keyRooms) { | ||
super(); | ||
this.history = createHistoryDelegate(); | ||
this.rooms = createRoomsDelegate(); | ||
this.keyRooms = keyRooms; | ||
this.admins = admins; | ||
} | ||
|
||
@Override | ||
public String getNamespace() { | ||
return namespace; | ||
} | ||
|
||
@Override | ||
public Rooms getRoomsApi() { | ||
return rooms; | ||
} | ||
|
||
@Override | ||
public History getHistoryApi() { | ||
return history; | ||
} | ||
|
||
|
||
private Rooms createRoomsDelegate() { | ||
return new Rooms() { | ||
|
||
@Override | ||
public Set<Room> getAllRooms() { | ||
return roomsProviders.stream() | ||
.flatMap(rp -> rp.getAllRooms().stream()) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
@Override | ||
public Room ensureRoom(Room r) { | ||
return roomsProviders.stream() | ||
.map(rp -> rp.ensureRoom(r)) | ||
.findFirst() | ||
.orElseThrow(() -> new UnsupportedOperationException("Couldn't ensure room "+r)); | ||
} | ||
}; | ||
} | ||
|
||
private History createHistoryDelegate() { | ||
return new History() { | ||
|
||
@Override | ||
public <X> Optional<X> getLastFromHistory(Class<X> type, Addressable address) { | ||
return historyProviders.stream() | ||
.map(hp -> hp.getLastFromHistory(type, address)) | ||
.filter(Optional::isPresent) | ||
.map(Optional::get) | ||
.findFirst(); | ||
} | ||
|
||
@Override | ||
public <X> List<X> getFromHistory(Class<X> type, Addressable address, Instant since) { | ||
return historyProviders.stream() | ||
.flatMap(hp -> hp.getFromHistory(type, address, since).stream()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
}; | ||
} | ||
|
||
@Override | ||
public List<Room> getKeyRooms() { | ||
return keyRooms; | ||
} | ||
|
||
@Override | ||
public List<User> getAdministrators() { | ||
return admins; | ||
} | ||
|
||
@Override | ||
public void registerHistoryProvider(History h) { | ||
historyProviders.add(h); | ||
} | ||
|
||
@Override | ||
public void registerRoomsProvider(Rooms r) { | ||
roomsProviders.add(r); | ||
} | ||
|
||
|
||
} |
53 changes: 53 additions & 0 deletions
53
chat-workflow/src/main/java/com/github/deutschebank/symphony/workflow/Workflow.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,53 @@ | ||
package com.github.deutschebank.symphony.workflow; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.github.deutschebank.symphony.workflow.content.Message; | ||
import com.github.deutschebank.symphony.workflow.content.Room; | ||
import com.github.deutschebank.symphony.workflow.content.User; | ||
import com.github.deutschebank.symphony.workflow.form.Button; | ||
import com.github.deutschebank.symphony.workflow.history.History; | ||
import com.github.deutschebank.symphony.workflow.response.Response; | ||
import com.github.deutschebank.symphony.workflow.room.Rooms; | ||
|
||
/** | ||
* A workflow is a collection of steps, which can be triggered by messages posted in a Symphony room. | ||
* | ||
* @author Rob Moffat | ||
* | ||
*/ | ||
public interface Workflow { | ||
|
||
public String getNamespace(); | ||
|
||
public Map<String, String> getCommands(Room r); | ||
|
||
public List<Response> applyCommand(User u, Room r, String commandName, Object argument, Message m); | ||
|
||
List<Button> gatherButtons(Object out, Room r); | ||
|
||
public Rooms getRoomsApi(); | ||
|
||
public History getHistoryApi(); | ||
|
||
/** | ||
* Important named rooms that must exist for the workflow. | ||
*/ | ||
public List<Room> getKeyRooms(); | ||
|
||
/** | ||
* List of administrators to be set on any rooms that get created. | ||
*/ | ||
public List<User> getAdministrators(); | ||
|
||
/** | ||
* This is the set of classes that will be sent in the "data" payload of the messages used to communicate workflow. | ||
*/ | ||
public List<Class<?>> getDataTypes(); | ||
|
||
public void registerHistoryProvider(History h); | ||
|
||
public void registerRoomsProvider(Rooms r); | ||
} | ||
|
5 changes: 5 additions & 0 deletions
5
...workflow/src/main/java/com/github/deutschebank/symphony/workflow/content/Addressable.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,5 @@ | ||
package com.github.deutschebank.symphony.workflow.content; | ||
|
||
public interface Addressable { | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
chat-workflow/src/main/java/com/github/deutschebank/symphony/workflow/content/Author.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,13 @@ | ||
package com.github.deutschebank.symphony.workflow.content; | ||
|
||
/** | ||
* Declare this class in a workflow object, and it will get populated automatically with the | ||
* person submitting the object. | ||
*/ | ||
public interface Author extends User { | ||
|
||
/** | ||
* Keeps track of who is working on the workflow, so we can get the author details back. | ||
*/ | ||
public static final ThreadLocal<Author> CURRENT_AUTHOR = new ThreadLocal<>(); | ||
} |
35 changes: 35 additions & 0 deletions
35
chat-workflow/src/main/java/com/github/deutschebank/symphony/workflow/content/Content.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 com.github.deutschebank.symphony.workflow.content; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
|
||
public interface Content { | ||
|
||
@JsonIgnore | ||
public String getText(); | ||
|
||
public default <X extends Content> List<X> only(Class<X> x) { | ||
if (x.isAssignableFrom(this.getClass())) { | ||
return Collections.singletonList((X) this); | ||
} else if (this instanceof Iterable<?>) { | ||
return StreamSupport.stream(((Iterable<Content>) this).spliterator(), false) | ||
.flatMap(i -> i.only(x).stream()) | ||
.collect(Collectors.toList()); | ||
} else { | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
public default <X extends Content> Optional<X> getNth(Class<X> x, int n) { | ||
try { | ||
return Optional.of(only(x).get(n)); | ||
} catch (Exception e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
chat-workflow/src/main/java/com/github/deutschebank/symphony/workflow/content/ID.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,21 @@ | ||
package com.github.deutschebank.symphony.workflow.content; | ||
|
||
import java.util.UUID; | ||
|
||
/** | ||
* This is a special class of tag which is a globally unique ID for the workflow element, | ||
* which can be used to track the evolution of a workflow. | ||
* | ||
* @author Rob Moffat | ||
* | ||
*/ | ||
public class ID extends TagDef { | ||
|
||
public ID() { | ||
this(UUID.randomUUID()); | ||
} | ||
|
||
public ID(UUID uuid) { | ||
super(uuid.toString(), uuid.toString(), Type.HASH); | ||
} | ||
} |
Oops, something went wrong.