]> git.mxchange.org Git - pizzaservice-swing.git/blob - src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java
Continued a bit:
[pizzaservice-swing.git] / src / org / mxchange / pizzaapplication / application / PizzaServiceApplication.java
1 /*
2  * Copyright (C) 2016, 2017 Roland Häder
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.jproduct.exceptions.CategoryTitleAlreadyUsedException;
25 import org.mxchange.jproduct.exceptions.ProductTitleAlreadyUsedException;
26 import org.mxchange.jproduct.model.category.Category;
27 import org.mxchange.jproduct.model.product.Product;
28 import org.mxchange.pizzaapplication.BasePizzaServiceSystem;
29
30 /**
31  * Main application class
32  * <p>
33  * @author Roland Häder<roland@mxchange.org>
34  */
35 public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication {
36
37         /**
38          * Default constructor
39          */
40         public PizzaServiceApplication () {
41                 // Trace message
42                 this.getLogger().logTrace("CALLED!"); //NOI18N
43         }
44
45         @Override
46         public void doAdminAddCategory (final Category category) throws CategoryTitleAlreadyUsedException {
47                 // Trace message
48                 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
49
50                 // category must not be null
51                 if (null == category) {
52                         // Is null
53                         throw new NullPointerException("category is null"); //NOI18N
54                 }
55
56                 // Get all fields
57                 String title = category.getCategoryTitle();
58                 Category parentCategory = category.getParentCategory();
59
60                 // Debug message
61                 this.getLogger().logDebug(MessageFormat.format("title={0},parentCategory={1}", title, parentCategory)); //NOI18N
62
63                 // Init variables for casting
64                 Integer id = 0;
65
66                 // Check all fields
67                 if (null == title) {
68                         // "title" not set
69                         throw new IllegalArgumentException("title is not set."); //NOI18N
70                 } else if (title.isEmpty()) {
71                         // Is left empty
72                         throw new IllegalArgumentException("title is empty."); //NOI18N
73                 } else if (null == parentCategory) {
74                         // Is left empty
75                         throw new IllegalArgumentException("parentCategory is null."); //NOI18N
76                 }
77
78                 // Try to check if title is used already
79                 if (this.isCategoryTitleUsed(category)) {
80                         // Title already used
81                         throw new CategoryTitleAlreadyUsedException(category);
82                 }
83
84                 // Unfinished
85                 throw new UnsupportedOperationException("Unfinished method.");
86
87                 // Trace message
88                 //* NOISY-DEBUG: */ System.out.println("EXIT!"); //NOI18N
89         }
90
91         @Override
92         public void doAdminAddProduct (final Product product) throws ProductTitleAlreadyUsedException {
93                 // Trace message
94                 this.getLogger().logTrace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
95
96                 // product must not be null
97                 if (null == product) {
98                         // Is null
99                         throw new NullPointerException("product is null"); //NOI18N
100                 }
101
102                 // Get title, price and category id
103                 String title = product.getProductTitle();
104                 Float price = product.getProductPrice();
105                 Long id = product.getProductId();
106                 Boolean available = product.getProductAvailability();
107
108                 // Debug message
109                 this.getLogger().logDebug(MessageFormat.format("title={0},price={1},id={2},available={3}", title, price, id, available)); //NOI18N
110
111                 // Check all fields
112                 if (null == title) {
113                         // "title" not set
114                         throw new IllegalArgumentException("product title is not set"); //NOI18N
115                 } else if (title.isEmpty()) {
116                         // Is left empty
117                         throw new IllegalArgumentException("product title is empty"); //NOI18N
118                 } else if (null == price) {
119                         // "price" not set
120                         throw new IllegalArgumentException("product price is not set."); //NOI18N
121                 } else if (null == id) {
122                         // "title" not set
123                         throw new IllegalArgumentException("product category id is not set."); //NOI18N
124                 } else if (id == 0) {
125                         // "title" not set
126                         throw new IllegalArgumentException("product category id is zero."); //NOI18N
127                 } else if (null == available) {
128                         // "title" not set
129                         throw new IllegalArgumentException("product availability not set."); //NOI18N
130                 }
131
132                 // Try to check if title is used already
133                 if (this.isProductTitleUsed(product)) {
134                         // Title already used
135                         throw new ProductTitleAlreadyUsedException(product);
136                 }
137
138                 // Unfinished
139                 throw new UnsupportedOperationException("Unfinished method.");
140
141                 // Trace message
142                 //* NOISY-DEBUG: */ System.out.println("EXIT!"); //NOI18N
143         }
144
145         @Override
146         public void doBootstrap () {
147                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
148         }
149
150         @Override
151         public void doMainLoop () {
152                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
153         }
154
155         @Override
156         public void doShutdown () {
157                 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
158         }
159
160         @Override
161         public Deque<Category> getAllCategories () {
162                 // Unfinished
163                 throw new UnsupportedOperationException("Unfinished method.");
164         }
165
166         @Override
167         @SuppressWarnings ("unchecked")
168         public Iterator<Category> getAllCategoriesIterator () {
169                 // Trace message
170                 this.getLogger().logTrace("CALLED!"); //NOI18N
171
172                 // Unfinished
173                 throw new UnsupportedOperationException("Unfinished method.");
174         }
175
176         @Override
177         public Deque<Product> getAllProducts () {
178                 // Unfinished
179                 throw new UnsupportedOperationException("Unfinished method.");
180         }
181
182         @Override
183         @SuppressWarnings ("unchecked")
184         public Iterator<Product> getAllProductsIterator () {
185                 // Trace message
186                 this.getLogger().logTrace("CALLED!"); //NOI18N
187
188                 // Unfinished
189                 throw new UnsupportedOperationException("Unfinished method.");
190         }
191
192         @Override
193         public Deque<Product> getAvailableProducts () {
194                 // Unfinished
195                 throw new UnsupportedOperationException("Unfinished method.");
196         }
197
198         @Override
199         @SuppressWarnings ("unchecked")
200         public Iterator<Product> getAvailableProductsIterator () {
201                 // Trace message
202                 this.getLogger().logTrace("CALLED!"); //NOI18N
203
204                 // Unfinished
205                 throw new UnsupportedOperationException("Unfinished method.");
206         }
207
208         @Override
209         public void init () throws SQLException {
210                 // Trace message
211                 this.getLogger().logTrace("CALLED!"); //NOI18N
212
213                 // Is the bundle initialized?
214                 if (!BaseFrameworkSystem.isBundledInitialized()) {
215                         // Temporary initialize default bundle
216                         // TODO The enum Gender uses this
217                         this.initBundle();
218                 }
219
220                 // Trace message
221                 this.getLogger().logTrace("EXIT!"); //NOI18N
222         }
223
224         /**
225          * Checks whether given category title is already used
226          * <p>
227          * @param title Title of category to check
228          * <p>
229          * @return Whether it has been found
230          */
231         private boolean isCategoryTitleUsed (final String title) {
232                 // Trace message
233                 this.getLogger().logTrace(MessageFormat.format("title={0} - CALLED!", title)); //NOI18N
234
235                 // Unfinished
236                 throw new UnsupportedOperationException("Unfinished method.");
237         }
238
239         /**
240          * Checks if category's title is already used.
241          * <p>
242          * @param category Category instance
243          * <p>
244          * @return Whether the product title is already used
245          */
246         private boolean isCategoryTitleUsed (final Category category) {
247                 // Trace message
248                 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
249
250                 // Init title
251                 String title = category.getCategoryTitle();
252
253                 // category must not be null and "title" must be found and non-empty
254                 if (null == category) {
255                         // Abort here
256                         throw new NullPointerException("category is null"); //NOI18N
257                 } else if (null == title) {
258                         // title is not set
259                         throw new IllegalArgumentException("category title is not set."); //NOI18N
260                 } else if (title.isEmpty()) {
261                         // Is left empty
262                         throw new IllegalArgumentException("category title is empty."); //NOI18N
263                 }
264
265                 // Default is not used
266                 boolean isUsed = this.isCategoryTitleUsed(title);
267
268                 // Trace message
269                 this.getLogger().logTrace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
270
271                 // Return it
272                 return isUsed;
273         }
274
275         /**
276          * Checks if product's title is already used.
277          * <p>
278          * @param product Product instance
279          * <p>
280          * @return Whether the product title is already used
281          */
282         private boolean isProductTitleUsed (final Product product) {
283                 // Trace message
284                 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", product)); //NOI18N
285
286                 // Init title
287                 String title = product.getProductTitle();
288
289                 // category must not be null and "title" must be found and non-empty
290                 if (null == product) {
291                         // Abort here
292                         throw new NullPointerException("category is null"); //NOI18N
293                 } else if (null == title) {
294                         // title is not set
295                         throw new IllegalArgumentException("product title is not set"); //NOI18N
296                 } else if (title.isEmpty()) {
297                         // Is left empty
298                         throw new IllegalArgumentException("product title is empty"); //NOI18N
299                 }
300
301                 // Default is not used
302                 // TODO Call backend
303                 throw new UnsupportedOperationException("not finished yet.");
304
305                 // Trace message
306                 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
307                 // Return it
308                 //return isUsed;
309         }
310 }