diff --git a/src/main/java/org/s4s/dao/ProductDAO.java b/src/main/java/org/s4s/dao/ProductDAO.java index 1c95fa3109cb15378771214175d718f438754355..0bf630b9b2920b42e7a7dcfb66e3011fdda0e521 100644 --- a/src/main/java/org/s4s/dao/ProductDAO.java +++ b/src/main/java/org/s4s/dao/ProductDAO.java @@ -3,6 +3,7 @@ package org.s4s.dao; import java.util.List; import org.s4s.exceptions.DAOException; import org.s4s.modell.dto.Product; +import org.s4s.modell.dto.Shop; /** * @@ -15,4 +16,6 @@ public interface ProductDAO { List<Product> getProductByDescription(String typ) throws DAOException; Product getProductById(int id) throws DAOException; + + Shop getProductOwner(Product product) throws DAOException; } diff --git a/src/main/java/org/s4s/gui/views/ArtikeldetailsView.java b/src/main/java/org/s4s/gui/views/ArtikeldetailsView.java index 99d0064ec28c972ce34746d7a63c5d312b314cbb..f8fa9d58bd2ea7f8849f5296606aa765e927f1ae 100644 --- a/src/main/java/org/s4s/gui/views/ArtikeldetailsView.java +++ b/src/main/java/org/s4s/gui/views/ArtikeldetailsView.java @@ -2,6 +2,7 @@ package org.s4s.gui.views; import com.vaadin.navigator.ViewChangeListener; import com.vaadin.ui.Alignment; +import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; @@ -12,7 +13,10 @@ import java.util.logging.Logger; import org.s4s.dao.ProductDAO; import org.s4s.exceptions.DAOException; import org.s4s.modell.dto.Product; +import org.s4s.modell.dto.Shop; +import org.s4s.modell.dto.Warenkorb; import org.s4s.process.control.ProductSearch; +import org.s4s.services.util.Roles; import org.s4s.services.util.Views; /** @@ -21,7 +25,9 @@ import org.s4s.services.util.Views; */ public class ArtikeldetailsView extends TemplateView { + private Warenkorb warenkorb = Warenkorb.getInstance(); private Product product = new Product(); + private Shop shop = new Shop(); private final ProductDAO products = ProductSearch.getInstance(); private VerticalLayout verticalLayout = new VerticalLayout(); @@ -40,21 +46,47 @@ public class ArtikeldetailsView extends TemplateView { } public void setUp(int id) { - getInformation(id); - super.setUpFooterAndHeader(verticalLayout); - } - - private void getInformation(int id) { try { product = products.getProductById(id); + shop = products.getProductOwner(product); HorizontalLayout horizontalLayout = new HorizontalLayout(); Panel p = new Panel("Name: " + product.getName()); - horizontalLayout.addComponent(p); - horizontalLayout.setComponentAlignment(p, Alignment.MIDDLE_LEFT); + Panel p1 = new Panel("Beschreibung: " + product.getDescription()); + Panel p2 = new Panel("Preis: " + product.getPrice()); + Panel p3 = new Panel("Anbieter: " + shop.getName()); + verticalLayout.addComponent(p); + verticalLayout.setComponentAlignment(p, Alignment.MIDDLE_LEFT); + verticalLayout.addComponent(p1); + verticalLayout.setComponentAlignment(p1, Alignment.MIDDLE_LEFT); + verticalLayout.addComponent(p2); + verticalLayout.setComponentAlignment(p2, Alignment.MIDDLE_LEFT); + verticalLayout.addComponent(p3); + verticalLayout.setComponentAlignment(p3, Alignment.MIDDLE_LEFT); verticalLayout.addComponent(horizontalLayout); + + if (session.getAttribute(Roles.CURRENTUSER) != null) { + System.out.println(session.getAttribute(Roles.CURRENTUSER)); + Button addButton = new Button("Hinzufügen"); + + addButton.addClickListener((event) -> { + if (warenkorb.contains(product)) { + Notification.show(null, product.getName() + " befindet sich schon in Ihrem Warenkorb!", + Notification.Type.WARNING_MESSAGE); + } else { + warenkorb.add(product); + Notification.show(null, product.getName() + " wurde in den Warenkorb hinzugefügt!", + Notification.Type.WARNING_MESSAGE); + System.out.println(warenkorb.getAnzahl()); + } + }); + verticalLayout.addComponent(addButton); + verticalLayout.setComponentAlignment(addButton, Alignment.TOP_RIGHT); + } + this.addComponent(verticalLayout); } catch (DAOException ex) { Logger.getLogger(ArtikeldetailsView.class.getName()).log(Level.SEVERE, null, ex); } + super.setUpFooterAndHeader(verticalLayout); } } diff --git a/src/main/java/org/s4s/gui/views/BenutzerkontoView.java b/src/main/java/org/s4s/gui/views/BenutzerkontoView.java index a79010eeb7d48c03c9f4a6d2fbe6f25f200c5fe8..a31447240a9ddac97b36a4df2806051c2d886524 100644 --- a/src/main/java/org/s4s/gui/views/BenutzerkontoView.java +++ b/src/main/java/org/s4s/gui/views/BenutzerkontoView.java @@ -1,6 +1,10 @@ package org.s4s.gui.views; import com.vaadin.navigator.ViewChangeListener; +import com.vaadin.ui.Notification; +import com.vaadin.ui.UI; +import org.s4s.services.util.Roles; +import org.s4s.services.util.Views; /** * @@ -10,7 +14,16 @@ public class BenutzerkontoView extends TemplateView { @Override public void enter(ViewChangeListener.ViewChangeEvent event) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + if (session.getAttribute(Roles.CURRENTUSER) == null) { + UI.getCurrent().getNavigator().navigateTo(Views.LOGIN); + Notification.show(null, "Einloggen, um auf Ihr Benutzerkonto zugreifen zu können!", + Notification.Type.WARNING_MESSAGE); + } + this.setUp(); + } + + public void setUp() { + } } diff --git a/src/main/java/org/s4s/gui/views/RegistrierungView.java b/src/main/java/org/s4s/gui/views/RegistrierungView.java index 0b341786285d2c0e54cac0e5bb71ddf80df80e9a..5692e7b593511c96083555c9eb5b8e31f9f4dc48 100644 --- a/src/main/java/org/s4s/gui/views/RegistrierungView.java +++ b/src/main/java/org/s4s/gui/views/RegistrierungView.java @@ -14,137 +14,124 @@ import com.vaadin.ui.DateField; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; -import com.vaadin.ui.NativeSelect; import com.vaadin.ui.Panel; import com.vaadin.ui.PasswordField; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; import java.util.Date; -import org.s4s.dao.impl.RegistrationControl; +import org.s4s.process.control.RegistrationControl; import org.s4s.services.util.Views; - /** * * @author JanPhilipp */ public class RegistrierungView extends TemplateView implements View { - + // RegistrierungControl regControl; -// VerticalLayout layout; - +// VerticalLayout layout; @Override public void enter(ViewChangeListener.ViewChangeEvent event) { this.setUp(); } - private void setUp() { - - - Panel panel = new Panel("Registrierung"); - panel.setSizeUndefined(); - - FormLayout content = new FormLayout(); - - TextField benutzername = new TextField("Benutzername"); - content.addComponent(benutzername); - - DateField bday = new DateField("Geburtstag"); - bday.setDateFormat("YYYY-MM-DD"); - content.addComponent(bday); - - TextField nachnameTxt = new TextField("Nachname:"); - nachnameTxt.setIcon(FontAwesome.USER); - content.addComponent(nachnameTxt); - - - TextField vornameTxt = new TextField("Vorname:"); - vornameTxt.setIcon(FontAwesome.ANDROID); - content.addComponent(vornameTxt); - - - /* NativeSelect fachbereich = new NativeSelect("Fachbereich"); //hier braucht die Datenbank Integer Werte! Fachbereich ist nicht Student, Hiwi oder Prof sonder FB01, 02,03 etc!! + + Panel panel = new Panel("Registrierung"); + panel.setSizeUndefined(); + + FormLayout content = new FormLayout(); + + TextField benutzername = new TextField("Benutzername"); + content.addComponent(benutzername); + + DateField bday = new DateField("Geburtstag"); + bday.setDateFormat("YYYY-MM-DD"); + content.addComponent(bday); + + TextField nachnameTxt = new TextField("Nachname:"); + nachnameTxt.setIcon(FontAwesome.USER); + content.addComponent(nachnameTxt); + + TextField vornameTxt = new TextField("Vorname:"); + vornameTxt.setIcon(FontAwesome.ANDROID); + content.addComponent(vornameTxt); + + /* NativeSelect fachbereich = new NativeSelect("Fachbereich"); //hier braucht die Datenbank Integer Werte! Fachbereich ist nicht Student, Hiwi oder Prof sonder FB01, 02,03 etc!! fachbereich.addItems("Student", "Hivi", "Prof"); //ich kann das grad nicht selber machen, weil ich beim deployen fehler kriege und nicht ungetestetes commiten möchte! Also bitte abändern! fachbereich.setNullSelectionAllowed(false); content.addComponent(fachbereich); -*/ - TextField fachbereich = new TextField("Fachbereich:"); - fachbereich.setConverter(Integer.class); - fachbereich.setIcon(FontAwesome.ANDROID); - content.addComponent(fachbereich); - - - TextField emailTxt = new TextField("E-Mail:"); - emailTxt.setIcon(FontAwesome.MAIL_FORWARD); - content.addComponent(emailTxt); - - TextField emailTxtWdh = new TextField("E-Mail wiederholen:"); - emailTxtWdh.setIcon(FontAwesome.MAIL_FORWARD); - content.addComponent(emailTxtWdh); - - PasswordField passwortTxt = new PasswordField("Passwort:"); - passwortTxt.setIcon(FontAwesome.KEY); - content.addComponent(passwortTxt); - - PasswordField passwortTxtWdh = new PasswordField("Passwort wiederholen:"); - passwortTxtWdh.setIcon(FontAwesome.KEY); - content.addComponent(passwortTxtWdh); - - - - HorizontalLayout buttons = new HorizontalLayout(); - Button abbruch = new Button("Abbruch"); - abbruch.setIcon(FontAwesome.STOP_CIRCLE); - buttons.addComponent(abbruch); - buttons.addComponent(new Label(" ", ContentMode.HTML)); - Button bestätigen = new Button("Bestätigen"); - bestätigen.setIcon(FontAwesome.CHECK); - buttons.addComponent(bestätigen); - - content.addComponent(buttons); + */ + TextField fachbereich = new TextField("Fachbereich:"); + fachbereich.setConverter(Integer.class); + fachbereich.setIcon(FontAwesome.ANDROID); + content.addComponent(fachbereich); + + TextField emailTxt = new TextField("E-Mail:"); + emailTxt.setIcon(FontAwesome.MAIL_FORWARD); + content.addComponent(emailTxt); + + TextField emailTxtWdh = new TextField("E-Mail wiederholen:"); + emailTxtWdh.setIcon(FontAwesome.MAIL_FORWARD); + content.addComponent(emailTxtWdh); + + PasswordField passwortTxt = new PasswordField("Passwort:"); + passwortTxt.setIcon(FontAwesome.KEY); + content.addComponent(passwortTxt); + + PasswordField passwortTxtWdh = new PasswordField("Passwort wiederholen:"); + passwortTxtWdh.setIcon(FontAwesome.KEY); + content.addComponent(passwortTxtWdh); + + HorizontalLayout buttons = new HorizontalLayout(); + Button abbruch = new Button("Abbruch"); + abbruch.setIcon(FontAwesome.STOP_CIRCLE); + buttons.addComponent(abbruch); + buttons.addComponent(new Label(" ", ContentMode.HTML)); + Button bestätigen = new Button("Bestätigen"); + bestätigen.setIcon(FontAwesome.CHECK); + buttons.addComponent(bestätigen); + + content.addComponent(buttons); // content.setSizeUndefined(); - content.setMargin(true); - - panel.setContent(content); - //this.addComponent(panel); - //this.setComponentAlignment(panel, Alignment.MIDDLE_CENTER); - - - - bestätigen.addClickListener( e -> { - String benutzer = benutzername.getValue(); - String nachname = nachnameTxt.getValue(); - String vorname = vornameTxt.getValue(); - Date gebDate = bday.getValue(); - int fBereich = (int) fachbereich.getConvertedValue(); - String email = emailTxt.getValue(); - String emailwdh = emailTxtWdh.getValue(); - String passwort = passwortTxt.getValue(); - String passwortWdh = passwortTxtWdh.getValue(); - UI.getCurrent().getNavigator().navigateTo(Views.REGISTRIERUNGSBESTAETIGUNG); - - //Anbindungstestblock. svolle2s - //RegistrationControl.init(new String[]{nachname, vorname, email, emailwdh, passwort, passwortWdh, benutzer,}); // diverse Daten fehlen siehe bday fachbereich - RegistrationControl.init(benutzer, nachname, vorname, gebDate, fBereich, email, emailwdh, passwort, passwortWdh); - - System.out.println(benutzer); - System.out.println(nachname); - System.out.println(vorname); - System.out.println(gebDate); - System.out.println(email); - System.out.println(emailwdh); - System.out.println(passwort); - System.out.println(passwortWdh); - System.out.println(fBereich); - - // Weiterleitung auf Bestätigunsseite - + content.setMargin(true); + + panel.setContent(content); + //this.addComponent(panel); + //this.setComponentAlignment(panel, Alignment.MIDDLE_CENTER); + + bestätigen.addClickListener(e -> { + String benutzer = benutzername.getValue(); + String nachname = nachnameTxt.getValue(); + String vorname = vornameTxt.getValue(); + Date gebDate = bday.getValue(); + int fBereich = (int) fachbereich.getConvertedValue(); + String email = emailTxt.getValue(); + String emailwdh = emailTxtWdh.getValue(); + String passwort = passwortTxt.getValue(); + String passwortWdh = passwortTxtWdh.getValue(); + UI.getCurrent().getNavigator().navigateTo(Views.REGISTRIERUNGSBESTAETIGUNG); + + //Anbindungstestblock. svolle2s + //RegistrationControl.init(new String[]{nachname, vorname, email, emailwdh, passwort, passwortWdh, benutzer,}); // diverse Daten fehlen siehe bday fachbereich + RegistrationControl.init(benutzer, nachname, vorname, gebDate, fBereich, email, emailwdh, passwort, passwortWdh); + + System.out.println(benutzer); + System.out.println(nachname); + System.out.println(vorname); + System.out.println(gebDate); + System.out.println(email); + System.out.println(emailwdh); + System.out.println(passwort); + System.out.println(passwortWdh); + System.out.println(fBereich); + + // Weiterleitung auf Bestätigunsseite }); abbruch.addClickListener(e -> { UI.getCurrent().getNavigator().navigateTo(Views.WELCOME); }); - - super.setUpFooterAndHeader(panel); + + super.setUpFooterAndHeader(panel); } } diff --git a/src/main/java/org/s4s/gui/views/ShopErstellung.java b/src/main/java/org/s4s/gui/views/ShopErstellung.java index eb7996615523dab9db911cf457d25789cc8c5a6b..ecba07ed7bd367a7d5a45311ab14d08c1b708941 100644 --- a/src/main/java/org/s4s/gui/views/ShopErstellung.java +++ b/src/main/java/org/s4s/gui/views/ShopErstellung.java @@ -8,6 +8,7 @@ import com.vaadin.ui.Button; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.Notification; import com.vaadin.ui.Panel; import com.vaadin.ui.TextField; import com.vaadin.ui.UI; @@ -16,6 +17,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import org.s4s.exceptions.OwnsAlreadyShop; import org.s4s.process.control.ShopControl; +import org.s4s.services.util.Roles; import org.s4s.services.util.Views; /** @@ -28,6 +30,10 @@ public class ShopErstellung extends TemplateView implements View { @Override public void enter(ViewChangeListener.ViewChangeEvent event) { + if (session.getAttribute(Roles.CURRENTUSER) == null) { + UI.getCurrent().getNavigator().navigateTo(Views.LOGIN); + Notification.show(null, "Einloggen, um einen Shop erstellen zu können!", Notification.Type.WARNING_MESSAGE); + } this.setUp(); } diff --git a/src/main/java/org/s4s/gui/views/SucheView.java b/src/main/java/org/s4s/gui/views/SucheView.java index d750d272ae44b28c53f006071026ac5e65518ad0..ee21d12e1fbd911da3a2985be355d780c617c5c3 100644 --- a/src/main/java/org/s4s/gui/views/SucheView.java +++ b/src/main/java/org/s4s/gui/views/SucheView.java @@ -84,10 +84,15 @@ public class SucheView extends TemplateView { if (this.product == null) { Notification.show(null, "Bitte Produkt(e) auswählen!", Notification.Type.HUMANIZED_MESSAGE); } else { - warenkorb.add(product); - Notification.show(null, product.getName() + " wurde in den Warenkorb hinzugefügt!", - Notification.Type.WARNING_MESSAGE); - System.out.println(warenkorb.getAnzahl()); + if (warenkorb.contains(product)) { + Notification.show(null, product.getName() + " befindet sich schon in Ihrem Warenkorb!", + Notification.Type.WARNING_MESSAGE); + } else { + warenkorb.add(product); + Notification.show(null, product.getName() + " wurde in den Warenkorb hinzugefügt!", + Notification.Type.WARNING_MESSAGE); + System.out.println(warenkorb.getAnzahl()); + } } }); addComponent(addButton); @@ -122,6 +127,9 @@ public class SucheView extends TemplateView { table.addItemClickListener((ItemClickEvent event) -> { BeanItem<Product> productBean = data.getItem(event.getItemId()); product = productBean.getBean(); + if (event.isDoubleClick()) { + UI.getCurrent().getNavigator().navigateTo(Views.ARTIKELDETAILS + "/" + product.getId()); + } }); } } diff --git a/src/main/java/org/s4s/gui/views/VerkaeuferbewertungView.java b/src/main/java/org/s4s/gui/views/VerkaeuferbewertungView.java index 531a43ef9afacf514ced340bb0111f88c88c1742..7221fa0d4dcc10018972daf4d1b30f19dd38d28b 100644 --- a/src/main/java/org/s4s/gui/views/VerkaeuferbewertungView.java +++ b/src/main/java/org/s4s/gui/views/VerkaeuferbewertungView.java @@ -1,6 +1,10 @@ package org.s4s.gui.views; import com.vaadin.navigator.ViewChangeListener; +import com.vaadin.ui.Notification; +import com.vaadin.ui.UI; +import org.s4s.services.util.Roles; +import org.s4s.services.util.Views; /** * @@ -10,6 +14,11 @@ public class VerkaeuferbewertungView extends TemplateView { @Override public void enter(ViewChangeListener.ViewChangeEvent event) { + if (session.getAttribute(Roles.CURRENTUSER) == null) { + UI.getCurrent().getNavigator().navigateTo(Views.LOGIN); + Notification.show(null, "Einloggen, um einen Verkäufer bewerten zu können!", + Notification.Type.WARNING_MESSAGE); + } this.setUp(); } diff --git a/src/main/java/org/s4s/gui/views/WarenkorbView.java b/src/main/java/org/s4s/gui/views/WarenkorbView.java index 419e2dd38620000fe897bf398c9f9eaad591d977..127a8c3f27a693d5699f1b7ecc7926e85250a24f 100644 --- a/src/main/java/org/s4s/gui/views/WarenkorbView.java +++ b/src/main/java/org/s4s/gui/views/WarenkorbView.java @@ -30,14 +30,14 @@ public class WarenkorbView extends TemplateView { @Override public void enter(ViewChangeListener.ViewChangeEvent event) { - this.setUp(); - } - - public void setUp() { if (session.getAttribute(Roles.CURRENTUSER) == null) { UI.getCurrent().getNavigator().navigateTo(Views.LOGIN); Notification.show(null, "Einloggen, um auf den Warenkorb zuzugreifen!", Notification.Type.WARNING_MESSAGE); } + this.setUp(); + } + + public void setUp() { final VerticalLayout contentLayout = new VerticalLayout(); super.setUpFooterAndHeader(contentLayout); diff --git a/src/main/java/org/s4s/modell/dto/Product.java b/src/main/java/org/s4s/modell/dto/Product.java index 3bc792e652e4331d9ecbb021a196009deb6369a6..9fc8e510da019dbd98cb17cbfe1d5cd6a282907d 100644 --- a/src/main/java/org/s4s/modell/dto/Product.java +++ b/src/main/java/org/s4s/modell/dto/Product.java @@ -14,6 +14,7 @@ public class Product { private double price; private Integer id; private String typ; + private int shopId; public Product(String name, Integer id, String typ, double price, String description) { this.name = name; @@ -23,6 +24,15 @@ public class Product { this.description = description; } + public Product(String name, Integer id, String typ, double price, String description, int shopId) { + this.name = name; + this.id = id; + this.typ = typ; + this.price = price; + this.description = description; + this.shopId = shopId; + } + public Product() { } @@ -96,4 +106,11 @@ public class Product { this.description = description; } + public int getShopId() { + return shopId; + } + + public void setShopId(int shopId) { + this.shopId = shopId; + } } diff --git a/src/main/java/org/s4s/modell/dto/User.java b/src/main/java/org/s4s/modell/dto/User.java index 271e9cc912b6c25b3aeba8bff0a0c691cb39f806..4dd5c822ce3a897a41daece10d366768d0952e1d 100644 --- a/src/main/java/org/s4s/modell/dto/User.java +++ b/src/main/java/org/s4s/modell/dto/User.java @@ -12,14 +12,17 @@ public class User { private int fachbereichId; private String vorname; private String nachname; - - private final String benutzername; + private String benutzername; public User(String benutzername, int userId) { this.benutzername = benutzername; this.userId = userId; } + public User() { + + } + public int getUserId() { return userId; } diff --git a/src/main/java/org/s4s/process/control/ProductSearch.java b/src/main/java/org/s4s/process/control/ProductSearch.java index e1d347846c7f5c81dbb6c2ca8bba4d23fb91a372..87c7fd39f7e354169e28a4439397443ac48e68ab 100644 --- a/src/main/java/org/s4s/process/control/ProductSearch.java +++ b/src/main/java/org/s4s/process/control/ProductSearch.java @@ -8,6 +8,7 @@ import org.s4s.dao.ProductDAO; import org.s4s.dao.impl.AbstractDatabaseClass; import org.s4s.exceptions.DAOException; import org.s4s.modell.dto.Product; +import org.s4s.modell.dto.Shop; /** * @@ -40,8 +41,9 @@ public class ProductSearch extends AbstractDatabaseClass implements ProductDAO { String kategorie = set.getString("kategorie"); double price = set.getDouble("preis"); String description = set.getString("beschreibung"); + int shopId = set.getInt("shopid"); - Product p = new Product(name, id, kategorie, price, description); + Product p = new Product(name, id, kategorie, price, description, shopId); liste.add(p); } } catch (SQLException ex) { @@ -62,8 +64,9 @@ public class ProductSearch extends AbstractDatabaseClass implements ProductDAO { String kategorie = set.getString("kategorie"); double price = set.getDouble("preis"); String description = set.getString("beschreibung"); + int shopId = set.getInt("shopid"); - Product p = new Product(name, id, kategorie, price, description); + Product p = new Product(name, id, kategorie, price, description, shopId); liste.add(p); } } catch (SQLException ex) { @@ -84,12 +87,14 @@ public class ProductSearch extends AbstractDatabaseClass implements ProductDAO { String kategorie = set.getString("kategorie"); double price = set.getDouble("preis"); String description = set.getString("beschreibung"); + int shopId = set.getInt("shopid"); p.setName(name); p.setId(pId); p.setTyp(kategorie); p.setPrice(price); p.setDescription(description); + p.setShopId(shopId); } } catch (SQLException ex) { throw new DAOException(ex); @@ -97,4 +102,24 @@ public class ProductSearch extends AbstractDatabaseClass implements ProductDAO { return p; } + // Noch fertig zu stellen!!!!!!!!! + @Override + public Shop getProductOwner(Product product) throws DAOException { + Shop s = new Shop(); + try (ResultSet set = executeQuery("SELECT *" + + " FROM \"ERR\".\"shop\" s, \"ERR\".\"artikel\" a" + + " WHERE s.shopid = a.shopid AND a.shopid = ('" + product.getShopId() + "');")) { + if (set.next()) { + int shopId = set.getInt("shopid"); + String name = set.getString("name"); + + s.setShopId(shopId); + s.setName(name); + + } + } catch (SQLException ex) { + throw new DAOException(ex); + } + return s; + } } diff --git a/src/main/java/org/s4s/process/control/RegistrationControl.java b/src/main/java/org/s4s/process/control/RegistrationControl.java index 5283da00b58d8c5eb51f34adcecb1c81cee78def..dfa49a1c6d4396589d498859fa4bed6f88ea2a37 100644 --- a/src/main/java/org/s4s/process/control/RegistrationControl.java +++ b/src/main/java/org/s4s/process/control/RegistrationControl.java @@ -3,27 +3,22 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.s4s.dao.impl; +package org.s4s.process.control; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.commons.validator.routines.EmailValidator; import org.s4s.dao.RegistrationDAO; import org.s4s.exceptions.WrongInputException; - /** * * @author Simon */ public class RegistrationControl { + //User-Block private static String email; private static RegistrationDAO regDAO = new RegistrationDAO(); - - - + /** * * @param benutzer @@ -36,59 +31,56 @@ public class RegistrationControl { * @param passwort * @param passwortWdh */ - public static void init(String benutzer, String nachname, String vorname, java.util.Date gebDate, int fBereich, String email, String emailwdh, String passwort, String passwortWdh) { - - + try { - if(!passwort.equals(passwortWdh)) { - throw new WrongInputException("Passwort entspricht nicht den Anforderungen!"); - } - - if(!email.equals(emailwdh) && !emailValidator()) { - throw new WrongInputException("Email-Adressen stimmen nicht überein oder sind nicht gültig!"); - } - if (!nameValidator(nachname)) { - throw new WrongInputException("Nachname enthält ungültige Zeichen!"); - } - - if (!nameValidator(vorname)) { - throw new WrongInputException("Vorname enthält ungültige Zeichen!"); - } - - if (!passwordValidator(passwort)) { - throw new WrongInputException("Passwort ungültig!"); - } - } catch(WrongInputException w) { + if (!passwort.equals(passwortWdh)) { + throw new WrongInputException("Passwort entspricht nicht den Anforderungen!"); + } + + if (!email.equals(emailwdh) && !emailValidator()) { + throw new WrongInputException("Email-Adressen stimmen nicht überein oder sind nicht gültig!"); + } + if (!nameValidator(nachname)) { + throw new WrongInputException("Nachname enthält ungültige Zeichen!"); + } + + if (!nameValidator(vorname)) { + throw new WrongInputException("Vorname enthält ungültige Zeichen!"); + } + + if (!passwordValidator(passwort)) { + throw new WrongInputException("Passwort ungültig!"); + } + } catch (WrongInputException w) { w.printStackTrace(); System.out.println("Exception occur: " + w.getMessage()); } - regDAO.addUser(benutzer, nachname, vorname, gebDate, fBereich, email, emailwdh, passwort, passwortWdh); + regDAO.addUser(benutzer, nachname, vorname, gebDate, fBereich, email, emailwdh, passwort, passwortWdh); } - - + public static boolean nameValidator(String toValidate) { - //wenn Eingabe falsch -> Notification - - for (int i = 0; i < toValidate.length(); ++i) { - if (!Character.isLetter(toValidate.charAt(i))) { - return false; - } - } - return true; + //wenn Eingabe falsch -> Notification + + for (int i = 0; i < toValidate.length(); ++i) { + if (!Character.isLetter(toValidate.charAt(i))) { + return false; + } + } + return true; } - + public static boolean emailValidator() { return EmailValidator.getInstance().isValid(email); } - + public static boolean passwordValidator(String passwort) { - + return passwort.length() > 8; /* String regex = "^.*(?=.{8,})(?=..*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&+=]).*$"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(passwort); return m.matches(); */ } - + }