Search in sources :

Example 11 with UserTaskInstance

use of org.kie.kogito.index.model.UserTaskInstance in project kogito-apps by kiegroup.

the class UserTaskInstanceMarshaller method readFrom.

@Override
public UserTaskInstance readFrom(ProtoStreamReader reader) throws IOException {
    UserTaskInstance ut = new UserTaskInstance();
    ut.setId(reader.readString(ID));
    ut.setDescription(reader.readString(DESCRIPTION));
    ut.setName(reader.readString(NAME));
    ut.setPriority(reader.readString(PRIORITY));
    ut.setProcessInstanceId(reader.readString(PROCESS_INSTANCE_ID));
    ut.setProcessId(reader.readString(PROCESS_ID));
    ut.setRootProcessInstanceId(reader.readString(ROOT_PROCESS_INSTANCE_ID));
    ut.setRootProcessId(reader.readString(ROOT_PROCESS_ID));
    ut.setState(reader.readString(STATE));
    ut.setActualOwner(reader.readString(ACTUAL_OWNER));
    ut.setAdminGroups(reader.readCollection(ADMIN_GROUPS, new HashSet<>(), String.class));
    ut.setAdminUsers(reader.readCollection(ADMIN_USERS, new HashSet<>(), String.class));
    ut.setCompleted(dateToZonedDateTime(reader.readDate(COMPLETED)));
    ut.setStarted(dateToZonedDateTime(reader.readDate(STARTED)));
    ut.setExcludedUsers(reader.readCollection(EXCLUDED_USERS, new HashSet<>(), String.class));
    ut.setPotentialGroups(reader.readCollection(POTENTIAL_GROUPS, new HashSet<>(), String.class));
    ut.setPotentialUsers(reader.readCollection(POTENTIAL_USERS, new HashSet<>(), String.class));
    ut.setInputs((ObjectNode) jsonFromString(reader.readString(INPUTS)));
    ut.setOutputs((ObjectNode) jsonFromString(reader.readString(OUTPUTS)));
    ut.setReferenceName(reader.readString(REFERENCE_NAME));
    ut.setLastUpdate(dateToZonedDateTime(reader.readDate(LAST_UPDATE)));
    ut.setEndpoint(reader.readString(ENDPOINT));
    ut.setComments(reader.readCollection(COMMENTS, new ArrayList<>(), Comment.class));
    ut.setAttachments(reader.readCollection(ATTACHMENTS, new ArrayList<>(), Attachment.class));
    return ut;
}
Also used : UserTaskInstance(org.kie.kogito.index.model.UserTaskInstance) Comment(org.kie.kogito.index.model.Comment) ArrayList(java.util.ArrayList) Attachment(org.kie.kogito.index.model.Attachment) HashSet(java.util.HashSet)

Example 12 with UserTaskInstance

use of org.kie.kogito.index.model.UserTaskInstance in project kogito-apps by kiegroup.

the class AbstractUserTaskInstanceQueryIT method testUserTaskInstanceQuery.

@Test
void testUserTaskInstanceQuery() {
    String taskId1 = UUID.randomUUID().toString();
    String processInstanceId1 = UUID.randomUUID().toString();
    String taskId2 = UUID.randomUUID().toString();
    String processInstanceId2 = UUID.randomUUID().toString();
    UserTaskInstance userTaskInstance1 = TestUtils.createUserTaskInstance(taskId1, processInstanceId1, RandomStringUtils.randomAlphabetic(5), UUID.randomUUID().toString(), RandomStringUtils.randomAlphabetic(10), "InProgress", 0L);
    UserTaskInstance userTaskInstance2 = TestUtils.createUserTaskInstance(taskId2, processInstanceId2, RandomStringUtils.randomAlphabetic(5), null, null, "Completed", 1000L);
    Storage<String, UserTaskInstance> storage = getStorage();
    storage.put(taskId1, userTaskInstance1);
    storage.put(taskId2, userTaskInstance2);
    queryAndAssert(assertWithId(), storage, singletonList(in("state", asList("InProgress", "Completed"))), null, null, null, taskId1, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(equalTo("state", "InProgress")), null, null, null, taskId1);
    queryAndAssert(assertWithId(), storage, singletonList(greaterThan("started", getDateTime())), null, null, null);
    queryAndAssert(assertWithId(), storage, singletonList(greaterThanEqual("completed", getDateTime(userTaskInstance2.getCompleted()))), null, null, null, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(lessThan("completed", getDateTime())), null, null, null, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(lessThanEqual("started", getDateTime())), null, null, null, taskId1, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(between("completed", getDateTime(userTaskInstance2.getCompleted()), getDateTime())), null, null, null, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(isNull("rootProcessInstanceId")), null, null, null, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(notNull("rootProcessInstanceId")), null, null, null, taskId1);
    queryAndAssert(assertWithId(), storage, singletonList(contains("adminUsers", "kogito")), null, null, null, taskId1, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(containsAny("adminGroups", asList("admin", "agroup"))), null, null, null, taskId1, taskId2);
    queryAndAssert(assertWithId(), storage, singletonList(containsAll("adminGroups", asList("admin", "agroup"))), null, null, null);
    queryAndAssert(assertWithId(), storage, singletonList(like("state", "*ss")), null, null, null, taskId1);
    queryAndAssert(assertWithId(), storage, singletonList(and(asList(equalTo("id", taskId1), equalTo("processInstanceId", processInstanceId1)))), null, null, null, taskId1);
    queryAndAssert(assertWithId(), storage, singletonList(or(asList(equalTo("id", taskId1), equalTo("id", taskId2)))), null, null, null, taskId1, taskId2);
    queryAndAssert(assertWithId(), storage, asList(equalTo("id", taskId1), equalTo("processInstanceId", processInstanceId2)), null, null, null);
    queryAndAssert(assertWithIdInOrder(), storage, asList(in("id", asList(taskId1, taskId2)), in("processInstanceId", asList(processInstanceId1, processInstanceId2))), singletonList(orderBy("state", SortDirection.ASC)), 1, 1, taskId1);
    queryAndAssert(assertWithIdInOrder(), storage, null, singletonList(orderBy("state", SortDirection.DESC)), null, null, taskId1, taskId2);
    queryAndAssert(assertWithIdInOrder(), storage, null, null, 1, 1, taskId2);
    queryAndAssert(assertWithIdInOrder(), storage, null, asList(orderBy("state", SortDirection.ASC), orderBy("completed", SortDirection.ASC)), 1, 1, taskId1);
}
Also used : UserTaskInstance(org.kie.kogito.index.model.UserTaskInstance) Test(org.junit.jupiter.api.Test)

Example 13 with UserTaskInstance

use of org.kie.kogito.index.model.UserTaskInstance in project kogito-apps by kiegroup.

the class GraphQLSchemaManager method deleteUserTaskComment.

private CompletableFuture<String> deleteUserTaskComment(DataFetchingEnvironment env) {
    Query<UserTaskInstance> query = cacheService.getUserTaskInstancesCache().query();
    query.filter(singletonList(equalTo("comments.id", env.getArgument("commentId"))));
    UserTaskInstance userTaskInstance = query.execute().get(0);
    return dataIndexApiExecutor.deleteUserTaskInstanceComment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()), userTaskInstance, env.getArgument("user"), env.getArgument("groups"), env.getArgument("commentId"));
}
Also used : UserTaskInstance(org.kie.kogito.index.model.UserTaskInstance)

Example 14 with UserTaskInstance

use of org.kie.kogito.index.model.UserTaskInstance in project kogito-apps by kiegroup.

the class GraphQLSchemaManager method updateUserTaskAttachment.

private CompletableFuture<String> updateUserTaskAttachment(DataFetchingEnvironment env) {
    Query<UserTaskInstance> query = cacheService.getUserTaskInstancesCache().query();
    query.filter(singletonList(equalTo("attachments.id", env.getArgument("attachmentId"))));
    UserTaskInstance userTaskInstance = query.execute().get(0);
    return dataIndexApiExecutor.updateUserTaskInstanceAttachment(getServiceUrl(userTaskInstance.getEndpoint(), userTaskInstance.getProcessId()), userTaskInstance, env.getArgument("user"), env.getArgument("groups"), env.getArgument("attachmentId"), env.getArgument("name"), env.getArgument("uri"));
}
Also used : UserTaskInstance(org.kie.kogito.index.model.UserTaskInstance)

Example 15 with UserTaskInstance

use of org.kie.kogito.index.model.UserTaskInstance in project kogito-apps by kiegroup.

the class GraphQLSchemaManager method createSchema.

private GraphQLSchema createSchema() {
    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("schema.graphqls");
    SchemaParser schemaParser = new SchemaParser();
    TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(new InputStreamReader(stream));
    RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().type("Query", builder -> {
        builder.dataFetcher("ProcessInstances", this::getProcessInstancesValues);
        builder.dataFetcher("UserTaskInstances", this::getUserTaskInstancesValues);
        builder.dataFetcher("Jobs", this::getJobsValues);
        return builder;
    }).type("Mutation", builder -> {
        builder.dataFetcher("ProcessInstanceAbort", this::abortProcessInstance);
        builder.dataFetcher("ProcessInstanceRetry", this::retryProcessInstance);
        builder.dataFetcher("ProcessInstanceSkip", this::skipProcessInstance);
        builder.dataFetcher("ProcessInstanceUpdateVariables", this::updateProcessInstanceVariables);
        builder.dataFetcher("NodeInstanceTrigger", this::triggerNodeInstance);
        builder.dataFetcher("NodeInstanceRetrigger", this::retriggerNodeInstance);
        builder.dataFetcher("NodeInstanceCancel", this::cancelNodeInstance);
        builder.dataFetcher("JobCancel", this::cancelJob);
        builder.dataFetcher("JobReschedule", this::rescheduleJob);
        builder.dataFetcher("UserTaskInstanceUpdate", this::updateUserTaskInstance);
        builder.dataFetcher("UserTaskInstanceCommentCreate", this::createTaskInstanceComment);
        builder.dataFetcher("UserTaskInstanceAttachmentCreate", this::createTaskInstanceAttachment);
        builder.dataFetcher("UserTaskInstanceCommentUpdate", this::updateUserTaskComment);
        builder.dataFetcher("UserTaskInstanceCommentDelete", this::deleteUserTaskComment);
        builder.dataFetcher("UserTaskInstanceAttachmentUpdate", this::updateUserTaskAttachment);
        builder.dataFetcher("UserTaskInstanceAttachmentDelete", this::deleteUserTaskAttachment);
        return builder;
    }).type("ProcessInstance", builder -> {
        builder.dataFetcher("parentProcessInstance", this::getParentProcessInstanceValue);
        builder.dataFetcher("childProcessInstances", this::getChildProcessInstancesValues);
        builder.dataFetcher("serviceUrl", this::getProcessInstanceServiceUrl);
        builder.dataFetcher("diagram", this::getProcessInstanceDiagram);
        builder.dataFetcher("nodeDefinitions", this::getProcessNodes);
        return builder;
    }).type("UserTaskInstance", builder -> {
        builder.dataFetcher("schema", this::getUserTaskInstanceSchema);
        return builder;
    }).type("ProcessInstanceMeta", builder -> {
        builder.dataFetcher("serviceUrl", this::getProcessInstanceJsonServiceUrl);
        return builder;
    }).type("ProcessInstanceState", builder -> {
        builder.enumValues(name -> ProcessInstanceState.valueOf(name).ordinal());
        return builder;
    }).type("Subscription", builder -> {
        builder.dataFetcher(PROCESS_INSTANCE_ADDED, getProcessInstanceAddedDataFetcher());
        builder.dataFetcher(PROCESS_INSTANCE_UPDATED, getProcessInstanceUpdatedDataFetcher());
        builder.dataFetcher(USER_TASK_INSTANCE_ADDED, getUserTaskInstanceAddedDataFetcher());
        builder.dataFetcher(USER_TASK_INSTANCE_UPDATED, getUserTaskInstanceUpdatedDataFetcher());
        builder.dataFetcher(JOB_ADDED, getJobAddedDataFetcher());
        builder.dataFetcher(JOB_UPDATED, getJobUpdatedDataFetcher());
        return builder;
    }).scalar(qlDateTimeScalarType).build();
    SchemaGenerator schemaGenerator = new SchemaGenerator();
    return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
}
Also used : DataIndexStorageService(org.kie.kogito.index.DataIndexStorageService) DataFetchingEnvironment(graphql.schema.DataFetchingEnvironment) GraphQLNamedType(graphql.schema.GraphQLNamedType) ProcessInstanceState(org.kie.kogito.index.model.ProcessInstanceState) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) ProcessInstance(org.kie.kogito.index.model.ProcessInstance) GraphQLScalarType(graphql.schema.GraphQLScalarType) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) Query(org.kie.kogito.persistence.api.query.Query) JsonUtils.getObjectMapper(org.kie.kogito.index.json.JsonUtils.getObjectMapper) Supplier(java.util.function.Supplier) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Collections.singletonList(java.util.Collections.singletonList) Inject(javax.inject.Inject) SchemaParser(graphql.schema.idl.SchemaParser) Map(java.util.Map) DataIndexParsingException(org.kie.kogito.index.json.DataIndexParsingException) DataFetcher(graphql.schema.DataFetcher) GraphQLSchema(graphql.schema.GraphQLSchema) GraphQLQueryParserRegistry(org.kie.kogito.index.graphql.query.GraphQLQueryParserRegistry) Storage(org.kie.kogito.persistence.api.Storage) JsonNode(com.fasterxml.jackson.databind.JsonNode) KogitoRuntimeClient(org.kie.kogito.index.api.KogitoRuntimeClient) DataIndexServiceException(org.kie.kogito.index.service.DataIndexServiceException) Logger(org.slf4j.Logger) Job(org.kie.kogito.index.model.Job) Collection(java.util.Collection) Publisher(org.reactivestreams.Publisher) QueryFilterFactory.equalTo(org.kie.kogito.persistence.api.query.QueryFilterFactory.equalTo) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) IOException(java.io.IOException) UserTaskInstance(org.kie.kogito.index.model.UserTaskInstance) InputStreamReader(java.io.InputStreamReader) String.format(java.lang.String.format) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RuntimeWiring(graphql.schema.idl.RuntimeWiring) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) GraphQLQueryOrderByParser(org.kie.kogito.index.graphql.query.GraphQLQueryOrderByParser) SchemaGenerator(graphql.schema.idl.SchemaGenerator) Node(org.kie.kogito.index.model.Node) InputStream(java.io.InputStream) InputStreamReader(java.io.InputStreamReader) RuntimeWiring(graphql.schema.idl.RuntimeWiring) InputStream(java.io.InputStream) TypeDefinitionRegistry(graphql.schema.idl.TypeDefinitionRegistry) SchemaGenerator(graphql.schema.idl.SchemaGenerator) SchemaParser(graphql.schema.idl.SchemaParser)

Aggregations

UserTaskInstance (org.kie.kogito.index.model.UserTaskInstance)35 Test (org.junit.jupiter.api.Test)24 Handler (io.vertx.core.Handler)8 UserTaskInstanceDataEvent (org.kie.kogito.event.process.UserTaskInstanceDataEvent)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 QuarkusTest (io.quarkus.test.junit.QuarkusTest)5 UserTaskInstanceEventBody (org.kie.kogito.event.process.UserTaskInstanceEventBody)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 JsonObject (io.vertx.core.json.JsonObject)3 Map (java.util.Map)3 Attachment (org.kie.kogito.index.model.Attachment)3 Comment (org.kie.kogito.index.model.Comment)3 Transactional (javax.transaction.Transactional)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DataFetcher (graphql.schema.DataFetcher)1 DataFetchingEnvironment (graphql.schema.DataFetchingEnvironment)1 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)1 GraphQLNamedType (graphql.schema.GraphQLNamedType)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1