Skip to content
Snippets Groups Projects
Commit 4108250a authored by hkarwa2s's avatar hkarwa2s
Browse files

Super tolles Refaktorn -> entfernen unnötiger imports

Funktionen für Kategorie Unterpunkte, mit Parametern für die Produktsuche
parent 4d415678
No related branches found
No related tags found
No related merge requests found
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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 nachname;
private static String vorname;
private static String email;
private static String passwort;
private static RegistrationDAO regDAO = new RegistrationDAO();
/**
*
* @param benutzer
......@@ -39,59 +29,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()) {
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()) {
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);
}
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() {
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(); */
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.process.control;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import java.sql.SQLException;
import org.s4s.dao.ShopDAO;
import org.s4s.services.util.Roles;
import org.s4s.exceptions.OwnsAlreadyShop;
import org.s4s.modell.dto.User;
import org.s4s.services.util.Roles;
import org.s4s.services.util.Views;
/**
......@@ -19,29 +14,30 @@ import org.s4s.services.util.Views;
* @author Benjamin
*/
public class ShopControl {
private static final User user = (User) VaadinSession.getCurrent().getAttribute(Roles.CURRENTUSER);
//bekommt User aus der View übergeben und prüft ob dieser schon in der Shopdb vorhanden ist (= hat schon einen Shop).
public static void checkUserShop( String shopName, String shopBeschreibung) throws OwnsAlreadyShop, SQLException {
public static void checkUserShop(String shopName, String shopBeschreibung) throws OwnsAlreadyShop, SQLException {
boolean test = ShopDAO.getInstance().viewShop(user);
//Shop mit dem Nutzer schon vorhanden
if (test == false) {
throw new OwnsAlreadyShop("Sie besitzen bereits einen Shop!");
} //noch kein Shop vorhanden
} //noch kein Shop vorhanden
else {
addUserShop(shopName, shopBeschreibung);
addUserShop(shopName, shopBeschreibung);
}
}
private static void addUserShop(String shopName, String shopBeschreibung) throws SQLException {
boolean erstellung = ShopDAO.getInstance().addShop(user, shopName, shopBeschreibung);
if (erstellung == true){
if (erstellung == true) {
//Weiterleitung zur Shopseite, wenn Shop erfolgreich erstellt
UI.getCurrent().getNavigator().navigateTo(Views.SHOP);
UI.getCurrent().getNavigator().navigateTo(Views.SHOP);
} else {
//Fehlerhandling
throw new SQLException("Fehler beim Anlegen des Shops bitte noch einmal versuchen oder Programmierer kontaktieren!");
//Fehlerhandling
throw new SQLException("Fehler beim Anlegen des Shops bitte noch einmal versuchen oder Programmierer kontaktieren!");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.process.control;
import java.sql.ResultSet;
......
/*
* To change this license header, choose License Headers in Project Properties.
* 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 com.vaadin.ui.UI;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.s4s.dao.impl.AbstractDatabaseClass;
import org.s4s.exceptions.DAOException;
import org.s4s.modell.dto.Product;
import org.s4s.modell.dto.User;
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.services.db;
import java.sql.*;
......@@ -38,7 +33,7 @@ public class JDBCConnection {
this.openConnection();
} catch (SQLException ex) {
Logger.getLogger(JDBCConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
private void openConnection() {
......@@ -54,7 +49,7 @@ public class JDBCConnection {
Logger.getLogger(JDBCConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
public Statement getStatement() {
try {
if (this.conn.isClosed()) {
......
///*
// * To change this license header, choose License Headers in Project Properties.
// * To change this template file, choose Tools | Templates
// * and open the template in the editor.
// */
//package org.s4s.services.util;
//
//import com.vaadin.data.Validator;
//
///**
// *
// * @author synot
// */
//public class EmailValidator implements Validator {
// /**
// * Tests if the given value is valid
// * @param value the value to test
// */
// public boolean isValid(Object value) {
// try {
// validate(value);
// } catch (Validator.InvalidValueException ive) {
// return false;
// }
// return true;
// }
//
// /**
// * Validates
// * @param value the value to test
// */
// public void validate(Object value) throws Validator.InvalidValueException {
// // Here value is a String containing what *should* be an e-mail address
// if (value instanceof String) {
// String email = (String)value;
// // Match the email string against a (simplistic) regular expression matching e-mail addresses
// if (!email.matches("^[_\\w\\.\\-]+@[\\w\\.-]+\\.[a-z]{2,6}$"))
// throw new Validator.InvalidValueException("The e-mail address provided is not valid!");
// }
// }
//}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.services.util;
/**
......@@ -10,6 +5,7 @@ package org.s4s.services.util;
* @author Holger
*/
public class Roles {
public static final String CURRENTUSER = "currentUser";
public static final String HIWI = "hiWi";
public static final String STUDENT = "student";
......
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.services.util;
/**
......@@ -10,6 +5,7 @@ package org.s4s.services.util;
* @author Holger
*/
public final class Views {
public final static String REGISTRIERUNG = "registrierung";
public final static String WELCOME = "welcome";
public final static String SHOP = "shop";
......@@ -28,8 +24,8 @@ public final class Views {
public final static String SHOPERSTELLUNGSBESTAETIGUNG = "shoperstellungsbestaetigung";
public final static String REGISTRIERUNGSBESTAETIGUNG = "registrierungsbestaetigung";
public final static String KONTAKTBESTAETIGUNG = "kontaktbestaetigung";
private Views(){
private Views() {
}
}
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