Commit a8ed8b76 authored by Lefebvre michael's avatar Lefebvre michael

tomee

parent 4ef90b12
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/web" relative="/" />
</webroots>
</configuration>
</facet>
<facet type="jpa" name="JPA">
<configuration>
<setting name="validation-enabled" value="true" />
<setting name="provider-name" value="EclipseLink" />
<datasource-mapping>
<factory-entry name="EcommercePU" value="63abfc4d-ef4c-4b4d-9617-b966bb866f2e" />
</datasource-mapping>
<naming-strategy-map />
<deploymentDescriptor name="persistence.xml" url="file://$MODULE_DIR$/src/META-INF/persistence.xml" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="JSF" level="application" />
<orderEntry type="library" scope="PROVIDED" name="Tomcat 9.0.31" level="application_server_libraries" />
<orderEntry type="library" name="mysql-connector-java-5.1.6-bin1" level="project" />
<orderEntry type="library" name="JPA 2.0" level="application" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="EcommercePU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>modele.Client</class>
<class>modele.Commande</class>
<class>modele.DetailCde</class>
<class>modele.Item</class>
<class>modele.Payment</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/my_ecommerce"/>
<property name="javax.persistence.jdbc.user" value="michael"/>
<property name="javax.persistence.jdbc.password" value="mdppopmichael"/>
</properties>
</persistence-unit>
</persistence>
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
</faces-config>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Index</title>
</h:head>
<h:body>
<f:view>
<h3>E-Cultura : Authentification</h3>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Nom:"/>
<h:inputText value="#{cartCtrl.nom}" required="true" requiredMessage="Le nom est obligatoire"/>
<h:outputLabel value="Prenom:"/>
<h:inputText value="#{cartCtrl.prenom}"/>
<h:commandButton value="Login" action="#{cartCtrl.doLogin}"/>
</h:panelGrid>
</h:form>
</f:view>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Index</title>
</h:head>
<h:body>
<f:view>
<h3>E-Cultura : Produits</h3>
<h:form>
<h:dataTable cellspacing="6" columns="2" value="#{cartCtrl.ensItems}" var="i">
<h:column>
<f:facet name = "header">Titre</f:facet>
<h:outputText value="#{i.titre}" required="true" requiredMessage="Le nom est obligatoire"/>
</h:column>
<h:column>
<f:facet name = "header">Catégorie</f:facet>
<h:outputText value="#{i.categorie}" required="true" requiredMessage="obligatoire"/>
</h:column>
<h:column>
<f:facet name = "header">Prix</f:facet>
<h:outputText value="#{i.prix}" required="true" requiredMessage="obligatoire"/>
</h:column>
<h:column>
<f:facet name = "header">Panier</f:facet>
<h:commandButton value="Ajouter" action="#{cartCtrl.doSelectItem(i)}"/>
</h:column>
</h:dataTable>
</h:form>
</f:view>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Panier</title>
</h:head>
<h:body>
<f:view>
<h3>E-Cultura : Panier</h3>
<h:form>
<h:dataTable cellspacing="6" columns="2" value="#{cartCtrl.panier}" var="achat">
<h:column>
<f:facet name = "header">Titre</f:facet>
<h:outputText value="#{achat.titre}" required="true"/>
</h:column>
<!--<h:column>
<f:facet name = "header">Catégorie</f:facet>
<h:outputText value="#{achat.categorie}" required="true"/>
</h:column>-->
<h:column>
<f:facet name = "header">Quantité</f:facet>
<h:inputText value="#{achat.quantite}" valueChangeListener="#{cartCtrl.updateQte}">
<f:validateLongRange minimum="1" maximum="3"/>
</h:inputText>
</h:column>
<h:column>
<f:facet name = "header">Prix</f:facet>
<h:outputText value="#{achat.prix}" required="true">
<f:convertNumber type="currency" pattern="####.##"/>
</h:outputText>
<f:facet name="footer">
<h:outputText value="#{cartCtrl.totalPanier}" styleClass="prix">
<f:convertNumber type="currency" pattern="####.##"/>
</h:outputText>
</f:facet>
</h:column>
<h:column>
<h:commandButton value="modifier" action="#{cartCtrl.doModifierAchat}"/>
</h:column>
<h:column>
<h:commandButton value="supprimer" action="#{cartCtrl.doSupprimer}"/>
</h:column>
</h:dataTable>
</h:form>
<h:form>
<h:panelGrid columns="2" cellspacing="10">
<h:commandButton value="Valider le panier" action="#{cartCtrl.doHome}"/>
</h:panelGrid>
</h:form>
</f:view>
</h:body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="EcommercePU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>modele.Client</class>
<class>modele.Commande</class>
<class>modele.DetailCde</class>
<class>modele.Item</class>
<class>modele.Payment</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/my_ecommerce"/>
<property name="javax.persistence.jdbc.user" value="michael"/>
<property name="javax.persistence.jdbc.password" value="mdppopmichael"/>
</properties>
</persistence-unit>
</persistence>
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" version="2.1">
<persistence-unit name="EcommercePU">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>modele.Client</class>
<class>modele.Commande</class>
<class>modele.DetailCde</class>
<class>modele.Item</class>
<class>modele.Payment</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/my_ecommerce"/>
<property name="javax.persistence.jdbc.user" value="michael"/>
<property name="javax.persistence.jdbc.password" value="mdppopmichael"/>
</properties>
</persistence-unit>
</persistence>
import modele.Client;
import service.ServiceCart;
import util.Achat;
import util.CardExpiredException;
import util.InfoCB;
import java.util.Date;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
public class Main {
public static void main(String[] args) {
// ServiceItem service = ServiceItem.getSingleton();
// System.out.println(service.findAllClient());
// System.out.println(service.findAllItem());
// service.findAllItem().forEach(System.out::println);
// System.out.println(service.findClientById(1));
Client client = ServiceCart.getSingleton().findOrCreate("Thomas","Gayllier");
// ServiceCart.getSingleton().findAllClient().forEach(System.out::println);
/*List<Achat> panier = new ArrayList<>();
panier.add(new Achat(item.getId(), item.getTitre(), 1,3));
panier.add(new Achat(item.getId(), item.getTitre(), 2,5));*/
/*System.out.println(ServiceCart.getSingleton().valeurDuPanier(panier));
System.out.println(ServiceCart.getSingleton().contenuDuPanierValue(panier));
String creditCardNumber = "1234-5678-9012-3456";
Date expirationDate = new GregorianCalendar(2001, Calendar.JULY,1).getTime();
InfoCB infoCB = new InfoCB(creditCardNumber, expirationDate);*/
/*try{
ServiceCart.getSingleton().validerPanier(client,panier,infoCB);
} catch (CardExpiredException e) {
System.err.println(e.getMessage());
}*/
}
}
package controller;
import modele.Client;
import modele.Item;
import service.ServiceCart;
import service.ServiceItem;
import util.Achat;
import util.InfoCB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import java.io.Serializable;
import java.util.*;
@ManagedBean(name= "cartCtrl")
@SessionScoped
public class CartController implements Serializable {
private Client client;
private List<Achat> panier;
private InfoCB infoCB;
private Boolean authentifie;
// public Map<Item, Integer> getContenuPanier(){
// Map<Item, Integer> panier = new HashMap<>();
// Item p1 = new Item();
// return panier;
// }
public Client getClient() {
return client;
}
public void setClient(Client client) {
this.client = client;
}
public List<Achat> getPanier() {
return panier;
}
public void setPanier(List<Achat> panier) {
this.panier = panier;
}
public InfoCB getInfoCB() {
return infoCB;
}
public void setInfoCB(InfoCB infoCB) {
this.infoCB = infoCB;
}
public Boolean getAuthentifie() {
return authentifie;
}
public void setAuthentifie(Boolean authentifie) {
this.authentifie = authentifie;
}
//Login
private String nom;
private String prenom;
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public String doLogin(){
this.client = ServiceCart.getSingleton().findOrCreate(this.nom,this.prenom);
this.authentifie = true;
this.panier = new ArrayList<>();
return "showItems";
}
public String doHome(){
this.client = null;
this.authentifie = false;
return "index";
}
//---------------------- ShowItems
public List<Item> getEnsItems(){
return ServiceItem.getSingleton().findAllItem();
}
private Item itemSelectionne;
public String doSelectItem(Item item){
this.itemSelectionne = item;
this.panier.add(new Achat(item.getId(),item.getTitre(), item.getCodeBarre(), item.getPrix(), 1));
System.out.println(item.getId()+"titre"+item.getTitre()+" code barre "+item.getCodeBarre());
return "showPanier";
}
//--------------------- ShowPanier
private Integer nouvQte;
private Achat achatSelectionne;
public Double getTotalPanier(){
return ServiceCart.getSingleton().valeurDuPanier(panier);
}
public void updateQte(ValueChangeEvent event){
nouvQte = (Integer) event.getNewValue();
}
public String doModifierAchat(Achat achat){
this.achatSelectionne = achat;
achatSelectionne.setQuantite(nouvQte);
this.panier.remove(achat);
this.panier.add(achatSelectionne);
return "showPanier";
}
public String doSupprimer(Achat achat){
this.achatSelectionne = achat;
this.panier.remove(achat);
if (this.panier.isEmpty()) return "showItems";
return "showPanier";
}
}
package controller;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import java.io.Serializable;
@ManagedBean(name = "itemCtrl")
@ViewScoped
public class ItemController implements Serializable {
}
package modele;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
@Entity
@Table(name = "client")
@NamedQueries({
@NamedQuery(name="Client.findAll",query = "select c from Client c order by c.nom, c.prenom"),
@NamedQuery(name="Client.findByNomAndPrenom",query = "select c from Client c where upper(c.nom) = upper(:nom) and" +
" upper(c.prenom) = upper(:prenom)")
})
public class Client {
private int id;
private String nom;
private String prenom;
private List<Commande> commandes = new ArrayList<>();
private List<Payment> payments = new ArrayList<>();
public Client(String nom, String prenom) {
this.setNom(nom);
this.setPrenom(prenom);
}
public Client() {
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;