From: Roland Häder Date: Fri, 11 Oct 2019 09:32:59 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c05bce762b6daaabd28ac2602350741373fd257c;p=jjobs-war.git Don't cherry-pick: - renamed a lot files according to naming convention, like no Headquarter>s< (s is plural here) and no CompanyEmployee and so on - used java.util.Date instead of java.util.Calendar as it is done everywhere - fixed a lot errors to make this project at least compile again Signed-off-by: Roland Häder --- diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java index a883a7f0..95563b83 100644 --- a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java @@ -17,8 +17,8 @@ package org.mxchange.jjobs.beans.addressbook; import java.text.MessageFormat; -import java.util.Calendar; import java.util.Collections; +import java.util.Date; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -41,7 +41,7 @@ import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException; import org.mxchange.jaddressbook.model.addressbook.Addressbook; import org.mxchange.jaddressbook.model.addressbook.UserAddressbook; import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry; -import org.mxchange.jjobs.beans.BaseJobsController; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; import org.mxchange.jusercore.model.user.User; import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; @@ -53,7 +53,7 @@ import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; */ @Named ("addressbookController") @SessionScoped -public class JobsAddressbookWebSessionBean extends BaseJobsController implements JobsAddressbookWebSessionController { +public class JobsAddressbookWebSessionBean extends BaseJobsBean implements JobsAddressbookWebSessionController { /** * Serial number @@ -73,7 +73,7 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements /** * When this address book has been created */ - private Calendar addressbookCreated; + private Date addressbookCreated; /** * Address book id number (from URL for example) @@ -175,7 +175,7 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements } // Get address book instance - Addressbook book = event.getAddressbook(); + final Addressbook book = event.getAddressbook(); // Set address book data this.setAddressbookId(book.getAddressbookId()); @@ -249,13 +249,13 @@ public class JobsAddressbookWebSessionBean extends BaseJobsController implements @Override @SuppressWarnings ("ReturnOfDateField") - public Calendar getAddressbookCreated () { + public Date getAddressbookCreated () { return this.addressbookCreated; } @Override @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setAddressbookCreated (final Calendar addressbookCreated) { + public void setAddressbookCreated (final Date addressbookCreated) { this.addressbookCreated = addressbookCreated; } diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java index ee30ec31..56a9d6cb 100644 --- a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java +++ b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java @@ -17,7 +17,7 @@ package org.mxchange.jjobs.beans.addressbook; import java.io.Serializable; -import java.util.Calendar; +import java.util.Date; import java.util.List; import org.mxchange.jaddressbook.events.addressbook.ObservableAddressbookLoadedEvent; import org.mxchange.jaddressbook.model.addressbook.Addressbook; @@ -130,14 +130,14 @@ public interface JobsAddressbookWebSessionController extends Serializable { *

* @return When the address book has been created */ - Calendar getAddressbookCreated (); + Date getAddressbookCreated (); /** * Setter for when the address book has been created *

* @param addressbookCreated When the address book has been created */ - void setAddressbookCreated (final Calendar addressbookCreated); + void setAddressbookCreated (final Date addressbookCreated); /** * This method is called when an address book has been successfully loaded diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java deleted file mode 100644 index 961daf8e..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestBean.java +++ /dev/null @@ -1,444 +0,0 @@ -/* - * Copyright (C) 2017, 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.jjobs.beans.business.employee; - -import javax.ejb.EJB; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontactsbusiness.events.employee.added.EmployeeAddedEvent; -import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; -import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeAlreadyAddedException; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; -import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; -import org.mxchange.jcontactsbusiness.model.department.Department; -import org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; -import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.employee.Employees; -import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; -import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; -import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; -import org.mxchange.jusercore.model.user.User; - -/** - * A request-scoped bean for administrative purposes for administrative employee - * purposes. - *

- * @author Roland Häder - */ -@Named ("adminEmployeeController") -@RequestScoped -public class JobsAdminEmployeeWebRequestBean extends BaseJobsBean implements JobsAdminEmployeeWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 12_886_968_547_360L; - - /** - * An event being fired when an employee has been added - */ - @Inject - @Any - private Event addedEmployeeEvent; - - /** - * EJB for administrative company employee purposes - */ - @EJB (lookup = "java:global/jjobs-ejb/adminEmployee!org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote") - private AdminEmployeeSessionBeanRemote adminEmployeeBean; - - /** - * Assigned basic data instance - */ - private BasicData employeeBasicData; - - /** - * Assigned branch office - */ - private BranchOffice employeeBranchOffice; - - /** - * General employee controller - */ - @Inject - private JobsEmployeeWebRequestController employeeController; - - /** - * Department where employee works (alternative to headquarter) - */ - private Department employeeDepartment; - - /** - * Employee's business email address - */ - private String employeeEmailAddress; - - /** - * Employee's Headquarter data, if he is working there - */ - private Headquarter employeeHeadquarter; - - /** - * Employee's staff number - */ - private String employeeNumber; - - /** - * Assigned personal data of the employee - */ - private Contact employeePersonalData; - - /** - * Employee's phone extension (on top of a "main number") - */ - private Integer employeePhoneExtension; - - /** - * Assigned user account - */ - private User employeeUserOwner; - - /** - * Mobile number for employee's business mobile - */ - private Long mobileNumber; - - /** - * Mobile provider instance for employee's business mobile - */ - private MobileProvider mobileProvider; - - /** - * Default constructor - */ - public JobsAdminEmployeeWebRequestBean () { - // Call super constructor - super(); - } - - /** - * Adds branch office with all data from this backing bean. First this - * action method will validate if the branch office's address is already - * registered and if found, it will output a proper faces message. - */ - public void addEmployee () { - // Get instance - final Employable employee = this.createEmployee(); - - // Is the branch office not created yet? - if (this.isEmployeeCreatedByRequiredData(employee)) { - // Then show proper faces message - this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED"); //NOI18N - return; - } - - // Delcare updated instance - final Employable updatedOffice; - - try { - // Try to call EJB - updatedOffice = this.adminEmployeeBean.addEmployee(employee); - } catch (final EmployeeAlreadyAddedException ex) { - // Output message - this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED"); //NOI18N - return; - } - - // Fire event - this.addedEmployeeEvent.fire(new EmployeeAddedEvent(updatedOffice)); - - // Clear this bean - this.clear(); - } - - /** - * Getter for employee's assigned basic company data - *

- * @return Employee's assigned basic company data - */ - public BasicData getEmployeeBasicData () { - return this.employeeBasicData; - } - - /** - * Setter for employee's assigned basic company data - *

- * @param employeeBasicData Employee's assigned basic company data - */ - public void setEmployeeBasicData (final BasicData employeeBasicData) { - this.employeeBasicData = employeeBasicData; - } - - /** - * Getter for employee's assigned branch office - *

- * @return Employee's assigned branch office - */ - public BranchOffice getEmployeeBranchOffice () { - return this.employeeBranchOffice; - } - - /** - * Setter for employee's assigned branch office - *

- * @param employeeBranchOffice Employee's assigned branch office - */ - public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) { - this.employeeBranchOffice = employeeBranchOffice; - } - - /** - * Getter for employee's assigned department - *

- * @return Employee's assigned department - */ - public Department getEmployeeDepartment () { - return this.employeeDepartment; - } - - /** - * Setter for employee's assigned department - *

- * @param employeeDepartment Employee's assigned department - */ - public void setEmployeeDepartment (final Department employeeDepartment) { - this.employeeDepartment = employeeDepartment; - } - - /** - * Getter for employee's business email address - *

- * @return Employee's business email address - */ - public String getEmployeeEmailAddress () { - return this.employeeEmailAddress; - } - - /** - * Setter for employee's business email address - *

- * @param employeeEmailAddress Employee's business email address - */ - public void setEmployeeEmailAddress (final String employeeEmailAddress) { - this.employeeEmailAddress = employeeEmailAddress; - } - - /** - * Getter for employee's assigned headquarter (if no branch office) - *

- * @return Employee's assigned headquarter - */ - public Headquarter getEmployeeHeadquarter () { - return this.employeeHeadquarter; - } - - /** - * Setter for employee's assigned headquarter (if no branch office) - *

- * @param employeeHeadquarter Employee's assigned headquarter - */ - public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) { - this.employeeHeadquarter = employeeHeadquarter; - } - - /** - * Getter for employee's staff number - *

- * @return Employee's staff number - */ - public String getEmployeeNumber () { - return this.employeeNumber; - } - - /** - * Setter for employee's staff number - *

- * @param employeeNumber Employee's staff number - */ - public void setEmployeeNumber (final String employeeNumber) { - this.employeeNumber = employeeNumber; - } - - /** - * Getter for employee's personal contact data - *

- * @return Employee's personal contact data - */ - public Contact getEmployeePersonalData () { - return this.employeePersonalData; - } - - /** - * Setter for employee's personal contact data - *

- * @param employeePersonalData Employee's personal contact data - */ - public void setEmployeePersonalData (final Contact employeePersonalData) { - this.employeePersonalData = employeePersonalData; - } - - /** - * Getter for employee's phone extension - *

- * @return Employee's phone extension - */ - public Integer getEmployeePhoneExtension () { - return this.employeePhoneExtension; - } - - /** - * Getter for employee's phone extension - *

- * @param employeePhoneExtension Employee's phone extension - */ - public void setEmployeePhoneExtension (final Integer employeePhoneExtension) { - this.employeePhoneExtension = employeePhoneExtension; - } - - /** - * Getter for employee's user "owner" - *

- * @return Employee's user "owner" - */ - public User getEmployeeUserOwner () { - return this.employeeUserOwner; - } - - /** - * Setter for employee's user "owner" - *

- * @param employeeUserOwner Employee's user "owner" - */ - public void setEmployeeUserOwner (final User employeeUserOwner) { - this.employeeUserOwner = employeeUserOwner; - } - - /** - * Getter for mobile number - *

- * @return Mobile number - */ - public Long getMobileNumber () { - return this.mobileNumber; - } - - /** - * Setter for mobile number - *

- * @param mobileNumber Mobile number - */ - public void setMobileNumber (final Long mobileNumber) { - this.mobileNumber = mobileNumber; - } - - /** - * Getter for mobile provider instance - *

- * @return Mobile provider instance - */ - public MobileProvider getMobileProvider () { - return this.mobileProvider; - } - - /** - * Setter for mobile provider instance - *

- * @param mobileProvider Mobile provider instance - */ - public void setMobileProvider (final MobileProvider mobileProvider) { - this.mobileProvider = mobileProvider; - } - - /** - * Clears all bean fields - */ - private void clear () { - // Clear all fields - this.setEmployeeBranchOffice(null); - this.setEmployeeCompany(null); - this.setEmployeeDepartment(null); - this.setEmployeeEmailAddress(null); - this.setEmployeeHeadquarter(null); - this.setEmployeePersonalData(null); - this.setEmployeePhoneExtension(null); - this.setEmployeeNumber(null); - this.setEmployeeUserOwner(null); - } - - /** - * Creates employee instance with all data from this bean - *

- * @return Employee instance - */ - private Employable createEmployee () { - // Init instance - final Employable employee = new BusinessEmployee(this.getEmployeeCompany(), this.getEmployeeNumber(), this.getEmployeePersonalData()); - - // Set all othewr data - employee.setEmployeeBranchOffice(this.getEmployeeBranchOffice()); - employee.setEmployeeDepartment(this.getEmployeeDepartment()); - employee.setEmployeeHeadquarter(this.getEmployeeHeadquarter()); - employee.setEmployeePhoneExtension(this.getEmployeePhoneExtension()); - // @TODO employee.setEmployeePosition(this.getEmployeePosition()); - employee.setEmployeeUserOwner(this.getEmployeeUserOwner()); - - // Is mobile provider and number set? - if ((this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { - // Init mobile number instance - final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); - - // Set it in employee - employee.setEmployeeMobileNumber(number); - } - - // Return it - return employee; - } - - /** - * Checks whether given employee is already added - *

- * @param employee Employee to be checked - *

- * @return Whether the employee has already been added - */ - private boolean isEmployeeCreatedByRequiredData (final Employable employee) { - // Default is not found - boolean isFound = false; - - // Check all employees - for (final Employable otherEmployee : this.employeeController.allEmployees()) { - // Is same found? - if (Employees.isSameEmployeeFound(employee, otherEmployee)) { - // Okay, found it - isFound = true; - break; - } - } - - // Return it - return isFound; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java deleted file mode 100644 index 00a5932a..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminCompanyEmployeeWebRequestController.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2017, 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.jjobs.beans.business.employee; - -import java.io.Serializable; - -/** - * An interface for request-scoped administrative company employee beans - *

- * @author Roland Häder - */ -public interface JobsAdminEmployeeWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java new file mode 100644 index 00000000..40a862fa --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java @@ -0,0 +1,448 @@ +/* + * Copyright (C) 2017, 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.jjobs.beans.business.employee; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontactsbusiness.events.employee.added.EmployeeAddedEvent; +import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; +import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeAlreadyAddedException; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice; +import org.mxchange.jcontactsbusiness.model.department.Department; +import org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote; +import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.employee.Employees; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber; +import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; +import org.mxchange.jusercore.model.user.User; + +/** + * A request-scoped bean for administrative purposes for administrative employee + * purposes. + *

+ * @author Roland Häder + */ +@Named ("adminEmployeeController") +@RequestScoped +public class JobsAdminEmployeeWebRequestBean extends BaseJobsBean implements JobsAdminEmployeeWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 12_886_968_547_360L; + + /** + * An event being fired when an employee has been added + */ + @Inject + @Any + private Event addedEmployeeEvent; + + /** + * EJB for administrative company employee purposes + */ + @EJB (lookup = "java:global/jjobs-ejb/adminEmployee!org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote") + private AdminEmployeeSessionBeanRemote adminEmployeeBean; + + /** + * Assigned basic data instance + */ + private BasicData employeeBasicData; + + /** + * Assigned branch office + */ + private BranchOffice employeeBranchOffice; + + /** + * General employee controller + */ + @Inject + private JobsEmployeeWebRequestController employeeController; + + /** + * Department where employee works (alternative to headquarter) + */ + private Department employeeDepartment; + + /** + * Employee's business email address + */ + private String employeeEmailAddress; + + /** + * Employee's Headquarter data, if he is working there + */ + private Headquarter employeeHeadquarter; + + /** + * Employee's staff number + */ + private String employeeNumber; + + /** + * Assigned personal data of the employee + */ + private Contact employeePersonalData; + + /** + * Employee's phone extension (on top of a "main number") + */ + private Integer employeePhoneExtension; + + /** + * Assigned user account + */ + private User employeeUserOwner; + + /** + * Mobile number for employee's business mobile + */ + private Long mobileNumber; + + /** + * Mobile provider instance for employee's business mobile + */ + private MobileProvider mobileProvider; + + /** + * Default constructor + */ + public JobsAdminEmployeeWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Adds branch office with all data from this backing bean. First this + * action method will validate if the branch office's address is already + * registered and if found, it will output a proper faces message. + */ + public void addEmployee () { + // Get instance + final Employable employee = this.createEmployee(); + + // Is the branch office not created yet? + if (this.isEmployeeCreatedByRequiredData(employee)) { + // Then show proper faces message + this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED"); //NOI18N + return; + } + + // Delcare updated instance + final Employable updatedOffice; + + try { + // Try to call EJB + updatedOffice = this.adminEmployeeBean.addEmployee(employee); + } catch (final EmployeeAlreadyAddedException ex) { + // Output message + this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED"); //NOI18N + return; + } + + // Fire event + this.addedEmployeeEvent.fire(new EmployeeAddedEvent(updatedOffice)); + + // Clear this bean + this.clear(); + } + + /** + * Getter for employee's assigned basic company data + *

+ * @return Employee's assigned basic company data + */ + public BasicData getEmployeeBasicData () { + return this.employeeBasicData; + } + + /** + * Setter for employee's assigned basic company data + *

+ * @param employeeBasicData Employee's assigned basic company data + */ + public void setEmployeeBasicData (final BasicData employeeBasicData) { + this.employeeBasicData = employeeBasicData; + } + + /** + * Getter for employee's assigned branch office + *

+ * @return Employee's assigned branch office + */ + public BranchOffice getEmployeeBranchOffice () { + return this.employeeBranchOffice; + } + + /** + * Setter for employee's assigned branch office + *

+ * @param employeeBranchOffice Employee's assigned branch office + */ + public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) { + this.employeeBranchOffice = employeeBranchOffice; + } + + /** + * Getter for employee's assigned department + *

+ * @return Employee's assigned department + */ + public Department getEmployeeDepartment () { + return this.employeeDepartment; + } + + /** + * Setter for employee's assigned department + *

+ * @param employeeDepartment Employee's assigned department + */ + public void setEmployeeDepartment (final Department employeeDepartment) { + this.employeeDepartment = employeeDepartment; + } + + /** + * Getter for employee's business email address + *

+ * @return Employee's business email address + */ + public String getEmployeeEmailAddress () { + return this.employeeEmailAddress; + } + + /** + * Setter for employee's business email address + *

+ * @param employeeEmailAddress Employee's business email address + */ + public void setEmployeeEmailAddress (final String employeeEmailAddress) { + this.employeeEmailAddress = employeeEmailAddress; + } + + /** + * Getter for employee's assigned headquarter (if no branch office) + *

+ * @return Employee's assigned headquarter + */ + public Headquarter getEmployeeHeadquarter () { + return this.employeeHeadquarter; + } + + /** + * Setter for employee's assigned headquarter (if no branch office) + *

+ * @param employeeHeadquarter Employee's assigned headquarter + */ + public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) { + this.employeeHeadquarter = employeeHeadquarter; + } + + /** + * Getter for employee's staff number + *

+ * @return Employee's staff number + */ + public String getEmployeeNumber () { + return this.employeeNumber; + } + + /** + * Setter for employee's staff number + *

+ * @param employeeNumber Employee's staff number + */ + public void setEmployeeNumber (final String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + /** + * Getter for employee's personal contact data + *

+ * @return Employee's personal contact data + */ + public Contact getEmployeePersonalData () { + return this.employeePersonalData; + } + + /** + * Setter for employee's personal contact data + *

+ * @param employeePersonalData Employee's personal contact data + */ + public void setEmployeePersonalData (final Contact employeePersonalData) { + this.employeePersonalData = employeePersonalData; + } + + /** + * Getter for employee's phone extension + *

+ * @return Employee's phone extension + */ + public Integer getEmployeePhoneExtension () { + return this.employeePhoneExtension; + } + + /** + * Getter for employee's phone extension + *

+ * @param employeePhoneExtension Employee's phone extension + */ + public void setEmployeePhoneExtension (final Integer employeePhoneExtension) { + this.employeePhoneExtension = employeePhoneExtension; + } + + /** + * Getter for employee's user "owner" + *

+ * @return Employee's user "owner" + */ + public User getEmployeeUserOwner () { + return this.employeeUserOwner; + } + + /** + * Setter for employee's user "owner" + *

+ * @param employeeUserOwner Employee's user "owner" + */ + public void setEmployeeUserOwner (final User employeeUserOwner) { + this.employeeUserOwner = employeeUserOwner; + } + + /** + * Getter for mobile number + *

+ * @return Mobile number + */ + public Long getMobileNumber () { + return this.mobileNumber; + } + + /** + * Setter for mobile number + *

+ * @param mobileNumber Mobile number + */ + public void setMobileNumber (final Long mobileNumber) { + this.mobileNumber = mobileNumber; + } + + /** + * Getter for mobile provider instance + *

+ * @return Mobile provider instance + */ + public MobileProvider getMobileProvider () { + return this.mobileProvider; + } + + /** + * Setter for mobile provider instance + *

+ * @param mobileProvider Mobile provider instance + */ + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; + } + + /** + * Clears all bean fields + */ + private void clear () { + // Clear all fields + this.setEmployeeBranchOffice(null); + this.setEmployeeBasicData(null); + this.setEmployeeDepartment(null); + this.setEmployeeEmailAddress(null); + this.setEmployeeHeadquarter(null); + this.setEmployeePersonalData(null); + this.setEmployeePhoneExtension(null); + this.setEmployeeNumber(null); + this.setEmployeeUserOwner(null); + } + + /** + * Creates employee instance with all data from this bean + *

+ * @return Employee instance + */ + private Employable createEmployee () { + // Init instance + final Employable employee = new BusinessEmployee( + this.getEmployeeBasicData(), + this.getEmployeeNumber(), + this.getEmployeePersonalData() + ); + + // Set all othewr data + employee.setEmployeeBranchOffice(this.getEmployeeBranchOffice()); + employee.setEmployeeDepartment(this.getEmployeeDepartment()); + employee.setEmployeeHeadquarter(this.getEmployeeHeadquarter()); + employee.setEmployeePhoneExtension(this.getEmployeePhoneExtension()); + // @TODO employee.setEmployeePosition(this.getEmployeePosition()); + employee.setEmployeeUserOwner(this.getEmployeeUserOwner()); + + // Is mobile provider and number set? + if ((this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) { + // Init mobile number instance + final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); + + // Set it in employee + employee.setEmployeeMobileNumber(number); + } + + // Return it + return employee; + } + + /** + * Checks whether given employee is already added + *

+ * @param employee Employee to be checked + *

+ * @return Whether the employee has already been added + */ + private boolean isEmployeeCreatedByRequiredData (final Employable employee) { + // Default is not found + boolean isFound = false; + + // Check all employees + for (final Employable otherEmployee : this.employeeController.allEmployees()) { + // Is same found? + if (Employees.isSameEmployeeFound(employee, otherEmployee)) { + // Okay, found it + isFound = true; + break; + } + } + + // Return it + return isFound; + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestController.java new file mode 100644 index 00000000..00a5932a --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestController.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2017, 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.jjobs.beans.business.employee; + +import java.io.Serializable; + +/** + * An interface for request-scoped administrative company employee beans + *

+ * @author Roland Häder + */ +public interface JobsAdminEmployeeWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java deleted file mode 100644 index 36e056ae..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebRequestBean.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * Copyright (C) 2017, 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.jjobs.beans.business.employee; - -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.Observes; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; -import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; -import org.mxchange.jcontactsbusiness.model.employee.Employable; -import org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote; -import org.mxchange.jjobs.beans.BaseJobsBean; - -/** - * A request-scoped bean for general purposes for company employees. - *

- * @author Roland Häder - */ -@Named ("employeeController") -@RequestScoped -public class JobsEmployeeWebRequestBean extends BaseJobsBean implements JobsEmployeeWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 12_886_968_547_361L; - - /** - * List of all employees - */ - private final List allEmployees; - - /** - * EJB for general company employee purposes - */ - @EJB (lookup = "java:global/jjobs-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote") - private EmployeeSessionBeanRemote employeeBean; - - /** - * List of all company employees - */ - @Inject - @NamedCache (cacheName = "companyEmployeeCache") - private Cache employeeCache; - - /** - * A list of filtered employees - */ - private List filteredEmployees; - - /** - * Default constructor - */ - public JobsEmployeeWebRequestBean () { - // Call super constructor - super(); - - // Init list - this.allEmployees = new LinkedList<>(); - } - - /** - * Observes events being fired when an employee has been added - *

- * @param event Event being fired - */ - public void afterEmployeeAddedEvent (@Observes final ObservableEmployeeAddedEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getEmployee() == null) { - // Throw it again - throw new NullPointerException("event.employee is null"); //NOI18N - } else if (event.getEmployee().getEmployeeId() == null) { - // Throw it again - throw new NullPointerException("event.employee.employeeId is null"); //NOI18N - } else if (event.getEmployee().getEmployeeId() < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("event.employee.employeeId={0} is invalid", event.getEmployee().getEmployeeId())); //NOI18N - } - - // Add employee to cache and list - this.employeeCache.put(event.getEmployee().getEmployeeId(), event.getEmployee()); - this.allEmployees.add(event.getEmployee()); - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List allEmployees () { - return this.allEmployees; - } - - @Override - public Employable findEmployeeById (final Long employeeId) throws EmployeeNotFoundException { - // Validate parameter - if (null == employeeId) { - // Throw NPE - throw new NullPointerException("employeeId is null"); //NOI18N - } else if (employeeId < 1) { - // Throw IAE - throw new IllegalArgumentException(MessageFormat.format("employeeId={0} is invalid", employeeId)); //NOI18N - } else if (!this.employeeCache.containsKey(employeeId)) { - // Not found - throw new EmployeeNotFoundException(employeeId); - } - - // Get it from cache - final Employable employee = this.employeeCache.get(employeeId); - - // Return it - return employee; - } - - /** - * Getter for filtered list of employees - *

- * @return Filtered list of employees - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredEmployees () { - return this.filteredEmployees; - } - - /** - * Getter for filtered list of employees - *

- * @param filteredEmployees Filtered list of employees - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredEmployees (final List filteredEmployees) { - this.filteredEmployees = filteredEmployees; - } - - /** - * Initialization method - */ - @PostConstruct - public void init () { - // Is cache there? - if (!this.employeeCache.iterator().hasNext()) { - // Get whole list - final List employees = this.employeeBean.allEmployees(); - - // Add all - for (final Employable employee : employees) { - // Add it to cache - this.employeeCache.put(employee.getEmployeeId(), employee); - } - } - - // Is cache filled and list is empty - if ((this.employeeCache.iterator().hasNext()) && (this.allEmployees.isEmpty())) { - // Get iterator - final Iterator> iterator = this.employeeCache.iterator(); - - // Build up list - while (iterator.hasNext()) { - // GEt next element - final Cache.Entry next = iterator.next(); - - // Add to list - this.allEmployees.add(next.getValue()); - } - - // Sort list - this.allEmployees.sort(new Comparator() { - @Override - public int compare (final Employable o1, final Employable o2) { - return o1.getEmployeeId() > o2.getEmployeeId() ? 1 : o1.getEmployeeId() < o2.getEmployeeId() ? -1 : 0; - } - }); - } - } - - @Override - public Boolean isEmailAddressRegistered (final String emailAddress) { - // Validate parameter - if (null == emailAddress) { - // Throw NPE - throw new NullPointerException("emailAddress is null"); //NOI18N - } else if (emailAddress.isEmpty()) { - // Throw IAE - throw new IllegalArgumentException("emailAddress is empty"); //NOI18N - } - - // Default is not found - boolean isFound = false; - - // Check all entries - for (final Employable basicData : this.allEmployees()) { - // Is email address used? - if (Objects.equals(basicData.getEmployeeEmailAddress(), emailAddress)) { - // Found it - isFound = true; - break; - } - } - - // Return flag - return isFound; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java deleted file mode 100644 index a11f0bd4..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsCompanyEmployeeWebSessionController.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2017, 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.jjobs.beans.business.employee; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; -import org.mxchange.jcontactsbusiness.model.employee.Employable; - -/** - * An interface for request-scoped general company employee beans - *

- * @author Roland Häder - */ -public interface JobsEmployeeWebRequestController extends Serializable { - - /** - * Validates if given email address is already in use by an employee - *

- * @param emailAddress Email address to be validated - *

- * @return Whether the email address is already used - */ - Boolean isEmailAddressRegistered (final String emailAddress); - - /** - * Returns a list of all company employees - *

- * @return List of all company employees - */ - List allEmployees (); - - /** - * Finds a company employee by given employee id - *

- * @param employeeId Employable id to find company employee instance for - *

- * @return Company employee instance - *

- * @throws EmployeeNotFoundException If the company employee was not found - */ - Employable findEmployeeById (final Long employeeId) throws EmployeeNotFoundException; - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestBean.java new file mode 100644 index 00000000..36e056ae --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestBean.java @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2017, 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.jjobs.beans.business.employee; + +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.Observes; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent; +import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote; +import org.mxchange.jjobs.beans.BaseJobsBean; + +/** + * A request-scoped bean for general purposes for company employees. + *

+ * @author Roland Häder + */ +@Named ("employeeController") +@RequestScoped +public class JobsEmployeeWebRequestBean extends BaseJobsBean implements JobsEmployeeWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 12_886_968_547_361L; + + /** + * List of all employees + */ + private final List allEmployees; + + /** + * EJB for general company employee purposes + */ + @EJB (lookup = "java:global/jjobs-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote") + private EmployeeSessionBeanRemote employeeBean; + + /** + * List of all company employees + */ + @Inject + @NamedCache (cacheName = "companyEmployeeCache") + private Cache employeeCache; + + /** + * A list of filtered employees + */ + private List filteredEmployees; + + /** + * Default constructor + */ + public JobsEmployeeWebRequestBean () { + // Call super constructor + super(); + + // Init list + this.allEmployees = new LinkedList<>(); + } + + /** + * Observes events being fired when an employee has been added + *

+ * @param event Event being fired + */ + public void afterEmployeeAddedEvent (@Observes final ObservableEmployeeAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getEmployee() == null) { + // Throw it again + throw new NullPointerException("event.employee is null"); //NOI18N + } else if (event.getEmployee().getEmployeeId() == null) { + // Throw it again + throw new NullPointerException("event.employee.employeeId is null"); //NOI18N + } else if (event.getEmployee().getEmployeeId() < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("event.employee.employeeId={0} is invalid", event.getEmployee().getEmployeeId())); //NOI18N + } + + // Add employee to cache and list + this.employeeCache.put(event.getEmployee().getEmployeeId(), event.getEmployee()); + this.allEmployees.add(event.getEmployee()); + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List allEmployees () { + return this.allEmployees; + } + + @Override + public Employable findEmployeeById (final Long employeeId) throws EmployeeNotFoundException { + // Validate parameter + if (null == employeeId) { + // Throw NPE + throw new NullPointerException("employeeId is null"); //NOI18N + } else if (employeeId < 1) { + // Throw IAE + throw new IllegalArgumentException(MessageFormat.format("employeeId={0} is invalid", employeeId)); //NOI18N + } else if (!this.employeeCache.containsKey(employeeId)) { + // Not found + throw new EmployeeNotFoundException(employeeId); + } + + // Get it from cache + final Employable employee = this.employeeCache.get(employeeId); + + // Return it + return employee; + } + + /** + * Getter for filtered list of employees + *

+ * @return Filtered list of employees + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredEmployees () { + return this.filteredEmployees; + } + + /** + * Getter for filtered list of employees + *

+ * @param filteredEmployees Filtered list of employees + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredEmployees (final List filteredEmployees) { + this.filteredEmployees = filteredEmployees; + } + + /** + * Initialization method + */ + @PostConstruct + public void init () { + // Is cache there? + if (!this.employeeCache.iterator().hasNext()) { + // Get whole list + final List employees = this.employeeBean.allEmployees(); + + // Add all + for (final Employable employee : employees) { + // Add it to cache + this.employeeCache.put(employee.getEmployeeId(), employee); + } + } + + // Is cache filled and list is empty + if ((this.employeeCache.iterator().hasNext()) && (this.allEmployees.isEmpty())) { + // Get iterator + final Iterator> iterator = this.employeeCache.iterator(); + + // Build up list + while (iterator.hasNext()) { + // GEt next element + final Cache.Entry next = iterator.next(); + + // Add to list + this.allEmployees.add(next.getValue()); + } + + // Sort list + this.allEmployees.sort(new Comparator() { + @Override + public int compare (final Employable o1, final Employable o2) { + return o1.getEmployeeId() > o2.getEmployeeId() ? 1 : o1.getEmployeeId() < o2.getEmployeeId() ? -1 : 0; + } + }); + } + } + + @Override + public Boolean isEmailAddressRegistered (final String emailAddress) { + // Validate parameter + if (null == emailAddress) { + // Throw NPE + throw new NullPointerException("emailAddress is null"); //NOI18N + } else if (emailAddress.isEmpty()) { + // Throw IAE + throw new IllegalArgumentException("emailAddress is empty"); //NOI18N + } + + // Default is not found + boolean isFound = false; + + // Check all entries + for (final Employable basicData : this.allEmployees()) { + // Is email address used? + if (Objects.equals(basicData.getEmployeeEmailAddress(), emailAddress)) { + // Found it + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestController.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestController.java new file mode 100644 index 00000000..a11f0bd4 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsEmployeeWebRequestController.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017, 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.jjobs.beans.business.employee; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; +import org.mxchange.jcontactsbusiness.model.employee.Employable; + +/** + * An interface for request-scoped general company employee beans + *

+ * @author Roland Häder + */ +public interface JobsEmployeeWebRequestController extends Serializable { + + /** + * Validates if given email address is already in use by an employee + *

+ * @param emailAddress Email address to be validated + *

+ * @return Whether the email address is already used + */ + Boolean isEmailAddressRegistered (final String emailAddress); + + /** + * Returns a list of all company employees + *

+ * @return List of all company employees + */ + List allEmployees (); + + /** + * Finds a company employee by given employee id + *

+ * @param employeeId Employable id to find company employee instance for + *

+ * @return Company employee instance + *

+ * @throws EmployeeNotFoundException If the company employee was not found + */ + Employable findEmployeeById (final Long employeeId) throws EmployeeNotFoundException; + +} diff --git a/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java index 4a7983d6..741988e0 100644 --- a/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java @@ -21,7 +21,6 @@ import javax.inject.Named; import org.mxchange.jcontacts.model.contact.title.PersonalTitle; import org.mxchange.jcontactsbusiness.model.opening_time.dayofweek.DayOfTheWeek; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jproduct.model.payment.PaymentType; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -56,15 +55,6 @@ public class JobsDataWebApplicationBean extends BaseJobsBean { return DayOfTheWeek.values(); } - /** - * Returns an array of all payment types - *

- * @return An array of all payment types - */ - public PaymentType[] getPaymentTypes () { - return PaymentType.values(); - } - /** * Returns an array of all personal titles *

diff --git a/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBasicCompanyDataConverter.java b/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBasicCompanyDataConverter.java new file mode 100644 index 00000000..3dc4c726 --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBasicCompanyDataConverter.java @@ -0,0 +1,93 @@ +/* + * 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.jjobs.converter.business.basicdata; + +import javax.enterprise.inject.spi.CDI; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataNotFoundException; +import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; +import org.mxchange.jjobs.beans.business.basicdata.list.JobsBasicDataListWebViewBean; +import org.mxchange.jjobs.beans.business.basicdata.list.JobsBasicDataListWebViewController; + +/** + * Converter for basic company data id <-> valid basic company data instance + *

+ * @author Roland Häder + */ +@FacesConverter ("BasicCompanyDataConverter") +public class JobsBasicCompanyDataConverter implements Converter { + + /** + * Basic company data backing bean + */ + private static JobsBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER; + + @Override + public BasicData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (null == BASIC_DATA_LIST_CONTROLLER) { + // Get bean from CDI directly + BASIC_DATA_LIST_CONTROLLER = CDI.current().select(JobsBasicDataListWebViewBean.class).get(); + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + BasicData basicData = null; + + try { + // Try to parse the value as long + final Long basicDataId = Long.valueOf(submittedValue); + + // Try to get user instance from it + basicData = BASIC_DATA_LIST_CONTROLLER.findBasicDataById(basicDataId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final BasicDataNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return basicData; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final BasicData value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getBasicDataId()); + } + +} diff --git a/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java b/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java deleted file mode 100644 index 3dc4c726..00000000 --- a/src/java/org/mxchange/jjobs/converter/business/basicdata/JobsBusinessContactConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.jjobs.converter.business.basicdata; - -import javax.enterprise.inject.spi.CDI; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataNotFoundException; -import org.mxchange.jcontactsbusiness.model.basicdata.BasicData; -import org.mxchange.jjobs.beans.business.basicdata.list.JobsBasicDataListWebViewBean; -import org.mxchange.jjobs.beans.business.basicdata.list.JobsBasicDataListWebViewController; - -/** - * Converter for basic company data id <-> valid basic company data instance - *

- * @author Roland Häder - */ -@FacesConverter ("BasicCompanyDataConverter") -public class JobsBasicCompanyDataConverter implements Converter { - - /** - * Basic company data backing bean - */ - private static JobsBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER; - - @Override - public BasicData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == BASIC_DATA_LIST_CONTROLLER) { - // Get bean from CDI directly - BASIC_DATA_LIST_CONTROLLER = CDI.current().select(JobsBasicDataListWebViewBean.class).get(); - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - BasicData basicData = null; - - try { - // Try to parse the value as long - final Long basicDataId = Long.valueOf(submittedValue); - - // Try to get user instance from it - basicData = BASIC_DATA_LIST_CONTROLLER.findBasicDataById(basicDataId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final BasicDataNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return basicData; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final BasicData value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getBasicDataId()); - } - -} diff --git a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java deleted file mode 100644 index 10f02451..00000000 --- a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsCompanyEmployeeConverter.java +++ /dev/null @@ -1,104 +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.jjobs.converter.business.company_employee; - -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import javax.faces.validator.ValidatorException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException; -import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.employee.Employee; - -/** - * Converter for converting company employee to and from id number - *

- * @author Roland Häder - */ -@FacesConverter ("CompanyEmployeeConverter") -public class JobsCompanyEmployeeConverter implements Converter { - - /** - * CompanyEmployee EJB - */ - private static CompanyEmployeeSessionBeanRemote EMPLOYEE_BEAN; - - @Override - public Employee getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (EMPLOYEE_BEAN == null) { - try { - // Not yet, attempt lookup - final Context initial = new InitialContext(); - - // Lookup EJB - EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initial.lookup("java:global/jjobs-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Throw it again - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); //NOI18N - } - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - Employee companyEmployee = null; - - try { - // Try to parse the value as long - final Long employeeId = Long.valueOf(submittedValue); - - // Try to get user instance from it - companyEmployee = EMPLOYEE_BEAN.findCompanyEmployeeById(employeeId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final CompanyEmployeeNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return companyEmployee; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Employee value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getEmployeeId()); - } - -} diff --git a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsEmployeeConverter.java b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsEmployeeConverter.java new file mode 100644 index 00000000..62917c49 --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsEmployeeConverter.java @@ -0,0 +1,93 @@ +/* + * 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.jjobs.converter.business.company_employee; + +import javax.enterprise.inject.spi.CDI; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException; +import org.mxchange.jcontactsbusiness.model.employee.Employable; +import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestBean; +import org.mxchange.jjobs.beans.business.employee.JobsEmployeeWebRequestController; + +/** + * Converter for converting company employee to and from id number + *

+ * @author Roland Häder + */ +@FacesConverter ("EmployeeConverter") +public class JobsEmployeeConverter implements Converter { + + /** + * Employable EJB + */ + private static JobsEmployeeWebRequestController EMPLOYEE_CONTROLLER; + + @Override + public Employable getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (null == EMPLOYEE_CONTROLLER) { + // Get bean from CDI directly + EMPLOYEE_CONTROLLER = CDI.current().select(JobsEmployeeWebRequestBean.class).get(); + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Employable companyEmployee = null; + + try { + // Try to parse the value as long + final Long employeeId = Long.valueOf(submittedValue); + + // Try to get user instance from it + companyEmployee = EMPLOYEE_CONTROLLER.findEmployeeById(employeeId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final EmployeeNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return companyEmployee; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Employable value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getEmployeeId()); + } + +} diff --git a/src/java/org/mxchange/jjobs/converter/business/department/JobsCompanyDepartmentConverter.java b/src/java/org/mxchange/jjobs/converter/business/department/JobsCompanyDepartmentConverter.java deleted file mode 100644 index 60bc536b..00000000 --- a/src/java/org/mxchange/jjobs/converter/business/department/JobsCompanyDepartmentConverter.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * 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.jjobs.converter.business.department; - -import javax.enterprise.inject.spi.CDI; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException; -import org.mxchange.jcontactsbusiness.model.department.Department; -import org.mxchange.jjobs.beans.business.department.JobsDepartmentWebRequestBean; -import org.mxchange.jjobs.beans.business.department.JobsDepartmentWebRequestController; - -/** - * Converter for company department id <-> instance - *

- * @author Roland Häder - */ -@FacesConverter ("DepartmentConverter") -public class JobsDepartmentConverter implements Converter { - - /** - * Company department EJB - */ - private static JobsDepartmentWebRequestController DEPARTMENT_CONTROLLER; - - @Override - public Department getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (null == DEPARTMENT_CONTROLLER) { - // Get bean from CDI directly - DEPARTMENT_CONTROLLER = CDI.current().select(JobsDepartmentWebRequestBean.class).get(); - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - Department companyDepartment = null; - - try { - // Try to parse the value as long - final Long departmentId = Long.valueOf(submittedValue); - - // Try to get user instance from it - companyDepartment = DEPARTMENT_CONTROLLER.findDepartmentById(departmentId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final DepartmentNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return companyDepartment; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final Department value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getDepartmentId()); - } - -} diff --git a/src/java/org/mxchange/jjobs/converter/business/department/JobsDepartmentConverter.java b/src/java/org/mxchange/jjobs/converter/business/department/JobsDepartmentConverter.java new file mode 100644 index 00000000..60bc536b --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/business/department/JobsDepartmentConverter.java @@ -0,0 +1,93 @@ +/* + * 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.jjobs.converter.business.department; + +import javax.enterprise.inject.spi.CDI; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException; +import org.mxchange.jcontactsbusiness.model.department.Department; +import org.mxchange.jjobs.beans.business.department.JobsDepartmentWebRequestBean; +import org.mxchange.jjobs.beans.business.department.JobsDepartmentWebRequestController; + +/** + * Converter for company department id <-> instance + *

+ * @author Roland Häder + */ +@FacesConverter ("DepartmentConverter") +public class JobsDepartmentConverter implements Converter { + + /** + * Company department EJB + */ + private static JobsDepartmentWebRequestController DEPARTMENT_CONTROLLER; + + @Override + public Department getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (null == DEPARTMENT_CONTROLLER) { + // Get bean from CDI directly + DEPARTMENT_CONTROLLER = CDI.current().select(JobsDepartmentWebRequestBean.class).get(); + } + + // Is the value null or empty? + if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { + // Warning message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N + + // Return null + return null; + } + + // Init instance + Department companyDepartment = null; + + try { + // Try to parse the value as long + final Long departmentId = Long.valueOf(submittedValue); + + // Try to get user instance from it + companyDepartment = DEPARTMENT_CONTROLLER.findDepartmentById(departmentId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final DepartmentNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return companyDepartment; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Department value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getDepartmentId()); + } + +} diff --git a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java deleted file mode 100644 index 64ebf4df..00000000 --- a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsCompanyHeadquartersConverter.java +++ /dev/null @@ -1,105 +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.jjobs.converter.business.headquarters; - -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.convert.Converter; -import javax.faces.convert.ConverterException; -import javax.faces.convert.FacesConverter; -import javax.faces.validator.ValidatorException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.jcontactsbusiness.exceptions.headquarters.CompanyHeadquartersNotFoundException; -import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersSessionBeanRemote; -import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData; - -/** - * Converter for converting company headquarters to and from id number - *

- * @author Roland Häder - */ -@FacesConverter ("CompanyHeadquartersConverter") -public class JobsCompanyHeadquartersConverter implements Converter { - - /** - * Headquarters backing bean - * @TODO Undone - */ - private static CompanyHeadquartersSessionBeanRemote HEADQUARTERS_CONTROLLER; - - @Override - public HeadquartersData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { - // Is the instance there? - if (HEADQUARTERS_CONTROLLER == null) { - try { - // Not yet, attempt lookup - final Context initial = new InitialContext(); - - // Lookup EJB - HEADQUARTERS_CONTROLLER = (CompanyHeadquartersSessionBeanRemote) initial.lookup("java:global/jjobs-ejb/headquarters!org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Throw it again - throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup backing bean", ex.getMessage()), ex); //NOI18N - } - } - - // Is the value null or empty? - if ((null == submittedValue) || (submittedValue.trim().isEmpty())) { - // Warning message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N - - // Return null - return null; - } - - // Init instance - HeadquartersData companyHeadquarters = null; - - try { - // Try to parse the value as long - final Long headquartersId = Long.valueOf(submittedValue); - - // Try to get user instance from it - companyHeadquarters = HEADQUARTERS_CONTROLLER.findCompanyHeadquartersById(headquartersId); - } catch (final NumberFormatException ex) { - // Throw again - throw new ConverterException(ex); - } catch (final CompanyHeadquartersNotFoundException ex) { - // Debug message - // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N - } - - // Return it - return companyHeadquarters; - } - - @Override - public String getAsString (final FacesContext context, final UIComponent component, final HeadquartersData value) { - // Is the object null? - if ((null == value) || (String.valueOf(value).isEmpty())) { - // Is null - return ""; //NOI18N - } - - // Return id number - return String.valueOf(value.getHeadquartersId()); - } - -} diff --git a/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsHeadquarterConverter.java b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsHeadquarterConverter.java new file mode 100644 index 00000000..c1cc945d --- /dev/null +++ b/src/java/org/mxchange/jjobs/converter/business/headquarters/JobsHeadquarterConverter.java @@ -0,0 +1,83 @@ +/* + * 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.jjobs.converter.business.headquarters; + +import javax.enterprise.inject.spi.CDI; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.ConverterException; +import javax.faces.convert.FacesConverter; +import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException; +import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; +import org.mxchange.jjobs.beans.business.headquarter.JobsHeadquarterWebRequestBean; +import org.mxchange.jjobs.beans.business.headquarter.JobsHeadquarterWebRequestController; + +/** + * Converter for converting company headquarters to and from id number + *

+ * @author Roland Häder + */ +@FacesConverter ("HeadquarterConverter") +public class JobsHeadquarterConverter implements Converter { + + /** + * Headquarter backing bean + */ + private static JobsHeadquarterWebRequestController HEADQUARTER_CONTROLLER; + + @Override + public Headquarter getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { + // Is the instance there? + if (null == HEADQUARTER_CONTROLLER) { + HEADQUARTER_CONTROLLER = CDI.current().select(JobsHeadquarterWebRequestBean.class).get(); + } + + // Init instance + Headquarter headquarter = null; + + try { + // Try to parse the value as long + final Long headquarterId = Long.valueOf(submittedValue); + + // Try to get user instance from it + headquarter = HEADQUARTER_CONTROLLER.findHeadquarterById(headquarterId); + } catch (final NumberFormatException ex) { + // Throw again + throw new ConverterException(ex); + } catch (final HeadquarterNotFoundException ex) { + // Debug message + // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N + } + + // Return it + return headquarter; + } + + @Override + public String getAsString (final FacesContext context, final UIComponent component, final Headquarter value) { + // Is the object null? + if ((null == value) || (String.valueOf(value).isEmpty())) { + // Is null + return ""; //NOI18N + } + + // Return id number + return String.valueOf(value.getHeadquarterId()); + } + +}