ResourceUpdate#

An edit to one existing resource of a live project. It goes in the update list of SchedulingChanges.resources, which Project#apply and Project#preview take. Create it with new ResourceUpdate(id) and set the fields to change with the fluent withX setters. To add a resource, put a ResourceData in SchedulingChanges.resources.add instead.

Declaration#

package org.dhtmlx.plen;

public class ResourceUpdate extends ValueRecord implements DeepCloneable<ResourceUpdate>

Constructors#

ResourceUpdate(Id)#

public ResourceUpdate(Id id)

Creates an update for the resource with the given id. capacity and calendarId start as Patch.missing(), so the update changes nothing until one of them is set.

Name Type Description
id Id Id of the resource to edit, e.g. Id.str("dev1") or Id.num(1).

Fields#

All fields are public and mutable. capacity and calendarId are Patch<T> values: Patch.missing() (the default) keeps the stored value, Patch.of(value) sets it, and Patch.nullValue() clears it. The On nullValue() column shows what clearing leaves behind. For the meaning of each value, see the field of the same name on ResourceData.

Patch.of(null) on either field stores null, the same as Patch.nullValue().

Field Type On nullValue() Description
id Id required Id of the resource to edit.
capacity Patch<Double> null, so SchedulingConfig.defaultResourceCapacity applies New capacity, in assignment value units (1.0 = 100 %).
calendarId Patch<Id> null, no calendar of its own New working calendar of the resource.

Dates after an update#

In CalendarMode.RESOURCE with useCalendars on, a calendarId change can change the calendars that a leaf task's assignments work on. Each leaf task whose set of working calendars changes keeps its start and duration, and its end is derived again. In the TASK and TASK_INHERITED modes, the update doesn't move any dates. For how a resource calendar combines with a task calendar, see Working-time calendars.

Methods#

withId, withCapacity, withCalendarId#

public ResourceUpdate withId(Id value)
public ResourceUpdate withCapacity(Patch<Double> value)
public ResourceUpdate withCalendarId(Patch<Id> value)

Each setter assigns its field and returns this instance.

Returns - this ResourceUpdate.

deepClone#

public ResourceUpdate deepClone()

Returns a new ResourceUpdate with the same id, capacity and calendarId.

Returns - a new ResourceUpdate.

copy#

public ResourceUpdate copy()

Returns a shallow copy of this instance.

Returns - a new ResourceUpdate with the same field values.

equals, hashCode, toString#

public boolean equals(Object other)
public int hashCode()
public String toString()

Inherited from ValueRecord. Two updates are equal when id, capacity and calendarId are equal; patches compare by kind and carried value. toString() lists the fields, for logging; each patch shows only its kind.

Errors#

An update is rejected as a single operation, at path resources.update[i]. Project#apply and Project#preview describe how a rejection is reported.

Message When it occurs
unknown resource id No resource has id.
a validation message The edited resource breaks a ResourceData rule: capacity is negative, NaN or infinite, or, in CalendarMode.RESOURCE, calendarId names no calendar.

Example#

Double a resource's capacity and drop its own calendar:

import java.util.List;
import org.dhtmlx.plen.*;

public class ResourceUpdateExample {
  public static void main(String[] args) throws Exception {
    Moment monday = Moment.fromYmdHm(2026, 4, 6, 8, 0);

    ProjectData data = new ProjectData()
        .withTasks(List.of(
            new TaskData(Id.str("design")).withStartDate(monday).withDuration(2.0),
            new TaskData(Id.str("build")).withStartDate(monday).withDuration(2.0)))
        .withResources(List.of(
            new ResourceData().withId(Id.str("dev1")).withCapacity(1.0)))
        .withAssignments(List.of(
            new AssignmentData().withTask(Id.str("design")).withResource(Id.str("dev1")).withValue(1.0),
            new AssignmentData().withTask(Id.str("build")).withResource(Id.str("dev1")).withValue(1.0)));

    Project project = new Project();
    project.solve(data, new SolveOptions());

    SchedulingChanges changes = new SchedulingChanges();
    changes.resources.update.add(new ResourceUpdate(Id.str("dev1"))
        .withCapacity(Patch.of(2.0))
        .withCalendarId(Patch.nullValue()));

    ApplyReport report = project.apply(changes);
    if (report.rejected.isEmpty()) {
      ScheduleResult result = project.solve(null, new SolveOptions());
      int overallocated = result.overallocations == null ? 0 : result.overallocations.size();
      System.out.println("Overallocated resources: " + overallocated);
    }
  }
}