From 6ba0155dc5f309424e20c2cbb5cbebad16b83772 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 7 Jun 2017 22:47:46 +0200 Subject: [PATCH] Continued: - moved generic methods to BaseBean - added new controller for receipts - renamed income controller as it is not for administrative purposes - continued with receipt form, used PrimeFaces tags for calendar MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../beans/BaseFinancialsController.java | 159 +----------------- ...va => FinancialsIncomeWebRequestBean.java} | 8 +- ...FinancialsIncomeWebRequestController.java} | 4 +- .../FinancialsReceiptWebRequestBean.java | 82 +++++++++ ...FinancialsReceiptWebRequestController.java | 28 +++ .../templates/contact/form_contact_data.tpl | 3 +- .../login_financials_add_income.xhtml | 4 +- .../login_financials_add_receipt.xhtml | 46 ++++- 8 files changed, 167 insertions(+), 167 deletions(-) rename src/java/org/mxchange/jfinancials/beans/financial/income/{FinancialsAdminFinancialIncomeWebRequestBean.java => FinancialsIncomeWebRequestBean.java} (94%) rename src/java/org/mxchange/jfinancials/beans/financial/income/{FinancialsAdminFinancialIncomeWebRequestController.java => FinancialsIncomeWebRequestController.java} (93%) create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java create mode 100644 src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java diff --git a/src/java/org/mxchange/jfinancials/beans/BaseFinancialsController.java b/src/java/org/mxchange/jfinancials/beans/BaseFinancialsController.java index c18c2ee8..6ecb7e3e 100644 --- a/src/java/org/mxchange/jfinancials/beans/BaseFinancialsController.java +++ b/src/java/org/mxchange/jfinancials/beans/BaseFinancialsController.java @@ -17,13 +17,7 @@ package org.mxchange.jfinancials.beans; import java.io.Serializable; -import java.security.Principal; -import java.text.MessageFormat; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import javax.faces.application.FacesMessage; -import javax.faces.context.FacesContext; +import org.mxchange.jcoreee.bean.BaseBean; import org.mxchange.jusercore.model.user.UserUtils; /** @@ -31,7 +25,7 @@ import org.mxchange.jusercore.model.user.UserUtils; *

* @author Roland Häder */ -public abstract class BaseFinancialsController implements Serializable { +public abstract class BaseFinancialsController extends BaseBean implements Serializable { /** * Serial number @@ -44,97 +38,6 @@ public abstract class BaseFinancialsController implements Serializable { protected BaseFinancialsController () { } - /** - * Determines principal's name or returns null if no principal (security) is - * set. - *

- * @return Principal's name or null - */ - protected String determinePrincipalName () { - // Get principal - Principal userPrincipal = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); - - // Init with null - String principalName = null; - - // Is the principal set? - if (userPrincipal instanceof Principal) { - // Get principal's name - principalName = userPrincipal.getName(); - } - - // Return it - return principalName; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - * @throws NumberFormatException If no number is given in context parameter - */ - protected int getIntegerContextParameter (final String parameterKey) throws NullPointerException, NumberFormatException { - // Get context parameter - Integer contextValue = Integer.parseInt(this.getStringContextParameter(parameterKey)); - - // Return it - return contextValue; - } - - /** - * Returns given property key or throws an exception if not found. - *

- * @param parameterKey Property key - *

- * @return Property value - *

- * @throws NullPointerException If given key is not found - */ - protected String getStringContextParameter (final String parameterKey) throws NullPointerException { - // Get context parameter - String contextValue = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(parameterKey); - - // Is it null? - if (null == contextValue) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("parameterKey={0} is not set.", parameterKey)); //NOI18N - } - - // Return it - return contextValue; - } - - /** - * Checks whether debug mode is enabled for given controller - *

- * @param controllerName Name of controller - *

- * @return Whether debug mode is enabled - */ - protected boolean isDebugModeEnabled (final String controllerName) { - // Parameters should be valid - if (null == controllerName) { - // Throw NPE - throw new NullPointerException("controllerName is null"); //NOI18N - } else if (controllerName.isEmpty()) { - // Is empty - throw new IllegalArgumentException("controllerName is empty"); //NOI18N - } - - // Try to get context parameter - String contextParameter = this.getStringContextParameter(String.format("is_debug_%s_enabled", controllerName)); //NOI18N - - // Is it set and true? - boolean isEnabled = (Boolean.parseBoolean(contextParameter) == Boolean.TRUE); - - // Return it - return isEnabled; - } - /** * Checks if given password is to weak to be used *

@@ -159,62 +62,4 @@ public abstract class BaseFinancialsController implements Serializable { return isWeak; } - /** - * Shows a faces message for given causing exception. The message from the - * exception is being inserted into the message. - *

- * @param clientId Client id to send message to - * @param cause Causing exception - */ - protected void showFacesMessage (final String clientId, final Throwable cause) { - // Get context and add message - this.showFacesMessage(clientId, cause.getMessage()); - } - - /** - * Shows a faces message with given message (i18n) key. - *

- * @param clientId Client id to send message to - * @param i18nKey Message key - *

- * @throws NullPointerException If clientId or i18nKey is null - * @throws IllegalArgumentException If clientId or i18nKey is empty - */ - protected void showFacesMessage (final String clientId, final String i18nKey) throws NullPointerException, IllegalArgumentException { - // Both parameter must be valid - if (null == clientId) { - // Throw NPE - throw new NullPointerException("clientId is null"); //NOI18N - } else if (clientId.isEmpty()) { - // Is empty - throw new IllegalArgumentException("clientId is null"); //NOI18N - } else if (null == i18nKey) { - // Throw NPE - throw new NullPointerException("i18nKey is null"); //NOI18N - } else if (i18nKey.isEmpty()) { - // Is empty - throw new IllegalArgumentException("i18nKey is null"); //NOI18N - } - - // Get current locale - Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale(); - - // Get bundle bundle - ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale); - - // Default is i18nKey - String message = i18nKey; - - // Try it - try { - // Get message - message = bundle.getString(i18nKey); - } catch (final MissingResourceException ex) { - // Did not find it, ignored - } - - // Get context and add message - FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(message)); - } - } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java similarity index 94% rename from src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java rename to src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java index dd921455..5accbae9 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestBean.java @@ -41,7 +41,7 @@ import org.mxchange.jfinancials.model.income.interval.FinancialInterval; */ @Named ("financialIncomeController") @RequestScoped -public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancialsController implements FinancialsAdminFinancialIncomeWebRequestController { +public class FinancialsIncomeWebRequestBean extends BaseFinancialsController implements FinancialsIncomeWebRequestController { /** * Serial number @@ -77,7 +77,7 @@ public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancials /** * Constructor */ - public FinancialsAdminFinancialIncomeWebRequestBean () { + public FinancialsIncomeWebRequestBean () { // Call super constructor super(); } @@ -87,7 +87,7 @@ public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancials *

* @return Redirect outcome */ - public String addFinancialIncome () { + public String addIncome () { // Is all data valid? if (!this.userLoginController.isUserLoggedIn()) { // Not logged-in @@ -121,7 +121,7 @@ public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancials } @Override - public List getAllIncomeIntervals () { + public List allIncomeIntervals () { // Init array List incomeIntervals = Arrays.asList(FinancialInterval.values()); diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java similarity index 93% rename from src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java rename to src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java index 85b993d7..e25f954e 100644 --- a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java +++ b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsIncomeWebRequestController.java @@ -25,7 +25,7 @@ import org.mxchange.jfinancials.model.income.interval.FinancialInterval; *

* @author Roland Häder */ -public interface FinancialsAdminFinancialIncomeWebRequestController extends Serializable { +public interface FinancialsIncomeWebRequestController extends Serializable { /** * Getter for income single amount @@ -74,6 +74,6 @@ public interface FinancialsAdminFinancialIncomeWebRequestController extends Seri *

* @return Income intervals */ - List getAllIncomeIntervals (); + List allIncomeIntervals (); } diff --git a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java new file mode 100644 index 00000000..62dcccf9 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestBean.java @@ -0,0 +1,82 @@ +/* + * 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.beans.financial.receipt; + +import javax.annotation.PostConstruct; +import javax.enterprise.context.RequestScoped; +import javax.faces.view.facelets.FaceletException; +import javax.inject.Inject; +import javax.inject.Named; +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import org.mxchange.jfinancials.beans.BaseFinancialsController; +import org.mxchange.jfinancials.beans.login.user.FinancialsUserLoginWebSessionController; +import org.mxchange.jfinancials.financial.receipt.FinancialReceiptSessionBeanRemote; + +/** + * An administrative financial receipt bean (controller) + *

+ * @author Roland Häder + */ +@Named ("financialReceiptController") +@RequestScoped +public class FinancialsReceiptWebRequestBean extends BaseFinancialsController implements FinancialsReceiptWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_371L; + + /** + * Remote contact bean + */ + private FinancialReceiptSessionBeanRemote financialBean; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * Constructor + */ + public FinancialsReceiptWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.financialBean = (FinancialReceiptSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/financial!org.mxchange.jfinancials.financial.receipt.FinancialReceiptSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java new file mode 100644 index 00000000..67416d87 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/receipt/FinancialsReceiptWebRequestController.java @@ -0,0 +1,28 @@ +/* + * 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.beans.financial.receipt; + +import java.io.Serializable; + +/** + * An administrative interface for financial receipt beans + *

+ * @author Roland Häder + */ +public interface FinancialsReceiptWebRequestController extends Serializable { + +} diff --git a/web/WEB-INF/templates/contact/form_contact_data.tpl b/web/WEB-INF/templates/contact/form_contact_data.tpl index 2d9fc075..822148ca 100644 --- a/web/WEB-INF/templates/contact/form_contact_data.tpl +++ b/web/WEB-INF/templates/contact/form_contact_data.tpl @@ -4,7 +4,8 @@ xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://xmlns.jcp.org/jsf/facelets" - xmlns:p="http://primefaces.org/ui"> + xmlns:p="http://primefaces.org/ui" + >

#{msg.PERSONAL_DATA_MINIMUM_NOTICE} diff --git a/web/user/financials/login_financials_add_income.xhtml b/web/user/financials/login_financials_add_income.xhtml index b789487e..a81cd7f8 100644 --- a/web/user/financials/login_financials_add_income.xhtml +++ b/web/user/financials/login_financials_add_income.xhtml @@ -44,7 +44,7 @@
- +
@@ -68,7 +68,7 @@ diff --git a/web/user/financials/login_financials_add_receipt.xhtml b/web/user/financials/login_financials_add_receipt.xhtml index 9cfbc754..1a0e88ee 100644 --- a/web/user/financials/login_financials_add_receipt.xhtml +++ b/web/user/financials/login_financials_add_receipt.xhtml @@ -4,7 +4,8 @@ xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://xmlns.jcp.org/jsf/html" xmlns:f="http://xmlns.jcp.org/jsf/core" - > + xmlns:p="http://primefaces.org/ui"> + > @@ -17,7 +18,50 @@ + +
+ +
+
+
+ +
+ +
+ + + + +
+ +
+
+ +
+
+ +
+ +
+ +
+ +
+
+ +
+ + + +
+ + +
-- 2.39.5