diff --git a/Adresse.java b/Adresse.java new file mode 100644 index 0000000..3621b1e --- /dev/null +++ b/Adresse.java @@ -0,0 +1,76 @@ +package com.fasoyaar.entity.client; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name="t_adresse") +public class Adresse implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long idAddress; + @Column(name="ville",length=60) + private String city; + @Column(name="rue",length=60) + private String street; + @Column(name="pays",length=60) + private String Country; + + + + + + public Long getIdAddress() { + return idAddress; + } + public void setIdAddress(Long idAddress) { + this.idAddress = idAddress; + } + public String getCity() { + return city; + } + public void setCity(String city) { + this.city = city; + } + public String getStreet() { + return street; + } + public void setStreet(String street) { + this.street = street; + } + public String getCountry() { + return Country; + } + public void setCountry(String country) { + Country = country; + } + /** + * + */ + public Adresse() { + super(); + } + /** + * @param idAddress + * @param city + * @param street + * @param country + */ + public Adresse(String city, String street, String country) { + super(); + this.city = city; + this.street = street; + Country = country; + } +} diff --git a/Article.java b/Article.java new file mode 100644 index 0000000..1ec5ef2 --- /dev/null +++ b/Article.java @@ -0,0 +1,91 @@ +package com.fasoyaar.entity.categorie; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name="t_article") +public class Article implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long idArt; + @Column(name="nom_article",length=60) + private String nomArt; + @Column(name="prix_unitaire") + private Float pu; + @Column(name="chemin_image",length=255) + private String imagePath; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="produit_fk") + private Produit produit; + + public Produit getProduit() { + return produit; + } + public void setProduit(Produit produit) { + this.produit = produit; + } + /** + * @param idArt + * @param nomArt + * @param pu + * @param imagePath + */ + public Article( String nomArt, Float pu, String imagePath) { + super(); + this.nomArt = nomArt; + this.pu = pu; + this.imagePath = imagePath; + } + /** + * + */ + public Article() { + super(); + } + @Override + public String toString() { + return "Article [idArt=" + idArt + ", nomArt=" + nomArt + ", pu=" + pu + ", imagePath=" + imagePath + "]"; + } + public Long getIdArt() { + return idArt; + } + public void setIdArt(Long idArt) { + this.idArt = idArt; + } + public String getNomArt() { + return nomArt; + } + public void setNomArt(String nomArt) { + this.nomArt = nomArt; + } + public Float getPu() { + return pu; + } + public void setPu(Float pu) { + this.pu = pu; + } + public String getImagePath() { + return imagePath; + } + public void setImagePath(String imagePath) { + this.imagePath = imagePath; + } + + + +} diff --git a/CatalogueImpl.java b/CatalogueImpl.java new file mode 100644 index 0000000..dc5993e --- /dev/null +++ b/CatalogueImpl.java @@ -0,0 +1,184 @@ +package com.fasoyaar.session.catalogue; + + +import java.util.ArrayList; +import java.util.List; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.categorie.Categorie; +import com.fasoyaar.entity.categorie.Produit; + +@Stateless(name="CatalogueMetier") +public class CatalogueImpl implements ICatalogueLocal,ICatalogueRemote{ + + @PersistenceContext(unitName="UP_FasoYaar") + private EntityManager em; + @Override + public Categorie createCategorie(Categorie cat) { + // TODO Auto-generated method stub + em.persist(cat); + return cat; + } + + @Override + public void deleteCategorie(Long idCat) { + // TODO Auto-generated method stub + Categorie c= em.find(Categorie.class, idCat); + if(c==null) throw new RuntimeException("Categorie introuvable"); + else + em.remove(c); + } + + @Override + public Categorie updateCategorie(Categorie cat) { + // TODO Auto-generated method stub + Categorie categ=em.find(Categorie.class, cat.getIdCat()); + categ.setNomCat(cat.getNomCat()); + categ.setDescCat(cat.getDescCat()); + em.persist(cat); + return categ; + + } + + @SuppressWarnings("unchecked") + @Override + public List getAllCategories() { + // TODO Auto-generated method stub + Query request=em.createQuery("select c from Categorie c"); + return request.getResultList(); + + } + + @Override + public Produit createProduit(Produit p,Long idCat) { + // TODO Auto-generated method stub + p.setCategorie(em.find(Categorie.class, idCat)); + em.persist(p); + return p; + } + + @Override + public void deleteProduit(Long idPrct) { + // TODO Auto-generated method stub + Produit p= em.find(Produit.class, idPrct); + if(p==null) throw new RuntimeException("Produit introuvable"); + else + em.remove(p); + } + + @Override + public Produit updateProduit(Produit p) { + // TODO Auto-generated method stub + em.merge(p); + Produit prd=em.find(Produit.class, p.getIdPrct()); + prd.setNomPrct(p.getNomPrct()); + prd.setDescPrct(p.getDescPrct()); + em.persist(p); + return prd; + } + + @SuppressWarnings("unchecked") + @Override + public List getAllProduits(Long idCat){ + // TODO Auto-generated method stub + Query request=em.createQuery("select p from Produit p where p.categorie.idCat="+idCat+""); + return request.getResultList(); + } + + @Override + public Article createArticle(Article a,Long idPrct) { + // TODO Auto-generated method stub + a.setProduit(em.find(Produit.class,idPrct)); + em.persist(a); + return a; + } + + @Override + public void deleteArticle(Long idArt) { + // TODO Auto-generated method stub + Article a= em.find(Article.class, idArt); + if(a==null) throw new RuntimeException("Article introuvable"); + else + em.remove(a); + } + + @Override + public Article updateArticle(Article a) { + // TODO Auto-generated method stub + em.merge(a); + Article art=em.find(Article.class, a.getIdArt()); + art.setNomArt(a.getNomArt()); + art.setPu(a.getPu()); + art.setImagePath(a.getImagePath()); + em.persist(a); + return art; + } + + @SuppressWarnings("unchecked") + @Override + public List
getAllArticles(Long idCat) { + // TODO Auto-generated method stub + List
arts =this.getAllArticle(idCat); + return arts; + } + + + @Override + public Categorie findCategorie(Long idCat) { + // TODO Auto-generated method stub + + return em.find(Categorie.class, idCat); + } + + @Override + public Produit findProduit(Long idPrct) { + // TODO Auto-generated method stub + + return em.find(Produit.class, idPrct); + } + + @Override + public Article findArticle(Long idArt) { + // TODO Auto-generated method stub + Article art=em.find(Article.class, idArt); + return art; + } + + @Override + public Produit addArticle(Produit p, Article a) { + // TODO Auto-generated method stub + em.find(Produit.class, p.getIdPrct()); + em.flush(); + em.find(Article.class, a.getIdArt()); + a.setProduit(p); + + + return p; + + } + @SuppressWarnings("unchecked") + public List
getAllArticle(Long idCat) { + // TODO Auto-generated method stub + List
arts; + Query request=em.createQuery("SELECT c FROM Article c where c.produit.categorie.idCat="+idCat+""); + arts=request.getResultList(); + return (arts); + } + + @SuppressWarnings("unchecked") + @Override + public List
getAllArticles() { + // TODO Auto-generated method stub + List
arts; + Query request=em.createQuery("SELECT c FROM Article c "); + + return request.getResultList(); + } + + +} diff --git a/Categorie.java b/Categorie.java new file mode 100644 index 0000000..488abbf --- /dev/null +++ b/Categorie.java @@ -0,0 +1,84 @@ +package com.fasoyaar.entity.categorie; + +import java.io.Serializable; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name="t_categorie") + +public class Categorie implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.IDENTITY) + private Long idCat; + @Column(name="nom_categorie") + private String nomCat; + @Column(name="desc_categorie") + private String descCat; + + @OneToMany(mappedBy="categorie",cascade=CascadeType.REMOVE,fetch=FetchType.EAGER) + private List produits; + + + /** + * + */ + public Categorie() { + super(); + } + + /** + * @param idCat + * @param nomCat + * @param descCat + */ + public Categorie( String nomCat, String descCat) { + super(); + + this.nomCat = nomCat; + this.descCat = descCat; + } + + public Long getIdCat() { + return idCat; + } + public void setIdCat(Long idCat) { + this.idCat = idCat; + } + public String getNomCat() { + return nomCat; + } + public void setNomCat(String nomCat) { + this.nomCat = nomCat; + } + public String getDescCat() { + return descCat; + } + public void setDescCat(String descCat) { + this.descCat = descCat; + } + + public List getProduits() { + return produits; + } + + public void setProduits(List produits) { + this.produits = produits; + } + + +} diff --git a/Client.java b/Client.java new file mode 100644 index 0000000..54ad981 --- /dev/null +++ b/Client.java @@ -0,0 +1,137 @@ +package com.fasoyaar.entity.client; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.MappedSuperclass; +import javax.persistence.OneToOne; +import javax.persistence.Table; +//@MappedSuperclass +@Entity +@Table(name="t_client") +public class Client implements Serializable{ + + @Override + public String toString() { + return "Client [idCl=" + idCl + ", nomCl=" + nomCl + ", prenom=" + prenom + ", telephone=" + telephone + + ", password=" + password + ", email=" + email + ", login=" + login + ", dateNaiss=" + dateNaiss; + } + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + protected Long idCl; + @Column(name="nom_client",length=60) + protected String nomCl; + @Column(name="prenom_client",length=60) + protected String prenom; + @Column(name="tel_client",length=60) + protected String telephone; + @Column(name="mot_de_passe",length=60) + protected String password; + @Column(name="mail",length=60) + protected String email; + @Column(nullable=false,length=60) + protected String login; + @Column(nullable=false) + protected Date dateNaiss; + + @OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL) + @JoinColumn(name="adresse_fk",nullable=true) + protected Adresse adresse; + + + public Long getIdCl() { + return idCl; + } + public void setIdCl(Long idCl) { + this.idCl = idCl; + } + public String getNomCl() { + return nomCl; + } + public void setNomCl(String nomCl) { + this.nomCl = nomCl; + } + public String getPrenom() { + return prenom; + } + public void setPrenom(String prenom) { + this.prenom = prenom; + } + public String getTelephone() { + return telephone; + } + public void setTelephone(String telephone) { + this.telephone = telephone; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public String getLogin() { + return login; + } + public void setLogin(String login) { + this.login = login; + } + public Date getDateNaiss() { + return dateNaiss; + } + public void setDateNaiss(Date dateNaiss) { + this.dateNaiss = dateNaiss; + } + /** + * + */ + public Client() { + super(); + } + /** + * @param idCl + * @param nomCl + * @param prenom + * @param telephone + * @param password + * @param email + * @param login + * @param dateNaiss + */ + public Client( String nomCl, String prenom, String telephone, String password, String email, String login, + Date dateNaiss) { + super(); + + this.nomCl = nomCl; + this.prenom = prenom; + this.telephone = telephone; + this.password = password; + this.email = email; + this.login = login; + this.dateNaiss = dateNaiss; + } + public Adresse getAdresse() { + return adresse; + } + public void setAdresse(Adresse adresse) { + this.adresse = adresse; + } + +} diff --git a/ClientImpl.java b/ClientImpl.java new file mode 100644 index 0000000..28a949d --- /dev/null +++ b/ClientImpl.java @@ -0,0 +1,73 @@ +package com.fasoyaar.session.client; + +import java.util.List; + +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; + + +@Stateless(name="ClientMetier") +public class ClientImpl implements IClientLocal,IClientRemote{ + + @PersistenceContext(unitName="UP_FasoYaar") + private EntityManager em; + + + @Override + public void deleteClient(Long idCl) { + // TODO Auto-generated method stub + Client cl=em.find(Client.class, idCl); + Long idAd=cl.getAdresse().getIdAddress(); + em.remove(em.find(Adresse.class, idAd)); + em.remove(em.find(Client.class, idCl)); + + } + + @SuppressWarnings("unchecked") + @Override + public List getAllClients() { + // TODO Auto-generated method stub + Query query; + List clients; + query=em.createQuery("SELECT c FROM Client c"); + clients=query.getResultList(); + return clients; + } + + + + @Override + public Client createClient(Client cl, Adresse ad) { + // TODO Auto-generated method stub + cl.setAdresse(ad); + em.persist(cl); + return cl; + } + + @Override + public Client findCient(Long Idclient) { + // TODO Auto-generated method stub + Client client; + client=em.find(Client.class, Idclient); + return client; + } + + @Override + public Client UpdateClient(Long idCl, Adresse ad) { + // TODO Auto-generated method stub + Client clt=em.find(Client.class, idCl); + Adresse adr=clt.getAdresse(); + adr.setCity(ad.getCity()); + adr.setCountry(ad.getCountry()); + adr.setStreet(ad.getStreet()); + em.persist(clt); + + return clt; + } + +} diff --git a/Commande.java b/Commande.java new file mode 100644 index 0000000..d570004 --- /dev/null +++ b/Commande.java @@ -0,0 +1,113 @@ +package com.fasoyaar.entity.commande; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; + +@Entity +@Table(name="t_commande") +public class Commande implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long idCmd; + @Column(name="date_commande",updatable=false) + @Temporal(TemporalType.DATE) + private Date dateCmd; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="client_fk") + private Client client; + @OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.ALL) + @JoinColumn(name="adress_fk") + private Adresse addresse; + @OneToMany(/*cascade=CascadeType.ALL,*/fetch=FetchType.EAGER) + @JoinTable(name="cmd_ligneCmd", joinColumns={@JoinColumn(name="cmd_fk")},inverseJoinColumns={@JoinColumn(name="ligneCmd_fk")}) + private List lignesDeCmd; + /** + * + */ + public Commande() { + super(); + } + /** + * @param idCmd + * @param dateCmd + * @param client + * @param lignesDeCmd + */ + public Commande( Date dateCmd, Client client) { + super(); + this.dateCmd = dateCmd; + this.client = client; + + } + /** + * @param dateCmd + * @param client + * @param addresse + * @param lignesDeCmd + */ + public Commande(Date dateCmd, Client client, Adresse addresse, List lignesDeCmd) { + super(); + this.dateCmd = dateCmd; + this.client = client; + //this.addresse = addresse; + this.lignesDeCmd = lignesDeCmd; + } + public Long getIdCmd() { + return idCmd; + } + public void setIdCmd(Long idCmd) { + this.idCmd = idCmd; + } + public Date getDateCmd() { + return dateCmd; + } + public void setDateCmd(Date dateCmd) { + this.dateCmd = dateCmd; + } + public Client getClient() { + return client; + } + public void setClient(Client client) { + this.client = client; + } + public List getLignesDeCmd() { + return lignesDeCmd; + } + public void setLignesDeCmd(List lignesDeCmd) { + this.lignesDeCmd = lignesDeCmd; + } + public Adresse getAddresse() { + return addresse; + } + public void setAddresse(Adresse addresse) { + this.addresse = addresse; + } + + + +} diff --git a/CommandeImpl.java b/CommandeImpl.java new file mode 100644 index 0000000..8b895de --- /dev/null +++ b/CommandeImpl.java @@ -0,0 +1,168 @@ +package com.fasoyaar.session.commande; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import javax.ejb.EJB; +import javax.ejb.Stateless; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; + + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.entity.commande.LigneCmd; +import com.fasoyaar.session.catalogue.ICatalogueLocal; +import com.fasoyaar.session.client.IClientLocal; + +@Stateless(name="CommandeMetier") +public class CommandeImpl implements ICommandeLocal,ICommandeRemote { + + @EJB + private IClientLocal client; + @PersistenceContext(unitName="UP_FasoYaar") + private EntityManager em; + + @SuppressWarnings("unchecked") + @Override + public List findAllCommande() { + // TODO Auto-generated method stub + Query query; + List commandes; + query=em.createQuery("SELECT c FROM Commande c"); + commandes=query.getResultList(); + return commandes; + } + + @Override + public Commande findCommande(Long idCmd) { + // TODO Auto-generated method stub + + Commande cmd; + cmd=em.find(Commande.class,idCmd); + return cmd; + } + + @Override + public void deleteCommande(Commande cmd) { + // TODO Auto-generated method stub + em.remove(em.merge(cmd)); + } + + @SuppressWarnings("unchecked") + @Override + public ArrayList getCommande(Long idCl) { + // TODO Auto-generated method stub + Query query=em.createQuery("select c from Commande c where c.client.idCl="+idCl+""); + + return (ArrayList) query.getResultList(); + } + + @Override + public Commande updateCommande(Adresse adr,Commande cmd) { + // TODO Auto-generated method stub + em.merge(cmd); + //cmd.setAddresse(adr); + em.refresh(cmd); + return cmd; + } + + @Override + public Commande createCommande(Long idCl) { + // TODO Auto-generated method stub + Client cl=client.findCient(idCl); + Commande c= new Commande(); + c.setClient(cl); + c.setDateCmd(new Date()); + c.setAddresse((cl.getAdresse())); + em.persist(c); + return c; + } + + @Override + public LigneCmd createLigneCommande(Long idArt) { + // TODO Auto-generated method stub + Article a=em.find(Article.class, idArt); + LigneCmd lc=new LigneCmd(); + Adresse ad= em.find(Adresse.class, 23L); + lc.setArticle(a); + lc.setQuantite(1); + em.persist(lc); + return lc; + } + + @Override + public Commande addLigneCommande(Long idCmd, Long idArt) { + // TODO Auto-generated method stub + Commande c=em.find(Commande.class, idCmd); + int i=0; + + if(c.getLignesDeCmd().isEmpty()){ + List lignes= new ArrayList(); + + LigneCmd ligne=this.createLigneCommande(idArt); + lignes.add(ligne); + c.setLignesDeCmd(lignes); + em.persist(c); + } + else{ + //Iterator it=lc.iterator(); + List lc=c.getLignesDeCmd(); + for (LigneCmd ligne : lc) { + if(ligne.getArticle().getIdArt()==idArt){ + ligne.setQuantite(ligne.getQuantite()+1); + em.persist(c); + i++; + + } + } + if(i==0){ + List lcs=c.getLignesDeCmd(); + LigneCmd lign=this.createLigneCommande(idArt); + lcs.add(lign); + c.setLignesDeCmd(lcs); + em.persist(c); + + } + + } + + + + + return c; + } + + @Override + public Commande deletLigneCommande(Commande cmd, LigneCmd ligne) { + // TODO Auto-generated method stub + em.merge(cmd); + ArrayList lc=(ArrayList)cmd.getLignesDeCmd(); + int i; + if(lc.contains(ligne)){ + i=lc.indexOf(ligne); + LigneCmd l=lc.get(i); + l.setQuantite(l.getQuantite()-1); + lc.set(i, l); + cmd.setLignesDeCmd(lc); + } + em.refresh(cmd); + return cmd; + } + + @Override + public Commande updateCommande(Commande cmd) { + // TODO Auto-generated method stub + em.merge(cmd); + em.refresh(cmd); + return null; + } + + + +} diff --git a/Controlleur.java b/Controlleur.java new file mode 100644 index 0000000..356526e --- /dev/null +++ b/Controlleur.java @@ -0,0 +1,81 @@ +package fasoyaar.vue; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.entity.commande.LigneCmd; +import com.fasoyaar.session.catalogue.ICatalogueLocal; +import com.fasoyaar.session.client.IClientLocal; +import com.fasoyaar.session.commande.ICommandeLocal; + +@WebServlet(name="controlleur",urlPatterns={"/controlleur"}) +public class Controlleur extends HttpServlet { + /** + * + */ + private static final long serialVersionUID = 1L; + @EJB + private IClientLocal metier; + @EJB + private ICommandeLocal commande; + @EJB + private ICatalogueLocal catalogue; + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + List clts=(ArrayList)metier.getAllClients(); + //Commande cmd = commande.getCommande((Client)clts[1]); + //commande.deleteCommande(cmd); + request.setAttribute("clients", clts); + request.getRequestDispatcher("client.jsp").forward(request, response); + + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + + + + String nom=request.getParameter("nom"); + String prenom=request.getParameter("prenom"); + String login=request.getParameter("login"); + String email=request.getParameter("email"); + String password=request.getParameter("password"); + String ville=request.getParameter("ville"); + String pays=request.getParameter("pays"); + String telephone=request.getParameter("telephone"); + String idClient=request.getParameter("id"); + Adresse a= new Adresse(ville, "", pays); + + if(!nom.isEmpty() && !prenom.isEmpty() && !login.isEmpty() && !email.isEmpty() && !password.isEmpty()){ + Client cl=metier.createClient(new Client(nom, prenom, telephone, password,email, login,new Date()),a); + //commande.deleteCommande(commande.getCommande(cl)); + //commande.createCommande(cl,commande.createLigneCommande(2, new Article()) ); + //commande.getCommande(cl); + + } + + + + + + doGet(request, response); + + + } +} diff --git a/ControlleurAuth.java b/ControlleurAuth.java new file mode 100644 index 0000000..8b6e844 --- /dev/null +++ b/ControlleurAuth.java @@ -0,0 +1,68 @@ +package fasoyaar.vue; + +import java.io.IOException; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.session.client.IClientLocal; + +@WebServlet(name="auth",urlPatterns={"/login"}) +public class ControlleurAuth extends HttpServlet{ + + /** + * + */ + private static final long serialVersionUID = 1L; + @EJB + private IClientLocal client; + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + request.getRequestDispatcher("authent.jsp").forward(request, response); + } + + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + String login=request.getParameter("login"); + String password=request.getParameter("password"); + String ids=request.getParameter("id"); + if(ids==null) ids="0"; + Long id=Long.parseLong(ids); + if(id==null) id=0L; + Client cl=client.findCient(id); + + String reponse=""; + if(cl==null){ + reponse="Erreur veillez ressayer"; + request.setAttribute("reponse", reponse); + request.getRequestDispatcher("authent.jsp").forward(request, response); + } + else if (login.equals(cl.getLogin()) && password.equals(cl.getPassword()) ) { + + request.setAttribute("client", cl.getNomCl()); + request.setAttribute("idCl", cl.getIdCl()); + getServletContext().getRequestDispatcher("/articles").forward(request, response); + + } + else { + + reponse="Cient introuvable"; + request.setAttribute("reponse", reponse); + request.getRequestDispatcher("authent.jsp").forward(request, response); + } + + } + + + } + + diff --git a/ControlleurCommande.java b/ControlleurCommande.java new file mode 100644 index 0000000..4d5e52d --- /dev/null +++ b/ControlleurCommande.java @@ -0,0 +1,61 @@ +package fasoyaar.vue; + +import java.io.IOException; +import java.util.ArrayList; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.session.client.IClientLocal; +import com.fasoyaar.session.commande.ICommandeLocal; + +/** + * Servlet implementation class ControlleurCommande + */ +@WebServlet(name="commande",urlPatterns={"/commande"}) +public class ControlleurCommande extends HttpServlet { + private static final long serialVersionUID = 1L; + private int nb=1; + @EJB + private ICommandeLocal commande; + + + + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + getServletContext().getRequestDispatcher("/vueCmd").forward(request, response); + } + + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + String idCl = request.getParameter("idCl"); + String idArt =request.getParameter("idArt"); + ArrayList cmd=commande.getCommande(Long.parseLong(idCl)); + if(!cmd.isEmpty()) + { + for(int i=0;i arts=metier.getAllArticles(); + + request.setAttribute("articles", arts); + + }else{ + List
arts=metier.getAllArticles(id); + + request.setAttribute("articles", arts); + + } + request.getRequestDispatcher("VueArticles.jsp").forward(request, response); + + } + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + + + this.doGet(request, response); + } +} diff --git a/ControlleurVueCmd.java b/ControlleurVueCmd.java new file mode 100644 index 0000000..b4fc036 --- /dev/null +++ b/ControlleurVueCmd.java @@ -0,0 +1,38 @@ +package fasoyaar.vue; + +import java.io.IOException; +import java.util.ArrayList; + +import javax.ejb.EJB; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.session.commande.ICommandeLocal; + +@WebServlet(name="vuecmd",urlPatterns={"/vueCmd"}) +public class ControlleurVueCmd extends HttpServlet{ + /** + * + */ + private static final long serialVersionUID = 1L; + @EJB + private ICommandeLocal commande; + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String idCl=request.getParameter("idCl"); + String idCmd=request.getParameter("idCmd"); + ArrayList commandes=commande.getCommande(Long.parseLong(idCl)); + request.setAttribute("commandes", commandes); + request.getRequestDispatcher("vueCmd.jsp").forward(request, response); + } + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + } + +} diff --git a/FasoyaarSercvice.java b/FasoyaarSercvice.java new file mode 100644 index 0000000..6c77f6b --- /dev/null +++ b/FasoyaarSercvice.java @@ -0,0 +1,102 @@ +package com.fasoyaar.services.webservices; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.ejb.EJB; +import javax.ejb.Stateless; +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebService; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.categorie.Categorie; +import com.fasoyaar.entity.categorie.Produit; +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.session.catalogue.ICatalogueLocal; +import com.fasoyaar.session.client.IClientLocal; +import com.fasoyaar.session.commande.ICommandeLocal; + +@Stateless +@WebService +public class FasoyaarSercvice { + + @EJB(beanName="CommandeMetier") + private ICommandeLocal commandeLocale; + @EJB(beanName="ClientMetier") + private IClientLocal clientLocal; + @EJB(beanName="CatalogueMetier") + private ICatalogueLocal catalogueLocal; + + /* methodes de l'interface locale des commandes*/ + @WebMethod + public void deleteCommande(@WebParam(name="commande") Commande cmd){ + + commandeLocale.deleteCommande(cmd); + } + @WebMethod + public ArrayList getCommande(Long idCl){ + + return commandeLocale.getCommande(idCl); + } + @WebMethod + public Commande updateCommande(@WebParam(name="adresse") Adresse adr,@WebParam(name="commande") Commande cmd){ + + return commandeLocale.updateCommande(cmd); + } + + /* methodes de l'interface locale du client*/ + + + + @WebMethod + public Client createClient(@WebParam(name="nom")String nom,@WebParam(name="email")String email,@WebParam(name="prenom")String prenom,@WebParam(name="login")String login,@WebParam(name="password")String password,@WebParam(name="telephone")String tel,@WebParam(name="ville")String ville,@WebParam(name="pays")String pays,@WebParam(name="rue")String rue){ + Date date =new Date(); + Client clt=new Client( nom, prenom, tel, password,email, login, date); + Adresse ad= new Adresse(ville,rue, pays); + return clientLocal.createClient(clt, ad); + } + + @WebMethod + public Client findCient(@WebParam(name="id_client")Long Idclient){ + + return clientLocal.findCient(Idclient); + } + + @WebMethod + public Client UpdateClient(@WebParam(name="idClient")Long idCl,@WebParam(name="adresse")Adresse ad){ + + return clientLocal.UpdateClient(idCl, ad); + } + + + /* methodes de l'interface locale du catalogue*/ + + @WebMethod + public Categorie findCategorie(@WebParam(name="id_categorie")Long idCat){ + + return catalogueLocal.findCategorie(idCat); + } + + @WebMethod + public Produit findProduit(@WebParam(name="id_produit")Long idPrct){ + + return catalogueLocal.findProduit(idPrct); + } + + @WebMethod + public Article findArticle(@WebParam(name="id_article")Long idArt){ + + return catalogueLocal.findArticle(idArt); + } + + @WebMethod + public List
searchArticle(@WebParam(name="idCat") Long idCat){ + + return catalogueLocal.getAllArticles(idCat); + + } +} diff --git a/ICatalogueLocal.java b/ICatalogueLocal.java new file mode 100644 index 0000000..7618b52 --- /dev/null +++ b/ICatalogueLocal.java @@ -0,0 +1,26 @@ +package com.fasoyaar.session.catalogue; + +import java.util.List; + +import javax.ejb.Local; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.categorie.Categorie; +import com.fasoyaar.entity.categorie.Produit; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; + +@Local +public interface ICatalogueLocal { + + public Categorie findCategorie(Long idCat); + public Produit findProduit(Long idPrct); + public Article findArticle(Long idArt); + public List
getAllArticles(Long idCat); + public List getAllProduits(Long idCat); + public List getAllCategories(); + public List
getAllArticles(); + + + +} diff --git a/ICatalogueRemote.java b/ICatalogueRemote.java new file mode 100644 index 0000000..901e116 --- /dev/null +++ b/ICatalogueRemote.java @@ -0,0 +1,38 @@ +package com.fasoyaar.session.catalogue; + +import java.util.List; + +import javax.ejb.Remote; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.categorie.Categorie; +import com.fasoyaar.entity.categorie.Produit; + +@Remote +public interface ICatalogueRemote { + + public Categorie createCategorie(Categorie cat); + public Categorie findCategorie(Long idCat); + public void deleteCategorie(Long idCat); + public Categorie updateCategorie(Categorie cat); + public List getAllCategories(); + + public Produit createProduit(Produit p,Long idCat); + public Produit findProduit(Long idPrct); + public void deleteProduit(Long idPrct); + public Produit updateProduit(Produit p); + public List getAllProduits(Long idCat); + public Produit addArticle(Produit p,Article a); + + public Article createArticle(Article a,Long idPrct); + public Article findArticle(Long idArt); + public void deleteArticle(Long idArt); + public Article updateArticle(Article a); + public List
getAllArticles(Long idPrct); + public List
getAllArticles(); + + + + + +} diff --git a/IClientLocal.java b/IClientLocal.java new file mode 100644 index 0000000..1f3cc65 --- /dev/null +++ b/IClientLocal.java @@ -0,0 +1,24 @@ +package com.fasoyaar.session.client; + +import java.util.List; + +import javax.ejb.Local; +import javax.jws.WebParam; + +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; + +@Local +public interface IClientLocal { + + + public Client createClient(Client cl,Adresse ad); + public Client findCient(Long Idclient); + public Client UpdateClient(Long idCl,Adresse ad); + void deleteClient(Long idCl); + List getAllClients(); + + + +} diff --git a/IClientRemote.java b/IClientRemote.java new file mode 100644 index 0000000..ed35e52 --- /dev/null +++ b/IClientRemote.java @@ -0,0 +1,19 @@ +package com.fasoyaar.session.client; + +import java.util.List; + +import javax.ejb.Remote; + +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; + +@Remote +public interface IClientRemote { + + Client createClient(Client cl,Adresse ad); + Client findCient(Long Idclient); + void deleteClient(Long idCl); + Client UpdateClient(Long idCl,Adresse ad); + List getAllClients(); + +} diff --git a/ICommandeLocal.java b/ICommandeLocal.java new file mode 100644 index 0000000..73368da --- /dev/null +++ b/ICommandeLocal.java @@ -0,0 +1,26 @@ +package com.fasoyaar.session.commande; + +import java.util.ArrayList; +import java.util.List; + +import javax.ejb.Local; + +import com.fasoyaar.entity.categorie.Article; +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.client.Client; +import com.fasoyaar.entity.commande.Commande; +import com.fasoyaar.entity.commande.LigneCmd; +import com.sun.jmx.remote.internal.ClientCommunicatorAdmin; + +@Local +public interface ICommandeLocal { + + public Commande createCommande(Long idCl); + public void deleteCommande(Commande cmd); + public LigneCmd createLigneCommande(Long idArt); + public Commande addLigneCommande(Long idCmd,Long idArt); + public Commande deletLigneCommande(Commande cmd,LigneCmd ligne); + public ArrayList getCommande(Long idCl); + public Commande updateCommande(Commande cmd); + +} diff --git a/ICommandeRemote.java b/ICommandeRemote.java new file mode 100644 index 0000000..53c721c --- /dev/null +++ b/ICommandeRemote.java @@ -0,0 +1,21 @@ +package com.fasoyaar.session.commande; + +import java.util.List; + +import javax.ejb.Remote; + +import com.fasoyaar.entity.client.Adresse; +import com.fasoyaar.entity.commande.Commande; + +@Remote +public interface ICommandeRemote { + + public void deleteCommande(Commande cmd); + public List findAllCommande(); + public Commande findCommande(Long idCmd); + public Commande updateCommande(Adresse adr,Commande cmd); + + + + +} diff --git a/LigneCmd.java b/LigneCmd.java new file mode 100644 index 0000000..b3d968b --- /dev/null +++ b/LigneCmd.java @@ -0,0 +1,67 @@ +package com.fasoyaar.entity.commande; + +import java.io.Serializable; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +import com.fasoyaar.entity.categorie.Article; + +@Entity +@Table(name="t_ligneCmd") +public class LigneCmd implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long idLigneCmd; + private Integer quantite; + @OneToOne(fetch=FetchType.EAGER,cascade=CascadeType.MERGE) + @JoinColumn(name="article_fk") + private Article article; + /** + * + */ + public LigneCmd() { + super(); + } + /** + * @param idLigneCmd + * @param quantite + * @param article + */ + public LigneCmd( Integer quantite, Article article) { + super(); + + this.quantite = quantite; + this.article = article; + } + public Long getIdLigneCmd() { + return idLigneCmd; + } + public void setIdLigneCmd(Long idLigneCmd) { + this.idLigneCmd = idLigneCmd; + } + public Integer getQuantite() { + return quantite; + } + public void setQuantite(Integer quantite) { + this.quantite = quantite; + } + public Article getArticle() { + return article; + } + public void setArticle(Article article) { + this.article = article; + } +} diff --git a/Produit.java b/Produit.java new file mode 100644 index 0000000..186055b --- /dev/null +++ b/Produit.java @@ -0,0 +1,113 @@ +package com.fasoyaar.entity.categorie; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name="t_produit") +public class Produit implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + + /** + * @param idPrct + * @param nomPrct + * @param descPrct + * @param categorie + * @param articles + */ + public Produit(Long idPrct, String nomPrct, String descPrct, Categorie categorie, List
articles) { + super(); + this.idPrct = idPrct; + this.nomPrct = nomPrct; + this.descPrct = descPrct; + this.categorie = categorie; + this.articles = articles; + } + public Categorie getCategorie() { + return categorie; + } + public void setCategorie(Categorie categorie) { + this.categorie = categorie; + } + public List
getArticles() { + return articles; + } + public void setArticles(List
articles) { + this.articles = articles; + } + + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private Long idPrct; + @Column(name="nom_produit",nullable=false,length=60) + private String nomPrct; + @Column(name="desc_produit",nullable=false,length=60) + private String descPrct; + @ManyToOne(fetch=FetchType.EAGER) + @JoinColumn(name="categorie_fk") + private Categorie categorie; + + @Override + public String toString() { + return "Produit [idPrct=" + idPrct + ", nomPrct=" + nomPrct + ", descPrct=" + descPrct + ", categorie=" + + categorie + ", articles=" + articles + "]"; + } + + @OneToMany(cascade=CascadeType.MERGE,fetch=FetchType.EAGER) + private List
articles; + + + /** + * + */ + public Produit() { + super(); + } + /** + * @param idPrct + * @param nomPrct + * @param descPrct + */ + public Produit( String nomPrct, String descPrct) { + super(); + + this.nomPrct = nomPrct; + this.descPrct = descPrct; + } + public Long getIdPrct() { + return idPrct; + } + public void setIdPrct(Long idPrct) { + this.idPrct = idPrct; + } + public String getNomPrct() { + return nomPrct; + } + public void setNomPrct(String nomPrct) { + this.nomPrct = nomPrct; + } + public String getDescPrct() { + return descPrct; + } + public void setDescPrct(String descPrct) { + this.descPrct = descPrct; + } + +} diff --git a/VueArticles.jsp b/VueArticles.jsp new file mode 100644 index 0000000..d3cbbba --- /dev/null +++ b/VueArticles.jsp @@ -0,0 +1,96 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + +Articles + + + + + + + +<%@ include file="menu.jsp" %> +<% HttpSession sessions= request.getSession(); +if(request.getAttribute("client")!=null){ +sessions.setAttribute("clientNom", request.getAttribute("client") ); +sessions.setAttribute("idCl",request.getAttribute("idCl")); +} +if(request.getAttribute("idCmd")!=null){ + sessions.setAttribute("idCmd", request.getAttribute("idCmd")); +} +%> +

+ <%String p=(String)sessions.getAttribute("clientNom"); +Long i=(Long)sessions.getAttribute("idCl"); +Long x=(Long)sessions.getAttribute("idCmd"); +if(p!=null) +out.println("Bienvenue"+" "+p); +else out.println("Veillez vous connectez"); +%>

+ + +
+

+
+ + +

+ +
+
+ + + + + + + + + + + + + + + +
Commander DesignationPrixPhotoCategorie Description
+ + + +
+ + + +
+ + + + +
${articles.nomArt } ${articles.pu } T.N.D${articles.produit.categorie.nomCat }${articles.produit.descPrct }
${articles.produit.categorie.descCat }


+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/authent.jsp b/authent.jsp new file mode 100644 index 0000000..44e5407 --- /dev/null +++ b/authent.jsp @@ -0,0 +1,34 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + + + + +Insert title here + + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+

${reponse}

+ + \ No newline at end of file diff --git a/client.jsp b/client.jsp new file mode 100644 index 0000000..89bad8c --- /dev/null +++ b/client.jsp @@ -0,0 +1,119 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + + + + +Clients + + +

Opérations C.R.U.D

+


+

Ajout d'un client

+
+

+
+
+
+
+ +
+
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+ +

+ +
+
+
+
+ + + + + + + + + + + + + + + + + + +
Id ClientNomPrenomEmailLogintelephoneDate de d'ajoutAdresse
${cl.idCl }${cl.nomCl }${cl.prenom }${cl.email }${cl.login }${cl.telephone }${cl.dateNaiss }${cl.adresse.country } ${cl.adresse.city } ${cl.adresse.street }
+
+
+
+
+

Suppression d'un client

+
+ +
+
+ +
+ +
+
+ +
+ + + \ No newline at end of file diff --git a/menu.jsp b/menu.jsp new file mode 100644 index 0000000..47c092c --- /dev/null +++ b/menu.jsp @@ -0,0 +1,18 @@ + \ No newline at end of file diff --git a/pageClient.jsp b/pageClient.jsp new file mode 100644 index 0000000..b979cdf --- /dev/null +++ b/pageClient.jsp @@ -0,0 +1,12 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Insert title here + + + + + \ No newline at end of file diff --git a/vueCmd.jsp b/vueCmd.jsp new file mode 100644 index 0000000..8af6684 --- /dev/null +++ b/vueCmd.jsp @@ -0,0 +1,40 @@ +<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> + + + + + + + +Commande + + +
+
+<% Float total=0F; %> + +
+ + + + + + + + + + +
Commande N° ${commandes.idCmd}
ClientDate CommandeArticleAdresse de Livraison
${commandes.client.nomCl } ${commandes.client.prenom }${commandes.dateCmd }
DesignationQuantite
${ligne.article.nomArt }${ligne.quantite }
${commandes.addresse.country } ${commandes.addresse.city }
+
+
+ + + + \ No newline at end of file diff --git a/vueclient.css b/vueclient.css new file mode 100644 index 0000000..c617ec1 --- /dev/null +++ b/vueclient.css @@ -0,0 +1,13 @@ +@CHARSET "UTF-8"; +input{ + border-radius: 3px 3px 3px 3px; + border-width: 1px; + + + +} +td,th{ + + border-radius: 3px 3px 3px 3px; + text-align: center; +} \ No newline at end of file