diff options
-rw-r--r-- | Week9/com.camilstaps.shop.png | bin | 0 -> 312239 bytes | |||
-rw-r--r-- | Week9/solution.tex | 60 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/Article.java | 10 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/Cart.java | 7 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/Database.java | 3 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/Order.java | 2 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/Shell.java | 54 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/User.java | 18 | ||||
-rw-r--r-- | Week9/src/com/camilstaps/shop/UserInteraction.java | 2 | ||||
-rw-r--r-- | Week9/uml-project.vpp | bin | 508928 -> 509952 bytes |
10 files changed, 106 insertions, 50 deletions
diff --git a/Week9/com.camilstaps.shop.png b/Week9/com.camilstaps.shop.png Binary files differnew file mode 100644 index 0000000..9cfc89b --- /dev/null +++ b/Week9/com.camilstaps.shop.png diff --git a/Week9/solution.tex b/Week9/solution.tex index eff9370..f6c46b7 100644 --- a/Week9/solution.tex +++ b/Week9/solution.tex @@ -4,6 +4,7 @@ \usepackage[hidelinks]{hyperref} \usepackage[dutch]{babel} \usepackage[utf8]{inputenc} +\usepackage{graphicx} \usepackage{fourier} \author{Camil Staps} @@ -32,4 +33,63 @@ We gebruiken geen database backend maar een aantal bestanden die lokaal opgeslag \item[Beheer] Het zal niet mogelijk zijn bestaande artikelen aan te passen. In plaats daarvan zal de beheerder ófwel de lokale bestanden die als database fungeren handmatig moeten aanpassen, of het artikel moeten verwijderen en een nieuw artikel in de plaats zetten. Het zal niet mogelijk zijn personen voor bepaalde tijd te blokkeren, waarbij ze automatisch worden gedeblokkeerd. Het zal wel mogelijk zijn personen handmatig te (de)blokkeren. De beheerder zal geen gebruikers kunnen toevoegen. Gebruikers worden geacht zich zelf te registreren. \end{description} +\section*{UML-schema's} + +\begin{figure}[h] +\centering +\includegraphics[width=\linewidth]{{com.camilstaps.shop}.png} +\caption{Klassediagram} +\end{figure} + +\section*{Interface} +Bij het opstarten van het programma wordt een Shell-achtige interface getoond. Een overzicht van de beschikbare commando's: + +\subsection*{Sessiebeheer} +\begin{description} +\item[login] Inloggen als gebruiker. +\item[logout] Uitloggen (inloggen vereist). +\item[exit] De Shell verlaten en de Database opslaan. +\end{description} + +\subsection*{Artikelen} +\begin{description} +\item[addArticle] Artikel toevoegen (inloggen vereist). +\item[setArticleDescription] De beschrijving van een artikel veranderen, dan wel toevoegen (inloggen vereist). +\item[setArticleMultimedia] Het multimedia bestand gelinkt aan een artikel veranderen, dan wel een multimedia bestand linken (inloggen vereist). +\item[removeArticle] Artikel verwijderen (inloggen vereist). +\item[listArticles] Overzicht van de artikelen in de database weergeven. +\item[searchArticle] Zoek een artikel met een regular expression op de naam en beschrijving. +\item[showArticle] Toon gedetailleerde informatie over een artikel. +\end{description} + +\subsection*{Categorieën} +\begin{description} +\item[addCategory] Categorie toevoegen (inloggen als administrator vereist). +\item[listCategories] Overzicht van de categorieën weergeven. +\end{description} + +\subsection*{Winkelwagen} +\begin{description} +\item[addToCart] Voeg een artikel toe aan de winkelwagen (inloggen vereist). +\item[listCart] Toon een overzicht van de winkelwagen (inloggen vereist). +\item[removeFromCart] Verwijder een artikel uit de winkelwagen (inloggen vereist). +\item[clearCart] Verwijder alle artikelen uit de winkelwagen (inloggen vereist). +\item[checkout] Ga door naar de kassa. +\end{description} + +\subsection*{Bestellingen} +\begin{description} +\item[listOrders] Toon een overzicht van de bestellingen (inloggen vereist). +\item[showOrder] Toon gedetailleerde informatie over een bestelling (inloggen vereist). +\item[setOrderPaid] Geef aan dat een bestelling betaald is (inloggen als administrator vereist). +\end{description} + +\subsection*{Gebruikers (zie ook Sessiebeheer bovenaan)} +\begin{description} +\item[register] Registreer een nieuwe gebruiker. De eerste gebruiker toegevoegd is altijd administrator. +\item[listUsers] Overzicht van de gebruikers weergeven. Administrators krijgen een geavanceerd overzicht, waarbij emailadressen worden weergegeven, `\texttt{++}' administrators aanduidt, en `\texttt{-!-}' geblokkeerde gebruikers aanduidt. +\item[blockUser] Blokkeer een gebruiker (inloggen als administrator vereist). +\item[unblockUser] Deblokkeer een gebruiker (inloggen als administrator vereist). +\end{description} + \end{document}
\ No newline at end of file diff --git a/Week9/src/com/camilstaps/shop/Article.java b/Week9/src/com/camilstaps/shop/Article.java index 92b496f..d22a323 100644 --- a/Week9/src/com/camilstaps/shop/Article.java +++ b/Week9/src/com/camilstaps/shop/Article.java @@ -23,9 +23,9 @@ public class Article extends DatabaseItem { private final float price; /** - * The user who added the article + * The owner who added the article */ - private final User user; + private final User owner; /** * Straightforwardly creating a new article @@ -35,14 +35,14 @@ public class Article extends DatabaseItem { * @param price */ public Article(User user, String name, Category category, float price) { - this.user = user; + this.owner = user; this.name = name; this.category = category; this.price = price; } - public User getUser() { - return user; + public User getOwner() { + return owner; } public String getName() { diff --git a/Week9/src/com/camilstaps/shop/Cart.java b/Week9/src/com/camilstaps/shop/Cart.java index 6c2b836..74f6ccd 100644 --- a/Week9/src/com/camilstaps/shop/Cart.java +++ b/Week9/src/com/camilstaps/shop/Cart.java @@ -63,12 +63,5 @@ public class Cart implements Serializable { remove(a); } } - - /** - * Remove all articles, but don't put them back in the database - */ - public void clear() { - articles.clear(); - } }
\ No newline at end of file diff --git a/Week9/src/com/camilstaps/shop/Database.java b/Week9/src/com/camilstaps/shop/Database.java index b04eaf5..8344bca 100644 --- a/Week9/src/com/camilstaps/shop/Database.java +++ b/Week9/src/com/camilstaps/shop/Database.java @@ -37,6 +37,9 @@ public class Database { /** * Files to store the database + * Considering backups, it's nicer to have different objects stored in + * different files, so that if the Orders file breaks, we still have the + * Users, etc. */ private final File FILE_DB = new File("./db"); private final File FILE_USERS = new File("./db/users.db"); diff --git a/Week9/src/com/camilstaps/shop/Order.java b/Week9/src/com/camilstaps/shop/Order.java index 92d04d7..2b0c5a7 100644 --- a/Week9/src/com/camilstaps/shop/Order.java +++ b/Week9/src/com/camilstaps/shop/Order.java @@ -29,7 +29,7 @@ public class Order extends DatabaseItem { for (Article a : user.getCart().getArticles()) { articles.add(a); } - user.getCart().clear(); + user.getCart().getArticles().clear(); } public User getUser() { diff --git a/Week9/src/com/camilstaps/shop/Shell.java b/Week9/src/com/camilstaps/shop/Shell.java index 69d5207..7939963 100644 --- a/Week9/src/com/camilstaps/shop/Shell.java +++ b/Week9/src/com/camilstaps/shop/Shell.java @@ -51,11 +51,11 @@ public class Shell { return; } } catch (NoSuchMethodException ex) { - ui.putStringLn("Failure: no such command"); + ui.putStringln("Failure: no such command"); } catch (InvocationTargetException ex) { - ui.putStringLn("Failure: " + ex.getCause().toString()); + ui.putStringln("Failure: " + ex.getCause().toString()); } catch (SecurityException | IllegalAccessException | IllegalArgumentException ex) { - ui.putStringLn("Failure: unknown error"); + ui.putStringln("Failure: unknown error"); } } } @@ -67,7 +67,7 @@ public class Shell { */ public void requireLogin() throws LoginRequiredException, ItemNotFoundException { if (user == null) { - ui.putStringLn("You must login first."); + ui.putStringln("You must login first."); try { execLogin(); @@ -87,7 +87,7 @@ public class Shell { */ public void requireAdmin() throws AdminRequiredException, ItemNotFoundException { if (user == null || !user.isAdmin()) { - ui.putStringLn("You must login as an administrator first."); + ui.putStringln("You must login as an administrator first."); try { execLogin(); @@ -180,7 +180,7 @@ public class Shell { */ public void execListArticles() { for (Article a : database.getArticles()) { - ui.putStringLn(a.toString()); + ui.putStringln(a.toString()); } } @@ -190,7 +190,7 @@ public class Shell { public void execSearchArticle() { String regex = ui.getString("Keywords: "); for (Article a : database.searchArticle(Pattern.compile(regex))) { - ui.putStringLn(a.toString()); + ui.putStringln(a.toString()); } } @@ -201,16 +201,16 @@ public class Shell { */ public void execShowArticle() throws InputRequiredException, ItemNotFoundException { Article a = ui.getArticle(); - ui.putStringLn(a.toString()); + ui.putStringln(a.toString()); if (a.getDescription() != null) { - ui.putStringLn(a.getDescription()); + ui.putStringln(a.getDescription()); } File multimedia = a.getMultimedia(); if (multimedia != null) { - ui.putStringLn("Multimedia: " + multimedia.getPath()); + ui.putStringln("Multimedia: " + multimedia.getPath()); } if (user != null && user.isAdmin()) { - ui.putStringLn("User: " + a.getUser().toString(true)); + ui.putStringln("User: " + a.getOwner().toString(true)); } } @@ -233,7 +233,7 @@ public class Shell { */ public void execListCategories() { for (String c : database.getCategoryNames()) { - ui.putStringLn(c); + ui.putStringln(c); } } @@ -243,7 +243,7 @@ public class Shell { */ public void execListUsers() { for (User u : database.getUsers()) { - ui.putStringLn(u.toString(user != null && user.isAdmin())); + ui.putStringln(u.toString(user != null && user.isAdmin())); } } @@ -257,7 +257,7 @@ public class Shell { if (database.getUsers().isEmpty()) { addAsAdmin = true; - ui.putStringLn("This is the first user and will therefore be added as administrator."); + ui.putStringln("This is the first user and will therefore be added as administrator."); } else if (user != null && user.isAdmin()) { addAsAdmin = ui.getBoolean("Add user as administrator"); } @@ -268,7 +268,7 @@ public class Shell { User u = new User(nr, email, addAsAdmin); String password = u.setRandomPassword(); - ui.putStringLn("Password: " + password); + ui.putStringln("Password: " + password); database.addItem(u); } @@ -280,7 +280,7 @@ public class Shell { */ public void execLogin() throws InputRequiredException, ItemNotFoundException { if (user != null) { - ui.putStringLn("You are already logged in."); + ui.putStringln("You are already logged in."); return; } @@ -288,12 +288,12 @@ public class Shell { String pw = ui.getRequiredString("Password: "); if (!u.verify(pw)) { - ui.putStringLn("Failed to login."); + ui.putStringln("Failed to login."); return; } if (u.isBlocked()) { - ui.putStringLn("You are blocked."); + ui.putStringln("You are blocked."); return; } @@ -339,10 +339,10 @@ public class Shell { requireLogin(); for (Article a : user.getCart().getArticles()) { - ui.putStringLn(a.toString()); + ui.putStringln(a.toString()); } - ui.putStringLn("Total value: " + user.getCart().getTotalAmount()); + ui.putStringln("Total value: " + user.getCart().getTotalAmount()); } /** @@ -369,14 +369,14 @@ public class Shell { throw new ItemNotFoundException(); } - ui.putStringLn("By checking out, you agree to pay the total amount."); + ui.putStringln("By checking out, you agree to pay the total amount."); if (!ui.getBoolean("Do you agree?")) return; Order order = new Order(user); database.addItem(order); - ui.putStringLn("Your order has been added as " + order.toString()); + ui.putStringln("Your order has been added as " + order.toString()); } /** @@ -394,7 +394,7 @@ public class Shell { orders = user.getOrders(); } for (Order o : orders) { - ui.putStringLn(o.toString()); + ui.putStringln(o.toString()); } } @@ -413,12 +413,12 @@ public class Shell { } else { o = ui.getOrder(user); } - ui.putStringLn(o.toString()); + ui.putStringln(o.toString()); for (Article a : o.getArticles()) { - ui.putStringLn(" " + a.toString()); + ui.putStringln(" " + a.toString()); } - ui.putStringLn("Total amount: " + o.getTotalAmount()); - ui.putStringLn("Paid: " + (o.isPaid() ? "yes" : "no")); + ui.putStringln("Total amount: " + o.getTotalAmount()); + ui.putStringln("Paid: " + (o.isPaid() ? "yes" : "no")); } /** diff --git a/Week9/src/com/camilstaps/shop/User.java b/Week9/src/com/camilstaps/shop/User.java index 5696a60..12cfd4d 100644 --- a/Week9/src/com/camilstaps/shop/User.java +++ b/Week9/src/com/camilstaps/shop/User.java @@ -51,11 +51,19 @@ public class User extends DatabaseItem { return cart; } + public void setBlocked(boolean set) { + isBlocked = set; + } + + public boolean isBlocked() { + return isBlocked; + } + public Set<Article> getArticles() { Set<Article> articles = Database.getInstance().getArticles(); Set<Article> result = new HashSet<>(); for (Article a : articles) { - if (a.getUser().getNr().equals(nr)) { + if (a.getOwner().getNr().equals(nr)) { result.add(a); } } @@ -73,14 +81,6 @@ public class User extends DatabaseItem { return result; } - public void setBlocked(boolean set) { - isBlocked = set; - } - - public boolean isBlocked() { - return isBlocked; - } - /** * Set a random new password for the user * @return the new password diff --git a/Week9/src/com/camilstaps/shop/UserInteraction.java b/Week9/src/com/camilstaps/shop/UserInteraction.java index a857f85..1140089 100644 --- a/Week9/src/com/camilstaps/shop/UserInteraction.java +++ b/Week9/src/com/camilstaps/shop/UserInteraction.java @@ -23,7 +23,7 @@ public abstract class UserInteraction { * Show a String with a linefeed * @param string */ - void putStringLn(String string) { + void putStringln(String string) { putString(string + System.lineSeparator()); } diff --git a/Week9/uml-project.vpp b/Week9/uml-project.vpp Binary files differindex fdd56f8..4357ce6 100644 --- a/Week9/uml-project.vpp +++ b/Week9/uml-project.vpp |