Package actions

Source Code of actions.CreationCompteAction

package actions;

import interfaces.exceptions.MetierException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

//import metier.clients.MetierClients;
import interfaces.clients.*;
import ressources.Message;
import base.Client;

public class CreationCompteAction implements Action {
 


    private String suite,erreur,suiteSiCreationOk;
   
    public CreationCompteAction(String suite,String erreur,String suiteSiCreationOk){
      this.suite = suite;
      this.erreur = erreur;
      this.suiteSiCreationOk = suiteSiCreationOk;
    }
   
    /**
     *
     */
    public String execute(HttpServletRequest req) throws Exception {
      String actionCreation = req.getParameter(Message.ACTION_CREATION);
     
      //MetierClients mc = new MetierClients();     
      IMetierClients mc = (IMetierClients)req.getSession().getServletContext().getAttribute("metierClients");
       
      String actionValidation = req.getParameter(Message.ACTION_VALIDATION);
      // On est sur une validation panier
      if(actionValidation != null){
        System.out.println("Creation ACTION VAL Ok :");
        // Si erreur on revient avec le bon message
        req.setAttribute(Message.ACTION_VALIDATION, Message.VALIDATION);
        req.setAttribute(Message.ACTION_VALIDATION, Message.AFF_VALIDATION);
       
      }
     
     
      if(actionCreation != null){
        if(actionCreation.equals(Message.VERIF_CREATION)){       
          String id = req.getParameter("id");
          if(!verifierChaine(id)){         
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_ID);         
            return erreur;
          }
          String nom = req.getParameter("nom");
          if(!verifierChaine(nom)){
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_NOM);         
            return erreur;
          }
          String prenom = req.getParameter("prenom");
          if(!verifierChaine(prenom)){
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_PRENOM);         
            return erreur;
          }
          String adresse = req.getParameter("adresse");
          if(!verifierChaine(adresse)){
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_ADRESSE);         
            return erreur;
          }       
          String mdp = req.getParameter("mdp");
          String mdp2 = req.getParameter("mdp2");
          if(!verifierChaine(mdp) || !verifierChaine(mdp2) || !mdp.equals(mdp2)){           
            req.setAttribute(Message.MESSAGE_ERREUR, Message.SAISIE_MDP);         
            return erreur;
          }
                   
         
          try{           
            Client client = new Client();
            client.setId(id);
            client.setNom(nom);
            client.setPrenom(prenom);
            client.setAdresse(adresse);
            client.setMdp(mdp);
            mc.creerClient(client);
            HttpSession session = req.getSession(true);
            session.setAttribute("client", client);
           
            // Tout est Ok
            return suiteSiCreationOk;
          }catch(MetierException me){
            me.printStackTrace();
            req.setAttribute(Message.MESSAGE_ERREUR, Message.CLIENT_EXISTE);
            return erreur;
          }
         
        }else if(actionCreation.equals(Message.CREATION)){
         
        }
      }
     
     
      return suite;
    }
   
   
    /**
     * Si aucun problème, on renvoit true
     *
     * @param chaine La chaine à vérifier
     * @return
     */
    private boolean verifierChaine(String chaine){
      if(chaine == null || chaine.trim().equals("")){
        return false;
      }
     
      return true;
    }

}
TOP

Related Classes of actions.CreationCompteAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.