use of org.kie.kogito.process.workitem.Attachment 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);
}
}
use of org.kie.kogito.process.workitem.Attachment in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceWriter method buildAttachments.
private List<KogitoWorkItemsProtobuf.Attachment> buildAttachments(Iterable<Attachment> attachments) {
List<KogitoWorkItemsProtobuf.Attachment> attachmentProtobuf = new ArrayList<>();
for (Attachment attachment : attachments) {
KogitoWorkItemsProtobuf.Attachment workItemAttachment = KogitoWorkItemsProtobuf.Attachment.newBuilder().setId(attachment.getId().toString()).setContent(attachment.getContent().toString()).setUpdatedBy(attachment.getUpdatedBy()).setUpdatedAt(attachment.getUpdatedAt().getTime()).setName(attachment.getName()).build();
attachmentProtobuf.add(workItemAttachment);
}
return attachmentProtobuf;
}
use of org.kie.kogito.process.workitem.Attachment 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"));
}
}
use of org.kie.kogito.process.workitem.Attachment 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);
}
use of org.kie.kogito.process.workitem.Attachment in project kogito-runtimes by kiegroup.
the class ProtobufProcessInstanceReader method buildAttachment.
private Attachment buildAttachment(KogitoWorkItemsProtobuf.Attachment attachment) {
Attachment result = new Attachment(attachment.getId(), attachment.getUpdatedBy());
result.setContent(URI.create(attachment.getContent()));
result.setUpdatedAt(new Date(attachment.getUpdatedAt()));
result.setName(attachment.getName());
return result;
}
Aggregations