]> git.mxchange.org Git - pizzaservice-swing.git/blob - src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
updated jars
[pizzaservice-swing.git] / src / org / mxchange / pizzaapplication / application / PizzaServiceApplication.java
1 /*
2  * Copyright (C) 2015 Roland Haeder
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.pizzaapplication.application;
18
19 import java.sql.SQLException;
20 import java.text.MessageFormat;
21 import java.util.Deque;
22 import java.util.Iterator;
23 import org.mxchange.jcore.BaseFrameworkSystem;
24 import org.mxchange.jshopcore.exceptions.CategoryTitleAlreadyUsedException;
25 import org.mxchange.jshopcore.exceptions.ProductTitleAlreadyUsedException;
26 import org.mxchange.jshopcore.model.category.Category;
27 import org.mxchange.jshopcore.model.product.Product;
28
29 /**
30  * Main application class
31  *
32  * @author Roland Haeder<roland@mxchange.org>
33  */
34 public class PizzaServiceApplication extends BaseFrameworkSystem implements PizzaApplication {
35         /**
36          * Default constructor
37          */
38         public PizzaServiceApplication () {
39                 // Trace message
40                 this.getLogger().trace("CALLED!"); //NOI18N
41         }
42
43         @Override
44         public Deque<Category> getAllCategories () {
45                 // Unfinished
46                 throw new UnsupportedOperationException("Unfinished method.");
47         }
48
49         @Override
50         public Deque<Product> getAllProducts () {
51                 // Unfinished
52                 throw new UnsupportedOperationException("Unfinished method.");
53         }
54
55         @Override
56         public Deque<Product> getAvailableProducts () {
57                 // Unfinished
58                 throw new UnsupportedOperationException("Unfinished method.");
59         }
60
61         @Override
62         public void init () throws SQLException {
63                 // Trace message
64                 this.getLogger().trace("CALLED!"); //NOI18N
65
66                 // Is the bundle initialized?
67                 if (!BaseFrameworkSystem.isBundledInitialized()) {
68                         // Temporary initialize default bundle
69                         // TODO The enum Gender uses this
70                         this.initBundle();
71                 }
72
73                 // Trace message
74                 this.getLogger().trace("EXIT!"); //NOI18N
75         }
76
77         @Override
78         public void doBootstrap () {
79                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
80         }
81
82         @Override
83         public void doMainLoop () {
84                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
85         }
86
87         @Override
88         public void doShutdown () {
89                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
90         }
91
92         @Override
93         @SuppressWarnings ("unchecked")
94         public Iterator<Product> getAvailableProductsIterator () {
95                 // Trace message
96                 this.getLogger().trace("CALLED!"); //NOI18N
97
98                 // Unfinished
99                 throw new UnsupportedOperationException("Unfinished method.");
100         }
101
102         @Override
103         @SuppressWarnings ("unchecked")
104         public Iterator<Product> getAllProductsIterator () {
105                 // Trace message
106                 this.getLogger().trace("CALLED!"); //NOI18N
107
108                 // Unfinished
109                 throw new UnsupportedOperationException("Unfinished method.");
110         }
111
112         @Override
113         @SuppressWarnings ("unchecked")
114         public Iterator<Category> getAllCategoriesIterator () {
115                 // Trace message
116                 this.getLogger().trace("CALLED!"); //NOI18N
117
118                 // Unfinished
119                 throw new UnsupportedOperationException("Unfinished method.");
120         }
121
122         /**
123          * Checks whether given category title is already used
124          *
125          * @param title Title of category to check
126          * @return Whether it has been found
127          */
128         private boolean isCategoryTitleUsed(final String title) {
129                 // Trace message
130                 this.getLogger().trace("title=" + title + " - CALLED!"); //NOI18N
131
132                 // Unfinished
133                 throw new UnsupportedOperationException("Unfinished method.");
134         }
135
136         @Override
137         public void doAdminAddCategory (final Category category) throws CategoryTitleAlreadyUsedException {
138                 // Trace message
139                 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
140
141                 // category must not be null
142                 if (null == category) {
143                         // Is null
144                         throw new NullPointerException("category is null"); //NOI18N
145                 }
146
147                 // Get all fields
148                 String title = category.getTitle();
149                 Long parentId = category.getParentId();
150
151                 // Debug message
152                 this.getLogger().debug(MessageFormat.format("title={0},parentId={1}", title, parentId)); //NOI18N
153
154                 // Init variables for casting
155                 Integer id = 0;
156
157                 // Check all fields
158                 if (null == title) {
159                         // "title" not set
160                         throw new IllegalArgumentException("title is not set."); //NOI18N
161                 } else if (title.isEmpty()) {
162                         // Is left empty
163                         throw new IllegalArgumentException("title is empty."); //NOI18N
164                 } else if ((parentId == null) || (parentId == 0)) {
165                         // Is left empty
166                         throw new IllegalArgumentException("parentId is empty."); //NOI18N
167                 }
168
169                 // Try to check if title is used already
170                 if (this.isCategoryTitleUsed(category)) {
171                         // Title already used
172                         throw new CategoryTitleAlreadyUsedException(category);
173                 }
174
175                 // Unfinished
176                 throw new UnsupportedOperationException("Unfinished method.");
177
178                 // Trace message
179                 //this.getLogger().trace("EXIT!"); //NOI18N
180         }
181
182         @Override
183         public void doAdminAddProduct (final Product product) throws ProductTitleAlreadyUsedException {
184                 // Trace message
185                 this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
186
187                 // product must not be null
188                 if (null == product) {
189                         // Is null
190                         throw new NullPointerException("product is null"); //NOI18N
191                 }
192
193                 // Get title, price and category id
194                 String title = product.getTitle();
195                 Float price = product.getPrice();
196                 Long id = product.getId();
197                 Boolean available = product.getAvailable();
198
199                 // Debug message
200                 this.getLogger().debug(MessageFormat.format("title={0},price={1},id={2},available={3}", title, price, id, available)); //NOI18N
201
202                 // Check all fields
203                 if (null == title) {
204                         // "title" not set
205                         throw new IllegalArgumentException("product title is not set"); //NOI18N
206                 } else if (title.isEmpty()) {
207                         // Is left empty
208                         throw new IllegalArgumentException("product title is empty"); //NOI18N
209                 } else if (null == price) {
210                         // "price" not set
211                         throw new IllegalArgumentException("product price is not set."); //NOI18N
212                 } else if (null == id) {
213                         // "title" not set
214                         throw new IllegalArgumentException("product category id is not set."); //NOI18N
215                 } else if (id == 0) {
216                         // "title" not set
217                         throw new IllegalArgumentException("product category id is zero."); //NOI18N
218                 } else if (null == available) {
219                         // "title" not set
220                         throw new IllegalArgumentException("product availability not set."); //NOI18N
221                 }
222
223                 // Try to check if title is used already
224                 if (this.isProductTitleUsed(product)) {
225                         // Title already used
226                         throw new ProductTitleAlreadyUsedException(product);
227                 }
228
229                 // Unfinished
230                 throw new UnsupportedOperationException("Unfinished method.");
231
232                 // Trace message
233                 //this.getLogger().trace("EXIT!"); //NOI18N
234         }
235
236         /**
237          * Checks if product's title is already used.
238          * 
239          * @param product Product instance
240          * @return Whether the product title is already used
241          */
242         private boolean isProductTitleUsed (final Product product) {
243                 // Trace message
244                 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", product)); //NOI18N
245
246                 // Init title
247                 String title = product.getTitle();
248
249                 // category must not be null and "title" must be found and non-empty
250                 if (null == product) {
251                         // Abort here
252                         throw new NullPointerException("category is null"); //NOI18N
253                 } else if (null == title) {
254                         // title is not set
255                         throw new IllegalArgumentException("product title is not set"); //NOI18N
256                 } else if (title.isEmpty()) {
257                         // Is left empty
258                         throw new IllegalArgumentException("product title is empty"); //NOI18N
259                 }
260
261                 // Default is not used
262                 // TODO Call backend
263                 throw new UnsupportedOperationException("not finished yet.");
264
265                 // Trace message
266                 //this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
267
268                 // Return it
269                 //return isUsed;
270         }
271
272         /**
273          * Checks if category's title is already used.
274          * 
275          * @param category Category instance
276          * @return Whether the product title is already used
277          */
278         private boolean isCategoryTitleUsed (final Category category) {
279                 // Trace message
280                 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
281
282                 // Init title
283                 String title = category.getTitle();
284
285                 // category must not be null and "title" must be found and non-empty
286                 if (null == category) {
287                         // Abort here
288                         throw new NullPointerException("category is null"); //NOI18N
289                 } else if (null == title) {
290                         // title is not set
291                         throw new IllegalArgumentException("category title is not set."); //NOI18N
292                 } else if (title.isEmpty()) {
293                         // Is left empty
294                         throw new IllegalArgumentException("category title is empty."); //NOI18N
295                 }
296
297                 // Default is not used
298                 boolean isUsed = this.isCategoryTitleUsed(title);
299
300                 // Trace message
301                 this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
302
303                 // Return it
304                 return isUsed;
305         }
306 }