2 * Copyright (C) 2016 - 2022 Free Software Foundation
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.
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.
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/>.
17 package org.mxchange.pizzaapplication.application;
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;
31 * Main application class
33 * @author Roland Häder<roland@mxchange.org>
35 public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication {
40 public PizzaServiceApplication () {
42 this.getLogger().logTrace("CALLED!"); //NOI18N
46 public void doAdminAddCategory (final Category category) throws CategoryTitleAlreadyUsedException {
48 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
50 // category must not be null
51 if (null == category) {
53 throw new NullPointerException("category is null"); //NOI18N
57 String title = category.getCategoryTitle();
58 Category parentCategory = category.getParentCategory();
61 this.getLogger().logDebug(MessageFormat.format("title={0},parentCategory={1}", title, parentCategory)); //NOI18N
63 // Init variables for casting
69 throw new IllegalArgumentException("title is not set."); //NOI18N
70 } else if (title.isEmpty()) {
72 throw new IllegalArgumentException("title is empty."); //NOI18N
73 } else if (null == parentCategory) {
75 throw new IllegalArgumentException("parentCategory is null."); //NOI18N
78 // Try to check if title is used already
79 if (this.isCategoryTitleUsed(category)) {
81 throw new CategoryTitleAlreadyUsedException(category);
85 throw new UnsupportedOperationException("Unfinished method.");
88 //* NOISY-DEBUG: */ System.out.println("EXIT!"); //NOI18N
92 public void doAdminAddProduct (final Product product) throws ProductTitleAlreadyUsedException {
94 this.getLogger().logTrace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
96 // product must not be null
97 if (null == product) {
99 throw new NullPointerException("product is null"); //NOI18N
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();
109 this.getLogger().logDebug(MessageFormat.format("title={0},price={1},id={2},available={3}", title, price, id, available)); //NOI18N
114 throw new IllegalArgumentException("product title is not set"); //NOI18N
115 } else if (title.isEmpty()) {
117 throw new IllegalArgumentException("product title is empty"); //NOI18N
118 } else if (null == price) {
120 throw new IllegalArgumentException("product price is not set."); //NOI18N
121 } else if (null == id) {
123 throw new IllegalArgumentException("product category id is not set."); //NOI18N
124 } else if (id == 0) {
126 throw new IllegalArgumentException("product category id is zero."); //NOI18N
127 } else if (null == available) {
129 throw new IllegalArgumentException("product availability not set."); //NOI18N
132 // Try to check if title is used already
133 if (this.isProductTitleUsed(product)) {
134 // Title already used
135 throw new ProductTitleAlreadyUsedException(product);
139 throw new UnsupportedOperationException("Unfinished method.");
142 //* NOISY-DEBUG: */ System.out.println("EXIT!"); //NOI18N
146 public void doBootstrap () {
147 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
151 public void doMainLoop () {
152 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
156 public void doShutdown () {
157 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
161 public Deque<Category> getAllCategories () {
163 throw new UnsupportedOperationException("Unfinished method.");
167 @SuppressWarnings ("unchecked")
168 public Iterator<Category> getAllCategoriesIterator () {
170 this.getLogger().logTrace("CALLED!"); //NOI18N
173 throw new UnsupportedOperationException("Unfinished method.");
177 public Deque<Product> getAllProducts () {
179 throw new UnsupportedOperationException("Unfinished method.");
183 @SuppressWarnings ("unchecked")
184 public Iterator<Product> getAllProductsIterator () {
186 this.getLogger().logTrace("CALLED!"); //NOI18N
189 throw new UnsupportedOperationException("Unfinished method.");
193 public Deque<Product> getAvailableProducts () {
195 throw new UnsupportedOperationException("Unfinished method.");
199 @SuppressWarnings ("unchecked")
200 public Iterator<Product> getAvailableProductsIterator () {
202 this.getLogger().logTrace("CALLED!"); //NOI18N
205 throw new UnsupportedOperationException("Unfinished method.");
209 public void init () throws SQLException {
211 this.getLogger().logTrace("CALLED!"); //NOI18N
213 // Is the bundle initialized?
214 if (!BaseFrameworkSystem.isBundledInitialized()) {
215 // Temporary initialize default bundle
216 // TODO The enum Gender uses this
221 this.getLogger().logTrace("EXIT!"); //NOI18N
225 * Checks whether given category title is already used
227 * @param title Title of category to check
229 * @return Whether it has been found
231 private boolean isCategoryTitleUsed (final String title) {
233 this.getLogger().logTrace(MessageFormat.format("title={0} - CALLED!", title)); //NOI18N
236 throw new UnsupportedOperationException("Unfinished method.");
240 * Checks if category's title is already used.
242 * @param category Category instance
244 * @return Whether the product title is already used
246 private boolean isCategoryTitleUsed (final Category category) {
248 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
251 String title = category.getCategoryTitle();
253 // category must not be null and "title" must be found and non-empty
254 if (null == category) {
256 throw new NullPointerException("category is null"); //NOI18N
257 } else if (null == title) {
259 throw new IllegalArgumentException("category title is not set."); //NOI18N
260 } else if (title.isEmpty()) {
262 throw new IllegalArgumentException("category title is empty."); //NOI18N
265 // Default is not used
266 boolean isUsed = this.isCategoryTitleUsed(title);
269 this.getLogger().logTrace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
276 * Checks if product's title is already used.
278 * @param product Product instance
280 * @return Whether the product title is already used
282 private boolean isProductTitleUsed (final Product product) {
284 this.getLogger().logTrace(MessageFormat.format("category={0} - CALLED!", product)); //NOI18N
287 String title = product.getProductTitle();
289 // category must not be null and "title" must be found and non-empty
290 if (null == product) {
292 throw new NullPointerException("category is null"); //NOI18N
293 } else if (null == title) {
295 throw new IllegalArgumentException("product title is not set"); //NOI18N
296 } else if (title.isEmpty()) {
298 throw new IllegalArgumentException("product title is empty"); //NOI18N
301 // Default is not used
303 throw new UnsupportedOperationException("not finished yet.");
306 //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N