2 * Copyright (C) 2017 - 2020 Free Software Foundation
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.business.department;
20 import javax.enterprise.context.RequestScoped;
21 import javax.enterprise.event.Event;
22 import javax.enterprise.inject.Any;
23 import javax.inject.Inject;
24 import javax.inject.Named;
25 import org.mxchange.jcontactsbusiness.events.department.added.DepartmentAddedEvent;
26 import org.mxchange.jcontactsbusiness.events.department.added.ObservableDepartmentAddedEvent;
27 import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
28 import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
29 import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
30 import org.mxchange.jcontactsbusiness.model.department.AdminDepartmentSessionBeanRemote;
31 import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
32 import org.mxchange.jcontactsbusiness.model.department.Department;
33 import org.mxchange.jcontactsbusiness.model.employee.Employable;
34 import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
35 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
36 import org.mxchange.jfinancials.beans.business.department.list.FinancialsDepartmentListWebViewtController;
37 import org.mxchange.jusercore.model.user.User;
40 * An administrative bean for departments
42 * @author Roland Häder<roland@mxchange.org>
44 @Named ("adminDepartmentController")
46 public class FinancialsAdminDepartmentWebRequestBean extends BaseFinancialsBean implements FinancialsAdminDepartmentWebRequestController {
51 private static final long serialVersionUID = 5_028_697_360_464L;
54 * EJB for administrative purposes
56 @EJB (lookup = "java:global/jfinancials-ejb/adminDepartment!org.mxchange.jcontactsbusiness.model.department.AdminDepartmentSessionBeanRemote")
57 private AdminDepartmentSessionBeanRemote adminDepartmentBean;
60 * An event being fired when a department has been successfully added
64 private Event<ObservableDepartmentAddedEvent> departmentAddedEvent;
67 * Assigned branch office (if apply-able)
69 private BranchOffice departmentBranchOffice;
72 * Assigned company for this department
74 private BasicData departmentCompany;
77 * Assigned headquarter (if apply-able)
79 private Headquarter departmentHeadquarter;
84 private String departmentI18nKey;
87 * Lead person of this department
89 private Employable departmentLead;
92 * A general department controller (backing bean)
95 private FinancialsDepartmentListWebViewtController departmentListController;
98 * Owning user instance (which this department is assigned to)
100 private User departmentUserOwner;
103 * Default constructor
105 public FinancialsAdminDepartmentWebRequestBean () {
106 // Call super constructor
111 * Adds department with all data from this backing bean. First this action
112 * method will validate if the department's address is already registered
113 * and if found, it will output a proper faces message.
115 public void addDepartment () {
117 final Department department = this.createDepartment();
119 // Is the department not created yet?
120 if (this.departmentListController.isDepartmentAlreadyAdded(department)) {
121 // Then show proper faces message
122 this.showFacesMessage("form-admin-add-department:branchStreet", "ADMIN_DEPARTMENT_ALREADY_CREATED"); //NOI18N
126 // Delcare updated instance
127 final Department updatedDepartment;
131 updatedDepartment = this.adminDepartmentBean.addDepartment(department);
132 } catch (final DepartmentAlreadyAddedException ex) {
134 this.showFacesMessage("form-admin-add-department:departmentI18nKey", "ADMIN_DEPARTMENT_ALREADY_CREATED"); //NOI18N
139 this.departmentAddedEvent.fire(new DepartmentAddedEvent(updatedDepartment));
143 * Getter for assigned branch office
145 * @return Branch office
147 public BranchOffice getDepartmentBranchOffice () {
148 return this.departmentBranchOffice;
152 * Setter for assigned branch office
154 * @param departmentBranchOffice Branch office
156 public void setDepartmentBranchOffice (final BranchOffice departmentBranchOffice) {
157 this.departmentBranchOffice = departmentBranchOffice;
161 * Getter for basic company data
163 * @return Basic company data
165 public BasicData getDepartmentCompany () {
166 return this.departmentCompany;
170 * Setter for basic company data
172 * @param departmentCompany Basic company data
174 public void setDepartmentCompany (final BasicData departmentCompany) {
175 this.departmentCompany = departmentCompany;
179 * Getter for assigned headquarter data
181 * @return Headquarter data
183 public Headquarter getDepartmentHeadquarter () {
184 return this.departmentHeadquarter;
188 * Setter for assigned headquarter data
190 * @param departmentHeadquarter Headquarter data
192 public void setDepartmentHeadquarter (final Headquarter departmentHeadquarter) {
193 this.departmentHeadquarter = departmentHeadquarter;
197 * Getter for department name
199 * @return Department name
201 public String getDepartmentI18nKey () {
202 return this.departmentI18nKey;
206 * Setter for department name
208 * @param departmentI18nKey Department name
210 public void setDepartmentI18nKey (final String departmentI18nKey) {
211 this.departmentI18nKey = departmentI18nKey;
215 * Getter for department contact person
217 * @return Department contact person
219 public Employable getDepartmentLead () {
220 return this.departmentLead;
224 * Setter for department contact person
226 * @param departmentLead Department contact person
228 public void setDepartmentLead (final Employable departmentLead) {
229 this.departmentLead = departmentLead;
233 * Getter for owning user instance
235 * @return Owning user instance
237 public User getDepartmentUserOwner () {
238 return this.departmentUserOwner;
242 * Setter for owning user instance
244 * @param departmentUserOwner Owning user instance
246 public void setDepartmentUserOwner (final User departmentUserOwner) {
247 this.departmentUserOwner = departmentUserOwner;
251 * Prepares an instance of a Department object (entity) with all data from
252 * this bean. If a complete fax number or land-line number was provided, it
253 * will be set in the instance as well.
255 * @return An instance of a Department class (entity)
257 private Department createDepartment () {
258 // Create new department instance
259 final Department department = new BusinessDepartment(this.getDepartmentCompany(), this.getDepartmentI18nKey());
261 // Add all optional fields
262 department.setDepartmentHeadquarter(this.getDepartmentHeadquarter());
263 department.setDepartmentBranchOffice(this.getDepartmentBranchOffice());
264 department.setDepartmentLead(this.getDepartmentLead());
265 department.setDepartmentUserOwner(this.getDepartmentUserOwner());
267 // Return fully prepared instance