From e565dcefa850884a5a3710dcf6c7c953d16a93ba Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 17 Oct 2017 23:50:54 +0200 Subject: [PATCH] Don't cherry-pick: - switched converters/validators which are converting primary keys (id numbers) into entities from EJB-based lookup to backing-bean-based lookup as this is much better performing (EJB calls are relative "expensive") - the backing bean will then check cache which is basically a distributed Map (Cache interface) where the primary key is also the key for cache entries - a SomeEntityNotFoundException is being thrown when containsKey() returns false which is then caught by the calling method - fixed imports from "renaming season" ;-) - added missing JSF tag template admin_receipt_item_links.tpl - added converter for receipt, generic product and product category - receipts/receipt items will always (?) be jfinancials ;-) - some messages needed to be switch msg -> project as they are project-specific MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../FinancialAdminCategoryWebRequestBean.java | 5 +- .../FinancialCategoryWebRequestBean.java | 22 ++++ ...FinancialCategoryWebRequestController.java | 15 +++ .../FinancialAdminReceiptWebRequestBean.java | 8 +- .../FinancialsReceiptWebRequestBean.java | 30 ++++- ...FinancialsReceiptWebRequestController.java | 14 +++ ...nancialAdminReceiptItemWebRequestBean.java | 101 ++++++++++++++++- .../FinancialAdminProductWebRequestBean.java | 5 +- .../FinancialProductWebRequestBean.java | 22 ++++ .../FinancialProductWebRequestController.java | 14 +++ .../receipt/FinancialsReceiptConverter.java | 103 ++++++++++++++++++ .../FinancialsGenericProductConverter.java | 103 ++++++++++++++++++ .../FinancialsProductCategoryConverter.java | 103 ++++++++++++++++++ .../localization/project_de_DE.properties | 40 +++---- .../localization/project_en_US.properties | 40 +++---- .../financial/receipt/admin_receipt_links.tpl | 6 +- .../receipt_item/admin_receipt_item_links.tpl | 33 ++++++ .../receipt/admin_form_financial_receipt.tpl | 26 ++--- .../admin_form_financial_receipt_item.tpl | 81 +++++--------- web/WEB-INF/templates/admin/menu/project.tpl | 6 +- .../receipt/login_form_financial_receipt.tpl | 24 ++-- .../admin_receipt_item_list.xhtml | 14 +-- .../receipts/admin_receipt_list.xhtml | 14 +-- .../login_financials_add_receipt.xhtml | 4 +- 24 files changed, 679 insertions(+), 154 deletions(-) create mode 100644 src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java create mode 100644 src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java create mode 100644 src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java create mode 100644 web/WEB-INF/resources/tags/admin/links/mini/financial/receipt_item/admin_receipt_item_links.tpl diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java index 3725f670..8acb6c52 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialAdminCategoryWebRequestBean.java @@ -26,8 +26,7 @@ import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jproduct.events.category.AddedCategoryEvent; import org.mxchange.jproduct.events.category.CategoryAddedEvent; -import org.mxchange.jproduct.exceptions.CannotAddCategoryException; -import org.mxchange.jproduct.exceptions.CategoryTitleAlreadyUsedException; +import org.mxchange.jproduct.exceptions.category.CategoryAlreadyAddedException; import org.mxchange.jproduct.model.category.AdminCategorySessionBeanRemote; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.category.ProductCategory; @@ -100,7 +99,7 @@ public class FinancialAdminCategoryWebRequestBean extends BaseFinancialsBean imp // Unset all older values this.clear(); - } catch (final CategoryTitleAlreadyUsedException | CannotAddCategoryException ex) { + } catch (final CategoryAlreadyAddedException ex) { // Continue to throw throw new FaceletException(ex); } diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java index bf1f9615..506e99b8 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestBean.java @@ -30,6 +30,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jproduct.events.category.AddedCategoryEvent; +import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.category.CategorySessionBeanRemote; @@ -101,6 +102,27 @@ public class FinancialCategoryWebRequestBean extends BaseFinancialsBean implemen return this.allCategories; } + @Override + public Category findCategoryById (final Long categoryId) throws CategoryNotFoundException { + // Validate parameter + if (null == categoryId) { + // Throw NPE + throw new NullPointerException("categoryId is null"); //NOI18N + } else if (categoryId < 1) { + // Throw IAE + throw new IllegalArgumentException("categoryId=" + categoryId + " is invalid"); //NOI18N + } else if (!this.categoryCache.containsKey(categoryId)) { + // Not found + throw new CategoryNotFoundException(categoryId); + } + + // Get it from cache + final Category category = this.categoryCache.get(categoryId); + + // Return it + return category; + } + /** * Initialization of this bean */ diff --git a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestController.java index ac32de13..c8caa54e 100644 --- a/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/category/FinancialCategoryWebRequestController.java @@ -17,6 +17,8 @@ package org.mxchange.jfinancials.beans.category; import java.io.Serializable; +import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; +import org.mxchange.jproduct.model.category.Category; /** * An interface for (product) categories @@ -25,4 +27,17 @@ import java.io.Serializable; */ public interface FinancialCategoryWebRequestController extends Serializable { + /** + * Returns a category instance (entity) for given primary key. If not found, + * a proper exception is thrown. + *

+ * @param categoryId Category id (primary key) + *

+ * @return Category entity matching to primary key + *

+ * @throws CategoryNotFoundException If a category with given primary key + * could not be found + */ + Category findCategoryById (final Long categoryId) throws CategoryNotFoundException; + } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java index c1626722..fc178db0 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialAdminReceiptWebRequestBean.java @@ -26,7 +26,6 @@ import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.Employee; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; @@ -36,6 +35,7 @@ import org.mxchange.jfinancials.model.receipt.FinancialAdminReceiptSessionBeanRe import org.mxchange.jfinancials.model.receipt.FinancialReceipt; import org.mxchange.jproduct.model.payment.PaymentType; import org.mxchange.jusercore.model.user.User; +import org.mxchange.jcontactsbusiness.model.employee.Employable; /** * An administrative backing bean for receipts @@ -103,7 +103,7 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl /** * Selling employee */ - private Employee receiptSellerEmployee; + private Employable receiptSellerEmployee; /** * User who "owns" this receipt @@ -289,7 +289,7 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl *

* @return Receipt seller employee */ - public Employee getReceiptSellerEmployee () { + public Employable getReceiptSellerEmployee () { return this.receiptSellerEmployee; } @@ -298,7 +298,7 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl *

* @param receiptSellerEmployee Receipt seller employee */ - public void setReceiptSellerEmployee (final Employee receiptSellerEmployee) { + public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) { this.receiptSellerEmployee = receiptSellerEmployee; } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java index 9ff56943..1ee5fbda 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestBean.java @@ -35,12 +35,13 @@ import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.employee.Employee; +import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; import org.mxchange.jfinancials.events.receipt.added.ObservableReceiptAddedEvent; import org.mxchange.jfinancials.events.receipt.added.ReceiptAddedEvent; import org.mxchange.jfinancials.exceptions.receipt.ReceiptAlreadyAddedException; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jfinancials.model.receipt.FinancialReceipt; import org.mxchange.jfinancials.model.receipt.FinancialReceiptSessionBeanRemote; @@ -124,7 +125,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen /** * Selling employee */ - private Employee receiptSellerEmployee; + private Employable receiptSellerEmployee; /** * User instance @@ -282,6 +283,27 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen return this.allReceipts; } + @Override + public BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException { + // Validate parameter + if (null == receiptId) { + // Throw NPE + throw new NullPointerException("receiptId is null"); //NOI18N + } else if (receiptId < 1) { + // Throw IAE + throw new IllegalArgumentException("receiptId=" + receiptId + " is invalid."); //NOI18N + } else if (!this.receiptCache.containsKey(receiptId)) { + // Not found + throw new ReceiptNotFoundException(receiptId); + } + + // Get it from cache + final BillableReceipt receipt = this.receiptCache.get(receiptId); + + // Return it + return receipt; + } + /** * Getter for filtered receipts *

@@ -417,7 +439,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen *

* @return Receipt seller employee */ - public Employee getReceiptSellerEmployee () { + public Employable getReceiptSellerEmployee () { return this.receiptSellerEmployee; } @@ -426,7 +448,7 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen *

* @param receiptSellerEmployee Receipt seller employee */ - public void setReceiptSellerEmployee (final Employee receiptSellerEmployee) { + public void setReceiptSellerEmployee (final Employable receiptSellerEmployee) { this.receiptSellerEmployee = receiptSellerEmployee; } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java index a79d5549..43adb376 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt/FinancialsReceiptWebRequestController.java @@ -17,6 +17,7 @@ package org.mxchange.jfinancials.beans.financial.model.receipt; import java.io.Serializable; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; import org.mxchange.jfinancials.model.receipt.BillableReceipt; /** @@ -26,6 +27,19 @@ import org.mxchange.jfinancials.model.receipt.BillableReceipt; */ public interface FinancialsReceiptWebRequestController extends Serializable { + /** + * Returns a receipt instance (entity) for given primary key. If not found, + * a proper exception is thrown. + *

+ * @param receiptId Receipt id (primary key) + *

+ * @return Receipt entity matching to primary key + *

+ * @throws ReceiptNotFoundException If a receipt with given primary key + * could not be found + */ + BillableReceipt findReceiptById (final Long receiptId) throws ReceiptNotFoundException; + /** * Checks if receipt has already been added to database *

diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java index df8336da..9c8af28c 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialAdminReceiptItemWebRequestBean.java @@ -28,9 +28,11 @@ import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent; import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; import org.mxchange.jfinancials.model.receipt.item.BillableReceiptItem; import org.mxchange.jfinancials.model.receipt.item.FinancialReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialAdminReceiptItemSessionBeanRemote; +import org.mxchange.jproduct.model.product.Product; /** * An administrative backing bean for receipt items @@ -59,6 +61,26 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean @EJB (lookup = "java:global/jfinancials-ejb/adminFinancialReceiptItem!org.mxchange.jfinancials.model.receipt.item.FinancialAdminReceiptItemSessionBeanRemote") private FinancialAdminReceiptItemSessionBeanRemote adminReceiptItemBean; + /** + * Discount on product price (if any) Valid: values 0...1 (1=100% discount) + */ + private Float itemDiscount; + + /** + * Item product + */ + private Product itemProduct; + + /** + * Quantity of item + */ + private Long itemQuantity; + + /** + * Assigned receipt + */ + private BillableReceipt itemReceipt; + /** * General receipt item controller */ @@ -114,11 +136,87 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean return "add_receipt_item?faces-redirect=true"; //NOI18N } + /** + * Getter for item discount + *

+ * @return Item discount + */ + public Float getItemDiscount () { + return this.itemDiscount; + } + + /** + * Setter for item discount + *

+ * @param itemDiscount Item discount + */ + public void setItemDiscount (final Float itemDiscount) { + this.itemDiscount = itemDiscount; + } + + /** + * Getter for assigned product + *

+ * @return Assigned product + */ + public Product getItemProduct () { + return this.itemProduct; + } + + /** + * Setter for assigned product + *

+ * @param itemProduct Assigned product + */ + public void setItemProduct (final Product itemProduct) { + this.itemProduct = itemProduct; + } + + /** + * Getter for item quantity + *

+ * @return Item quantity + */ + public Long getItemQuantity () { + return this.itemQuantity; + } + + /** + * Setter for item quantity + *

+ * @param itemQuantity Item quantity + */ + public void setItemQuantity (final Long itemQuantity) { + this.itemQuantity = itemQuantity; + } + + /** + * Getter for assigned receipt + *

+ * @return Assigned receipt + */ + public BillableReceipt getItemReceipt () { + return this.itemReceipt; + } + + /** + * Setter for assigned receipt + *

+ * @param itemReceipt Assigned receipt + */ + public void setItemReceipt (final BillableReceipt itemReceipt) { + this.itemReceipt = itemReceipt; + } + /** * Clears this bean */ private void clear () { // Clear all fields + this.setItemDiscount(null); + this.setItemProduct(null); + this.setItemQuantity(null); + this.setItemReceipt(null); } /** @@ -128,9 +226,10 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean */ private BillableReceiptItem createReceiptItemInstance () { // Create new instance with minimum required data - final BillableReceiptItem receiptItem = new FinancialReceiptItem(); + final BillableReceiptItem receiptItem = new FinancialReceiptItem(this.getItemProduct(), this.getItemQuantity(), this.getItemReceipt()); // Set optional data + receiptItem.setItemProductDiscount(this.getItemDiscount()); // Return prepared instance return receiptItem; diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java index 055aa89f..f22a312e 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialAdminProductWebRequestBean.java @@ -26,8 +26,7 @@ import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jproduct.events.product.AddedProductEvent; import org.mxchange.jproduct.events.product.ProductAddedEvent; -import org.mxchange.jproduct.exceptions.CannotAddProductException; -import org.mxchange.jproduct.exceptions.ProductTitleAlreadyUsedException; +import org.mxchange.jproduct.exceptions.product.ProductAlreadyAddedException; import org.mxchange.jproduct.model.category.Category; import org.mxchange.jproduct.model.product.AdminProductSessionBeanRemote; import org.mxchange.jproduct.model.product.GenericProduct; @@ -113,7 +112,7 @@ public class FinancialAdminProductWebRequestBean extends BaseFinancialsBean impl // Set all to null this.clear(); - } catch (final ProductTitleAlreadyUsedException | CannotAddProductException ex) { + } catch (final ProductAlreadyAddedException ex) { // Continue to throw throw new FaceletException(ex); } diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java index e3553dc0..9d9fb532 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestBean.java @@ -31,6 +31,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; import org.mxchange.jproduct.events.product.AddedProductEvent; +import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.product.Product; import org.mxchange.jproduct.model.product.ProductSessionBeanRemote; @@ -103,6 +104,27 @@ public class FinancialProductWebRequestBean extends BaseFinancialsBean implement return this.allProducts; } + @Override + public Product findProductById (final Long productId) throws ProductNotFoundException { + // Validate parameter + if (null == productId) { + // Throw NPE + throw new NullPointerException("productId is null"); //NOI18N + } else if (productId < 1) { + // Throw IAE + throw new IllegalArgumentException("productId=" + productId + " is invalid"); //NOI18N + } else if (!this.productCache.containsKey(productId)) { + // Not found + throw new ProductNotFoundException(productId); + } + + // Get it from cache + final Product product = this.productCache.get(productId); + + // Return it + return product; + } + /** * Initialization of this bean */ diff --git a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestController.java index 7aff5301..8543d3c1 100644 --- a/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/product/FinancialProductWebRequestController.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.List; import javax.ejb.Local; import javax.faces.view.facelets.FaceletException; +import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; import org.mxchange.jproduct.model.product.Product; /** @@ -39,4 +40,17 @@ public interface FinancialProductWebRequestController extends Serializable { */ List allProducts () throws FaceletException; + /** + * Returns a product instance (entity) for given primary key. If not found, + * a proper exception is thrown. + *

+ * @param productId Product id (primary key) + *

+ * @return Product entity matching to primary key + *

+ * @throws ProductNotFoundException If a product with given primary key + * could not be found + */ + Product findProductById (final Long productId) throws ProductNotFoundException; + } diff --git a/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java new file mode 100644 index 00000000..157edb89 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/financial/receipt/FinancialsReceiptConverter.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.financial.receipt; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jfinancials.beans.financial.model.receipt.FinancialsReceiptWebRequestController; +import org.mxchange.jfinancials.exceptions.receipt.ReceiptNotFoundException; +import org.mxchange.jfinancials.model.receipt.BillableReceipt; + +/** + * Converter for category id <-> valid category instance + *

+ * @author Roland Häder + */ +@FacesConverter ("ReceiptConverter") +public class FinancialsReceiptConverter implements Converter { + + /** + * Receipt backing bean + */ + private static FinancialsReceiptWebRequestController RECEIPT_CONTROLLER; + + @Override + public BillableReceipt getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (RECEIPT_CONTROLLER == null) { + try { + // Not yet, attempt lookup + final Context initial = new InitialContext(); + + // Lookup EJB + RECEIPT_CONTROLLER = (FinancialsReceiptWebRequestController) initial.lookup("java:module/receiptController!org.mxchange.jfinancials.beans.financial.model.receipt.FinancialsReceiptWebRequestController"); + } catch (final NamingException ex) { + // Throw it again + throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); + } + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + BillableReceipt receipt = null; + + try { + // Try to parse the value as long + final Long receiptId = Long.valueOf(submittedValue); + + // Try to get user instance from it + receipt = RECEIPT_CONTROLLER.findReceiptById(receiptId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final ReceiptNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return receipt; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final BillableReceipt value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getReceiptId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java b/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java new file mode 100644 index 00000000..7d03212d --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/generic_product/FinancialsGenericProductConverter.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.generic_product; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jfinancials.beans.product.FinancialProductWebRequestController; +import org.mxchange.jproduct.exceptions.product.ProductNotFoundException; +import org.mxchange.jproduct.model.product.Product; + +/** + * Converter for product id <-> valid product instance + *

+ * @author Roland Häder + */ +@FacesConverter ("GenericProductConverter") +public class FinancialsGenericProductConverter implements Converter { + + /** + * Product backing bean + */ + private static FinancialProductWebRequestController PRODUCT_CONTROLLER; + + @Override + public Product getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (PRODUCT_CONTROLLER == null) { + try { + // Not yet, attempt lookup + final Context initial = new InitialContext(); + + // Lookup EJB + PRODUCT_CONTROLLER = (FinancialProductWebRequestController) initial.lookup("java:global/jfinancials-ejb/productController!org.mxchange.jfinancials.beans.product.FinancialProductWebRequestController"); + } catch (final NamingException ex) { + // Throw it again + throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); + } + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Product product = null; + + try { + // Try to parse the value as long + final Long productId = Long.valueOf(submittedValue); + + // Try to get user instance from it + product = PRODUCT_CONTROLLER.findProductById(productId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final ProductNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return product; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Product value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getProductId()); + } + +} diff --git a/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java b/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java new file mode 100644 index 00000000..85124148 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/converter/product_category/FinancialsProductCategoryConverter.java @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2016, 2017 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.mxchange.jfinancials.converter.product_category; + +import javax.faces.application.FacesMessage; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jfinancials.beans.category.FinancialCategoryWebRequestController; +import org.mxchange.jproduct.exceptions.category.CategoryNotFoundException; +import org.mxchange.jproduct.model.category.Category; + +/** + * Converter for category id <-> valid category instance + *

+ * @author Roland Häder + */ +@FacesConverter ("ProductCategoryConverter") +public class FinancialsProductCategoryConverter implements Converter { + + /** + * Category backing bean + */ + private static FinancialCategoryWebRequestController CATEGORY_CONTROLLER; + + @Override + public Category getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (CATEGORY_CONTROLLER == null) { + try { + // Not yet, attempt lookup + final Context initial = new InitialContext(); + + // Lookup EJB + CATEGORY_CONTROLLER = (FinancialCategoryWebRequestController) initial.lookup("java:module/categoryController!org.mxchange.jfinancials.beans.category.FinancialCategoryWebRequestController"); + } catch (final NamingException ex) { + // Throw it again + throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); + } + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Category category = null; + + try { + // Try to parse the value as long + final Long categoryId = Long.valueOf(submittedValue); + + // Try to get user instance from it + category = CATEGORY_CONTROLLER.findCategoryById(categoryId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final CategoryNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("getAsObject: Exception: {0} - Returning null ...", ex)); //NOI18N + } + + // Return it + return category; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Category value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getCategoryId()); + } + +} diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index 04b8eee9..a35ed504 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -39,35 +39,35 @@ FIELD_FINANCIAL_INCOME_TITLE_REQUIRED=Feld "Title" muss ausgefuellt werden. LOGIN_FINANCIAL_ENTER_RECEIPT_ISSUE_DATE_TITLE=Geben oder suchen Sie hier das genaue Datum aus, wann die Rechnung/der Kassenbon erstellt wurde. Dadurch kann ein genauer Zeitverlauf generiert werden. PAGE_TITLE_ADMIN_FINANCIALS_RECEIPT_LIST=Kassenbons auflisten CONTENT_TITLE_ADMIN_FINANCIALS_RECEIPT_LIST=Listet Kassenbons auf: -TABLE_SUMMARY_ADMIN_LIST_FINANCIAL_RECEIPTS=Diese Tabelle listet bereits registrierte Kassenbons auf. +TABLE_SUMMARY_ADMIN_LIST_RECEIPTS=Diese Tabelle listet bereits registrierte Kassenbons auf. #@TODO Please fix German umlauts! -ADMIN_EMPTY_LIST_FINANCIAL_RECEIPT=Es befinden sich keine Kassenbons in der Datenbank. Oder Ihre Suche ergab keine Uebereinstimmungen. +ADMIN_EMPTY_LIST_RECEIPT=Es befinden sich keine Kassenbons in der Datenbank. Oder Ihre Suche ergab keine Uebereinstimmungen. #@TODO Please fix German umlauts! -ADMIN_ADD_FINANCIAL_RECEIPT_TITLE=Neuen Kassenbon hinzufuegen +ADMIN_ADD_RECEIPT_TITLE=Neuen Kassenbon hinzufuegen #@TODO Please fix German umlauts! -BUTTON_ADMIN_ADD_FINANCIAL_RECEIPT=Kassenbon hinzufuegen -ADMIN_FINANCIAL_RECEIPT_ISSUE_DATE_REQUIRED=Bitte geben Sie das Ausstellungsdatum des Kassenbons ein. -ADMIN_MENU_FINANCIAL_RECEIPTS_TITLE=Kassenbons -ADMIN_LINK_LIST_FINANCIAL_RECEIPTS_TITLE=Listet alle registrierten Kassenbons/Rechnungen auf.. -ADMIN_LINK_LIST_FINANCIAL_RECEIPTS=Kassenbons/Rechnungen auflisten -ADMIN_LIST_FINANCIAL_RECEIPTS_HEADER=Alle Kassenbons/Rechnungen auflisten -ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND=Grunddaten des Kassenbons -ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND_TITLE=Geben Sie hier die Grunddaten des neuen Kassenbons einn. -ENTER_FINANCIAL_RECEIPT_ISSUE_DATE=Ausstellungsdatum des Kassenbons eingeben: -ENTER_FINANCIAL_RECEIPT_NUMBER=Rechnungsnummer eingeben: +BUTTON_ADMIN_ADD_RECEIPT=Kassenbon hinzufuegen +ADMIN_RECEIPT_ISSUE_DATE_REQUIRED=Bitte geben Sie das Ausstellungsdatum des Kassenbons ein. +ADMIN_MENU_RECEIPTS_TITLE=Kassenbons +ADMIN_LINK_LIST_RECEIPTS_TITLE=Listet alle registrierten Kassenbons/Rechnungen auf.. +ADMIN_LINK_LIST_RECEIPTS=Kassenbons/Rechnungen auflisten +ADMIN_LIST_RECEIPTS_HEADER=Alle Kassenbons/Rechnungen auflisten +ADMIN_RECEIPT_BASIC_LEGEND=Grunddaten des Kassenbons +ADMIN_RECEIPT_BASIC_LEGEND_TITLE=Geben Sie hier die Grunddaten des neuen Kassenbons einn. +ENTER_RECEIPT_ISSUE_DATE=Ausstellungsdatum des Kassenbons eingeben: +ENTER_RECEIPT_NUMBER=Rechnungsnummer eingeben: ENTERED_RECEIPT_NUMBER_INVALID=Die eingegebene Bonnummer/Rechnungsnummer ist kleiner 1 oder groesser 9999999999. -ADMIN_SELECT_FINANCIAL_RECEIPT_USER_OWNER=Kassenbon einem Benutzer zuweisen: -ENTER_FINANCIAL_RECEIPT_REGISTER_NUMBER=Kassennummer eingeben: -ENTER_FINANCIAL_RECEIPT_BARCODE_NUMBER=Barcode-Nummer eingeben: -ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND=Sonstige Daten des Kassenbons eingeben: -ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND_TITLE=Geben Sie hier weitere Daten an, die Sie auf dem Kassenbon finden koennen. +ADMIN_SELECT_RECEIPT_USER_OWNER=Kassenbon einem Benutzer zuweisen: +ENTER_RECEIPT_REGISTER_NUMBER=Kassennummer eingeben: +ENTER_RECEIPT_BARCODE_NUMBER=Barcode-Nummer eingeben: +ADMIN_RECEIPT_OTHER_LEGEND=Sonstige Daten des Kassenbons eingeben: +ADMIN_RECEIPT_OTHER_LEGEND_TITLE=Geben Sie hier weitere Daten an, die Sie auf dem Kassenbon finden koennen. ADMIN_LINK_SHOW_RECEIPT_OWNER_USER_TITLE=Zeigt zugewiesenen Benutzer des Kassenbons an. #@TODO Please fix German umlauts! ADMIN_ASSIGNED_RECEIPT_SELLER=Zugewiesener Verkaeufer: DEPARTMENT_NAME_SALES=Verkauf #@TODO Please fix German umlauts! -ADMIN_LINK_LIST_FINANCIAL_RECEIPT_ITEMS=Eintraege auflisten +ADMIN_LINK_LIST_RECEIPT_ITEMS=Eintraege auflisten #@TODO Please fix German umlauts! -ADMIN_LINK_LIST_FINANCIAL_RECEIPT_ITEMS_TITLE=Listet alle Eintraege aller Kassenbons auf. +ADMIN_LINK_LIST_RECEIPT_ITEMS_TITLE=Listet alle Eintraege aller Kassenbons auf. ADMIN_LINK_SHOW_RECEIPT_TITLE=Zeigt Daten des Kassenbons an. ADMIN_LINK_SHOW_RECEIPT_ITEM_TITLE=Zeigt Daten eines Eintrages eines Kassenbons an. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 5f298e44..7f80ad92 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -30,29 +30,29 @@ FIELD_FINANCIAL_INCOME_TITLE_REQUIRED=Field "Title" must be filled out. LOGIN_FINANCIAL_ENTER_RECEIPT_ISSUE_DATE_TITLE=Please enter or select here the exact date when the receipt has been issue. Then an exact time-line can be generated. PAGE_TITLE_ADMIN_FINANCIALS_RECEIPT_LIST=List receipts CONTENT_TITLE_ADMIN_FINANCIALS_RECEIPT_LIST=Lists receipts: -TABLE_SUMMARY_ADMIN_LIST_FINANCIAL_RECEIPTS=This table lists already registered receipts. -ADMIN_EMPTY_LIST_FINANCIAL_RECEIPT=There are no receipts in database. Or your search criteria doesn't match anything. -ADMIN_ADD_FINANCIAL_RECEIPT_TITLE=Add new receipt -BUTTON_ADMIN_ADD_FINANCIAL_RECEIPT=Add receipt -ADMIN_FINANCIAL_RECEIPT_ISSUE_DATE_REQUIRED=Please enter date of issue of receipt. -ADMIN_MENU_FINANCIAL_RECEIPTS_TITLE=Receipts -ADMIN_LINK_LIST_FINANCIAL_RECEIPTS_TITLE=Lists all registered receipts. -ADMIN_LINK_LIST_FINANCIAL_RECEIPTS=List receipts -ADMIN_LIST_FINANCIAL_RECEIPTS_HEADER=List all receipts -ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND=Basic data of receipt: -ADMIN_FINANCIAL_RECEIPT_BASIC_LEGEND_TITLE=Enter here basic data of the new receipt. -ENTER_FINANCIAL_RECEIPT_ISSUE_DATE=Enter date of issue of receipt: -ENTER_FINANCIAL_RECEIPT_NUMBER=Enter receipt number: +TABLE_SUMMARY_ADMIN_LIST_RECEIPTS=This table lists already registered receipts. +ADMIN_EMPTY_LIST_RECEIPT=There are no receipts in database. Or your search criteria doesn't match anything. +ADMIN_ADD_RECEIPT_TITLE=Add new receipt +BUTTON_ADMIN_ADD_RECEIPT=Add receipt +ADMIN_RECEIPT_ISSUE_DATE_REQUIRED=Please enter date of issue of receipt. +ADMIN_MENU_RECEIPTS_TITLE=Receipts +ADMIN_LINK_LIST_RECEIPTS_TITLE=Lists all registered receipts. +ADMIN_LINK_LIST_RECEIPTS=List receipts +ADMIN_LIST_RECEIPTS_HEADER=List all receipts +ADMIN_RECEIPT_BASIC_LEGEND=Basic data of receipt: +ADMIN_RECEIPT_BASIC_LEGEND_TITLE=Enter here basic data of the new receipt. +ENTER_RECEIPT_ISSUE_DATE=Enter date of issue of receipt: +ENTER_RECEIPT_NUMBER=Enter receipt number: ENTERED_RECEIPT_NUMBER_INVALID=Your entered receipt number is smaller than 1 or larger than 9999999999. -ADMIN_SELECT_FINANCIAL_RECEIPT_USER_OWNER=Assign receipt to user: -ENTER_FINANCIAL_RECEIPT_REGISTER_NUMBER=Enter cash register number: -ENTER_FINANCIAL_RECEIPT_BARCODE_NUMBER=Enter bar code number: -ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND=Enter other data of receipt: -ADMIN_FINANCIAL_RECEIPT_OTHER_LEGEND_TITLE=Enter other additional data you can find on the receipt. +ADMIN_SELECT_RECEIPT_USER_OWNER=Assign receipt to user: +ENTER_RECEIPT_REGISTER_NUMBER=Enter cash register number: +ENTER_RECEIPT_BARCODE_NUMBER=Enter bar code number: +ADMIN_RECEIPT_OTHER_LEGEND=Enter other data of receipt: +ADMIN_RECEIPT_OTHER_LEGEND_TITLE=Enter other additional data you can find on the receipt. ADMIN_LINK_SHOW_RECEIPT_OWNER_USER_TITLE=Shows assigned user of receipt. ADMIN_ASSIGNED_RECEIPT_SELLER=Assigned seller: DEPARTMENT_NAME_SALES=Sales -ADMIN_LINK_LIST_FINANCIAL_RECEIPT_ITEMS=List receipt items -ADMIN_LINK_LIST_FINANCIAL_RECEIPT_ITEMS_TITLE=Lists all receipt items. +ADMIN_LINK_LIST_RECEIPT_ITEMS=List receipt items +ADMIN_LINK_LIST_RECEIPT_ITEMS_TITLE=Lists all receipt items. ADMIN_LINK_SHOW_RECEIPT_TITLE=Shows receipt data. ADMIN_LINK_SHOW_RECEIPT_ITEM_TITLE=Shows receipt item data. diff --git a/web/WEB-INF/resources/tags/admin/links/mini/financial/receipt/admin_receipt_links.tpl b/web/WEB-INF/resources/tags/admin/links/mini/financial/receipt/admin_receipt_links.tpl index 993f6ba2..264c6ca5 100644 --- a/web/WEB-INF/resources/tags/admin/links/mini/financial/receipt/admin_receipt_links.tpl +++ b/web/WEB-INF/resources/tags/admin/links/mini/financial/receipt/admin_receipt_links.tpl @@ -10,21 +10,21 @@