2 * Copyright (C) 2015 Roland Haeder
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.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;
30 * Main application class
32 * @author Roland Haeder<roland@mxchange.org>
34 public class PizzaServiceApplication extends BaseFrameworkSystem implements PizzaApplication {
38 public PizzaServiceApplication () {
40 this.getLogger().trace("CALLED!"); //NOI18N
44 public Deque<Category> getAllCategories () {
46 throw new UnsupportedOperationException("Unfinished method.");
50 public Deque<Product> getAllProducts () {
52 throw new UnsupportedOperationException("Unfinished method.");
56 public Deque<Product> getAvailableProducts () {
58 throw new UnsupportedOperationException("Unfinished method.");
62 public void init () throws SQLException {
64 this.getLogger().trace("CALLED!"); //NOI18N
66 // Is the bundle initialized?
67 if (!BaseFrameworkSystem.isBundledInitialized()) {
68 // Temporary initialize default bundle
69 // TODO The enum Gender uses this
74 this.getLogger().trace("EXIT!"); //NOI18N
78 public void doBootstrap () {
79 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
83 public void doMainLoop () {
84 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
88 public void doShutdown () {
89 throw new UnsupportedOperationException("Not supported yet."); //NOI18N
93 @SuppressWarnings ("unchecked")
94 public Iterator<Product> getAvailableProductsIterator () {
96 this.getLogger().trace("CALLED!"); //NOI18N
99 throw new UnsupportedOperationException("Unfinished method.");
103 @SuppressWarnings ("unchecked")
104 public Iterator<Product> getAllProductsIterator () {
106 this.getLogger().trace("CALLED!"); //NOI18N
109 throw new UnsupportedOperationException("Unfinished method.");
113 @SuppressWarnings ("unchecked")
114 public Iterator<Category> getAllCategoriesIterator () {
116 this.getLogger().trace("CALLED!"); //NOI18N
119 throw new UnsupportedOperationException("Unfinished method.");
123 * Checks whether given category title is already used
125 * @param title Title of category to check
126 * @return Whether it has been found
128 private boolean isCategoryTitleUsed(final String title) {
130 this.getLogger().trace("title=" + title + " - CALLED!"); //NOI18N
133 throw new UnsupportedOperationException("Unfinished method.");
137 public void doAdminAddCategory (final Category category) throws CategoryTitleAlreadyUsedException {
139 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
141 // category must not be null
142 if (null == category) {
144 throw new NullPointerException("category is null"); //NOI18N
148 String title = category.getTitle();
149 Long parentId = category.getParentId();
152 this.getLogger().debug(MessageFormat.format("title={0},parentId={1}", title, parentId)); //NOI18N
154 // Init variables for casting
160 throw new IllegalArgumentException("title is not set."); //NOI18N
161 } else if (title.isEmpty()) {
163 throw new IllegalArgumentException("title is empty."); //NOI18N
164 } else if ((parentId == null) || (parentId == 0)) {
166 throw new IllegalArgumentException("parentId is empty."); //NOI18N
169 // Try to check if title is used already
170 if (this.isCategoryTitleUsed(category)) {
171 // Title already used
172 throw new CategoryTitleAlreadyUsedException(category);
176 throw new UnsupportedOperationException("Unfinished method.");
179 //this.getLogger().trace("EXIT!"); //NOI18N
183 public void doAdminAddProduct (final Product product) throws ProductTitleAlreadyUsedException {
185 this.getLogger().trace(MessageFormat.format("product={0} - CALLED!", product)); //NOI18N
187 // product must not be null
188 if (null == product) {
190 throw new NullPointerException("product is null"); //NOI18N
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();
200 this.getLogger().debug(MessageFormat.format("title={0},price={1},id={2},available={3}", title, price, id, available)); //NOI18N
205 throw new IllegalArgumentException("product title is not set"); //NOI18N
206 } else if (title.isEmpty()) {
208 throw new IllegalArgumentException("product title is empty"); //NOI18N
209 } else if (null == price) {
211 throw new IllegalArgumentException("product price is not set."); //NOI18N
212 } else if (null == id) {
214 throw new IllegalArgumentException("product category id is not set."); //NOI18N
215 } else if (id == 0) {
217 throw new IllegalArgumentException("product category id is zero."); //NOI18N
218 } else if (null == available) {
220 throw new IllegalArgumentException("product availability not set."); //NOI18N
223 // Try to check if title is used already
224 if (this.isProductTitleUsed(product)) {
225 // Title already used
226 throw new ProductTitleAlreadyUsedException(product);
230 throw new UnsupportedOperationException("Unfinished method.");
233 //this.getLogger().trace("EXIT!"); //NOI18N
237 * Checks if product's title is already used.
239 * @param product Product instance
240 * @return Whether the product title is already used
242 private boolean isProductTitleUsed (final Product product) {
244 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", product)); //NOI18N
247 String title = product.getTitle();
249 // category must not be null and "title" must be found and non-empty
250 if (null == product) {
252 throw new NullPointerException("category is null"); //NOI18N
253 } else if (null == title) {
255 throw new IllegalArgumentException("product title is not set"); //NOI18N
256 } else if (title.isEmpty()) {
258 throw new IllegalArgumentException("product title is empty"); //NOI18N
261 // Default is not used
263 throw new UnsupportedOperationException("not finished yet.");
266 //this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N
273 * Checks if category's title is already used.
275 * @param category Category instance
276 * @return Whether the product title is already used
278 private boolean isCategoryTitleUsed (final Category category) {
280 this.getLogger().trace(MessageFormat.format("category={0} - CALLED!", category)); //NOI18N
283 String title = category.getTitle();
285 // category must not be null and "title" must be found and non-empty
286 if (null == category) {
288 throw new NullPointerException("category is null"); //NOI18N
289 } else if (null == title) {
291 throw new IllegalArgumentException("category title is not set."); //NOI18N
292 } else if (title.isEmpty()) {
294 throw new IllegalArgumentException("category title is empty."); //NOI18N
297 // Default is not used
298 boolean isUsed = this.isCategoryTitleUsed(title);
301 this.getLogger().trace(MessageFormat.format("isUsed={0} - EXIT!", isUsed)); //NOI18N