package actions;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import interfaces.commandes.IMetierCommandes;
import interfaces.exceptions.MetierException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
//import metier.commandes.MetierCommandes;
import base.Client;
import base.Commande;
import ressources.Message;
import ressources.Panier;
public class MesCommandesAction implements Action {
private String suite, erreur;
/**
*
* @param suite
* @param erreur
*/
public MesCommandesAction(String suite, String erreur) {
this.suite = suite;
this.erreur = erreur;
}
public String execute(HttpServletRequest req) throws Exception {
String idProduit = req.getParameter("idCommande");
//MetierCommandes mc = new MetierCommandes();
IMetierCommandes mc = (IMetierCommandes)req.getSession().getServletContext().getAttribute("metierCommandes");
/*if (idProduit != null) {*/
try{
HttpSession session = req.getSession(false);
if (session != null) {
Client client = (Client) session.getAttribute("client");
if (client == null) {
throw new MetierException();
}
// On modifie l'adresse du client
ArrayList<Commande> lesCommandes = mc.rechercherCommandesClient(client.getId());
HashMap<String,Commande> mapCmds = new HashMap<String,Commande>();
Iterator it = lesCommandes.iterator();
while(it.hasNext()){
Commande c = (Commande)it.next();
mapCmds.put(c.getIdCommande(), c);
}
// On met les commandes dans la session
session.setAttribute("commandes", mapCmds);
}
}catch(MetierException me){
me.printStackTrace();
req.setAttribute(Message.MESSAGE_ERREUR, Message.COMMANDES_NON_RECUPERABLE);
return erreur;
}
//}
return suite;
}
}