2 * Copyright (C) 2016, 2017 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.beans.financial.income;
19 import java.text.MessageFormat;
20 import java.util.Arrays;
21 import java.util.List;
22 import javax.annotation.PostConstruct;
23 import javax.enterprise.context.RequestScoped;
24 import javax.faces.view.facelets.FaceletException;
25 import javax.inject.Inject;
26 import javax.inject.Named;
27 import javax.naming.Context;
28 import javax.naming.InitialContext;
29 import javax.naming.NamingException;
30 import org.mxchange.jfinancials.beans.BaseFinancialsController;
31 import org.mxchange.jfinancials.beans.login.user.FinancialsUserLoginWebSessionController;
32 import org.mxchange.jfinancials.financial.income.FinancialIncomeSessionBeanRemote;
33 import org.mxchange.jfinancials.model.income.BillableIncome;
34 import org.mxchange.jfinancials.model.income.FinancialIncome;
35 import org.mxchange.jfinancials.model.income.interval.FinancialInterval;
38 * An administrative financial income bean (controller)
40 * @author Roland Häder<roland@mxchange.org>
42 @Named ("financialIncomeController")
44 public class FinancialsAdminFinancialIncomeWebRequestBean extends BaseFinancialsController implements FinancialsAdminFinancialIncomeWebRequestController {
49 private static final long serialVersionUID = 56_189_028_928_371L;
54 private FinancialIncomeSessionBeanRemote financialBean;
59 private FinancialInterval incomeInterval;
62 * Income single amount
64 private Float incomeSingleAmount;
69 private String incomeTitle;
75 private FinancialsUserLoginWebSessionController userLoginController;
80 public FinancialsAdminFinancialIncomeWebRequestBean () {
81 // Call super constructor
86 * Adds income data by calling proper business method of the EJB.
88 * @return Redirect outcome
90 public String addFinancialIncome () {
92 if (!this.userLoginController.isUserLoggedIn()) {
94 throw new IllegalStateException("User is not logged-in"); //NOI18N
95 } else if (null == this.getIncomeInterval()) {
97 throw new NullPointerException("incomeInterval is null"); //NOI18N
98 } else if (null == this.getIncomeSingleAmount()) {
100 throw new NullPointerException("incomeSingleAmount is null"); //NOI18N
101 } else if (this.getIncomeSingleAmount() < 0) {
103 throw new IllegalArgumentException(MessageFormat.format("incomeSingleAmount={0} is not valid.", this.getIncomeSingleAmount())); //NOI18N
104 } else if (null == this.getIncomeTitle()) {
106 throw new NullPointerException("incomeTitle is null"); //NOI18N
107 } else if (this.getIncomeTitle().isEmpty()) {
108 // Should not be empty
109 throw new IllegalArgumentException("incomeTitle is empty"); //NOI18N
112 // Now that all required data has been entered, prepare new income instance
113 BillableIncome income = new FinancialIncome(this.getIncomeTitle(), this.getIncomeSingleAmount(), this.getIncomeInterval(), this.userLoginController.getLoggedInUser());
115 // Handle it over to the EJB
116 // @TODO Use updated income instance, e.g. fire event
117 BillableIncome updatedIncome = this.financialBean.addIncome(income);
120 return "add_user_fiancial_income"; //NOI18N
124 public List<FinancialInterval> getAllIncomeIntervals () {
126 List<FinancialInterval> incomeIntervals = Arrays.asList(FinancialInterval.values());
129 return incomeIntervals;
133 public FinancialInterval getIncomeInterval () {
134 return this.incomeInterval;
138 public void setIncomeInterval (final FinancialInterval incomeInterval) {
139 this.incomeInterval = incomeInterval;
143 public Float getIncomeSingleAmount () {
144 return this.incomeSingleAmount;
148 public void setIncomeSingleAmount (final Float incomeSingleAmount) {
149 this.incomeSingleAmount = incomeSingleAmount;
153 public String getIncomeTitle () {
154 return this.incomeTitle;
158 public void setIncomeTitle (final String incomeTitle) {
159 this.incomeTitle = incomeTitle;
163 * Post-initialization of this class
166 public void init () {
169 // Get initial context
170 Context context = new InitialContext();
173 this.financialBean = (FinancialIncomeSessionBeanRemote) context.lookup("java:global/jfinancials-ejb/financial!org.mxchange.jfinancials.financial.income.FinancialIncomeSessionBeanRemote"); //NOI18N
174 } catch (final NamingException e) {
176 throw new FaceletException(e);