ordering process done

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-06-05 18:41:59 +02:00
parent 88145df721
commit 6d6a1c9b2a
10 changed files with 114 additions and 86 deletions

View File

@ -180,13 +180,6 @@
<version>5.4.0</version> <version>5.4.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- other -->
<dependency>
<groupId>javaee</groupId>
<artifactId>javaee-api</artifactId>
<version>5</version>
</dependency>
</dependencies> </dependencies>

View File

@ -40,7 +40,10 @@ public class AuthorDB {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
Author author = null; Author author = null;
try { try {
rs.beforeFirst();
while(rs.next()) {
author = new Author(rs.getLong("id"), rs.getString("name")); author = new Author(rs.getLong("id"), rs.getString("name"));
}
entry.getValue().close(); entry.getValue().close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -35,6 +35,11 @@ public class BookDB {
public Book get(long id) { public Book get(long id) {
Map.Entry<ResultSet, Connection> entry = database.getResultSetById(database.tableBook, id); Map.Entry<ResultSet, Connection> entry = database.getResultSetById(database.tableBook, id);
assert entry != null; assert entry != null;
try {
entry.getKey().beforeFirst();
} catch (SQLException e) {
e.printStackTrace();
}
return build(entry); return build(entry);
} }
@ -50,6 +55,8 @@ public class BookDB {
Book book = null; Book book = null;
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
try { try {
rs.beforeFirst();
while(rs.next()) {
Category category = database.category().get(rs.getLong(database.tableCategory)); Category category = database.category().get(rs.getLong(database.tableCategory));
Publisher publisher = database.publisher().get(rs.getLong(database.tablePublisher)); Publisher publisher = database.publisher().get(rs.getLong(database.tablePublisher));
List<Integer> authorIds = database.author().getAll(rs.getLong("id")); List<Integer> authorIds = database.author().getAll(rs.getLong("id"));
@ -66,6 +73,7 @@ public class BookDB {
book = new Book(rs.getLong("id"), rs.getLong("isbn"), authors, publisher, category, rs.getString("title"), book = new Book(rs.getLong("id"), rs.getLong("isbn"), authors, publisher, category, rs.getString("title"),
Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"), Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"),
rs.getString("image")); rs.getString("image"));
}
entry.getValue().close(); entry.getValue().close();
} catch (SQLException e) { } catch (SQLException e) {

View File

@ -37,7 +37,10 @@ public class PublisherDB {
ResultSet rs = entry.getKey(); ResultSet rs = entry.getKey();
Publisher publisher = null; Publisher publisher = null;
try { try {
rs.beforeFirst();
while(rs.next()) {
publisher = new Publisher(rs.getLong("id"), rs.getString("name")); publisher = new Publisher(rs.getLong("id"), rs.getString("name"));
}
entry.getValue().close(); entry.getValue().close();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();

View File

@ -7,7 +7,7 @@ import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped; import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
@ -19,7 +19,7 @@ import java.util.List;
* @version 1.0 * @version 1.0
*/ */
@ManagedBean @ManagedBean
@RequestScoped @SessionScoped
public class AddressBean implements Serializable { public class AddressBean implements Serializable {
public User getUser() { public User getUser() {

View File

@ -1,16 +1,14 @@
package de.hsel.itech.jsf; package de.hsel.itech.jsf;
import de.hsel.itech.db.Database; import de.hsel.itech.db.Database;
import de.hsel.itech.db.pojo.Book; import de.hsel.itech.db.pojo.*;
import de.hsel.itech.db.pojo.OrderItem;
import de.hsel.itech.db.pojo.ShoppingCartItem;
import de.hsel.itech.db.pojo.User;
import lombok.Setter; import lombok.Setter;
import javax.faces.annotation.ManagedProperty; import javax.faces.annotation.ManagedProperty;
import javax.faces.bean.ManagedBean; import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped; import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import java.sql.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -24,36 +22,46 @@ public class CartBean {
public User getUser() { public User getUser() {
FacesContext context = FacesContext.getCurrentInstance(); FacesContext context = FacesContext.getCurrentInstance();
return (User) context.getApplication().evaluateExpressionGet(context,"#{userBean.user}", User.class); return (User) context.getApplication().evaluateExpressionGet(context, "#{userBean.user}", User.class);
} }
public String add(Book book){ public Payment getPayment () {
if(getUser() != null){ FacesContext context = FacesContext.getCurrentInstance();
for(ShoppingCartItem item : getItems()){ return (Payment) context.getApplication().evaluateExpressionGet(context, "#{paymentBean.selected}", Payment.class);
if(item.getArticle().getId() == book.getId()){ }
public Address getAddress() {
FacesContext context = FacesContext.getCurrentInstance();
return (Address) context.getApplication().evaluateExpressionGet(context, "#{addressBean.selected}", Address.class);
}
public String add(Book book) {
if (getUser() != null) {
for (ShoppingCartItem item : getItems()) {
if (item.getArticle().getId() == book.getId()) {
Database.getInstance().shoppingCart().delete(item); Database.getInstance().shoppingCart().delete(item);
item.setCount(item.getCount() + 1); item.setCount(item.getCount() + 1);
Database.getInstance().shoppingCart().insert(item); Database.getInstance().shoppingCart().insert(item);
return "cart.jsf"; return "cart.jsf";
} }
} }
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(),book,1)); Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(), book, 1));
} }
return "cart.jsf"; return "cart.jsf";
} }
public String remove(ShoppingCartItem item){ public String remove(ShoppingCartItem item) {
if(getUser() != null){ if (getUser() != null) {
Database.getInstance().shoppingCart().delete(item); Database.getInstance().shoppingCart().delete(item);
} }
return "cart.jsf"; return "cart.jsf";
} }
public List<ShoppingCartItem> getItems(){ public List<ShoppingCartItem> getItems() {
Database db = Database.getInstance(); Database db = Database.getInstance();
if(getUser()!=null){ if (getUser() != null) {
return db.shoppingCart().get(getUser()); return db.shoppingCart().get(getUser());
}else{ } else {
return new ArrayList<ShoppingCartItem>(); return new ArrayList<ShoppingCartItem>();
} }
} }
@ -63,31 +71,31 @@ public class CartBean {
}*/ }*/
public String buy(){ public String buy() {
ArrayList<OrderItem> orderList = new ArrayList<>(); ArrayList<OrderItem> orderList = new ArrayList<>();
for(ShoppingCartItem item : getItems()){ for (ShoppingCartItem item : getItems()) {
orderList.add(new OrderItem(item.getArticle(),item.getCount())); orderList.add(new OrderItem(item.getArticle(), item.getCount()));
} }
//Database.getInstance().order().insert(new Order(getUser(),orderList, new Date(234235235),sum(),null,null)); Database.getInstance().order().insert(new Order(getUser(), orderList, new Date(System.currentTimeMillis()), sum(), getPayment(), getAddress()));
for(ShoppingCartItem item : getItems()) { for (ShoppingCartItem item : getItems()) {
Database.getInstance().shoppingCart().delete(item); Database.getInstance().shoppingCart().delete(item);
} }
return "thanks.jsp"; return "index.jsf";
} }
public int getItemCount(){ public int getItemCount() {
return getItems().size(); return getItems().size();
} }
public long sum(){ public long sum() {
int sum = 0; int sum = 0;
for(ShoppingCartItem item : getItems()){ for (ShoppingCartItem item : getItems()) {
sum += item.getCount() * item.getArticle().getPrice(); sum += item.getCount() * item.getArticle().getPrice();
} }
return sum; return sum;
} }
public String getSum(){ public String getSum() {
long sum = sum(); long sum = sum();
String res = ""; String res = "";
res += sum / 100; res += sum / 100;

View File

@ -16,6 +16,7 @@
<ui:repeat value="#{addressBean.addressList}" var="address"> <ui:repeat value="#{addressBean.addressList}" var="address">
<h:panelGroup layout="block" styleClass="m-col-t-3"> <h:panelGroup layout="block" styleClass="m-col-t-3">
<h:form>
<h:commandLink action="#{addressBean.select(address)}"> <h:commandLink action="#{addressBean.select(address)}">
<div class="m-block m-primary"> <div class="m-block m-primary">
#{address.name}<br/> #{address.name}<br/>
@ -23,6 +24,7 @@
#{address.zipCode} #{address.city} #{address.zipCode} #{address.city}
</div> </div>
</h:commandLink> </h:commandLink>
</h:form>
</h:panelGroup> </h:panelGroup>
</ui:repeat> </ui:repeat>
</h:panelGroup> </h:panelGroup>

View File

@ -45,22 +45,22 @@
</ui:repeat> </ui:repeat>
<h:panelGroup type="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}"> <h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
<div class="m-col-t-5 m-push-t-7"> <div class="m-col-t-5 m-push-t-7">
<h1 class="m-text-right">Summe(#{cartBean.itemCount} Items): #{cartBean.sum}&#8364;</h1> <h1 class="m-text-right">Summe(#{cartBean.itemCount} Items): #{cartBean.sum}&#8364;</h1>
</div> </div>
</h:panelGroup> </h:panelGroup>
<h:panelGroup type="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}"> <h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount == 0}">
<h1 class="m-text-center">Der Warenkorb ist Leer</h1> <h1 class="m-text-center">Der Warenkorb ist Leer</h1>
</h:panelGroup> </h:panelGroup>
<div class="m-row"> <h:panelGroup layout="block" styleClass="m-row" rendered="#{cartBean.itemCount != 0}">
<div class="m-col-t-4 m-push-t-4 m-button m-success"> <div class="m-col-t-4 m-push-t-4 m-button m-success">
<a href="confirmation.jsf">Jetzt Kaufen</a> <a href="addressSelection.xhtml">Jetzt Kaufen</a>
</div>
</div> </div>
</h:panelGroup>
</ui:define> </ui:define>
</ui:composition> </ui:composition>

View File

@ -15,14 +15,21 @@
<div class="m-row"> <div class="m-row">
<div class="m-col-t-3 m-block"> <div class="m-col-t-3 m-block">
<h4>Addresse:</h4> <h4>Addresse:</h4>
Max Mustermann<br/> #{addressBean.selected.name}<br/>
Musterstraße 42<br/> #{addressBean.selected.street} #{addressBean.selected.number}<br/>
12345 Musterstadt #{addressBean.selected.zipCode} #{addressBean.selected.city}
</div> </div>
<div class="m-col-t-4 m-block m-push-t-5"> <div class="m-col-t-4 m-block m-push-t-5">
<h4>Konto</h4> <h4>#{paymentBean.selected.type.name}</h4>
IBAN: 12345&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;&bull;111<br/> <h:panelGroup layout="block" rendered="#{paymentBean.selected.type.name eq 'CreditCard'}">
Inhaber: Max Mustermann<br/> Inhaber: #{paymentBean.selected.owner}<br/>
Nummer : #{paymentBean.selected.number} / #{paymentBean.selected.checksum}
gültig bis: #{paymentBean.selected.expiration}
</h:panelGroup>
<h:panelGroup layout="block" rendered="#{paymentBean.selected.type.name eq 'PayPal'}">
Konto: #{paymentBean.selected.email}
</h:panelGroup>
</div> </div>
</div> </div>
@ -43,7 +50,7 @@
</ui:repeat> </ui:repeat>
<h:panelGroup type="block" styleClass="m-row"> <h:panelGroup layout="block" styleClass="m-row">
<div class="m-col-t-5 m-push-t-7"> <div class="m-col-t-5 m-push-t-7">
<h1 class="m-text-right">Summe: #{cartBean.sum}&#8364;</h1> <h1 class="m-text-right">Summe: #{cartBean.sum}&#8364;</h1>
</div> </div>

View File

@ -17,6 +17,7 @@
<h3 class="m-text-center m-text m-small">Kreditkarte</h3> <h3 class="m-text-center m-text m-small">Kreditkarte</h3>
<h:panelGroup layout="block" styleClass="m-row"> <h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.creditCard}" var="payment"> <ui:repeat value="#{paymentBean.creditCard}" var="payment">
<h:form>
<h:commandLink action="#{paymentBean.select(payment)}"> <h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3"> <div class="m-col-t-3">
<div class="m-block m-primary"> <div class="m-block m-primary">
@ -29,6 +30,7 @@
</div> </div>
</div> </div>
</h:commandLink> </h:commandLink>
</h:form>
</ui:repeat> </ui:repeat>
</h:panelGroup> </h:panelGroup>
@ -37,6 +39,7 @@
<h3 class="m-text-center m-text m-small">PayPal</h3> <h3 class="m-text-center m-text m-small">PayPal</h3>
<h:panelGroup layout="block" styleClass="m-row"> <h:panelGroup layout="block" styleClass="m-row">
<ui:repeat value="#{paymentBean.payPal}" var="payment"> <ui:repeat value="#{paymentBean.payPal}" var="payment">
<h:form>
<h:commandLink action="#{paymentBean.select(payment)}"> <h:commandLink action="#{paymentBean.select(payment)}">
<div class="m-col-t-3"> <div class="m-col-t-3">
<div class="m-block m-primary"> <div class="m-block m-primary">
@ -44,6 +47,7 @@
</div> </div>
</div> </div>
</h:commandLink> </h:commandLink>
</h:form>
</ui:repeat> </ui:repeat>
</h:panelGroup> </h:panelGroup>