-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModerationState.java
More file actions
28 lines (25 loc) · 863 Bytes
/
ModerationState.java
File metadata and controls
28 lines (25 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package behavioral.state;
public class ModerationState implements State {
public void goTo(DocumentContext context, StateType desired, UserRole role) {
switch (desired) {
case DRAFT -> {
context.setState(new DraftState());
Main.println("Moderation -> Draft");
}
case PUBLISHED -> {
if (role == UserRole.ADMIN) {
context.setState(new PublishedState());
Main.println("Admin: Moderation -> Published");
} else {
Main.errPrintln("Only Admin can publish");
}
}
default -> {
Main.errPrintln("Invalid transition from Moderation");
}
}
}
public StateType getType() {
return StateType.MODERATION;
}
}