Track deadlines and tasks
Start a decision clock and a review task when a permit enters review. The clock measures time until a decision; the task names a piece of work for someone to do. Allow about 20 minutes after the builds.
Continue in the permit-desk folder from Write a letter. The workflow already has Received,
In review, Approved and Refused states.
Define the office calendar
This example uses Monday to Friday in one named time zone. It does not claim to encode your organization's holiday schedule; the shipped holiday list is empty until you supply dates.
code: cal.permit-office
zone: America/Los_Angeles
holidays: ref.jcm.holidays
With no hours entry, this calendar counts business days. Before using it in a real project, review the time zone,
working week and holidays with the people responsible for the service. The
deadline reference explains how to add dated holidays and office hours.
Start a decision clock
code: dl.permit.decision
name: Permit decision due
binding: case.permit
starts-in: IN_REVIEW
stop-when: [APPROVED, REFUSED]
duration: {days: 10}
calendar: cal.permit-office
warn-before: {days: 2}
Entering In review starts the clock. Approved and Refused stop it. Here days means business days because the
policy names a calendar. Without a calendar, duration: {days: 10} counts calendar time. Do not remove the calendar
as a cosmetic edit: it changes the service commitment.
A clock reports where the record stands; this policy does not automatically approve a permit, send a reminder or create an escalation. Those are separate configurations. The clock is not a substitute for a scheduled work task.
Create the review task
code: tt.permit.review
title: Review the permit application
when: {binding: case.permit, state: IN_REVIEW}
due-in-days: 5
assign-to: record-assignees
This template creates one task for each user assigned to the permit when it enters review. With nobody assigned, it creates one unassigned task. Taking a permit before choosing Start review therefore matters. A later case assignment does not retroactively assign the task created earlier.
due-in-days counts calendar days; it does not use the office calendar above. Existing tasks keep their terms when
the template changes. The template creates no duplicate while its task is still open on the record.
Put tasks and clocks on the case
The timeline records changes, but it does not provide the task-completion form. Keep the letters tab from the previous tutorial and add the task and deadline controls:
In src/main/resources/jcm/case-types/case.permit.yml, change
tabs: [letters]
to
tabs: [letters, tasks, deadlines]
If your workspace already has other tabs, add these controls to the existing list. My tasks → Open returns to the task's record; complete the task from that record's Tasks control.
Test what starts and stops
The test starts with an unassigned permit. It verifies that entering review creates one clock and one unassigned task, and that approving stops the clock but leaves the task open.
package com.example.permitdesk;
import com.example.permitdesk.entity.Permit;
import com.jcm.deadlines.Deadline;
import com.jcm.deadlines.DeadlineService;
import com.jcm.tasks.Task;
import com.jcm.tasks.TaskService;
import com.jcm.workflow.WorkflowService;
import io.jmix.core.UnconstrainedDataManager;
import io.jmix.core.security.SystemAuthenticator;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@ActiveProfiles("test")
public class PermitReviewWorkTest {
static final String BINDING = "case.permit";
@Autowired UnconstrainedDataManager dataManager;
@Autowired SystemAuthenticator authenticator;
@Autowired WorkflowService workflow;
@Autowired DeadlineService deadlines;
@Autowired TaskService tasks;
@Test
void decidingStopsTheClockButDoesNotCompleteTheTask() {
authenticator.withUser("admin", () -> {
Permit permit = dataManager.create(Permit.class);
permit.setApplicant("Cedar Studio");
Permit saved = dataManager.save(permit);
assertTrue(deadlines.running(BINDING, saved).isEmpty());
assertTrue(tasks.openTasks(BINDING, saved).isEmpty());
workflow.transition(BINDING, saved, "start-review", null);
assertEquals(1, deadlines.running(BINDING, saved).size());
Deadline clock = deadlines.running(BINDING, saved).getFirst();
assertEquals("dl.permit.decision", clock.getPolicyCode());
assertEquals("cal.permit-office", clock.getCalendarCode());
assertNotNull(clock.getDueDate());
assertEquals(1, tasks.openTasks(BINDING, saved).size());
Task task = tasks.openTasks(BINDING, saved).getFirst();
assertEquals("tt.permit.review", task.getTemplateCode());
assertNull(task.getAssigneeUsername());
assertNull(task.getAssigneeGroup());
assertNotNull(task.getDueDate());
workflow.transition(BINDING, saved, "approve", null);
assertTrue(deadlines.running(BINDING, saved).isEmpty());
Deadline stopped = deadlines.deadlines(BINDING, saved).stream()
.filter(item -> item.getId().equals(clock.getId())).findFirst().orElseThrow();
assertNotNull(stopped.getStoppedOn());
assertEquals(1, tasks.openTasks(BINDING, saved).size());
assertEquals(task.getId(), tasks.openTasks(BINDING, saved).getFirst().getId());
return null;
});
}
}
jcm check
You should see passed.
This checks lifecycle behavior. It does not prove the due date for a particular holiday, daylight-saving boundary or working week. Add tests with agreed dates before relying on a project's service commitments.
Follow the work on screen
jcm run
You should see http://localhost:8080.
Open http://localhost:8080 and sign in as the local administrator described in the application's README. Create a new permit with an applicant and received date. In the Permits Inbox tab, choose Unassigned permits, then Get next. The permit selected by queue order opens; choose Start review. Inspect its timeline for the decision clock and review task. Open My tasks and find the review task assigned to you. Select it and choose Open to return to its permit. In Tasks, choose Mark done for the review task. This completes it immediately. Add a short review note on Overview, then approve the permit. Check that its clock has stopped and the completed task remains in its history.
If Get next chooses an older permit, follow that permit for this exercise. A permit already in review when the new files were added does not get a task or clock merely because you restarted the application; use a new permit. If you started review before taking the permit, its task can be unassigned and absent from My tasks.
jcm run --stop
The task reference describes who may close tasks; the deadline reference covers clock pauses, extensions and recalculation.
For a separate exercise with the prepared hearings sample, continue to Publish and inspect a studio change.