Skip to content

Commit

Permalink
Fix ScheduledEventManagerImpl::setStatus (#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
raul1ro authored Oct 5, 2024
1 parent 77ec412 commit e1188e7
Showing 1 changed file with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,44 @@ public ScheduledEventManager setEndTime(@Nonnull TemporalAccessor endTime)

@Nonnull
@Override
public ScheduledEventManager setStatus(@Nonnull ScheduledEvent.Status status)
public ScheduledEventManager setStatus(@Nonnull ScheduledEvent.Status newStatus)
{
Checks.notNull(status, "Status");
Checks.check(status != ScheduledEvent.Status.UNKNOWN, "Cannot set the event status to an unknown status!");
Checks.check(status != ScheduledEvent.Status.SCHEDULED && getScheduledEvent().getStatus() != ScheduledEvent.Status.ACTIVE, "Cannot perform status update!");
this.status = status;
Checks.notNull(newStatus, "Status");
switch (newStatus)
{
case SCHEDULED:
case UNKNOWN:
throw new IllegalArgumentException("Cannot change scheduled event status to " + newStatus);
}

//get the current status of the event. multiple-usage
ScheduledEvent.Status currentStatus = getScheduledEvent().getStatus();

switch (currentStatus)
{
case SCHEDULED:
//event is scheduled -> new status can be only active or cancel
Checks.check(
newStatus == ScheduledEvent.Status.ACTIVE || newStatus == ScheduledEvent.Status.CANCELED,
"Cannot perform status update! A scheduled event with status SCHEDULED can only be set to ACTIVE or CANCELED status."
);
break;

case ACTIVE:
//event is active -> new status can be only completed
Checks.check(
newStatus == ScheduledEvent.Status.COMPLETED,
"Cannot perform status updated! A scheduled event with status ACTIVE can only be set to COMPLETED status."
);
break;

case COMPLETED:
case CANCELED:
//event is completed or canceled -> can't update status
throw new IllegalArgumentException("Cannot perform status update! Event is " + currentStatus.name().toLowerCase() + ".");
}

this.status = newStatus;
set |= STATUS;
return this;
}
Expand Down

0 comments on commit e1188e7

Please sign in to comment.