예제 #1
0
 @Override
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   HttpSession session = request.getSession(false);
   User user = (User) session.getAttribute("user");
   MessageBox messageBox = new MessageBox();
   // Check the permissions.
   if (user.getRole() == UserRole.ADMIN || user.getRole() == UserRole.EDITOR) {
     if (request.getParameter("selectionIds") == null) {
       // The method is called from the chain list page.
       this.doGet(request, response);
     } else {
       // The method is called from the chain delete page.
       String[] selection = (request.getParameter("selectionIds")).split(",");
       List<String> selectionList = chainIdsToListOfTitles(selection);
       for (int i = 0; i < selection.length; i++) {
         ChainService.removeChain(Long.valueOf(selection[i].trim()));
       }
       // Form the success message.
       messageBox.setTitle("The following chains have been successfully deleted:");
       messageBox.setMessages(selectionList);
       Messager.sendMessage(request, messageBox, MessageSeverity.SUCCESS);
       response.sendRedirect(request.getContextPath() + "/ChainList");
     }
   } else {
     // Form the error message.
     messageBox.setTitle(
         "Not enough previlegues to perform the operation. Please contact the administrator.");
     Messager.sendMessage(request, messageBox, MessageSeverity.ERROR);
     response.sendRedirect(request.getContextPath() + "/ChainList");
   }
 }
예제 #2
0
 /**
  * Retrieves the title of the chain with the given id and forms a list of titles.
  *
  * @param ids - an array of chain ids.
  * @return a list of chain titles.
  */
 private static List<String> chainIdsToListOfTitles(String[] ids) {
   List<String> selectionList = new ArrayList<>();
   for (String id : ids) {
     selectionList.add(ChainService.openChain(Long.valueOf(id.trim())).getTitle());
   }
   return selectionList;
 }