Skip to content
Snippets Groups Projects
Commit b374e1b8 authored by Maximilian Komp's avatar Maximilian Komp
Browse files

Merge branch 'master' of https://git.fslab.de/tpinza2s/s4s

# Conflicts:
#	src/main/java/org/s4s/gui/views/ArtikelerstellungsView.java
parents 9db63689 21f621d4
Branches Anforderungen
No related tags found
No related merge requests found
Showing
with 105 additions and 59 deletions
......@@ -21,7 +21,7 @@ public interface ProductDAO {
List<Product> getProductListById(int id) throws DAOException;
Shop getProductOwner(Product product) throws DAOException;
Shop getOwnerOfProduct(Product product) throws DAOException;
List<Product> getAllProductsFromShop(int id) throws DAOException;
......
......@@ -29,10 +29,10 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
private final List<Product> liste = new ArrayList<>();
private static ProductDAO search = null;
private static final User user = (User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER);
private final Statement statement = JDBCConnection.getInstance().getStatement();
//DB-Block
Statement st;
String sql_select;
......@@ -104,8 +104,9 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
String kategorie = set.getString("kategorie");
double price = set.getDouble("preis");
String description = set.getString("beschreibung");
int sId = set.getInt("shopid");
p = new Product(name, pId, kategorie, price, description);
p = new Product(name, pId, kategorie, price, description, sId);
}
} catch (SQLException ex) {
throw new DAOException(ex);
......@@ -114,12 +115,13 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
}
@Override
public Shop getProductOwner(Product product) throws DAOException {
public Shop getOwnerOfProduct(Product product) throws DAOException {
Shop s = new Shop();
int tmp = product.getShopId();
try (ResultSet set = executeQuery("SELECT s.\"name\", s.\"shopid\""
+ " FROM \"ERR\".\"shop\" s, \"ERR\".\"artikel\" a"
+ " WHERE s.shopid = a.shopid AND a.shopid = ('" + tmp + "');")) {
try (ResultSet set = executeQuery("SELECT *"
+ " FROM \"ERR\".\"shop\" s"
+ " WHERE s.shopid = ('" + tmp + "');");) {
while (set.next()) {
int shopId = set.getInt("shopid");
String name = set.getString("name");
......@@ -182,13 +184,12 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
@Override
public boolean addProduct(String name, String beschreibung, double preis, Image pic, int shopID, int modulID, int cat) throws DAOException {
boolean done = false;
try {
sql_update = "INSERT INTO \"ERR\".\"artikel\"(name, beschreibung, preis, foto, shopid, modulid, kategorie) "
+ "VALUES(\'" + name + "\', \'" + beschreibung + "\', \'" + preis + "\', \'" + pic + "\', \'" + shopID + "\', \'" + modulID + "\', \'" + cat + "\')";
+ "VALUES(\'" + name + "\', \'" + beschreibung + "\', \'" + preis + "\', \'" + pic + "\', \'" + shopID + "\', \'" + modulID + "\', \'" + cat + "\')";
int exe = JDBCConnection.getInstance().getStatement().executeUpdate(sql_update);
if (exe < 0) {
throw new DAOException("Wrong Input!");
}
......@@ -198,20 +199,19 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
e.printStackTrace();
System.out.println("Exception occur: " + e);
}
return done;
}
@Override
public boolean addProduct(String name, String beschreibung, Date dVon, Date dBis, double preis, Image pic, int shopID, int modulID, int cat) throws DAOException {
boolean done = false;
try {
sql_update = "INSERT INTO \"ERR\".\"artikel\"(name, beschreibung, datum_von, preis, datum_bis, foto, shopid, modulid, kategorie) "
+ "VALUES(\'" + name + "\', \'" + beschreibung + "\', \'" + dVon + "\', \'" + preis + "\', \'" + dBis + "\', \'" + pic + "\', \'" + shopID + "\', \'" + modulID + "\', \'" + cat + "\')";
int exe = JDBCConnection.getInstance().getStatement().executeUpdate(sql_update);
if (exe < 0) {
throw new DAOException("Wrong Input!");
}
......@@ -221,7 +221,7 @@ public class ProductDAOimpl extends AbstractDatabaseClass implements ProductDAO
e.printStackTrace();
System.out.println("Exception occur: " + e);
}
return done;
}
}
......@@ -132,7 +132,7 @@ public class ShopDAOimpl extends AbstractDatabaseClass implements ShopDAO {
Shop s = new Shop();
try (ResultSet set = executeQuery("SELECT *"
+ "FROM \"ERR\".\"shop\" "
+ "WHERE besitzer = " + user.getUserId() + ";");) {
+ "WHERE besitzer = ('" + user.getUserId() + "');");) {
while (set.next()) {
int shopId = set.getInt("shopid");
String name = set.getString("name");
......
......@@ -30,37 +30,37 @@ import org.s4s.services.util.Views;
* @author Holger
*/
public class ArtikelShopView extends TemplateView {
private final ProductControl controllerProducts = new ProductControl();
private Product product = null;
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
if (event.getParameters() != null) {
// split at "/", add each part as a label
String str = event.getParameters();
int id = Integer.parseInt(str);
this.setUp(id);
} else {
Notification.show(null, "Kein Shop ausgewählt!", Notification.Type.HUMANIZED_MESSAGE);
UI.getCurrent().getNavigator().navigateTo(Views.WELCOME);
}
}
public void setUp(int id) {
VerticalLayout layout = new VerticalLayout();
setSizeFull();
Button zurueckButton = new Button("Weitersuchen!");
zurueckButton.setIcon(FontAwesome.ARROW_LEFT);
zurueckButton.addStyleName(ValoTheme.BUTTON_LINK);
zurueckButton.addClickListener((event) -> {
UI.getCurrent().getNavigator().navigateTo(Views.SUCHE);
});
BeanContainer<Integer, Product> dataProducts = new BeanContainer<>(Product.class);
Table table = new Table("Products", dataProducts);
dataProducts.setBeanIdProperty("id");
......@@ -78,7 +78,8 @@ public class ArtikelShopView extends TemplateView {
table.setColumnHeader("price", "Preis in €");
layout.addComponent(table);
table.setSizeFull();
table.setSelectable(true);
table.addItemClickListener((ItemClickEvent event) -> {
BeanItem<Product> productBean = dataProducts.getItem(event.getItemId());
product = productBean.getBean();
......@@ -87,8 +88,8 @@ public class ArtikelShopView extends TemplateView {
}
});
layout.addComponent(zurueckButton);
super.setUpFooterAndHeader(layout);
}
}
......@@ -37,9 +37,7 @@ public class ArtikeldetailsView extends TemplateView {
// split at "/", add each part as a label
String str = event.getParameters();
int id = Integer.parseInt(str);
for (Product p : warenkorb.inhalt()) {
System.out.println(p.getName());
}
System.out.println(id);
this.setUp(id);
} else {
Notification.show(null, "Kein Artikel ausgewählt!", Notification.Type.HUMANIZED_MESSAGE);
......@@ -51,9 +49,7 @@ public class ArtikeldetailsView extends TemplateView {
try {
this.setSizeFull();
product = controllerProduct.getProductById(id);
shop = controllerProduct.getProductOwner(product);
System.out.println(shop.getName());
System.out.println(shop.getShopId());
shop = controllerProduct.getOwnerOfProduct(product);
HorizontalLayout horizontalLayout = new HorizontalLayout();
Panel p = new Panel("Name: " + product.getName());
Panel p1 = new Panel("Beschreibung: " + product.getDescription());
......
......@@ -57,6 +57,11 @@ public class ArtikelerstellungsView extends TemplateView implements View {
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
if (UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER) == null) {
User user = (User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER);
Notification.show(null, "Sie müssen eingeloggt sein, um Artikel zu inserieren!", Notification.Type.HUMANIZED_MESSAGE);
UI.getCurrent().getNavigator().navigateTo(Views.WELCOME);
}
setUp();
}
......@@ -172,11 +177,10 @@ public class ArtikelerstellungsView extends TemplateView implements View {
mList.iterator().remove();
}
} catch (Exception e) {
System.out.println("gotta catch");
Logger.getLogger(ArtikelerstellungsView.class.getName()).log(Level.SEVERE, null, e);
}
nsModul.setNullSelectionAllowed(false);
// Kann hier jemand den Fehler finden? <------------------------------------------
HorizontalLayout hKommand = new HorizontalLayout(bAbbrechen, bErstellen);
HorizontalLayout hVerfuegbarkeit = new HorizontalLayout(dfVon, dfBis);
HorizontalLayout hKriterien = new HorizontalLayout(nsKategorie, nsModul);
......
package org.s4s.gui.views;
import com.vaadin.data.util.BeanContainer;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.shared.ui.label.ContentMode;
import com.vaadin.ui.*;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.s4s.exceptions.DAOException;
import org.s4s.modell.dto.*;
import org.s4s.process.control.ProductControl;
import org.s4s.process.control.ShopControl;
import org.s4s.services.util.Roles;
import org.s4s.services.util.Views;
......@@ -17,6 +23,10 @@ public class ShopView extends TemplateView {
private Shop shop = new Shop();
private final ShopControl controllerShops = new ShopControl();
private final ProductControl controllerProducts = new ProductControl();
private final BeanContainer<Integer, Product> dataProducts = new BeanContainer<>(Product.class);
private final Table tableProducts = new Table("Products", dataProducts);
@Override
public void enter(ViewChangeListener.ViewChangeEvent event) {
......@@ -36,20 +46,45 @@ public class ShopView extends TemplateView {
} catch (DAOException ex) {
Logger.getLogger(ShopView.class.getName()).log(Level.SEVERE, null, ex);
}
int id = shop.getShopId();
VerticalLayout verticalLayout = new VerticalLayout();
HorizontalLayout horizontalLayout = new HorizontalLayout();
Label label_hello = new Label("Hi, " + user.getVorname());
Label label_hello = new Label("Hi, <b>" + user.getVorname() + "</b>!" + "\n" + "Dein Shop, <b>" + shop.getName() + "</b>", ContentMode.HTML);
verticalLayout.addComponent(label_hello);
verticalLayout.setComponentAlignment(label_hello, Alignment.MIDDLE_CENTER);
Label label_yourShop = new Label("Dein Shop, ");
verticalLayout.addComponent(label_yourShop);
verticalLayout.setComponentAlignment(label_yourShop, Alignment.MIDDLE_CENTER);
//List all products by owner
BeanContainer<Integer, Product> dataProducts = new BeanContainer<>(Product.class);
Table table = new Table("",dataProducts);
dataProducts.setBeanIdProperty("id");
Set<Product> liste = new HashSet<>();
try {
liste.addAll(controllerProducts.getAllProductsFromShop(id));
} catch (DAOException ex) {
Logger.getLogger(SucheView.class.getName()).log(Level.SEVERE, null, ex);
}
dataProducts.removeAllItems();
dataProducts.addAll(liste);
Label label_OwnersProducts = new Label("Deine inserierten Artikel:");
verticalLayout.addComponent(label_OwnersProducts);
verticalLayout.setComponentAlignment(label_OwnersProducts, Alignment.MIDDLE_CENTER);
//TO-DO Make List Clickable to remove articles.
//TO-DO Panel has to count articles!
if(liste.isEmpty()){
Label label_noProducts = new Label("Du hast noch keine Produkte :-(");
verticalLayout.addComponent(label_noProducts);
verticalLayout.setComponentAlignment(label_noProducts,Alignment.MIDDLE_LEFT);
} else {
Label label_OwnersProducts = new Label("Deine inserierten Artikel:");
verticalLayout.addComponent(label_OwnersProducts);
verticalLayout.setComponentAlignment(label_OwnersProducts, Alignment.MIDDLE_CENTER);
table.setPageLength(table.size());
table.setVisibleColumns(new Object[]{"name", "price"});
table.setColumnHeader("name", "Name");
table.setColumnHeader("price", "Preis in €");
verticalLayout.addComponent(table);
table.setSizeFull();
}
verticalLayout.addComponent(horizontalLayout);
Button button_addProduct = new Button("Artikel inserieren");
......@@ -64,14 +99,14 @@ public class ShopView extends TemplateView {
verticalLayout.addComponent(label_ShopDetails);
verticalLayout.setComponentAlignment(label_ShopDetails, Alignment.MIDDLE_CENTER);
Panel panel_createdDate = new Panel("Erstellt: ");
Panel panel_ProductQuantity = new Panel("Anzahl Produkte: " );
Panel panel_Rating = new Panel("Bewertung: " + shop.getBewertung());
Panel panel_RatingNumber = new Panel("Bewertungsanzahl: " + shop.getBewertungsanzahl());
Panel panel_ShopName = new Panel("Anbieter: " + shop.getName());
Panel panel_ShopID = new Panel("ShopID: " + shop.getShopId());
verticalLayout.addComponent(panel_createdDate);
verticalLayout.setComponentAlignment(panel_createdDate, Alignment.MIDDLE_LEFT);
verticalLayout.addComponent((panel_ProductQuantity));
verticalLayout.setComponentAlignment(panel_ProductQuantity, Alignment.MIDDLE_LEFT);
verticalLayout.addComponent((panel_Rating));
verticalLayout.setComponentAlignment(panel_Rating, Alignment.MIDDLE_LEFT);
verticalLayout.addComponent(panel_RatingNumber);
......
......@@ -53,13 +53,18 @@ public class SucheView extends TemplateView {
public void setUp() {
final VerticalLayout contentLayout = new VerticalLayout();
super.setUpFooterAndHeader(contentLayout);
super.setUpFooterAndHeader(contentLayout);
setSizeFull();
contentLayout.addComponent(tableShops);
contentLayout.setComponentAlignment(tableShops, Alignment.TOP_LEFT);
contentLayout.addComponent(tableProducts);
contentLayout.setComponentAlignment(tableProducts, Alignment.TOP_LEFT);
addComponent(contentLayout);
final VerticalLayout layout = new VerticalLayout();
layout.addComponent(tableShops);
layout.setComponentAlignment(tableShops, Alignment.TOP_LEFT);
layout.addComponent(tableProducts);
layout.setComponentAlignment(tableProducts, Alignment.TOP_LEFT);
contentLayout.addComponent(layout);
contentLayout.setComponentAlignment(layout, Alignment.TOP_LEFT);
tableProducts.setSizeFull();
tableProducts.setSelectable(true);
tableProducts.setWidth("100%");
......
......@@ -90,9 +90,9 @@ public class TemplateView extends VerticalLayout implements View {
UI.getCurrent().getNavigator().navigateTo(Views.WARENKORB);
break;
case "Kasse":
UI.getCurrent().getNavigator().navigateTo(Views.CHECKOUT);
break;
// case "Kasse":
// UI.getCurrent().getNavigator().navigateTo(Views.CHECKOUT);
// break;
case "Login":
UI.getCurrent().getNavigator().navigateTo(Views.LOGIN);
break;
......@@ -108,7 +108,7 @@ public class TemplateView extends VerticalLayout implements View {
LogoutControl.logout();
UI.getCurrent().getNavigator().navigateTo(Views.WELCOME);
break;
case "Shop anzeigen":
case "Shop anzeigen":
UI.getCurrent().getNavigator().navigateTo(Views.SHOPVIEW);
break;
case "Kontakt":
......@@ -139,12 +139,12 @@ public class TemplateView extends VerticalLayout implements View {
// Yet another top-level item
MenuBar.MenuItem shoppingCardItem = barmenu.addItem("Warenkorb", null, mycommand);
MenuBar.MenuItem checktoutItem = barmenu.addItem("Kasse", null, mycommand);
//MenuBar.MenuItem checktoutItem = barmenu.addItem("Kasse", null, mycommand);
MenuBar.MenuItem loginItem = barmenu.addItem("Login", null, mycommand);
MenuBar.MenuItem registerItem = barmenu.addItem("Registrieren", null, mycommand);
MenuBar.MenuItem shopItem = barmenu.addItem("Shop erstellen", null, mycommand);
MenuBar.MenuItem shopItem2 = barmenu.addItem("Shop anzeigen", null, mycommand);
MenuBar.MenuItem userItem = barmenu.addItem("Mein Konto", null, null);
userItem.addItem("Einstellungen", null, mycommand);
......@@ -180,7 +180,7 @@ public class TemplateView extends VerticalLayout implements View {
} else {
registerItem.setVisible(false);
loginItem.setVisible(false);
User user = (User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER);
ShopControl control = new ShopControl();
if (control.viewShop(user)) {
......
......@@ -9,6 +9,7 @@ import com.vaadin.ui.Image;
import java.util.Date;
import java.util.List;
import org.s4s.dao.ProductDAO;
import org.s4s.dao.impl.ProductDAOimpl;
import org.s4s.exceptions.DAOException;
import org.s4s.modell.dto.Product;
......@@ -20,6 +21,10 @@ public class ArtikelerstellungsControl {
private static ProductDAO pDAO = null;
public ArtikelerstellungsControl() {
pDAO = ProductDAOimpl.getInstance();
}
public List<Product> getProductByDescription(String typ) throws DAOException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
......
......@@ -31,8 +31,8 @@ public class ProductControl {
return dao.getProductById(id);
}
public Shop getProductOwner(Product product) throws DAOException {
return dao.getProductOwner(product);
public Shop getOwnerOfProduct(Product product) throws DAOException {
return dao.getOwnerOfProduct(product);
}
public List<Product> getProductListById(int id) throws DAOException {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment