BrightSide Workbench Full Report + Source Code
StudentsInterceptor.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2024 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.students.command;
20 
21 import java.io.IOException;
22 import org.turro.action.AbstractInterceptor;
23 import org.turro.action.Parameters;
24 import org.turro.annotation.ElephantInterceptor;
25 import org.turro.collections.KeyValueMap;
26 import org.turro.elephant.context.Application;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.context.IConstructor;
29 import org.turro.string.Strings;
30 import org.turro.students.menu.StudentsMenu;
31 
36 @ElephantInterceptor
38 
39  @Override
40  protected boolean doExecuteWeb(IConstructor constructor, String goTo, KeyValueMap kvm) throws IOException {
41  if("challenge".equals(goTo)) {
42  String path = ElephantContext.getEntityWebContext("/challenge");
43  if(Strings.isBlank(path)) {
44  path = "/user/challenges";
45  }
46  constructor.redirect(Parameters.path(path)
47  .add("item", kvm.get("challengeId"))
48  .plain());
49  constructor.redirect(path + "?item=" + kvm.get(Long.class, "challengeId"));
50  return true;
51  }
52  return false;
53  }
54 
55  @Override
56  protected boolean doExecuteApp(Application application, String goTo, KeyValueMap kvm) {
57  if("challenge".equals(goTo)) {
58  if(Application.getApplication().isInRole("challenge:edit")) {
59  StudentsMenu.showChallenge(kvm.get(Long.class, "challengeId"));
60  }
61  return true;
62  }
63  return false;
64  }
65 
66 }
Parameters add(String key, Object value)
Definition: Parameters.java:48
static Parameters path(String path)
static String getEntityWebContext(String path)
boolean doExecuteWeb(IConstructor constructor, String goTo, KeyValueMap kvm)
boolean doExecuteApp(Application application, String goTo, KeyValueMap kvm)
static void showChallenge(Challenge challenge)