@Override public String execute(String[] params) { List<Application> liste = new LinkedList<Application>(); if (params.length > 0) { liste.add(applications.findByName(params[0])); if (liste.size() == 0) { return "Il n'y a pas d'application de nom " + params[0]; } } else { for (Application application : applications.findAll()) { if (!application.isValidated()) { liste.add(application); } } } for (Application application : liste) { application.setValidated(); applications.edit(application); } return "Toutes les applications on été validées"; }
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // not connected if (request.getSession().getAttribute("user") == null) { request.getSession().setAttribute("backTo", "post_application"); request.setAttribute("errorMessage", "error_not_logged_applications"); URLHelper.redirectTo(Page.connection, request, response); } // form is ok else if (FileUpload.isMultipartContent(request)) { String msg = "application_posted"; Connection connection = null; MessageProducer messageProducer = null; try { connection = connectionFactory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); messageProducer = session.createProducer(queue); ObjectMessage message = session.createObjectMessage(); // here we create NewsEntity, that will be sent in JMS message Application e = new Application(); // upload File and Icon on the server UploadFileHelper.uploadApplication(request, e, getServletContext().getRealPath("/")); // create the new app appFacade.create(e); // link app to User LinuxStoreUser user = (LinuxStoreUser) request.getSession().getAttribute("user"); e = appFacade.findByName(e.getName()); e.setOwner(user); appFacade.edit(e); List<Application> applist = new LinkedList<Application>(); applist.add(e); user.addToMyApplications(applist); userFacade.edit(user); // message.setObject(new UserAndApp(user,e)); // messageProducer.send(message); } catch (Exception ex) { msg = ex.getMessage(); // msg = "application_not_posted"; } finally { try { messageProducer.close(); connection.close(); } catch (JMSException ex) { // do nothing } } if (msg.equals("application_posted")) { request.setAttribute("confirmationMessage", msg); URLHelper.redirectTo(Page.confirmation, request, response); } else { request.setAttribute("errorMessage", msg); request.setAttribute("categories", Category.values()); URLHelper.redirectTo(Page.post_application, request, response); } } // access to form else { request.setAttribute("fileTypes", UploadFileHelper.listOfAppExtensions); request.setAttribute("imgTypes", UploadFileHelper.listOfImgExtensions); request.setAttribute("categories", Category.values()); URLHelper.redirectTo(Page.post_application, request, response); } }