ordering process done
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
88145df721
commit
6d6a1c9b2a
7
pom.xml
7
pom.xml
@ -180,13 +180,6 @@
|
||||
<version>5.4.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- other -->
|
||||
<dependency>
|
||||
<groupId>javaee</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
@ -40,7 +40,10 @@ public class AuthorDB {
|
||||
ResultSet rs = entry.getKey();
|
||||
Author author = null;
|
||||
try {
|
||||
author = new Author(rs.getLong("id"), rs.getString("name"));
|
||||
rs.beforeFirst();
|
||||
while(rs.next()) {
|
||||
author = new Author(rs.getLong("id"), rs.getString("name"));
|
||||
}
|
||||
entry.getValue().close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -35,6 +35,11 @@ public class BookDB {
|
||||
public Book get(long id) {
|
||||
Map.Entry<ResultSet, Connection> entry = database.getResultSetById(database.tableBook, id);
|
||||
assert entry != null;
|
||||
try {
|
||||
entry.getKey().beforeFirst();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return build(entry);
|
||||
}
|
||||
|
||||
@ -50,22 +55,25 @@ public class BookDB {
|
||||
Book book = null;
|
||||
ResultSet rs = entry.getKey();
|
||||
try {
|
||||
Category category = database.category().get(rs.getLong(database.tableCategory));
|
||||
Publisher publisher = database.publisher().get(rs.getLong(database.tablePublisher));
|
||||
List<Integer> authorIds = database.author().getAll(rs.getLong("id"));
|
||||
assert category != null;
|
||||
assert publisher != null;
|
||||
assert authorIds != null;
|
||||
rs.beforeFirst();
|
||||
while(rs.next()) {
|
||||
Category category = database.category().get(rs.getLong(database.tableCategory));
|
||||
Publisher publisher = database.publisher().get(rs.getLong(database.tablePublisher));
|
||||
List<Integer> authorIds = database.author().getAll(rs.getLong("id"));
|
||||
assert category != null;
|
||||
assert publisher != null;
|
||||
assert authorIds != null;
|
||||
|
||||
List<Author> authors = new ArrayList<>();
|
||||
for (int i : authorIds) {
|
||||
Author author = database.author().get(i);
|
||||
assert author != null;
|
||||
authors.add(author);
|
||||
List<Author> authors = new ArrayList<>();
|
||||
for (int i : authorIds) {
|
||||
Author author = database.author().get(i);
|
||||
assert author != null;
|
||||
authors.add(author);
|
||||
}
|
||||
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"),
|
||||
rs.getString("image"));
|
||||
}
|
||||
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"),
|
||||
rs.getString("image"));
|
||||
|
||||
entry.getValue().close();
|
||||
} catch (SQLException e) {
|
||||
|
@ -37,7 +37,10 @@ public class PublisherDB {
|
||||
ResultSet rs = entry.getKey();
|
||||
Publisher publisher = null;
|
||||
try {
|
||||
publisher = new Publisher(rs.getLong("id"), rs.getString("name"));
|
||||
rs.beforeFirst();
|
||||
while(rs.next()) {
|
||||
publisher = new Publisher(rs.getLong("id"), rs.getString("name"));
|
||||
}
|
||||
entry.getValue().close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.RequestScoped;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -19,7 +19,7 @@ import java.util.List;
|
||||
* @version 1.0
|
||||
*/
|
||||
@ManagedBean
|
||||
@RequestScoped
|
||||
@SessionScoped
|
||||
public class AddressBean implements Serializable {
|
||||
|
||||
public User getUser() {
|
||||
|
@ -1,16 +1,14 @@
|
||||
package de.hsel.itech.jsf;
|
||||
|
||||
import de.hsel.itech.db.Database;
|
||||
import de.hsel.itech.db.pojo.Book;
|
||||
import de.hsel.itech.db.pojo.OrderItem;
|
||||
import de.hsel.itech.db.pojo.ShoppingCartItem;
|
||||
import de.hsel.itech.db.pojo.User;
|
||||
import de.hsel.itech.db.pojo.*;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.faces.annotation.ManagedProperty;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import java.sql.Date;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -24,36 +22,46 @@ public class CartBean {
|
||||
|
||||
public User getUser() {
|
||||
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){
|
||||
if(getUser() != null){
|
||||
for(ShoppingCartItem item : getItems()){
|
||||
if(item.getArticle().getId() == book.getId()){
|
||||
public Payment getPayment () {
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
return (Payment) context.getApplication().evaluateExpressionGet(context, "#{paymentBean.selected}", Payment.class);
|
||||
}
|
||||
|
||||
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);
|
||||
item.setCount(item.getCount() + 1);
|
||||
Database.getInstance().shoppingCart().insert(item);
|
||||
return "cart.jsf";
|
||||
}
|
||||
}
|
||||
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(),book,1));
|
||||
Database.getInstance().shoppingCart().insert(new ShoppingCartItem(getUser(), book, 1));
|
||||
}
|
||||
return "cart.jsf";
|
||||
}
|
||||
|
||||
public String remove(ShoppingCartItem item){
|
||||
if(getUser() != null){
|
||||
public String remove(ShoppingCartItem item) {
|
||||
if (getUser() != null) {
|
||||
Database.getInstance().shoppingCart().delete(item);
|
||||
}
|
||||
return "cart.jsf";
|
||||
}
|
||||
|
||||
public List<ShoppingCartItem> getItems(){
|
||||
public List<ShoppingCartItem> getItems() {
|
||||
Database db = Database.getInstance();
|
||||
if(getUser()!=null){
|
||||
if (getUser() != null) {
|
||||
return db.shoppingCart().get(getUser());
|
||||
}else{
|
||||
} else {
|
||||
return new ArrayList<ShoppingCartItem>();
|
||||
}
|
||||
}
|
||||
@ -63,31 +71,31 @@ public class CartBean {
|
||||
|
||||
}*/
|
||||
|
||||
public String buy(){
|
||||
public String buy() {
|
||||
ArrayList<OrderItem> orderList = new ArrayList<>();
|
||||
for(ShoppingCartItem item : getItems()){
|
||||
orderList.add(new OrderItem(item.getArticle(),item.getCount()));
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
orderList.add(new OrderItem(item.getArticle(), item.getCount()));
|
||||
}
|
||||
//Database.getInstance().order().insert(new Order(getUser(),orderList, new Date(234235235),sum(),null,null));
|
||||
for(ShoppingCartItem item : getItems()) {
|
||||
Database.getInstance().order().insert(new Order(getUser(), orderList, new Date(System.currentTimeMillis()), sum(), getPayment(), getAddress()));
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
Database.getInstance().shoppingCart().delete(item);
|
||||
}
|
||||
return "thanks.jsp";
|
||||
return "index.jsf";
|
||||
}
|
||||
|
||||
public int getItemCount(){
|
||||
public int getItemCount() {
|
||||
return getItems().size();
|
||||
}
|
||||
|
||||
public long sum(){
|
||||
public long sum() {
|
||||
int sum = 0;
|
||||
for(ShoppingCartItem item : getItems()){
|
||||
for (ShoppingCartItem item : getItems()) {
|
||||
sum += item.getCount() * item.getArticle().getPrice();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
public String getSum(){
|
||||
public String getSum() {
|
||||
long sum = sum();
|
||||
String res = "";
|
||||
res += sum / 100;
|
||||
|
@ -16,13 +16,15 @@
|
||||
<ui:repeat value="#{addressBean.addressList}" var="address">
|
||||
|
||||
<h:panelGroup layout="block" styleClass="m-col-t-3">
|
||||
<h:commandLink action="#{addressBean.select(address)}">
|
||||
<div class="m-block m-primary">
|
||||
#{address.name}<br/>
|
||||
#{address.street} #{address.number}<br/>
|
||||
#{address.zipCode} #{address.city}
|
||||
</div>
|
||||
</h:commandLink>
|
||||
<h:form>
|
||||
<h:commandLink action="#{addressBean.select(address)}">
|
||||
<div class="m-block m-primary">
|
||||
#{address.name}<br/>
|
||||
#{address.street} #{address.number}<br/>
|
||||
#{address.zipCode} #{address.city}
|
||||
</div>
|
||||
</h:commandLink>
|
||||
</h:form>
|
||||
</h:panelGroup>
|
||||
</ui:repeat>
|
||||
</h:panelGroup>
|
||||
|
@ -45,22 +45,22 @@
|
||||
</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">
|
||||
<h1 class="m-text-right">Summe(#{cartBean.itemCount} Items): #{cartBean.sum}€</h1>
|
||||
</div>
|
||||
</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>
|
||||
</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">
|
||||
<a href="confirmation.jsf">Jetzt Kaufen</a>
|
||||
<a href="addressSelection.xhtml">Jetzt Kaufen</a>
|
||||
</div>
|
||||
</div>
|
||||
</h:panelGroup>
|
||||
|
||||
</ui:define>
|
||||
</ui:composition>
|
||||
|
@ -15,14 +15,21 @@
|
||||
<div class="m-row">
|
||||
<div class="m-col-t-3 m-block">
|
||||
<h4>Addresse:</h4>
|
||||
Max Mustermann<br/>
|
||||
Musterstraße 42<br/>
|
||||
12345 Musterstadt
|
||||
#{addressBean.selected.name}<br/>
|
||||
#{addressBean.selected.street} #{addressBean.selected.number}<br/>
|
||||
#{addressBean.selected.zipCode} #{addressBean.selected.city}
|
||||
</div>
|
||||
<div class="m-col-t-4 m-block m-push-t-5">
|
||||
<h4>Konto</h4>
|
||||
IBAN: 12345••••••••••••••••••••••••111<br/>
|
||||
Inhaber: Max Mustermann<br/>
|
||||
<h4>#{paymentBean.selected.type.name}</h4>
|
||||
<h:panelGroup layout="block" rendered="#{paymentBean.selected.type.name eq 'CreditCard'}">
|
||||
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>
|
||||
|
||||
@ -43,7 +50,7 @@
|
||||
</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">
|
||||
<h1 class="m-text-right">Summe: #{cartBean.sum}€</h1>
|
||||
</div>
|
||||
|
@ -17,18 +17,20 @@
|
||||
<h3 class="m-text-center m-text m-small">Kreditkarte</h3>
|
||||
<h:panelGroup layout="block" styleClass="m-row">
|
||||
<ui:repeat value="#{paymentBean.creditCard}" var="payment">
|
||||
<h:commandLink action="#{paymentBean.select(payment)}">
|
||||
<div class="m-col-t-3">
|
||||
<div class="m-block m-primary">
|
||||
#{payment.owner}<br/>
|
||||
#{payment.number} /
|
||||
#{payment.checksum}<br/>
|
||||
Ablaufdatum:<h:outputText value="#{payment.expiration}">
|
||||
<f:convertDateTime pattern="dd.MM.yyyy"/>
|
||||
</h:outputText>
|
||||
<h:form>
|
||||
<h:commandLink action="#{paymentBean.select(payment)}">
|
||||
<div class="m-col-t-3">
|
||||
<div class="m-block m-primary">
|
||||
#{payment.owner}<br/>
|
||||
#{payment.number} /
|
||||
#{payment.checksum}<br/>
|
||||
Ablaufdatum:<h:outputText value="#{payment.expiration}">
|
||||
<f:convertDateTime pattern="dd.MM.yyyy"/>
|
||||
</h:outputText>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</h:commandLink>
|
||||
</h:commandLink>
|
||||
</h:form>
|
||||
</ui:repeat>
|
||||
|
||||
</h:panelGroup>
|
||||
@ -37,13 +39,15 @@
|
||||
<h3 class="m-text-center m-text m-small">PayPal</h3>
|
||||
<h:panelGroup layout="block" styleClass="m-row">
|
||||
<ui:repeat value="#{paymentBean.payPal}" var="payment">
|
||||
<h:commandLink action="#{paymentBean.select(payment)}">
|
||||
<div class="m-col-t-3">
|
||||
<div class="m-block m-primary">
|
||||
#{payment.email}
|
||||
<h:form>
|
||||
<h:commandLink action="#{paymentBean.select(payment)}">
|
||||
<div class="m-col-t-3">
|
||||
<div class="m-block m-primary">
|
||||
#{payment.email}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</h:commandLink>
|
||||
</h:commandLink>
|
||||
</h:form>
|
||||
</ui:repeat>
|
||||
|
||||
</h:panelGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user