public class CommentThreadApp extends Controller {
@Transactional
public static Result updateState(Long id, CommentThread.ThreadState state) {
CommentThread thread = CommentThread.find.byId(id);
if (thread == null) {
return notFound();
}
Operation operation;
switch(state) {
case OPEN:
operation = Operation.REOPEN;
break;
case CLOSED:
operation = Operation.CLOSE;
break;
default:
throw new UnsupportedOperationException();
}
if (!AccessControl.isAllowed(UserApp.currentUser(), thread.asResource(), operation)) {
return forbidden();
}
CommentThread.ThreadState previousState = thread.state;
thread.state = state;
thread.update();
try {
NotificationEvent.afterStateChanged(previousState, thread);
} catch (Exception e) {
play.Logger.warn(