Search in sources :

Example 1 with Comment

use of org.kie.kogito.process.workitem.Comment in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceWriter method buildComments.

private List<KogitoWorkItemsProtobuf.Comment> buildComments(Iterable<Comment> comments) {
    List<KogitoWorkItemsProtobuf.Comment> commentsProtobuf = new ArrayList<>();
    for (Comment comment : comments) {
        KogitoWorkItemsProtobuf.Comment workItemComment = KogitoWorkItemsProtobuf.Comment.newBuilder().setId(comment.getId().toString()).setContent(comment.getContent()).setUpdatedBy(comment.getUpdatedBy()).setUpdatedAt(comment.getUpdatedAt().getTime()).build();
        commentsProtobuf.add(workItemComment);
    }
    return commentsProtobuf;
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) ArrayList(java.util.ArrayList) KogitoWorkItemsProtobuf(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf)

Example 2 with Comment

use of org.kie.kogito.process.workitem.Comment in project kogito-runtimes by kiegroup.

the class ProtobufProcessInstanceReader method buildWorkItemNodeInstance.

private NodeInstanceImpl buildWorkItemNodeInstance(WorkItemNodeInstanceContent content) {
    try {
        WorkItemNodeInstance nodeInstance = instanceWorkItem(content);
        if (nodeInstance instanceof HumanTaskNodeInstance) {
            HumanTaskNodeInstance humanTaskNodeInstance = (HumanTaskNodeInstance) nodeInstance;
            HumanTaskWorkItemImpl workItem = (HumanTaskWorkItemImpl) nodeInstance.getWorkItem();
            Any workItemDataMessage = content.getWorkItemData();
            if (workItemDataMessage.is(HumanTaskWorkItemData.class)) {
                HumanTaskWorkItemData workItemData = workItemDataMessage.unpack(HumanTaskWorkItemData.class);
                humanTaskNodeInstance.getNotCompletedDeadlineTimers().putAll(buildDeadlines(workItemData.getCompletedDeadlinesMap()));
                humanTaskNodeInstance.getNotCompletedReassigments().putAll(buildReassignments(workItemData.getCompletedReassigmentsMap()));
                humanTaskNodeInstance.getNotStartedDeadlineTimers().putAll(buildDeadlines(workItemData.getStartDeadlinesMap()));
                humanTaskNodeInstance.getNotStartedReassignments().putAll(buildReassignments(workItemData.getStartReassigmentsMap()));
                if (workItemData.hasTaskName()) {
                    workItem.setTaskName(workItemData.getTaskName());
                }
                if (workItemData.hasTaskDescription()) {
                    workItem.setTaskDescription(workItemData.getTaskDescription());
                }
                if (workItemData.hasTaskPriority()) {
                    workItem.setTaskPriority(workItemData.getTaskPriority());
                }
                if (workItemData.hasTaskReferenceName()) {
                    workItem.setReferenceName(workItemData.getTaskReferenceName());
                }
                if (workItemData.hasActualOwner()) {
                    workItem.setActualOwner(workItemData.getActualOwner());
                }
                workItem.getAdminUsers().addAll(workItemData.getAdminUsersList());
                workItem.getAdminGroups().addAll(workItemData.getAdminGroupsList());
                workItem.getPotentialUsers().addAll(workItemData.getPotUsersList());
                workItem.getPotentialGroups().addAll(workItemData.getPotGroupsList());
                workItem.getExcludedUsers().addAll(workItemData.getExcludedUsersList());
                workItem.getComments().putAll(workItemData.getCommentsList().stream().map(this::buildComment).collect(Collectors.toMap(Comment::getId, Function.identity())));
                workItem.getAttachments().putAll(workItemData.getAttachmentsList().stream().map(this::buildAttachment).collect(Collectors.toMap(Attachment::getId, Function.identity())));
            }
        }
        nodeInstance.internalSetWorkItemId(content.getWorkItemId());
        KogitoWorkItemImpl workItem = (KogitoWorkItemImpl) nodeInstance.getWorkItem();
        workItem.setId(content.getWorkItemId());
        workItem.setProcessInstanceId(ruleFlowProcessInstance.getStringId());
        workItem.setName(content.getName());
        workItem.setState(content.getState());
        workItem.setDeploymentId(ruleFlowProcessInstance.getDeploymentId());
        workItem.setProcessInstance(ruleFlowProcessInstance);
        workItem.setPhaseId(content.getPhaseId());
        workItem.setPhaseStatus(content.getPhaseStatus());
        workItem.setStartDate(new Date(content.getStartDate()));
        if (content.getCompleteDate() > 0) {
            workItem.setCompleteDate(new Date(content.getCompleteDate()));
        }
        if (content.getTimerInstanceIdCount() > 0) {
            nodeInstance.internalSetTimerInstances(new ArrayList<>(content.getTimerInstanceIdList()));
        }
        nodeInstance.internalSetProcessInstanceId(content.getErrorHandlingProcessInstanceId());
        varReader.buildVariables(content.getVariableList()).forEach(var -> nodeInstance.getWorkItem().getParameters().put(var.getName(), var.getValue()));
        varReader.buildVariables(content.getResultList()).forEach(var -> nodeInstance.getWorkItem().getResults().put(var.getName(), var.getValue()));
        return nodeInstance;
    } catch (InvalidProtocolBufferException ex) {
        throw new ProcessInstanceMarshallerException("cannot unpack node instance", ex);
    }
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) HumanTaskNodeInstance(org.jbpm.workflow.instance.node.HumanTaskNodeInstance) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ProcessInstanceMarshallerException(org.kie.kogito.serialization.process.ProcessInstanceMarshallerException) Attachment(org.kie.kogito.process.workitem.Attachment) WorkItemNodeInstance(org.jbpm.workflow.instance.node.WorkItemNodeInstance) HumanTaskWorkItemImpl(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl) HumanTaskWorkItemData(org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf.HumanTaskWorkItemData) KogitoWorkItemImpl(org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl) Any(com.google.protobuf.Any) Date(java.util.Date)

Example 3 with Comment

use of org.kie.kogito.process.workitem.Comment in project kogito-runtimes by kiegroup.

the class UserTaskInstanceDataEventCodecTest method encode.

@Test
void encode() {
    try (MockedStatic<CodecUtils> codecUtils = mockStatic(CodecUtils.class)) {
        Codec<Document> mockCodec = mock(Codec.class);
        codecUtils.when(CodecUtils::codec).thenReturn(mockCodec);
        codecUtils.when(() -> CodecUtils.encodeDataEvent(any(), any())).thenCallRealMethod();
        BsonWriter writer = mock(BsonWriter.class);
        EncoderContext context = EncoderContext.builder().build();
        codec.encode(writer, event, context);
        ArgumentCaptor<Document> captor = ArgumentCaptor.forClass(Document.class);
        verify(mockCodec, times(1)).encode(eq(writer), captor.capture(), eq(context));
        Document doc = captor.getValue();
        assertEquals(event.getId(), doc.get(ID));
        assertEquals(event.getSpecVersion().toString(), doc.get("specversion"));
        assertEquals(event.getSource().toString(), doc.get("source"));
        assertEquals(event.getType(), doc.get("type"));
        assertEquals(event.getTime(), doc.get("time"));
        assertEquals(event.getSubject(), doc.get("subject"));
        assertEquals(event.getDataContentType(), doc.get("dataContentType"));
        assertEquals(event.getDataSchema(), doc.get("dataSchema"));
        assertEquals(event.getKogitoProcessinstanceId(), doc.get("kogitoProcessinstanceId"));
        assertEquals(event.getKogitoRootProcessinstanceId(), doc.get("kogitoRootProcessinstanceId"));
        assertEquals(event.getKogitoProcessId(), doc.get("kogitoProcessId"));
        assertEquals(event.getKogitoRootProcessId(), doc.get("kogitoRootProcessId"));
        assertEquals(event.getKogitoAddons(), doc.get("kogitoAddons"));
        assertEquals(event.getKogitoUserTaskinstanceId(), doc.get("kogitoUserTaskinstanceId"));
        assertEquals(event.getKogitoUserTaskinstanceState(), doc.get("kogitoUserTaskinstanceState"));
        assertEquals(event.getData().getId(), ((Document) doc.get("data")).get("id"));
        assertEquals(event.getData().getTaskName(), ((Document) doc.get("data")).get("taskName"));
        assertEquals(event.getData().getTaskDescription(), ((Document) doc.get("data")).get("taskDescription"));
        assertEquals(event.getData().getTaskPriority(), ((Document) doc.get("data")).get("taskPriority"));
        assertEquals(event.getData().getReferenceName(), ((Document) doc.get("data")).get("referenceName"));
        assertEquals(event.getData().getStartDate(), ((Document) doc.get("data")).get("startDate"));
        assertEquals(event.getData().getCompleteDate(), ((Document) doc.get("data")).get("completeDate"));
        assertEquals(event.getData().getState(), ((Document) doc.get("data")).get("state"));
        assertEquals(event.getData().getActualOwner(), ((Document) doc.get("data")).get("actualOwner"));
        assertEquals(event.getData().getPotentialUsers(), ((Document) doc.get("data")).get("potentialUsers"));
        assertEquals(event.getData().getPotentialGroups(), ((Document) doc.get("data")).get("potentialGroups"));
        assertEquals(event.getData().getExcludedUsers(), ((Document) doc.get("data")).get("excludedUsers"));
        assertEquals(event.getData().getAdminUsers(), ((Document) doc.get("data")).get("adminUsers"));
        assertEquals(event.getData().getAdminGroups(), ((Document) doc.get("data")).get("adminGroups"));
        assertEquals(new Document(event.getData().getInputs()), ((Document) doc.get("data")).get("inputs"));
        assertEquals(new Document(event.getData().getOutputs()), ((Document) doc.get("data")).get("outputs"));
        assertEquals(event.getData().getProcessInstanceId(), ((Document) doc.get("data")).get("processInstanceId"));
        assertEquals(event.getData().getRootProcessInstanceId(), ((Document) doc.get("data")).get("rootProcessInstanceId"));
        assertEquals(event.getData().getProcessId(), ((Document) doc.get("data")).get("processId"));
        assertEquals(event.getData().getRootProcessId(), ((Document) doc.get("data")).get("rootProcessId"));
        Comment c = event.getData().getComments().iterator().next();
        Document comment = new Document().append("id", c.getId()).append("content", c.getContent()).append("updatedAt", c.getUpdatedAt()).append("updatedBy", c.getUpdatedBy());
        Set<Document> comments = new HashSet<>();
        comments.add(comment);
        assertEquals(comments, ((Document) doc.get("data")).get("comments"));
        Attachment a = event.getData().getAttachments().iterator().next();
        Document attachment = new Document().append("id", a.getId()).append("content", a.getContent()).append("updatedAt", a.getUpdatedAt()).append("updatedBy", a.getUpdatedBy()).append("name", a.getName());
        Set<Document> attachments = new HashSet<>();
        attachments.add(attachment);
        assertEquals(attachments, ((Document) doc.get("data")).get("attachments"));
    }
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) EncoderContext(org.bson.codecs.EncoderContext) BsonWriter(org.bson.BsonWriter) Attachment(org.kie.kogito.process.workitem.Attachment) Document(org.bson.Document) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 4 with Comment

use of org.kie.kogito.process.workitem.Comment in project kogito-runtimes by kiegroup.

the class HumanTaskHelper method addComment.

public static Comment addComment(KogitoWorkItem item, String commentInfo, String user) {
    HumanTaskWorkItemImpl humanTask = asHumanTask(item);
    Object id = getNewId();
    Comment comment = buildComment(id, commentInfo, user);
    humanTask.getComments().put(id, comment);
    return comment;
}
Also used : Comment(org.kie.kogito.process.workitem.Comment)

Example 5 with Comment

use of org.kie.kogito.process.workitem.Comment in project kogito-runtimes by kiegroup.

the class UserTaskInstanceDataEventCodecTest method setUp.

@BeforeEach
void setUp() {
    codec = new UserTaskInstanceDataEventCodec();
    String source = "testSource";
    String kogitoAddons = "testKogitoAddons";
    Comment comment = new Comment("testCommentId", "testCommentUpdatedBy");
    comment.setContent("testCommentContent");
    comment.setUpdatedAt(new Date());
    Set<Comment> comments = Collections.singleton(comment);
    Attachment attachment = new Attachment("testAttachmentId", "testAttachmentUpdatedBy");
    attachment.setContent(URI.create("test.attachment.test"));
    attachment.setName("testAttachmentName");
    attachment.setUpdatedAt(new Date());
    Set<Attachment> attachments = Collections.singleton(attachment);
    Map<String, String> metaData = new HashMap<>();
    metaData.put(ProcessInstanceEventBody.ID_META_DATA, "testKogitoProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.ROOT_ID_META_DATA, "testKogitoRootProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.PROCESS_ID_META_DATA, "testKogitoProcessId");
    metaData.put(ProcessInstanceEventBody.ROOT_PROCESS_ID_META_DATA, "testKogitoRootProcessId");
    metaData.put(UserTaskInstanceEventBody.UT_STATE_META_DATA, "testKogitoUserTaskinstanceState");
    metaData.put(UserTaskInstanceEventBody.UT_ID_META_DATA, "testKogitoUserTaskinstanceId");
    UserTaskInstanceEventBody body = UserTaskInstanceEventBody.create().id("testId").taskName("testTaskName").taskDescription("testTaskDescription").taskPriority("testTaskPriority").referenceName("testReferenceName").startDate(new Date()).completeDate(new Date()).state("testState").actualOwner("testActualOwner").potentialUsers(Collections.singleton("testPotentialUsers")).potentialGroups(Collections.singleton("testPotentialGroups")).excludedUsers(Collections.singleton("testExcludedUsers")).adminUsers(Collections.singleton("testAdminUsers")).adminGroups(Collections.singleton("testAdminGroups")).inputs(Collections.singletonMap("testInputsKey", "testInputsValue")).outputs(Collections.singletonMap("testOutputsKey", "testOutputsValue")).processInstanceId("testKogitoProcessinstanceId").rootProcessInstanceId("testKogitoRootProcessinstanceId").processId("testKogitoProcessId").rootProcessId("testKogitoRootProcessId").comments(comments).attachments(attachments).build();
    event = new UserTaskInstanceDataEvent(source, kogitoAddons, metaData, body);
}
Also used : Comment(org.kie.kogito.process.workitem.Comment) HashMap(java.util.HashMap) Attachment(org.kie.kogito.process.workitem.Attachment) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) BsonString(org.bson.BsonString) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Comment (org.kie.kogito.process.workitem.Comment)7 Date (java.util.Date)3 Attachment (org.kie.kogito.process.workitem.Attachment)3 Any (com.google.protobuf.Any)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 BsonString (org.bson.BsonString)1 BsonWriter (org.bson.BsonWriter)1 Document (org.bson.Document)1 EncoderContext (org.bson.codecs.EncoderContext)1 HumanTaskWorkItemImpl (org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemImpl)1 HumanTaskNodeInstance (org.jbpm.workflow.instance.node.HumanTaskNodeInstance)1 WorkItemNodeInstance (org.jbpm.workflow.instance.node.WorkItemNodeInstance)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 KogitoWorkItemImpl (org.kie.kogito.process.workitems.impl.KogitoWorkItemImpl)1 ProcessInstanceMarshallerException (org.kie.kogito.serialization.process.ProcessInstanceMarshallerException)1 KogitoWorkItemsProtobuf (org.kie.kogito.serialization.process.protobuf.KogitoWorkItemsProtobuf)1