BrightSide Workbench Full Report + Source Code
MenuCommand.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.elephant.user.menu;
20 
21 import javax.servlet.ServletContext;
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import org.turro.string.Strings;
25 import org.turro.action.Actions;
26 import org.turro.collections.KeyValueMap;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.direct.DirectContent;
29 import org.turro.elephant.direct.DirectContents;
30 import org.turro.elephant.direct.IDirectContent;
31 
36 @DirectContent(identifier="menu-command")
37 public class MenuCommand implements IDirectContent {
38 
39  public static String createURL(IUserMenu userMenu) {
40  if(userMenu.isValid()) {
41  String exrino = Actions.createRightNowAction("idMenu=" + userMenu.getId());
42  return DirectContents.DIRECT_CONTENT_PATH + getIdentifier() +
43  "?" + exrino;
44  }
45  return null;
46  }
47 
48  public static String getIdentifier() {
49  return MenuCommand.class.getAnnotation(DirectContent.class).identifier();
50  }
51 
52  @Override
53  public boolean itsMe(String id) {
54  return getIdentifier().equals(id);
55  }
56 
57  @Override
58  public boolean myTurn(HttpServletRequest request) {
59  return DirectContents.isYourTurn(request, getIdentifier());
60  }
61 
62  @Override
63  public void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
64  KeyValueMap map = Actions.getRightNowAction(ElephantContext.getConstructor(request, response));
65  if(map != null) {
66  String idMenu = map.get("idMenu");
67  if(!Strings.isBlank(idMenu)) {
68  UserMenus.executeMenu(idMenu);
69  }
70  }
71  }
72 
73 }
static KeyValueMap getRightNowAction(IConstructor constructor)
Definition: Actions.java:341
static String createRightNowAction(String values)
Definition: Actions.java:312
static IConstructor getConstructor(HttpServletRequest request, HttpServletResponse response)
static boolean isYourTurn(HttpServletRequest request, String path)
static String createURL(IUserMenu userMenu)
void execute(ServletContext context, HttpServletRequest request, HttpServletResponse response)
boolean myTurn(HttpServletRequest request)
static Object executeMenu(String idMenu)
Definition: UserMenus.java:52