Skip to content

Commit

Permalink
KOGITO-9522: add process instance operations to Data index GatewayAPI (
Browse files Browse the repository at this point in the history
  • Loading branch information
nmirasch authored Sep 14, 2023
1 parent e02d974 commit cb9f921
Show file tree
Hide file tree
Showing 7 changed files with 512 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.kie.kogito.index.model.ProcessDefinition;
import org.kie.kogito.index.model.ProcessInstance;
import org.kie.kogito.index.model.UserTaskInstance;
import org.kie.kogito.index.service.DataIndexServiceException;
import org.kie.kogito.index.storage.DataIndexStorageService;
import org.kie.kogito.persistence.api.Storage;
import org.kie.kogito.persistence.api.query.Query;
Expand All @@ -50,11 +51,21 @@
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;

import static java.lang.String.format;
import static java.util.Collections.singletonList;
import static org.kie.kogito.persistence.api.query.QueryFilterFactory.equalTo;

public abstract class AbstractGraphQLSchemaManager implements GraphQLSchemaManager {

private static final String ID = "id";
private static final String USER = "user";
private static final String GROUPS = "groups";
private static final String TASK_ID = "taskId";
private static final String COMMENT_ID = "commentId";
private static final String ATTACHMENT_ID = "attachmentId";

private static final String UNABLE_TO_FIND_ERROR_MSG = "Unable to find the instance with %s %s";

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractGraphQLSchemaManager.class);

@Inject
Expand Down Expand Up @@ -262,4 +273,176 @@ public void transform(Consumer<GraphQLSchema.Builder> builder) {
schema = schema.transform(builder);
}

public CompletableFuture<String> abortProcessInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().abortProcessInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()), processInstance);
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> retryProcessInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().retryProcessInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()), processInstance);
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> skipProcessInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().skipProcessInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()), processInstance);
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> updateProcessInstanceVariables(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().updateProcessInstanceVariables(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()), processInstance,
env.getArgument("variables"));

}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> triggerNodeInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().triggerNodeInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()),
processInstance,
env.getArgument("nodeId"));
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> retriggerNodeInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().retriggerNodeInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()),
processInstance,
env.getArgument("nodeInstanceId"));
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> cancelNodeInstance(DataFetchingEnvironment env) {
String id = env.getArgument("id");
ProcessInstance processInstance = getCacheService().getProcessInstancesCache().get(id);
if (processInstance != null) {
return getDataIndexApiExecutor().cancelNodeInstance(getServiceUrl(processInstance.getEndpoint(), processInstance.getProcessId()),
processInstance,
env.getArgument("nodeInstanceId"));
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> cancelJob(DataFetchingEnvironment env) {
String id = env.getArgument("id");
Job job = getCacheService().getJobsCache().get(id);
if (job != null) {
return getDataIndexApiExecutor().cancelJob(job.getEndpoint(), job);
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

public CompletableFuture<String> rescheduleJob(DataFetchingEnvironment env) {
String id = env.getArgument("id");
Job job = getCacheService().getJobsCache().get(id);
if (job != null) {
return getDataIndexApiExecutor().rescheduleJob(job.getEndpoint(), job, env.getArgument("data"));
}
return CompletableFuture.failedFuture(new DataIndexServiceException(format(UNABLE_TO_FIND_ERROR_MSG, ID, id)));
}

protected CompletableFuture<String> getUserTaskInstanceSchema(DataFetchingEnvironment env) {
UserTaskInstance userTaskInstance = env.getSource();
return getDataIndexApiExecutor().getUserTaskSchema(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS));
}

protected CompletableFuture<String> updateUserTaskInstance(DataFetchingEnvironment env) {
UserTaskInstance userTaskInstance = getCacheService().getUserTaskInstancesCache().get(env.getArgument(TASK_ID));
return getDataIndexApiExecutor().updateUserTaskInstance(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArguments());
}

protected CompletableFuture<String> createTaskInstanceComment(DataFetchingEnvironment env) {
UserTaskInstance userTaskInstance = getCacheService().getUserTaskInstancesCache().get(env.getArgument(TASK_ID));
return getDataIndexApiExecutor().createUserTaskInstanceComment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument("comment"));
}

protected CompletableFuture<String> createTaskInstanceAttachment(DataFetchingEnvironment env) {
UserTaskInstance userTaskInstance = getCacheService().getUserTaskInstancesCache().get(env.getArgument(TASK_ID));
return getDataIndexApiExecutor().createUserTaskInstanceAttachment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument("name"),
env.getArgument("uri"));
}

protected CompletableFuture<String> updateUserTaskComment(DataFetchingEnvironment env) {
Query<UserTaskInstance> query = getCacheService().getUserTaskInstancesCache().query();
query.filter(singletonList(equalTo("comments.id", env.getArgument(COMMENT_ID))));
UserTaskInstance userTaskInstance = query.execute().get(0);
return getDataIndexApiExecutor().updateUserTaskInstanceComment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument(COMMENT_ID),
env.getArgument("comment"));
}

protected CompletableFuture<String> deleteUserTaskComment(DataFetchingEnvironment env) {
Query<UserTaskInstance> query = getCacheService().getUserTaskInstancesCache().query();
query.filter(singletonList(equalTo("comments.id", env.getArgument(COMMENT_ID))));
UserTaskInstance userTaskInstance = query.execute().get(0);
return getDataIndexApiExecutor().deleteUserTaskInstanceComment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument(COMMENT_ID));
}

protected CompletableFuture<String> updateUserTaskAttachment(DataFetchingEnvironment env) {
Query<UserTaskInstance> query = getCacheService().getUserTaskInstancesCache().query();
query.filter(singletonList(equalTo("attachments.id", env.getArgument(ATTACHMENT_ID))));
UserTaskInstance userTaskInstance = query.execute().get(0);
return getDataIndexApiExecutor().updateUserTaskInstanceAttachment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument(ATTACHMENT_ID),
env.getArgument("name"),
env.getArgument("uri"));
}

protected CompletableFuture<String> deleteUserTaskAttachment(DataFetchingEnvironment env) {
Query<UserTaskInstance> query = getCacheService().getUserTaskInstancesCache().query();
query.filter(singletonList(equalTo("attachments.id", env.getArgument(ATTACHMENT_ID))));
UserTaskInstance userTaskInstance = query.execute().get(0);
return getDataIndexApiExecutor().deleteUserTaskInstanceAttachment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()),
userTaskInstance,
env.getArgument(USER),
env.getArgument(GROUPS),
env.getArgument(ATTACHMENT_ID));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scalar JSON

schema {
query: Query
mutation: Mutation
}

type Query {
Expand All @@ -13,6 +14,26 @@ type Query {
UserTaskInstances(where: UserTaskInstanceArgument, orderBy: UserTaskInstanceOrderBy, pagination: Pagination): [UserTaskInstance]
Jobs(where: JobArgument, orderBy: JobOrderBy, pagination: Pagination): [Job]
}
type Mutation {
ProcessInstanceAbort(id: String): String
ProcessInstanceRetry(id: String): String
ProcessInstanceSkip(id: String): String
ProcessInstanceUpdateVariables(id: String, variables: String): String
NodeInstanceTrigger(id: String, nodeId: String): String
NodeInstanceRetrigger(id: String, nodeInstanceId: String): String
NodeInstanceCancel(id: String, nodeInstanceId: String): String
JobCancel(id: String): String
JobReschedule(id: String, data: String): String
UserTaskInstanceUpdate(taskId: String, user: String, groups: [String], description: String, priority: String,
actualOwner: String, adminGroups: [String!], adminUsers: [String!], excludedUsers: [String!],
potentialGroups: [String!], potentialUsers: [String!], inputParams: String): String
UserTaskInstanceCommentCreate(taskId: String, user: String, groups: [String], comment: String): String
UserTaskInstanceAttachmentCreate(taskId: String, user: String, groups: [String], name: String, uri: String): String
UserTaskInstanceCommentUpdate(user:String, groups:[String],commentId: String, comment: String): String
UserTaskInstanceCommentDelete(user:String, groups:[String],commentId: String): String
UserTaskInstanceAttachmentUpdate(user:String, groups:[String],attachmentId: String, name: String, uri: String): String
UserTaskInstanceAttachmentDelete(user:String, groups:[String], attachmentId: String): String
}

type ProcessDefinition {
id: String!
Expand Down
Loading

0 comments on commit cb9f921

Please sign in to comment.