From: Roland Häder Date: Tue, 6 Jun 2017 21:01:04 +0000 (+0200) Subject: let's keep controller for income and expenses separate and not have one "super" contr... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=27d841962d56a3eb4efef4acd90a0aee6b6b32ca;p=jfinancials-war.git let's keep controller for income and expenses separate and not have one "super" controller for all admin/user-financial stuff Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestBean.java deleted file mode 100644 index 5907473d..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestBean.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * 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; - -import org.mxchange.jfinancials.FinancialSessionBeanRemote; -import java.text.MessageFormat; -import java.util.Arrays; -import java.util.List; -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.model.income.BillableIncome; -import org.mxchange.jfinancials.model.income.FinancialIncome; -import org.mxchange.jfinancials.model.income.interval.FinancialInterval; - -/** - * An administrative user bean (controller) - *

- * @author Roland Häder - */ -@Named ("financialController") -@RequestScoped -public class FinancialsAdminFinancialWebRequestBean extends BaseFinancialsController implements FinancialsAdminFinancialWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 56_189_028_928_371L; - - /** - * Remote contact bean - */ - private FinancialSessionBeanRemote financialBean; - - /** - * Income interval - */ - private FinancialInterval incomeInterval; - - /** - * Income single amount - */ - private Float incomeSingleAmount; - - /** - * Income (type) title - */ - private String incomeTitle; - - /** - * User instance - */ - @Inject - private FinancialsUserLoginWebSessionController userLoginController; - - /** - * Constructor - */ - public FinancialsAdminFinancialWebRequestBean () { - // Call super constructor - super(); - } - - public String addFinancialIncome () { - // Is all data valid? - if (null == this.getIncomeInterval()) { - // Throw NPE - throw new NullPointerException("incomeInterval is null"); //NOI18N - } else if (null == this.getIncomeSingleAmount()) { - // Throw again - throw new NullPointerException("incomeSingleAmount is null"); //NOI18N - } else if (this.getIncomeSingleAmount() < 0) { - // Not allowed value - throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", this.getIncomeSingleAmount())); //NOI18N - } else if (null == this.getIncomeTitle()) { - // Throw again - throw new NullPointerException("incomeTitle is null"); //NOI18N - } else if (this.getIncomeTitle().isEmpty()) { - // Should not be empty - throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N - } - - // Now that all required data has been entered, prepare new income instance - BillableIncome income = new FinancialIncome(this.getIncomeTitle(), this.getIncomeSingleAmount(), this.getIncomeInterval(), this.userLoginController.getLoggedInUser()); - - // Handle it over to the EJB - // @TODO Use updated income instance, e.g. fire event - BillableIncome updatedIncome = this.financialBean.addIncome(income); - - // All fine - return "add_user_fiancial_income"; //NOI18N - } - - @Override - public List getAllIncomeIntervals () { - // Init array - List incomeIntervals = Arrays.asList(FinancialInterval.values()); - - // Return it - return incomeIntervals; - } - - @Override - public FinancialInterval getIncomeInterval () { - return this.incomeInterval; - } - - @Override - public void setIncomeInterval (final FinancialInterval incomeInterval) { - this.incomeInterval = incomeInterval; - } - - @Override - public Float getIncomeSingleAmount () { - return this.incomeSingleAmount; - } - - @Override - public void setIncomeSingleAmount (final Float incomeSingleAmount) { - this.incomeSingleAmount = incomeSingleAmount; - } - - @Override - public String getIncomeTitle () { - return this.incomeTitle; - } - - @Override - public void setIncomeTitle (final String incomeTitle) { - this.incomeTitle = incomeTitle; - } - - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.financialBean = (FinancialSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/financial!org.mxchange.jfinancials.FinancialSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - } - -} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestController.java deleted file mode 100644 index df46fe68..00000000 --- a/src/java/org/mxchange/jfinancials/beans/financial/FinancialsAdminFinancialWebRequestController.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jfinancials.model.income.interval.FinancialInterval; - -/** - * An administrative interface for user beans - *

- * @author Roland Häder - */ -public interface FinancialsAdminFinancialWebRequestController extends Serializable { - - /** - * Getter for income single amount - *

- * @return Income single amount - */ - Float getIncomeSingleAmount (); - - /** - * Setter for income single amount - *

- * @param incomeSingleAmount Income single amount - */ - void setIncomeSingleAmount (final Float incomeSingleAmount); - - /** - * Getter for income (type) title - *

- * @return Income title - */ - String getIncomeTitle (); - - /** - * Setter for income (type) title - *

- * @param incomeTitle Income title - */ - void setIncomeTitle (final String incomeTitle); - - /** - * Getter for income interval - *

- * @return Income interval - */ - FinancialInterval getIncomeInterval (); - - /** - * Setter for income (type) interval - *

- * @param incomeInterval Income interval - */ - void setIncomeInterval (final FinancialInterval incomeInterval); - - /** - * Returns a list of all all income intervals - *

- * @return Income intervals - */ - List getAllIncomeIntervals (); - -} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java new file mode 100644 index 00000000..dd921455 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestBean.java @@ -0,0 +1,180 @@ +/* + * 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.income; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.List; +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.income.FinancialIncomeSessionBeanRemote; +import org.mxchange.jfinancials.model.income.BillableIncome; +import org.mxchange.jfinancials.model.income.FinancialIncome; +import org.mxchange.jfinancials.model.income.interval.FinancialInterval; + +/** + * An administrative financial income bean (controller) + *

+ * @author Roland Häder + */ +@Named ("financialIncomeController") +@RequestScoped +public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancialsController implements FinancialsAdminFinancialIncomeWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 56_189_028_928_371L; + + /** + * Remote contact bean + */ + private FinancialIncomeSessionBeanRemote financialBean; + + /** + * Income interval + */ + private FinancialInterval incomeInterval; + + /** + * Income single amount + */ + private Float incomeSingleAmount; + + /** + * Income (type) title + */ + private String incomeTitle; + + /** + * User instance + */ + @Inject + private FinancialsUserLoginWebSessionController userLoginController; + + /** + * Constructor + */ + public FinancialsAdminFinancialIncomeWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds income data by calling proper business method of the EJB. + *

+ * @return Redirect outcome + */ + public String addFinancialIncome () { + // Is all data valid? + if (!this.userLoginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (null == this.getIncomeInterval()) { + // Throw NPE + throw new NullPointerException("incomeInterval is null"); //NOI18N + } else if (null == this.getIncomeSingleAmount()) { + // Throw again + throw new NullPointerException("incomeSingleAmount is null"); //NOI18N + } else if (this.getIncomeSingleAmount() < 0) { + // Not allowed value + throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", this.getIncomeSingleAmount())); //NOI18N + } else if (null == this.getIncomeTitle()) { + // Throw again + throw new NullPointerException("incomeTitle is null"); //NOI18N + } else if (this.getIncomeTitle().isEmpty()) { + // Should not be empty + throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N + } + + // Now that all required data has been entered, prepare new income instance + BillableIncome income = new FinancialIncome(this.getIncomeTitle(), this.getIncomeSingleAmount(), this.getIncomeInterval(), this.userLoginController.getLoggedInUser()); + + // Handle it over to the EJB + // @TODO Use updated income instance, e.g. fire event + BillableIncome updatedIncome = this.financialBean.addIncome(income); + + // All fine + return "add_user_fiancial_income"; //NOI18N + } + + @Override + public List getAllIncomeIntervals () { + // Init array + List incomeIntervals = Arrays.asList(FinancialInterval.values()); + + // Return it + return incomeIntervals; + } + + @Override + public FinancialInterval getIncomeInterval () { + return this.incomeInterval; + } + + @Override + public void setIncomeInterval (final FinancialInterval incomeInterval) { + this.incomeInterval = incomeInterval; + } + + @Override + public Float getIncomeSingleAmount () { + return this.incomeSingleAmount; + } + + @Override + public void setIncomeSingleAmount (final Float incomeSingleAmount) { + this.incomeSingleAmount = incomeSingleAmount; + } + + @Override + public String getIncomeTitle () { + return this.incomeTitle; + } + + @Override + public void setIncomeTitle (final String incomeTitle) { + this.incomeTitle = incomeTitle; + } + + /** + * Post-initialization of this class + */ + @PostConstruct + public void init () { + // Try it + try { + // Get initial context + Context context = new InitialContext(); + + // Try to lookup + this.financialBean = (FinancialIncomeSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/financial!org.mxchange.jfinancials.financial.income.FinancialIncomeSessionBeanRemote"); //NOI18N + } catch (final NamingException e) { + // Throw again + throw new FaceletException(e); + } + } + +} diff --git a/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java new file mode 100644 index 00000000..85b993d7 --- /dev/null +++ b/src/java/org/mxchange/jfinancials/beans/financial/income/FinancialsAdminFinancialIncomeWebRequestController.java @@ -0,0 +1,79 @@ +/* + * 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.income; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jfinancials.model.income.interval.FinancialInterval; + +/** + * An administrative interface for financial income beans + *

+ * @author Roland Häder + */ +public interface FinancialsAdminFinancialIncomeWebRequestController extends Serializable { + + /** + * Getter for income single amount + *

+ * @return Income single amount + */ + Float getIncomeSingleAmount (); + + /** + * Setter for income single amount + *

+ * @param incomeSingleAmount Income single amount + */ + void setIncomeSingleAmount (final Float incomeSingleAmount); + + /** + * Getter for income (type) title + *

+ * @return Income title + */ + String getIncomeTitle (); + + /** + * Setter for income (type) title + *

+ * @param incomeTitle Income title + */ + void setIncomeTitle (final String incomeTitle); + + /** + * Getter for income interval + *

+ * @return Income interval + */ + FinancialInterval getIncomeInterval (); + + /** + * Setter for income (type) interval + *

+ * @param incomeInterval Income interval + */ + void setIncomeInterval (final FinancialInterval incomeInterval); + + /** + * Returns a list of all all income intervals + *

+ * @return Income intervals + */ + List getAllIncomeIntervals (); + +} diff --git a/web/user/financials/login_financials_add_income.xhtml b/web/user/financials/login_financials_add_income.xhtml index 274a26b3..b789487e 100644 --- a/web/user/financials/login_financials_add_income.xhtml +++ b/web/user/financials/login_financials_add_income.xhtml @@ -28,7 +28,7 @@

- +
@@ -42,9 +42,9 @@
- + - +
@@ -57,7 +57,7 @@
- +
@@ -68,7 +68,7 @@ diff --git a/web/user/financials/login_financials_overview.xhtml b/web/user/financials/login_financials_overview.xhtml index 5a5fae09..15aaec65 100644 --- a/web/user/financials/login_financials_overview.xhtml +++ b/web/user/financials/login_financials_overview.xhtml @@ -25,19 +25,19 @@ - + - + - +