diff --git a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/META-INF/services/org.kie.kogito.internal.process.workitem.KogitoWorkItemHandlerFactory b/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/META-INF/services/org.kie.kogito.internal.process.workitem.KogitoWorkItemHandlerFactory deleted file mode 100644 index 169cf1cf90f..00000000000 --- a/jbpm/jbpm-flow/src/main/java/org/jbpm/workflow/core/impl/META-INF/services/org.kie.kogito.internal.process.workitem.KogitoWorkItemHandlerFactory +++ /dev/null @@ -1 +0,0 @@ -org.kie.kogito.jbpm.usertask.internal.UserTaskKogitoWorkItemHandlerFactory \ No newline at end of file diff --git a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/HumanTaskHelper.java b/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/HumanTaskHelper.java deleted file mode 100644 index 45b7c446cd7..00000000000 --- a/jbpm/jbpm-usertask/src/main/java/org/kie/kogito/usertask/impl/model/HumanTaskHelper.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.kie.kogito.usertask.impl.model; - -public class HumanTaskHelper { - - // private HumanTaskHelper() { - // } - // - // - // public static Comment addComment(KogitoWorkItem item, String commentInfo, String user) { - // String id = getNewId(); - // Comment comment = buildComment(id, commentInfo, user); - // humanTask.setComment(id, comment); - // return comment; - // } - // - // public static Attachment addAttachment(KogitoWorkItem item, AttachmentInfo attachmentInfo, String user) { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // String id = getNewId(); - // Attachment attachment = buildAttachment(id, attachmentInfo, user); - // humanTask.setAttachment(id, attachment); - // return attachment; - // } - // - // public static Comment updateComment(KogitoWorkItem item, String id, String commentInfo, String user) { - // try { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // Comment comment = humanTask.getComments().get(id); - // if (comment == null) { - // throw new IllegalArgumentException("Comment " + id + " does not exist"); - // } - // if (!comment.getUpdatedBy().equals(user)) { - // throw new IllegalArgumentException("User " + user + " did not create the comment, cannot modify it"); - // } - // comment = comment.clone(); - // humanTask.setComment(id, fillTaskMetaEntity(comment, commentInfo)); - // return comment; - // } catch (CloneNotSupportedException e) { - // throw new IllegalArgumentException("Attachment could not be modified", e); - // } - // } - // - // public static Attachment updateAttachment(KogitoWorkItem item, - // String id, - // AttachmentInfo attachmentInfo, - // String user) { - // try { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // Attachment attachment = humanTask.getAttachments().get(id); - // if (attachment == null) { - // throw new IllegalArgumentException("Attachment " + id + " does not exist"); - // } - // if (!attachment.getUpdatedBy().equals(user)) { - // throw new IllegalArgumentException("User " + user + " did not create the attachment, cannot modify it"); - // } - // - // attachment = attachment.clone(); - // humanTask.setAttachment(id, setAttachmentName(fillTaskMetaEntity(attachment, attachmentInfo.getUri()), attachmentInfo)); - // return attachment; - // } catch (CloneNotSupportedException e) { - // throw new IllegalArgumentException("Attachment could not be modified", e); - // } - // - // } - // - // public static Map updateContent(KogitoWorkItem item, MapOutput model) { - // return updateContent(item, model.toMap()); - // } - // - // public static Map updateContent(KogitoWorkItem item, Map map) { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // humanTask.setResults(map); - // return humanTask.getResults(); - // } - // - // public static boolean deleteComment(KogitoWorkItem item, Object id, String user) { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // Map comments = humanTask.getComments(); - // Comment comment = comments.get(id); - // if (comment == null || !comment.getUpdatedBy().equals(user)) { - // return false; - // } - // return humanTask.removeComment((String) id) != null; - // } - // - // public static boolean deleteAttachment(KogitoWorkItem item, Object id, String user) { - // InternalHumanTaskWorkItem humanTask = asHumanTask(item); - // Map attachments = humanTask.getAttachments(); - // Attachment attachment = attachments.get(id); - // if (attachment == null || !attachment.getUpdatedBy().equals(user)) { - // return false; - // } - // return humanTask.removeAttachment((String) id) != null; - // } - // - // public static HumanTaskWorkItem findTask(ProcessInstance pi, String taskId, Policy... policies) { - // return pi.findNodes(ni -> isSearchWorkItem(ni, taskId, - // policies)).stream().findFirst().map(wi -> (HumanTaskWorkItem) ((WorkItemNodeInstance) wi).getWorkItem()) - // .orElseThrow(() -> new WorkItemNotFoundException(taskId)); - // } - // - // private static boolean isSearchWorkItem(KogitoNodeInstance ni, String taskId, Policy... policies) { - // return ni instanceof WorkItemNodeInstance && ((WorkItemNodeInstance) ni).getWorkItemId().equals( - // taskId) && ((WorkItemNodeInstance) ni).getWorkItem().enforce(policies) && - // ((WorkItemNodeInstance) ni).getWorkItem() instanceof HumanTaskWorkItem; - // } - // - // private static Comment buildComment(String id, String content, String user) { - // return fillTaskMetaEntity(new Comment(id, user), content); - // } - // - // private static Attachment buildAttachment(String id, AttachmentInfo attachmentInfo, String user) { - // return setAttachmentName(fillTaskMetaEntity(new Attachment(id, user), attachmentInfo.getUri()), attachmentInfo); - // } - // - // private static Attachment setAttachmentName(Attachment attachment, AttachmentInfo attachmentInfo) { - // String name = attachmentInfo.getName(); - // if (name == null) { - // name = Paths.get(attachmentInfo.getUri()).getFileName().toString(); - // } - // attachment.setName(name); - // return attachment; - // } - // - // private static > C fillTaskMetaEntity(C metaInfo, - // T content) { - // metaInfo.setUpdatedAt(new Date()); - // metaInfo.setContent(content); - // return metaInfo; - // } - // - // private static String getNewId() { - // return UUID.randomUUID().toString(); - // } -} diff --git a/jbpm/jbpm-usertask/src/test/java/org/jbpm/usertask/impl/DeadlineHelperTest.java b/jbpm/jbpm-usertask/src/test/java/org/jbpm/usertask/impl/DeadlineHelperTest.java deleted file mode 100644 index 8dbf9e0873b..00000000000 --- a/jbpm/jbpm-usertask/src/test/java/org/jbpm/usertask/impl/DeadlineHelperTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jbpm.usertask.impl; - -public class DeadlineHelperTest { - // - // @Test - // public void testRepetition() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs|body:NotCompleted repeated notification every 5secs]@[R/PT5S]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // assertThat(deadlineInfo.getNotification()).containsEntry("body", "NotCompleted repeated notification every 5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); - // assertThat(scheduleInfo.getEndDate()).isNull(); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isEqualTo(5000L); - // assertThat(time.repeatLimit()).isEqualTo(-1); - // assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).isTrue(); - // } - // - // @Test - // public void testRepetitionWithEndDate() { - // ZonedDateTime future = ZonedDateTime.now().plus(Duration.ofMinutes(2)).plus(Duration.ofSeconds(2)); - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs]@[R/PT5S/" + future.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + "]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); - // assertEqualsDate(future, scheduleInfo.getEndDate()); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isEqualTo(5000L); - // assertThat(time.repeatLimit()).isEqualTo(24); - // assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).as("Date is " + time.get()).isTrue(); - // } - // - // @Test - // public void testRepetitionWithEndDateCornerCase() { - // ZonedDateTime future = ZonedDateTime.now().plus(Duration.ofSeconds(5)); - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs]@[R/PT5S/" + future.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + "]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); - // assertEqualsDate(future, scheduleInfo.getEndDate()); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isNull(); - // assertThat(time.repeatLimit()).isZero(); - // assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).isTrue(); - // } - // - // @Test - // public void testRepetitionWithEndDateAndLimit() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs]@[R2/PT5S/2021-03-18T18:55:01+01:00]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(2); - // assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isEqualTo(5000L); - // assertThat(time.repeatLimit()).isEqualTo(2); - // assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:54:51+01:00"), time.get()); - // } - // - // @Test - // public void testRepetitionStartEndDate() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs]@[R1/2021-03-18T18:55:01+01:00/2021-03-18T18:55:06+01:00]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(1); - // assertThat(scheduleInfo.getStartDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); - // assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:06+01:00")); - // assertThat(scheduleInfo.getDuration()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isEqualTo(5000L); - // assertThat(time.repeatLimit()).isEqualTo(1); - // assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); - // } - // - // @Test - // public void testRepetitionWithStartDate() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:5secs]@[R26/2021-03-18T18:55:01+01:00/PT2M]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofMinutes(2)); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(26); - // assertThat(scheduleInfo.getStartDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); - // assertThat(scheduleInfo.getEndDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isEqualTo(Duration.ofMinutes(2).toMillis()); - // assertThat(time.repeatLimit()).isEqualTo(26); - // assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); - // } - // - // @Test - // public void testExactDate() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:exact date]@[2021-03-18T18:55:01+01:00]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "exact date"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isNull(); - // assertThat(scheduleInfo.getNumRepetitions()).isZero(); - // assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time.repeatInterval()).isNull(); - // assertThat(time.repeatLimit()).isZero(); - // assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); - // } - // - // @Test - // public void testLargeRepetition() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:more than 1 year]@[R/P1Y3WT1H]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "more than 1 year"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(1); - // ScheduleInfo scheduleInfo = scheduling.iterator().next(); - // assertThat(scheduleInfo.getDuration()).isEqualTo(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1))); - // assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); - // assertThat(scheduleInfo.getEndDate()).isNull(); - // assertThat(scheduleInfo.getStartDate()).isNull(); - // - // ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); - // assertThat(time - // .repeatInterval()).isEqualTo(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1)) - // .toMillis()); - // assertThat(time.repeatLimit()).isEqualTo(-1); - // } - // - // @Test - // public void testMultipleDuration() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:1 and 4 hour]@[PT1H,PT4H]"); - // assertThat(deadlines).hasSize(1); - // DeadlineInfo> deadlineInfo = deadlines.iterator().next(); - // assertThat(deadlineInfo.getNotification()).containsEntry("subject", "1 and 4 hour"); - // Collection scheduling = deadlineInfo.getScheduleInfo(); - // assertThat(scheduling).hasSize(2); - // assertThat(scheduling.stream().filter(s -> s.getDuration().equals(Duration.ofHours(1)) || s.getDuration() - // .equals(Duration.ofHours(4))).count()).isEqualTo(2); - // } - // - // @Test - // public void testMultipleNotification() { - // Collection>> deadlines = DeadlineHelper.parseDeadlines( - // "[subject:1 hour]@[PT1H]^[subject:4 hour]@[PT4H]"); - // assertThat(deadlines).hasSize(2); - // - // for (DeadlineInfo> deadline : deadlines) { - // if ("1 hour".equals(deadline.getNotification().get("subject"))) { - // assertThat(deadline.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofHours(1)); - // } else if ("4 hour".equals(deadline.getNotification().get("subject"))) { - // assertThat(deadline.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofHours(4)); - // } else { - // fail("Unexpected subject value"); - // } - // } - // } - // - // @Test - // public void testReassignment() { - // Collection> reassigments = DeadlineHelper.parseReassignments( - // "[users:Pepe,Pepa|groups:Admin,Managers]@[1m]"); - // assertThat(reassigments).hasSize(1); - // DeadlineInfo reassignment = reassigments.iterator().next(); - // assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("Pepe", "Pepa"); - // assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admin", "Managers"); - // assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofMinutes(1)); - // } - // - // private void assertEqualsDate(ZonedDateTime expectedDate, ZonedDateTime calculatedDate) { - // assertThat(calculatedDate.toInstant().getEpochSecond()).isEqualTo(expectedDate.toInstant().getEpochSecond()); - // } -} diff --git a/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java b/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java new file mode 100644 index 00000000000..0bf241c43bb --- /dev/null +++ b/jbpm/jbpm-usertask/src/test/java/org/kie/kogito/usertask/impl/model/DeadlineHelperTest.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.kie.kogito.usertask.impl.model; + +import java.time.Duration; +import java.time.Period; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Collection; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.kie.kogito.jobs.ExpirationTime; +import org.kie.kogito.usertask.model.DeadlineInfo; +import org.kie.kogito.usertask.model.Reassignment; +import org.kie.kogito.usertask.model.ScheduleInfo; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.fail; + +public class DeadlineHelperTest { + + @Test + public void testRepetition() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs|body:NotCompleted repeated notification every 5secs]@[R/PT5S]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + assertThat(deadlineInfo.getNotification()).containsEntry("body", "NotCompleted repeated notification every 5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); + assertThat(scheduleInfo.getEndDate()).isNull(); + assertThat(scheduleInfo.getStartDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isEqualTo(5000L); + assertThat(time.repeatLimit()).isEqualTo(-1); + assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).isTrue(); + } + + @Test + public void testRepetitionWithEndDate() { + ZonedDateTime future = ZonedDateTime.now().plus(Duration.ofMinutes(2)).plus(Duration.ofSeconds(2)); + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs]@[R/PT5S/" + future.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + "]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); + assertEqualsDate(future, scheduleInfo.getEndDate()); + assertThat(scheduleInfo.getStartDate()).isNull(); + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isEqualTo(5000L); + assertThat(time.repeatLimit()).isEqualTo(24); + assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).as("Date is " + time.get()).isTrue(); + } + + @Test + public void testRepetitionWithEndDateCornerCase() { + ZonedDateTime future = ZonedDateTime.now().plus(Duration.ofSeconds(5)); + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs]@[R/PT5S/" + future.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) + "]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); + assertEqualsDate(future, scheduleInfo.getEndDate()); + assertThat(scheduleInfo.getStartDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isNull(); + assertThat(time.repeatLimit()).isZero(); + assertThat(ZonedDateTime.now().plus(Duration.ofSeconds(5)).isAfter(time.get())).isTrue(); + } + + @Test + public void testRepetitionWithEndDateAndLimit() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs]@[R2/PT5S/2021-03-18T18:55:01+01:00]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofSeconds(5)); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(2); + assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); + assertThat(scheduleInfo.getStartDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isEqualTo(5000L); + assertThat(time.repeatLimit()).isEqualTo(2); + assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:54:51+01:00"), time.get()); + } + + @Test + public void testRepetitionStartEndDate() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs]@[R1/2021-03-18T18:55:01+01:00/2021-03-18T18:55:06+01:00]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(1); + assertThat(scheduleInfo.getStartDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); + assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:06+01:00")); + assertThat(scheduleInfo.getDuration()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isEqualTo(5000L); + assertThat(time.repeatLimit()).isEqualTo(1); + assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); + } + + @Test + public void testRepetitionWithStartDate() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:5secs]@[R26/2021-03-18T18:55:01+01:00/PT2M]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "5secs"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(Duration.ofMinutes(2)); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(26); + assertThat(scheduleInfo.getStartDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); + assertThat(scheduleInfo.getEndDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isEqualTo(Duration.ofMinutes(2).toMillis()); + assertThat(time.repeatLimit()).isEqualTo(26); + assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); + } + + @Test + public void testExactDate() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:exact date]@[2021-03-18T18:55:01+01:00]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "exact date"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isNull(); + assertThat(scheduleInfo.getNumRepetitions()).isZero(); + assertThat(scheduleInfo.getEndDate()).isEqualTo(ZonedDateTime.parse("2021-03-18T18:55:01+01:00")); + assertThat(scheduleInfo.getStartDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time.repeatInterval()).isNull(); + assertThat(time.repeatLimit()).isZero(); + assertEqualsDate(ZonedDateTime.parse("2021-03-18T18:55:01+01:00"), time.get()); + } + + @Test + public void testLargeRepetition() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:more than 1 year]@[R/P1Y3WT1H]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "more than 1 year"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(1); + ScheduleInfo scheduleInfo = scheduling.iterator().next(); + assertThat(scheduleInfo.getDuration()).isEqualTo(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1))); + assertThat(scheduleInfo.getNumRepetitions()).isEqualTo(-1); + assertThat(scheduleInfo.getEndDate()).isNull(); + assertThat(scheduleInfo.getStartDate()).isNull(); + + ExpirationTime time = DeadlineHelper.getExpirationTime(scheduleInfo); + assertThat(time + .repeatInterval()).isEqualTo(DeadlineHelper.getDuration(Period.ofYears(1).plus(Period.ofWeeks(3)), Duration.ofHours(1)) + .toMillis()); + assertThat(time.repeatLimit()).isEqualTo(-1); + } + + @Test + public void testMultipleDuration() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:1 and 4 hour]@[PT1H,PT4H]"); + assertThat(deadlines).hasSize(1); + DeadlineInfo> deadlineInfo = deadlines.iterator().next(); + assertThat(deadlineInfo.getNotification()).containsEntry("subject", "1 and 4 hour"); + Collection scheduling = deadlineInfo.getScheduleInfo(); + assertThat(scheduling).hasSize(2); + assertThat(scheduling.stream().filter(s -> s.getDuration().equals(Duration.ofHours(1)) || s.getDuration() + .equals(Duration.ofHours(4))).count()).isEqualTo(2); + } + + @Test + public void testMultipleNotification() { + Collection>> deadlines = DeadlineHelper.parseDeadlines( + "[subject:1 hour]@[PT1H]^[subject:4 hour]@[PT4H]"); + assertThat(deadlines).hasSize(2); + + for (DeadlineInfo> deadline : deadlines) { + if ("1 hour".equals(deadline.getNotification().get("subject"))) { + assertThat(deadline.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofHours(1)); + } else if ("4 hour".equals(deadline.getNotification().get("subject"))) { + assertThat(deadline.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofHours(4)); + } else { + fail("Unexpected subject value"); + } + } + } + + @Test + public void testReassignment() { + Collection> reassigments = DeadlineHelper.parseReassignments( + "[users:Pepe,Pepa|groups:Admin,Managers]@[1m]"); + assertThat(reassigments).hasSize(1); + DeadlineInfo reassignment = reassigments.iterator().next(); + assertThat(reassignment.getNotification().getPotentialUsers()).containsExactlyInAnyOrder("Pepe", "Pepa"); + assertThat(reassignment.getNotification().getPotentialGroups()).containsExactlyInAnyOrder("Admin", "Managers"); + assertThat(reassignment.getScheduleInfo().iterator().next().getDuration()).isEqualTo(Duration.ofMinutes(1)); + } + + private void assertEqualsDate(ZonedDateTime expectedDate, ZonedDateTime calculatedDate) { + assertThat(calculatedDate.toInstant().getEpochSecond()).isEqualTo(expectedDate.toInstant().getEpochSecond()); + } +} diff --git a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/marshallers/state/WorkItemNodeInstanceReader.java b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/marshallers/state/WorkItemNodeInstanceReader.java index 17f078abe11..544e1f40225 100644 --- a/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/marshallers/state/WorkItemNodeInstanceReader.java +++ b/jbpm/process-serialization-protobuf/src/main/java/org/jbpm/flow/serialization/impl/marshallers/state/WorkItemNodeInstanceReader.java @@ -56,10 +56,10 @@ public NodeInstance read(MarshallerReaderContext context, Any value) { try { ProtobufVariableReader varReader = new ProtobufVariableReader(context); WorkItemNodeInstanceContent content = value.unpack(WorkItemNodeInstanceContent.class); - WorkItemNodeInstance nodeInstance = instanceWorkItem(content); + WorkItemNodeInstance nodeInstance = instanceWorkItem(); RuleFlowProcessInstance ruleFlowProcessInstance = context.get(MarshallerContextName.MARSHALLER_PROCESS_INSTANCE); nodeInstance.internalSetWorkItemId(content.getWorkItemId()); - InternalKogitoWorkItem workItem = (InternalKogitoWorkItem) nodeInstance.getWorkItem(); + InternalKogitoWorkItem workItem = nodeInstance.getWorkItem(); workItem.setId(content.getWorkItemId()); workItem.setProcessInstanceId(ruleFlowProcessInstance.getStringId()); workItem.setName(content.getName()); @@ -94,7 +94,7 @@ public NodeInstance read(MarshallerReaderContext context, Any value) { } } - private WorkItemNodeInstance instanceWorkItem(WorkItemNodeInstanceContent content) { + private WorkItemNodeInstance instanceWorkItem() { WorkItemNodeInstance nodeInstance = new WorkItemNodeInstance(); KogitoWorkItemImpl workItem = new KogitoWorkItemImpl(); workItem.setId(UUID.randomUUID().toString());