From: Roland Häder Date: Fri, 6 Apr 2018 21:35:58 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=0dbd80562597822fc2df9fbd48177747ac92c879;p=jfinancials-war.git Don't cherry-pick: - added list and user bean for receipt items, need to have this for having "working" (at least partly) paginator+filter+sorting on a p:dataTable tag - also prepared listing of receipt items for clicking on a row to have a p:dialog shown up with all details, yet still unfinished - removed no longer used i18n key Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java index c02bcf3b..a0a4629a 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/income/FinancialsIncomeWebRequestBean.java @@ -82,10 +82,8 @@ public class FinancialsIncomeWebRequestBean extends BaseFinancialsBean implement /** * Adds income data by calling proper business method of the EJB. - *

- * @return Redirect outcome */ - public String addIncome () { + public void addIncome () { // Is all data valid? if (!this.userLoginController.isUserLoggedIn()) { // Not logged-in @@ -113,9 +111,6 @@ public class FinancialsIncomeWebRequestBean extends BaseFinancialsBean implement // Handle it over to the EJB // @TODO Use updated income instance, e.g. fire event final BillableIncome updatedIncome = this.financialBean.addIncome(income); - - // All fine - return "add_user_fiancial_income"; //NOI18N } /** 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 150cc03b..30621c30 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 @@ -134,9 +134,8 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl * Adds the completed receipt to database by calling an EJB business method. * If not all required fields are set, a proper exception is being thrown. *

- * @return Link outcome */ - public String addReceipt () { + public void addReceipt () { // Are all required fields set? if (this.getReceiptBranchOffice() == null) { // Is not set @@ -181,9 +180,6 @@ public class FinancialAdminReceiptWebRequestBean extends BaseFinancialsBean impl // Clear bean this.clear(); - - // Return redirect outcome - return ""; //NOI18N } /** 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 f829942b..15b4ad54 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 @@ -125,9 +125,8 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen * Adds the completed receipt to database by calling an EJB business method. * If not all required fields are set, a proper exception is being thrown. *

- * @return Link outcome */ - public String addReceipt () { + public void addReceipt () { // Are all required fields set? if (!this.userLoginController.isUserLoggedIn()) { // Not logged-in @@ -175,9 +174,6 @@ public class FinancialsReceiptWebRequestBean extends BaseFinancialsBean implemen // Clear bean this.clear(); - - // Return redirect outcome - return "admin_list_receipts?faces-redirect=true"; //NOI18N } /** 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 b114fafc..79c9607f 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 @@ -27,6 +27,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; 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; @@ -129,10 +130,10 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean private BigDecimal productTaxRate; /** - * General receipt item controller + * Receipt item list controller */ @Inject - private FinancialsReceiptItemWebRequestController receiptItemController; + private FinancialsReceiptItemListWebViewController receiptItemListController; /** * Default constructor @@ -147,16 +148,15 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean * method. If not all required fields are set, a proper exception is being * thrown. *

- * @return Link outcome */ - public String addReceiptItem () { + public void addReceiptItem () { // Are all required fields set? // Prepare receipt item instance final BillableReceiptItem receiptItem = this.createReceiptItemInstance(); // Is the receipt already there? - if (this.receiptItemController.isReceiptItemAdded(receiptItem)) { + if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) { // Receipt has already been added throw new FaceletException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N } @@ -178,9 +178,6 @@ public class FinancialAdminReceiptItemWebRequestBean extends BaseFinancialsBean // Clear bean this.clear(); - - // Return redirect outcome - return ""; //NOI18N } /** diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java index 8bdb93a0..0321e87e 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestBean.java @@ -16,24 +16,16 @@ */ package org.mxchange.jfinancials.beans.financial.model.receipt_item; -import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.annotation.PostConstruct; -import javax.cache.Cache; import javax.ejb.EJB; import javax.enterprise.context.RequestScoped; import javax.enterprise.event.Event; -import javax.enterprise.event.Observes; import javax.enterprise.inject.Any; import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; import org.mxchange.jfinancials.events.receipt_item.added.ReceiptItemAddedEvent; @@ -41,7 +33,6 @@ import org.mxchange.jfinancials.exceptions.receipt_item.ReceiptItemAlreadyAddedE import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItem; import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote; -import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; /** * A general financial receipt item bean (controller) @@ -64,16 +55,6 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl @Any private Event addedReceiptItemEvent; - /** - * All receipt items list - */ - private final List allReceiptItems; - - /** - * Filtered receipt items list - */ - private List filteredReceiptItems; - /** * EJB for general financial receipt purposes */ @@ -81,11 +62,10 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl private FinancialReceiptItemSessionBeanRemote receiptItemBean; /** - * A list of all branch offices (globally) + * Receipt item list controller */ @Inject - @NamedCache (cacheName = "receiptItemCache") - private Cache receiptItemCache; + private FinancialsReceiptItemListWebViewController receiptItemListController; /** * User instance @@ -93,11 +73,6 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl @Inject private FinancialsUserLoginWebSessionController userLoginController; - /** - * User's receipt items - */ - private final List userReceiptItems; - /** * Constructor */ @@ -105,19 +80,15 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl public FinancialsReceiptItemWebRequestBean () { // Call super constructor super(); - - // Init lists - this.allReceiptItems = new LinkedList<>(); - this.userReceiptItems = new LinkedList<>(); } /** - * Adds the completed receipt item to database by calling an EJB business method. - * If not all required fields are set, a proper exception is being thrown. + * Adds the completed receipt item to database by calling an EJB business + * method. If not all required fields are set, a proper exception is being + * thrown. *

- * @return Link outcome */ - public String addReceiptItem () { + public void addReceiptItem () { // Are all required fields set? if (!this.userLoginController.isUserLoggedIn()) { // Not logged-in @@ -128,7 +99,7 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl final BillableReceiptItem receiptItem = this.createReceiptInstance(); // Is the receipt already there? - if (this.isReceiptItemAdded(receiptItem)) { + if (this.receiptItemListController.isReceiptItemAdded(receiptItem)) { // Receipt has already been added throw new FaceletException(MessageFormat.format("Receipt for itemReceipt.receiptId={0},itemProduct.productId={1},itemProductQuantity={2} has already been added.", receiptItem.getItemReceipt().getReceiptId(), receiptItem.getItemProduct().getProductId(), receiptItem.getItemProductQuantity())); //NOI18N } @@ -150,138 +121,6 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl // Clear bean this.clear(); - - // Return redirect outcome - return "admin_list_receipt_items?faces-redirect=true"; //NOI18N - } - - /** - * Observes events being fired when a new receipt item has been added - *

- * @param event Event being fired - */ - public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } - - // Add to cache and general list - this.receiptItemCache.put(event.getReceiptItem().getItemId(), event.getReceiptItem()); - this.allReceiptItems.add(event.getReceiptItem()); - - // Is same user? - if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { - // Same user, then add it - this.userReceiptItems.add(event.getReceiptItem()); - } - } - - /** - * Event observer for logged-in user - *

- * @param event Event instance - */ - public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getLoggedInUser() == null) { - // Throw NPE again - throw new NullPointerException("event.loggedInUser is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N - } else if (event.getLoggedInUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N - } - - // Fill cache with all found user's receipts - for (final BillableReceiptItem receiptItem : this.allReceiptItems) { - // Is same user? - if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) { - // Yes, then add it - this.userReceiptItems.add(receiptItem); - } - } - } - - /** - * Returns all receipt items - *

- * @return All receipt items - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List allReceiptItems () { - return this.allReceiptItems; - } - - /** - * Getter for filtered receipt items - *

- * @return Filtered receipts - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredReceiptItems () { - return this.filteredReceiptItems; - } - - /** - * Setter for filtered receipt items - *

- * @param filteredReceiptItems Filtered receipt items - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredReceiptItems (final List filteredReceiptItems) { - this.filteredReceiptItems = filteredReceiptItems; - } - - @PostConstruct - public void initCache () { - // Is cache there? - if (!this.receiptItemCache.iterator().hasNext()) { - // Get whole list - final List receiptItems = this.receiptItemBean.allReceiptItems(); - - // Add all - for (final BillableReceiptItem receiptItem : receiptItems) { - // Add it to cache - this.receiptItemCache.put(receiptItem.getItemId(), receiptItem); - } - } - - // Is the list empty, but filled cache? - if (this.allReceiptItems.isEmpty() && this.receiptItemCache.iterator().hasNext()) { - // Get iterator - final Iterator> iterator = this.receiptItemCache.iterator(); - - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - - // Add to list - this.allReceiptItems.add(next.getValue()); - } - - // Sort list - this.allReceiptItems.sort(new Comparator() { - @Override - public int compare (final BillableReceiptItem o1, final BillableReceiptItem o2) { - return o1.getItemId() > o2.getItemId() ? 1 : o1.getItemId() < o2.getItemId() ? -1 : 0; - } - } - ); - } - } - - @Override - public boolean isReceiptItemAdded (final BillableReceiptItem receiptItem) { - // Always trust the cache - return this.allReceiptItems.contains(receiptItem); } /** @@ -292,7 +131,8 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl } /** - * Returns a fully created receipt item instance (except primary key, of course) + * Returns a fully created receipt item instance (except primary key, of + * course) *

* @return Receipt item instance */ @@ -302,8 +142,8 @@ public class FinancialsReceiptItemWebRequestBean extends BaseFinancialsBean impl final BillableReceiptItem receiptItem = new FinancialReceiptItem(); // Set optional fields - // Return it return receiptItem; } + } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestController.java index aaa3bb03..d988bece 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/FinancialsReceiptItemWebRequestController.java @@ -17,7 +17,6 @@ package org.mxchange.jfinancials.beans.financial.model.receipt_item; import java.io.Serializable; -import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; /** * An administrative interface for financial receipt item beans @@ -26,13 +25,4 @@ import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; */ public interface FinancialsReceiptItemWebRequestController extends Serializable { - /** - * Checks if receipt item has already been added to database - *

- * @param receiptItem Prepared receipt item instance - *

- * @return Whether the receipt item has already been added - */ - boolean isReceiptItemAdded (final BillableReceiptItem receiptItem); - } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java new file mode 100644 index 00000000..caf9b545 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewBean.java @@ -0,0 +1,249 @@ +/* + * Copyright (C) 2016 - 2018 Free Software Foundation + * + * 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.beans.financial.model.receipt_item.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; +import org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote; +import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; + +/** + * A list financial receipt item bean (controller) + *

+ * @author Roland Häder + */ +@Named ("receiptItemListController") +@ViewScoped +public class FinancialsReceiptItemListWebViewBean extends BaseFinancialsBean implements FinancialsReceiptItemListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_472L; + + /** + * All receipt items list + */ + private final List allReceiptItems; + + /** + * Filtered receipt items list + */ + private List filteredReceiptItems; + + /** + * EJB for general financial receipt purposes + */ + @EJB (lookup = "java:global/jfinancials-ejb/financialReceiptItem!org.mxchange.jfinancials.model.receipt_item.FinancialReceiptItemSessionBeanRemote") + private FinancialReceiptItemSessionBeanRemote receiptItemBean; + + /** + * A list of all branch offices (globally) + */ + @Inject + @NamedCache (cacheName = "receiptItemCache") + private transient Cache receiptItemCache; + + /** + * Selected receipt item + */ + private BillableReceiptItem selectedReceiptItem; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * User's receipt items + */ + private final List userReceiptItems; + + /** + * Constructor + */ + @SuppressWarnings ("CollectionWithoutInitialCapacity") + public FinancialsReceiptItemListWebViewBean () { + // Call super constructor + super(); + + // Init lists + this.allReceiptItems = new LinkedList<>(); + this.userReceiptItems = new LinkedList<>(); + } + + /** + * Observes events being fired when a new receipt item has been added + *

+ * @param event Event being fired + */ + public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } + + // Add to cache and general list + this.receiptItemCache.put(event.getReceiptItem().getItemId(), event.getReceiptItem()); + this.getAllReceiptItems().add(event.getReceiptItem()); + + // Is same user? + if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + // Same user, then add it + this.userReceiptItems.add(event.getReceiptItem()); + } + } + + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLoggedInUser() == null) { + // Throw NPE again + throw new NullPointerException("event.loggedInUser is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N + } + + // Fill cache with all found user's receipts + for (final BillableReceiptItem receiptItem : this.allReceiptItems) { + // Is same user? + if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) { + // Yes, then add it + this.userReceiptItems.add(receiptItem); + } + } + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllReceiptItems () { + return this.allReceiptItems; + } + + /** + * Getter for filtered receipt items + *

+ * @return Filtered receipts + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredReceiptItems () { + return this.filteredReceiptItems; + } + + /** + * Setter for filtered receipt items + *

+ * @param filteredReceiptItems Filtered receipt items + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredReceiptItems (final List filteredReceiptItems) { + this.filteredReceiptItems = filteredReceiptItems; + } + + /** + * Getter for selected receipt item + *

+ * @return Selected receipt item + */ + public BillableReceiptItem getSelectedReceiptItem () { + return this.selectedReceiptItem; + } + + /** + * Setter for selected receipt item + *

+ * @param selectedReceiptItem Selected receipt item + */ + public void setSelectedReceiptItem (final BillableReceiptItem selectedReceiptItem) { + this.selectedReceiptItem = selectedReceiptItem; + } + + @PostConstruct + public void initCache () { + // Is cache there? + if (!this.receiptItemCache.iterator().hasNext()) { + // Get whole list + final List receiptItems = this.receiptItemBean.allReceiptItems(); + + // Add all + for (final BillableReceiptItem receiptItem : receiptItems) { + // Add it to cache + this.receiptItemCache.put(receiptItem.getItemId(), receiptItem); + } + } + + // Is the list empty, but filled cache? + if (this.getAllReceiptItems().isEmpty() && this.receiptItemCache.iterator().hasNext()) { + // Get iterator + final Iterator> iterator = this.receiptItemCache.iterator(); + + // Build up list + while (iterator.hasNext()) { + // GEt next element + final Cache.Entry next = iterator.next(); + + // Add to list + this.getAllReceiptItems().add(next.getValue()); + } + + // Sort list + this.getAllReceiptItems().sort(new Comparator() { + @Override + public int compare (final BillableReceiptItem o1, final BillableReceiptItem o2) { + return o1.getItemId() > o2.getItemId() ? 1 : o1.getItemId() < o2.getItemId() ? -1 : 0; + } + } + ); + } + } + + @Override + public boolean isReceiptItemAdded (final BillableReceiptItem receiptItem) { + // Always trust the cache + return this.getAllReceiptItems().contains(receiptItem); + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java new file mode 100644 index 00000000..e94c69a3 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/list/FinancialsReceiptItemListWebViewController.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2016 - 2018 Free Software Foundation + * + * 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.beans.financial.model.receipt_item.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; + +/** + * An administrative interface for financial receipt item list beans + *

+ * @author Roland Häder + */ +public interface FinancialsReceiptItemListWebViewController extends Serializable { + + /** + * Checks if receipt item has already been added to database + *

+ * @param receiptItem Prepared receipt item instance + *

+ * @return Whether the receipt item has already been added + */ + boolean isReceiptItemAdded (final BillableReceiptItem receiptItem); + + /** + * Returns all receipt items + *

+ * @return All receipt items + */ + List getAllReceiptItems (); + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java new file mode 100644 index 00000000..3b4f0250 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionBean.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2016 - 2018 Free Software Foundation + * + * 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.beans.financial.model.receipt_item.user; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jfinancials.beans.financial.model.receipt_item.list.FinancialsReceiptItemListWebViewController; +import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; +import org.mxchange.jfinancials.events.receipt_item.added.ObservableReceiptItemAddedEvent; +import org.mxchange.jfinancials.model.receipt_item.BillableReceiptItem; +import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; + +/** + * A list financial receipt item bean (controller) + *

+ * @author Roland Häder + */ +@Named ("receiptItemUserController") +@ViewScoped +public class FinancialsReceiptItemUserWebSessionBean extends BaseFinancialsBean implements FinancialsReceiptItemUserWebSessionController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_572L; + + /** + * Receipt item list controller + */ + @Inject + private FinancialsReceiptItemListWebViewController receiptItemListController; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * User's receipt items + */ + private final List userReceiptItems; + + /** + * Constructor + */ + @SuppressWarnings ("CollectionWithoutInitialCapacity") + public FinancialsReceiptItemUserWebSessionBean () { + // Call super constructor + super(); + + // Init lists + this.userReceiptItems = new LinkedList<>(); + } + + /** + * Observes events being fired when a new receipt item has been added + *

+ * @param event Event being fired + */ + public void afterAddedReceiptItemEvent (@Observes final ObservableReceiptItemAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } + + // Is same user? + if (this.userLoginController.isUserLoggedIn() && Objects.equals(event.getReceiptItem().getItemReceipt().getReceiptUser(), this.userLoginController.getLoggedInUser())) { + // Same user, then add it + this.userReceiptItems.add(event.getReceiptItem()); + } + } + + /** + * Event observer for logged-in user + *

+ * @param event Event instance + */ + public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) { + // event should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getLoggedInUser() == null) { + // Throw NPE again + throw new NullPointerException("event.loggedInUser is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.loggedInUser.userId is null"); //NOI18N + } else if (event.getLoggedInUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N + } + + // Fill cache with all found user's receipts + for (final BillableReceiptItem receiptItem : this.receiptItemListController.getAllReceiptItems()) { + // Is same user? + if (Objects.equals(receiptItem.getItemReceipt().getReceiptUser(), event.getLoggedInUser())) { + // Yes, then add it + this.userReceiptItems.add(receiptItem); + } + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionController.java b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionController.java new file mode 100644 index 00000000..47269247 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/model/receipt_item/user/FinancialsReceiptItemUserWebSessionController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2016 - 2018 Free Software Foundation + * + * 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.beans.financial.model.receipt_item.user; + +import java.io.Serializable; + +/** + * An administrative interface for financial receipt item user beans + *

+ * @author Roland Häder + */ +public interface FinancialsReceiptItemUserWebSessionController extends Serializable { + +} diff --git a/src/java/org/mxchange/localization/project_de_DE.properties b/src/java/org/mxchange/localization/project_de_DE.properties index c74c277b..adaec546 100644 --- a/src/java/org/mxchange/localization/project_de_DE.properties +++ b/src/java/org/mxchange/localization/project_de_DE.properties @@ -93,7 +93,6 @@ CONTENT_TITLE_ADMIN_FINANCIALS_RECEIPT_ITEM_LIST=Artikel auflisten: TABLE_SUMMARY_ADMIN_LIST_RECEIPT_ITEMS=Diese Tabelle listet alle eingetragenen Artikel auf. #@TODO Please fix German umlauts! ADMIN_EMPTY_LIST_RECEIPT_ITEM=Es befinden sich keine Artikel in der Datenbank. Oder Ihre Suche ergab keine Uebereinstimmungen. -ADMIN_LIST_RECEIPT_ITEMS_HEADER=Alle Artikel auflisten ADMIN_ASSIGNED_ITEM_RECEIPT=Zugewiesener Kassenbon: ADMIN_ASSIGNED_ITEM_PRODUCT=Zugewiesenes Produkt: #@TODO Please fix German umlauts! @@ -325,3 +324,14 @@ RECEIPT_BARCODE_TITLE=Streifencode des Kassenbons. RECEIPT_SEQUENCE_NUMBER_HEADER=Durchlaufende Nummer: RECEIPT_SEQUENCE_NUMBER_TITLE=Durchlaufende Nummer des Kassenbons. RECEIPT_PAYMENT_TYPE_TITLE=Bezahlungsart des Kassenbons. +PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Produkt anzeigen +CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Produkt anzeigen: +PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Produkt editieren +CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Produkt editieren: +#@TODO Please fix German umlauts! +PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Produkt loeschen +#@TODO Please fix German umlauts! +CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Produkt loeschen: +ERROR_PARAMETER_PRODUCT_ID_NOT_SET=Fehler: Produkt-Id nicht gesetzt (Parameter: productId). +#@TODO Please fix German umlauts! +PARAMETER_PRODUCT_ID_INVALID=Parameter "productId" ist ungueltig. diff --git a/src/java/org/mxchange/localization/project_en_US.properties b/src/java/org/mxchange/localization/project_en_US.properties index 964894de..1f7e04de 100644 --- a/src/java/org/mxchange/localization/project_en_US.properties +++ b/src/java/org/mxchange/localization/project_en_US.properties @@ -68,7 +68,6 @@ PAGE_TITLE_ADMIN_FINANCIALS_RECEIPT_ITEM_LIST=List receipt items CONTENT_TITLE_ADMIN_FINANCIALS_RECEIPT_ITEM_LIST=List receipt items: TABLE_SUMMARY_ADMIN_LIST_RECEIPT_ITEMS=This table lists all registered receipt items. ADMIN_EMPTY_LIST_RECEIPT_ITEM=There are no receipt items in database. Or your search criteria doesn't match anything. -ADMIN_LIST_RECEIPT_ITEMS_HEADER=List all receipt items ADMIN_ASSIGNED_ITEM_RECEIPT=Assigned item's receipt: ADMIN_ASSIGNED_ITEM_PRODUCT=Assigned product: ADMIN_ADD_RECEIPT_ITEM_TITLE=Add new receipt item @@ -239,3 +238,11 @@ RECEIPT_BARCODE_TITLE=Barcode of receipt. RECEIPT_SEQUENCE_NUMBER_HEADER=Sequence number: RECEIPT_SEQUENCE_NUMBER_TITLE=Sequence number of receipt. RECEIPT_PAYMENT_TYPE_TITLE=Payment type of receipt. +PAGE_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Show product +CONTENT_TITLE_ADMIN_SHOW_GENERIC_PRODUCT=Show product: +PAGE_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Edit product +CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_EDIT=Edit product: +PAGE_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Delete product +CONTENT_TITLE_ADMIN_GENERIC_PRODUCT_DELETE=Delete product: +ERROR_PARAMETER_PRODUCT_ID_NOT_SET=Error: Product Id is not set (parameter: productId). +PARAMETER_PRODUCT_ID_INVALID=Parameter "productId" is invalid. diff --git a/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl b/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl index 598c637e..8cbb7ab9 100644 --- a/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl +++ b/web/WEB-INF/templates/admin/financial/receipt_item/admin_form_financial_receipt_item.tpl @@ -41,7 +41,7 @@ > - + diff --git a/web/admin/financial/receipt/admin_receipt_list.xhtml b/web/admin/financial/receipt/admin_receipt_list.xhtml index f3ba86d7..b3be3052 100644 --- a/web/admin/financial/receipt/admin_receipt_list.xhtml +++ b/web/admin/financial/receipt/admin_receipt_list.xhtml @@ -228,7 +228,7 @@ - +

diff --git a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml index 1f94db7f..16967d33 100644 --- a/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml +++ b/web/admin/financial/receipt_item/admin_receipt_item_list.xhtml @@ -19,16 +19,17 @@ - + - - + + - + + + + + + + - - + + + + @@ -86,11 +102,11 @@ title="#{project.FILTER_BY_MULTIPLE_ITEM_PRODUCTS_TITLE}" > - + - + @@ -101,7 +117,7 @@ filter="true" filterMatchMode="contains" label="#{msg.LABEL_COMPANIES}" - onchange="PF('itemList').filter()" + onchange="PF('receiptItemList').filter()" updateLabel="true" title="#{msg.FILTER_BY_MULTIPLE_COMPANIES_TITLE}" > @@ -127,9 +143,34 @@ + + + + + + + + + + + + + + + - +

@@ -151,7 +192,7 @@ type="submit" value="#{project.BUTTON_ADMIN_ADD_RECEIPT_TEM}" action="#{adminReceiptItemController.addReceiptItem()}" - update=":master:form-list-financial-receipt-item:receiptItemList" + update=":master:form-list-financial-receipt-items:receiptItemList" />