Skip to content

Commit

Permalink
Second commit of chat workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Moffat committed Sep 14, 2020
1 parent f9b0f3f commit 60bad80
Show file tree
Hide file tree
Showing 83 changed files with 5,334 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NOTICE
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.
7 changes: 0 additions & 7 deletions bindings/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
69 changes: 69 additions & 0 deletions chat-workflow/pom.xml
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>
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;
}


}
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);
}


}
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);
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.deutschebank.symphony.workflow.content;

public interface Addressable {

}
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<>();
}
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();
}
}
}
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);
}
}
Loading

0 comments on commit 60bad80

Please sign in to comment.