Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #126

Merged
merged 6 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions addons/automatiko-graphql-addon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.automatiko</groupId>
<artifactId>addons</artifactId>
<version>0.0.0-SNAPSHOT</version>
</parent>
<groupId>io.automatiko.addons</groupId>
<artifactId>automatiko-graphql-addon</artifactId>

<name>Automatiko Engine :: Add-Ons :: GraphQL</name>
<description>GraphQL AddOn for Automatiko Engine</description>

<properties>
<java.module.name>io.automatiko.addons.graphql</java.module.name>
</properties>

<dependencies>
<dependency>
<groupId>io.automatiko.engine</groupId>
<artifactId>automatiko-engine-api</artifactId>
</dependency>
<dependency>
<groupId>io.automatiko.engine</groupId>
<artifactId>automatiko-engine-common</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-graphql</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package io.automatiko.addons.graphql;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.enterprise.context.ApplicationScoped;

import io.automatiko.engine.api.event.DataEvent;
import io.automatiko.engine.api.event.EventPublisher;

@ApplicationScoped
public class GraphQLEventPublisher implements EventPublisher {

private Set<GraphQLSubscriptionEventPublisher<?>> subscribers = new HashSet<>();

@Override
public void publish(DataEvent<?> event) {

subscribers.forEach(s -> s.process(event));

}

@Override
public void publish(Collection<DataEvent<?>> events) {
events.forEach(this::publish);

}

public void register(GraphQLSubscriptionEventPublisher<?> subscriber) {
this.subscribers.add(subscriber);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package io.automatiko.addons.graphql;

import java.util.function.Function;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;

import io.automatiko.addons.graphql.internal.SecurityAwareBroadcastProcessor;
import io.automatiko.engine.api.event.DataEvent;
import io.automatiko.engine.api.workflow.ProcessInstance;
import io.automatiko.engine.services.event.ProcessInstanceDataEvent;

@Dependent
public class GraphQLSubscriptionEventPublisher<T> {

SecurityAwareBroadcastProcessor<T> createdProcessor = SecurityAwareBroadcastProcessor.create();

SecurityAwareBroadcastProcessor<T> completedProcessor = SecurityAwareBroadcastProcessor.create();

SecurityAwareBroadcastProcessor<T> abortedProcessor = SecurityAwareBroadcastProcessor.create();

SecurityAwareBroadcastProcessor<T> inErrorProcessor = SecurityAwareBroadcastProcessor.create();

SecurityAwareBroadcastProcessor<T> changedProcessor = SecurityAwareBroadcastProcessor.create();

GraphQLEventPublisher publisher;

private String processId;

private Function<ProcessInstance<?>, T> mapper;

@Inject
public GraphQLSubscriptionEventPublisher(GraphQLEventPublisher publisher) {
this.publisher = publisher;
}

public void process(DataEvent<?> event) {
if (processId == null || mapper == null) {
return;
}

if (event instanceof ProcessInstanceDataEvent) {
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) event;

ProcessInstance<?> instance = piEvent.getData().sourceInstance();

if (instance.process().id().equals(processId)) {

if (instance.status() == ProcessInstance.STATE_COMPLETED) {
completedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else if (instance.status() == ProcessInstance.STATE_ABORTED) {
abortedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else if (instance.status() == ProcessInstance.STATE_ERROR) {
inErrorProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
} else {
changedProcessor.onNext(mapper.apply(instance), piEvent.getData().getVisibleTo());
}
}
}

}

public void configure(String processId, Function<ProcessInstance<?>, T> mapper) {
this.processId = processId;
this.mapper = mapper;

this.publisher.register(this);
}

public SecurityAwareBroadcastProcessor<T> created(T clazz) {
return createdProcessor;
}

public SecurityAwareBroadcastProcessor<T> completed(T clazz) {
return completedProcessor;
}

public SecurityAwareBroadcastProcessor<T> aborted(T clazz) {
return abortedProcessor;
}

public SecurityAwareBroadcastProcessor<T> inError(T clazz) {
return inErrorProcessor;
}

public SecurityAwareBroadcastProcessor<T> changed(T clazz) {
return changedProcessor;
}
}
Loading