From: Roland Häder Date: Tue, 21 Apr 2020 23:59:56 +0000 (+0200) Subject: Don't cherry-pick: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=da6b6a57d6d7e1b82549eab1d0c41ccafe00cdb3;p=jjobs-war.git Don't cherry-pick: - JJobs has no need for addressbooks, it can be done without them - renamed backing beans for JJobs - fixed (maybe?) some JNDI names - a lot other fixes, still something is not correct, some interfaces have some missing methods while they should be there Signed-off-by: Roland Häder --- diff --git a/lib/jaddressbook-core.jar b/lib/jaddressbook-core.jar deleted file mode 100644 index 6578dc4f..00000000 Binary files a/lib/jaddressbook-core.jar and /dev/null differ diff --git a/lib/jaddressbook-lib.jar b/lib/jaddressbook-lib.jar deleted file mode 100644 index 7347bb6f..00000000 Binary files a/lib/jaddressbook-lib.jar and /dev/null differ diff --git a/nbproject/project.properties b/nbproject/project.properties index a078f235..c03f2a43 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -35,8 +35,6 @@ dist.javadoc.dir=${dist.dir}/javadoc dist.war=${dist.dir}/${war.name} endorsed.classpath= excludes= -file.reference.jaddressbook-core.jar=lib/jaddressbook-core.jar -file.reference.jaddressbook-lib.jar=lib/jaddressbook-lib.jar file.reference.jcontacts-business-core.jar=lib/jcontacts-business-core.jar file.reference.jcontacts-business-lib.jar=lib/jcontacts-business-lib.jar file.reference.cdi-api.jar=lib/cdi-api.jar @@ -84,8 +82,6 @@ javac.classpath=\ ${file.reference.juser-activity-lib.jar}:\ ${file.reference.jcontacts-business-core.jar}:\ ${file.reference.jcontacts-business-lib.jar}:\ - ${file.reference.jaddressbook-core.jar}:\ - ${file.reference.jaddressbook-lib.jar}:\ ${reference.jjobs-core.jar}:\ ${reference.jjobs-lib.jar}:\ ${file.reference.cdi-api.jar}:\ @@ -154,8 +150,6 @@ source.reference.juser-activity-core.jar=../juser-activity-core/src/ source.reference.juser-activity-lib.jar=../juser-activity-lib/src/ source.reference.juser-core.jar=../juser-core/src/ source.reference.juser-lib.jar=../juser-lib/src/ -source.reference.jaddressbook-core.jar=../jaddressbook-core/src/ -source.reference.jaddressbook-lib.jar=../jaddressbook-lib/src/ source.reference.juser-login-core.jar=../juser-login-core/src/ source.reference.juser-login-lib.jar=../juser-login-lib/src/ source.root=src diff --git a/nbproject/project.xml b/nbproject/project.xml index 39d6098d..1d1c7400 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -54,12 +54,6 @@ ${file.reference.jcontacts-business-lib.jar} - - ${file.reference.jaddressbook-core.jar} - - - ${file.reference.jaddressbook-lib.jar} - ${reference.jjobs-core.jar} diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java deleted file mode 100644 index 767b5f8b..00000000 --- a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionBean.java +++ /dev/null @@ -1,431 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.addressbook; - -import java.text.MessageFormat; -import java.util.Collections; -import java.util.Date; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.annotation.PostConstruct; -import javax.enterprise.context.SessionScoped; -import javax.enterprise.event.Event; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.Any; -import javax.faces.view.facelets.FaceletException; -import javax.inject.Inject; -import javax.inject.Named; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote; -import org.mxchange.jaddressbook.events.addressbook.AddressbookLoadedEvent; -import org.mxchange.jaddressbook.events.addressbook.ObservableAddressbookLoadedEvent; -import org.mxchange.jaddressbook.exceptions.AddressbookNameAlreadyUsedException; -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.BaseJobsBean; -import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; - -/** - * An address book bean (controller) - *

- * @author Roland Häder - */ -@Named ("addressbookController") -@SessionScoped -public class JobsAddressbookWebSessionBean extends BaseJobsBean implements JobsAddressbookWebSessionController { - - /** - * Serial number - */ - private static final long serialVersionUID = 185_781_756_712_969L; - - /** - * Address book instance - */ - private Addressbook addressbook; - - /** - * Remote address book bean - */ - private AddressbookSessionBeanRemote addressbookBean; - - /** - * When this address book has been created - */ - private Date addressbookCreated; - - /** - * Address book id number (from URL for example) - */ - private Long addressbookId; - - /** - * Name of the address book - */ - private String addressbookName; - - /** - * Who owns this address book - */ - private User addressbookUser; - - /** - * Event fired when user has logged in - */ - @Inject - @Any - private Event loadedEvent; - - /** - * Login controller - */ - @Inject - private JobsUserLoginWebSessionController userLoginController; - - /** - * A list of all user's address books - */ - private List usersAddressbooks; - - /** - * Default constructor - */ - public JobsAddressbookWebSessionBean () { - // Call super constructor - super(); - } - - @Override - public String addAddressbook () { - // Is this name already used? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged in - throw new FaceletException("This method can only be called as logged-in user."); //NOI18N - } else if (this.getAddressbookName() == null) { - // Address book name is null - throw new NullPointerException("addressbookName is null"); //NOI18N - } else if (this.getAddressbookName().isEmpty()) { - // Address book name is empty - throw new IllegalStateException("addressbookName is empty."); //NOI18N - } else if (this.isAddressbookNameUsed(this.getAddressbookName())) { - // Already used by this user - throw new FaceletException(MessageFormat.format("Address book name {0} already used.", this.getAddressbookName())); //NOI18N - } - - // Create address book instance with name - Addressbook book = new UserAddressbook(this.getAddressbookName(), this.userLoginController.getLoggedInUser()); - - try { - // Register this address book - Addressbook updatedAddressbook = this.addressbookBean.createAddressbook(book); - - // Remove name - this.setAddressbookName(null); - - // Add address book entry to list - this.usersAddressbooks.add(updatedAddressbook); - - // All fine - return "login_own_addressbooks"; //NOI18N - } catch (final AddressbookNameAlreadyUsedException ex) { - // Throw again as cause - throw new FaceletException(ex); - } - } - - @Override - public void afterAddressbookLoadedEvent (@Observes final ObservableAddressbookLoadedEvent event) { - // event should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddressbook() == null) { - // Throw NPE again - throw new NullPointerException("event.addressbook is null"); //NOI18N - } else if (event.getAddressbook().getAddressbookId() == null) { - // And again a NPE - throw new NullPointerException("event.addressbook.addressbookId is null"); //NOI18N - } else if (event.getAddressbook().getAddressbookId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("Address book instance {0} has invalid id number: {1}", event.getAddressbook(), event.getAddressbook().getAddressbookId())); //NOI18N - } else if (event.getAddressbook().getAddressbookUser() == null) { - // One more NPE ... - throw new NullPointerException("event.addressbook.addressbookUser is null"); //NOI18N - } - - // Get address book instance - final Addressbook book = event.getAddressbook(); - - // Set address book data - this.setAddressbookId(book.getAddressbookId()); - this.setAddressbookName(book.getAddressbookName()); - this.setAddressbookUser(book.getAddressbookUser()); - this.setAddressbookCreated(book.getAddressbookCreated()); - - // And instance ... - this.setAddressbook(book); - } - - @Override - public void afterLoginEvent (@Observes final ObservableUserLoggedInEvent event) { - // Is the user logged in? - if (null == event) { - // Is null - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getLoggedInUser() == null) { - // user is null - throw new NullPointerException("event.user is null"); //NOI18N - } else if (!event.getLoggedInUser().equals(this.userLoginController.getLoggedInUser())) { - // Not matching - throw new IllegalStateException("event.user and userLoginController.loggedInUser don't match."); //NOI18N - } else if (!this.userLoginController.isUserLoggedIn()) { - // Not logged in - throw new FaceletException("This method can only be called as logged-in user."); //NOI18N - } - - // Init user's address book list - this.initAddressbookList(); - } - - @Override - public List allAddressbooks () { - // Is the user logged in? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged in - throw new FaceletException("This method can only be called as logged-in user."); //NOI18N - } - - return Collections.unmodifiableList(this.usersAddressbooks); - } - - @Override - public List allEntries (final Addressbook addressbook) { - // Is the user logged in? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged in - throw new FaceletException("This method can only be called as logged-in user."); //NOI18N - } - - // Ask the bean - return this.addressbookBean.allEntries(addressbook); - } - - @Override - public int allEntriesSize (final Addressbook addressbook) { - // Ask the bean - return this.allEntries(addressbook).size(); - } - - @Override - public Addressbook getAddressbook () { - return this.addressbook; - } - - @Override - public void setAddressbook (final Addressbook addressbook) { - this.addressbook = addressbook; - } - - @Override - @SuppressWarnings ("ReturnOfDateField") - public Date getAddressbookCreated () { - return this.addressbookCreated; - } - - @Override - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - public void setAddressbookCreated (final Date addressbookCreated) { - this.addressbookCreated = addressbookCreated; - } - - @Override - public Long getAddressbookId () { - return this.addressbookId; - } - - @Override - public void setAddressbookId (final Long addressbookId) { - this.addressbookId = addressbookId; - } - - @Override - public String getAddressbookName () { - return this.addressbookName; - } - - @Override - public void setAddressbookName (final String addressbookName) { - this.addressbookName = addressbookName; - } - - @Override - public User getAddressbookUser () { - return this.addressbookUser; - } - - @Override - public void setAddressbookUser (final User addressbookUser) { - this.addressbookUser = addressbookUser; - } - - @Override - public boolean hasCreatedAddressbooks () { - // Is the user logged in? - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged in - throw new FaceletException("This method can only be called as logged-in user."); //NOI18N - } - - // Check if the list is filled - return (!this.usersAddressbooks.isEmpty()); - } - - /** - * Post-initialization of this class - */ - @PostConstruct - public void init () { - // Try it - try { - // Get initial context - Context context = new InitialContext(); - - // Try to lookup - this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("java:global/jjobs-ejb/jjobs-adr!org.mxchange.jjobs.model.addressbook.JobsAddressbookSessionBeanRemote"); //NOI18N - } catch (final NamingException e) { - // Throw again - throw new FaceletException(e); - } - - // Init list - this.usersAddressbooks = new LinkedList<>(); - - // Is the user logged-in? - if (this.userLoginController.isUserLoggedIn()) { - // Initialize list - this.initAddressbookList(); - } - - // TODO Initialize list from bean with just one call - //this.addressbookBean.getUserCountMap() - } - - @Override - public boolean isAddressbookLoaded () { - return ((this.getAddressbookId() instanceof Long) && - (this.getAddressbookName() instanceof String) && - (!this.getAddressbookName().isEmpty()) && - (this.getAddressbookUser() instanceof User)); - } - - @Override - public boolean isAddressbookNameUsed (final String addressbookName) { - // Is it zero size? - if (null == addressbookName) { - // Is null - throw new NullPointerException("addressbookName is null"); //NOI18N - } else if (this.usersAddressbooks.isEmpty()) { - // Not found! - return false; - } - - // Default is not found - boolean isFound = false; - - // Check all entries - for (final Addressbook book : this.usersAddressbooks) { - // Is the name same? - if (book.getAddressbookName().equals(addressbookName)) { - // Found a match - isFound = true; - break; - } - } - - // Return status - return isFound; - } - - @Override - public boolean isOtherAddressbook () { - // Just call the other method and invert it - return (!this.isOwnAddressbook()); - } - - @Override - public boolean isOwnAddressbook () { - // Is the user logged in? - if (!this.userLoginController.isUserLoggedIn()) { - // No, then no own address book - throw new IllegalStateException("isOwnAddressbook() has been invoked for a guest account"); //NOI18N - } - - // Is same user? - return Objects.equals(this.getAddressbookUser(), this.userLoginController.getLoggedInUser()); - } - - @Override - public boolean loadAddressbook () { - // Check if the id is set - if (this.getAddressbookId() == null) { - // Throw NPE - throw new NullPointerException("this.addressbookId is null"); - } else if (this.getAddressbookId() < 1) { - // Not valid id - throw new IllegalStateException(MessageFormat.format("this.addressbook={0} is invalid", this.getAddressbookId())); - } - - // Default is not found - boolean isFound = false; - - try { - // Then try to look it up - Addressbook a = this.addressbookBean.getAddressbookById(this.getAddressbookId()); - - // Fire event here - this.loadedEvent.fire(new AddressbookLoadedEvent(a)); - - // Found it - isFound = true; - } catch (final AddressbookNotFoundException ex) { - // Not found! - throw new FaceletException(ex); - } - - // Return status - return isFound; - } - - /** - * Initializes the user user's address book list - */ - private void initAddressbookList () { - // Get user instance - User user = this.userLoginController.getLoggedInUser(); - - // Fill list with entries - this.usersAddressbooks = this.addressbookBean.getUsersAddressbookList(user); - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java b/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java deleted file mode 100644 index ff7db6a0..00000000 --- a/src/java/org/mxchange/jjobs/beans/addressbook/JobsAddressbookWebSessionController.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.addressbook; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import org.mxchange.jaddressbook.events.addressbook.ObservableAddressbookLoadedEvent; -import org.mxchange.jaddressbook.model.addressbook.Addressbook; -import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent; - -/** - * An interface for address book beans - *

- * @author Roland Häder - */ -public interface JobsAddressbookWebSessionController extends Serializable { - - /** - * Checks whether the user has created addressbooks. For this method to work - * it is vital that the user is logged into his/her account. - *

- * @return Whether the user has created at least one addressbook - */ - boolean hasCreatedAddressbooks (); - - /** - * Creates a new address book with a name and redirects to proper target. - * For this method to work it is vital that the user is logged into his/her - * account. - *

- * @return Target to redirect to - */ - String addAddressbook (); - - /** - * Getter for address book name - *

- * @return Address book name - */ - String getAddressbookName (); - - /** - * Setter for address book name - *

- * @param addressbookName Address book name - */ - void setAddressbookName (final String addressbookName); - - /** - * Checks if the given address book name is already used by the user. - *

- * @param addressbookName Address book name to check - *

- * @return Whether the name has already been used by the user - */ - boolean isAddressbookNameUsed (final String addressbookName); - - /** - * Returns all address books with this user - *

- * @return A list of all address books by this user - */ - List allAddressbooks (); - - /** - * Returns a list of all address book entries for given address book - *

- * @param addressbook Address book instance - *

- * @return List of all entries - */ - List allEntries (final Addressbook addressbook); - - /** - * Size of all entries in given address book - *

- * @param addressbook Address book instance - *

- * @return Size of the entries in address book - */ - int allEntriesSize (final Addressbook addressbook); - - /** - * Getter for address book id number - *

- * @return Address book id number - */ - Long getAddressbookId (); - - /** - * Setter for address book id number - *

- * @param addressbookId Address book id number - */ - void setAddressbookId (final Long addressbookId); - - /** - * Getter for address book user (owner) - *

- * @return Address book user (owner) - */ - User getAddressbookUser (); - - /** - * Setter for address book user (owner) - *

- * @param addressbookUser Address book user (owner) - */ - void setAddressbookUser (final User addressbookUser); - - /** - * Getter for when the address book has been created - *

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

- * @param addressbookCreated When the address book has been created - */ - void setAddressbookCreated (final Date addressbookCreated); - - /** - * This method is called when an address book has been successfully loaded - * from JPA. - *

- * @param event Event with address book instance - */ - void afterAddressbookLoadedEvent (final ObservableAddressbookLoadedEvent event); - - /** - * This method is called when a user has successfully logged in his/her - * account. - *

- * @param event - */ - void afterLoginEvent (final ObservableUserLoggedInEvent event); - - /** - * Checks if the user is logged in and if so if it matches the current - * address book owner. - *

- * @return Whether the owner matches currently logged-in user - */ - boolean isOwnAddressbook (); - - /** - * Checks if the owner of the current address book is NOT matching the - * logged-in user. - *

- * @return Whether the user does NOT match - */ - boolean isOtherAddressbook (); - - /** - * Getter for address book instance - *

- * @return Address book instance - */ - Addressbook getAddressbook (); - - /** - * Setter for address book instance - *

- * @param addressbook Address book instance - */ - void setAddressbook (final Addressbook addressbook); - - /** - * Checks weather an address book has been loaded by checking the id number. - *

- * @return Whether the address book is loaded - */ - boolean isAddressbookLoaded (); - - /** - * Loads address book from current id - *

- * @return Whether the address book was found - */ - boolean loadAddressbook (); -} diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java index 2fb6b2fb..baa66ec8 100644 --- a/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/business/employee/JobsAdminEmployeeWebRequestBean.java @@ -40,7 +40,7 @@ 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; -import org.mxchange.jfinancials.beans.business.employee.list.FinancialsEmployeeListWebViewController; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewController; /** * A request-scoped bean for administrative purposes for administrative employee @@ -74,7 +74,7 @@ public class JobsAdminEmployeeWebRequestBean extends BaseJobsBean implements Job * Administrative list-all-employees controller */ @Inject - private FinancialsEmployeeListWebViewController adminEmployeeListController; + private JobsEmployeeListWebViewController adminEmployeeListController; /** * Assigned basic data instance diff --git a/src/java/org/mxchange/jjobs/beans/business/employee/list/FinancialsEmployeeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/list/FinancialsEmployeeListWebViewBean.java deleted file mode 100644 index 966e4329..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/list/FinancialsEmployeeListWebViewBean.java +++ /dev/null @@ -1,243 +0,0 @@ -/* - * Copyright (C) 2017 - 2020 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.jfinancials.beans.business.employee.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.text.MessageFormat; -import java.util.Comparator; -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.event.Observes; -import javax.faces.view.ViewScoped; -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.jfinancials.beans.BaseFinancialsBean; - -/** - * A view-scoped bean for listing purposes for e.g. administrative employee - * purposes. - *

- * @author Roland Häder - */ -@Named ("employeeListController") -@ViewScoped -public class FinancialsEmployeeListWebViewBean extends BaseFinancialsBean implements FinancialsEmployeeListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 12_886_968_547_362L; - - /** - * List of all employees - */ - private final List allEmployees; - - /** - * EJB for general company employee purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote") - private EmployeeSessionBeanRemote employeeBean; - - /** - * List of all company employees - */ - @Inject - @NamedCache (cacheName = "companyEmployeeCache") - private transient Cache employeeCache; - - /** - * A list of filtered employees - */ - private List filteredEmployees; - - /** - * Currently selected employee - */ - private Employable selectedEmployee; - - /** - * Default constructor - */ - public FinancialsEmployeeListWebViewBean () { - // 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.getAllEmployees().add(event.getEmployee()); - } - - @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; - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllEmployees () { - return this.allEmployees; - } - - /** - * 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; - } - - /** - * Getter for currently selected employee - *

- * @return Currently selected employee - */ - public Employable getSelectedEmployee () { - return this.selectedEmployee; - } - - /** - * Setter for currently selected employee - *

- * @param selectedEmployee Currently selected employee - */ - public void setSelectedEmployee (final Employable selectedEmployee) { - this.selectedEmployee = selectedEmployee; - } - - /** - * Initialization method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.employeeCache.iterator().hasNext()) { - // Add all - for (final Employable employee : this.employeeBean.fetchAllEmployees()) { - // Add it to cache - this.employeeCache.put(employee.getEmployeeId(), employee); - } - } - - // Is cache filled and list is empty - if ((this.employeeCache.iterator().hasNext()) && (this.getAllEmployees().isEmpty())) { - // Build up list - for (final Cache.Entry currentEntry : this.employeeCache) { - // Add to list - this.getAllEmployees().add(currentEntry.getValue()); - } - - // Sort list - this.getAllEmployees().sort(new Comparator() { - @Override - public int compare (final Employable employee1, final Employable employee2) { - return employee1.getEmployeeId() > employee2.getEmployeeId() ? 1 : employee1.getEmployeeId() < employee2.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.getAllEmployees()) { - // 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/list/FinancialsEmployeeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/business/employee/list/FinancialsEmployeeListWebViewController.java deleted file mode 100644 index 306bb460..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/employee/list/FinancialsEmployeeListWebViewController.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2017 - 2020 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.jfinancials.beans.business.employee.list; - -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 administrative company employee beans - *

- * @author Roland Häder - */ -public interface FinancialsEmployeeListWebViewController extends Serializable { - - /** - * Returns a list of all company employees - *

- * @return List of all company employees - */ - List getAllEmployees (); - - /** - * 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); - - /** - * 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/list/JobsEmployeeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/employee/list/JobsEmployeeListWebViewBean.java new file mode 100644 index 00000000..aba7e3ab --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/list/JobsEmployeeListWebViewBean.java @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2017 - 2020 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.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +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.event.Observes; +import javax.faces.view.ViewScoped; +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 view-scoped bean for listing purposes for e.g. administrative employee + * purposes. + *

+ * @author Roland Häder + */ +@Named ("employeeListController") +@ViewScoped +public class JobsEmployeeListWebViewBean extends BaseJobsBean implements JobsEmployeeListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 12_886_968_547_362L; + + /** + * 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 transient Cache employeeCache; + + /** + * A list of filtered employees + */ + private List filteredEmployees; + + /** + * Currently selected employee + */ + private Employable selectedEmployee; + + /** + * Default constructor + */ + public JobsEmployeeListWebViewBean () { + // 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.getAllEmployees().add(event.getEmployee()); + } + + @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; + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllEmployees () { + return this.allEmployees; + } + + /** + * 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; + } + + /** + * Getter for currently selected employee + *

+ * @return Currently selected employee + */ + public Employable getSelectedEmployee () { + return this.selectedEmployee; + } + + /** + * Setter for currently selected employee + *

+ * @param selectedEmployee Currently selected employee + */ + public void setSelectedEmployee (final Employable selectedEmployee) { + this.selectedEmployee = selectedEmployee; + } + + /** + * Initialization method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.employeeCache.iterator().hasNext()) { + // Add all + for (final Employable employee : this.employeeBean.fetchAllEmployees()) { + // Add it to cache + this.employeeCache.put(employee.getEmployeeId(), employee); + } + } + + // Is cache filled and list is empty + if ((this.employeeCache.iterator().hasNext()) && (this.getAllEmployees().isEmpty())) { + // Build up list + for (final Cache.Entry currentEntry : this.employeeCache) { + // Add to list + this.getAllEmployees().add(currentEntry.getValue()); + } + + // Sort list + this.getAllEmployees().sort(new Comparator() { + @Override + public int compare (final Employable employee1, final Employable employee2) { + return employee1.getEmployeeId() > employee2.getEmployeeId() ? 1 : employee1.getEmployeeId() < employee2.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.getAllEmployees()) { + // 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/list/JobsEmployeeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/business/employee/list/JobsEmployeeListWebViewController.java new file mode 100644 index 00000000..b6e98384 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/employee/list/JobsEmployeeListWebViewController.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2017 - 2020 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.list; + +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 administrative company employee beans + *

+ * @author Roland Häder + */ +public interface JobsEmployeeListWebViewController extends Serializable { + + /** + * Returns a list of all company employees + *

+ * @return List of all company employees + */ + List getAllEmployees (); + + /** + * 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); + + /** + * 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/opening_time/list/FinancialsOpeningTimeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/FinancialsOpeningTimeListWebViewBean.java deleted file mode 100644 index d82c0404..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/opening_time/list/FinancialsOpeningTimeListWebViewBean.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2017 - 2020 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.jfinancials.beans.business.opening_time.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.text.MessageFormat; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import javax.annotation.PostConstruct; -import javax.cache.Cache; -import javax.ejb.EJB; -import javax.enterprise.event.Observes; -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontactsbusiness.events.opening_time.added.ObservableOpeningTimeAddedEvent; -import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException; -import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; -import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; - -/** - * A general bean for opening times - *

- * @author Roland Häder - */ -@Named ("openingTimeListController") -@ViewScoped -public class FinancialsOpeningTimeListWebViewBean extends BaseFinancialsBean implements FinancialsOpeningTimeListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 5_028_697_360_467L; - - /** - * A list of all opening times - */ - private final List allOpeningTimes; - - /** - * A list of filtered opening times - */ - private List filteredOpeningTimes; - - /** - * EJB for administrative purposes - */ - @EJB (lookup = "java:global/jfinancials-ejb/openingTimes!org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote") - private OpeningTimeSessionBeanRemote openingTimesBean; - - /** - * A list of all opening times (globally) - */ - @Inject - @NamedCache (cacheName = "openingTimesCache") - private transient Cache openingTimesCache; - - /** - * Selected opening-time instance - */ - private OpeningTime selectedOpeningTime; - - /** - * Default constructor - */ - public FinancialsOpeningTimeListWebViewBean () { - // Call super constructor - super(); - - // Init list - this.allOpeningTimes = new LinkedList<>(); - } - - /** - * Observes events being thrown when a new opening time has been added - *

- * @param event Event being fired - */ - public void afterOpeningTimeAddedEvent (@Observes final ObservableOpeningTimeAddedEvent event) { - // Validate parameter - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); - } else if (event.getOpeningTime() == null) { - // Throw it again - throw new NullPointerException("event.openingTime is null"); - } else if (event.getOpeningTime().getOpeningTimeId() == null) { - // Throw it again - throw new NullPointerException("event.openingTime.openingTimeId is null"); - } else if (event.getOpeningTime().getOpeningTimeId() < 1) { - // Throw it again - throw new NullPointerException(MessageFormat.format("event.openingTime.openingTimeId={0} is invalid", event.getOpeningTime().getOpeningTimeId())); - } - - // Add to cache and list - this.openingTimesCache.put(event.getOpeningTime().getOpeningTimeId(), event.getOpeningTime()); - this.getAllOpeningTimes().add(event.getOpeningTime()); - } - - @Override - public OpeningTime findOpeningTimeById (final Long openingTimeId) throws OpeningTimeNotFoundException { - // Validate parameter - if (null == openingTimeId) { - // Throw NPE - throw new NullPointerException("openingTimeId is null"); //NOI18N - } else if (openingTimeId < 1) { - // Throw IAE - throw new IllegalArgumentException("openingTimeId=" + openingTimeId + " is invalid"); //NOI18N - } else if (!this.openingTimesCache.containsKey(openingTimeId)) { - // Not found - throw new OpeningTimeNotFoundException(openingTimeId); - } - - // Get it from cache - final OpeningTime opening = this.openingTimesCache.get(openingTimeId); - - // Return it - return opening; - } - - /** - * Returns a list of all opening times - *

- * @return A list of all opening times - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllOpeningTimes () { - return this.allOpeningTimes; - } - - /** - * Getter for a list of filtered opening times - *

- * @return Filtered opening times - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredOpeningTimes () { - return this.filteredOpeningTimes; - } - - /** - * Setter for a list of filtered opening times - *

- * @param filteredOpeningTimes Filtered opening times - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredOpeningTimes (final List filteredOpeningTimes) { - this.filteredOpeningTimes = filteredOpeningTimes; - } - - /** - * Getter for selected open-time instance - *

- * @return Selected open-time instance - */ - public OpeningTime getSelectedOpeningTime () { - return this.selectedOpeningTime; - } - - /** - * Setter for selected open-time instance - *

- * @param selectedOpeningTime Selected open-time instance - */ - public void setSelectedOpeningTime (final OpeningTime selectedOpeningTime) { - this.selectedOpeningTime = selectedOpeningTime; - } - - /** - * Initializer method - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.openingTimesCache.iterator().hasNext()) { - // Add all - for (final OpeningTime openingTime : this.openingTimesBean.fetchAllOpeningTimes()) { - // Add it to cache - this.openingTimesCache.put(openingTime.getOpeningTimeId(), openingTime); - } - } - - // Is the list empty, but filled cache? - if (this.getAllOpeningTimes().isEmpty() && this.openingTimesCache.iterator().hasNext()) { - // Build up list - for (final Cache.Entry currentEntry : this.openingTimesCache) { - // Add to list - this.getAllOpeningTimes().add(currentEntry.getValue()); - } - - // Sort list - this.getAllOpeningTimes().sort(new Comparator() { - @Override - public int compare (final OpeningTime openingTime1, final OpeningTime openingTime2) { - return openingTime1.getOpeningTimeId() > openingTime2.getOpeningTimeId() ? 1 : openingTime1.getOpeningTimeId() < openingTime2.getOpeningTimeId() ? -1 : 0; - } - } - ); - } - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/opening_time/list/FinancialsOpeningTimeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/FinancialsOpeningTimeListWebViewController.java deleted file mode 100644 index cadae503..00000000 --- a/src/java/org/mxchange/jjobs/beans/business/opening_time/list/FinancialsOpeningTimeListWebViewController.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2017 - 2020 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.jfinancials.beans.business.opening_time.list; - -import java.io.Serializable; -import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException; -import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; - -/** - * An interface for general opening times controller - *

- * @author Roland Häder - */ -public interface FinancialsOpeningTimeListWebViewController extends Serializable { - - /** - * Retrieves a single opening-time entity for given id number or throws a - * proper exception if not found. - *

- * @param openingTimeId Opening time id to lookup - *

- * @return Company department instance - *

- * @throws OpeningTimeNotFoundException If the id number could not be looked - * up and solved into an entity - */ - OpeningTime findOpeningTimeById (final Long openingTimeId) throws OpeningTimeNotFoundException; - -} diff --git a/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewBean.java new file mode 100644 index 00000000..a9c1f9e9 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewBean.java @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2017 - 2020 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.opening_time.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.text.MessageFormat; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.enterprise.event.Observes; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontactsbusiness.events.opening_time.added.ObservableOpeningTimeAddedEvent; +import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote; +import org.mxchange.jjobs.beans.BaseJobsBean; + +/** + * A general bean for opening times + *

+ * @author Roland Häder + */ +@Named ("openingTimeListController") +@ViewScoped +public class JobsOpeningTimeListWebViewBean extends BaseJobsBean implements JobsOpeningTimeListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 5_028_697_360_467L; + + /** + * A list of all opening times + */ + private final List allOpeningTimes; + + /** + * A list of filtered opening times + */ + private List filteredOpeningTimes; + + /** + * EJB for administrative purposes + */ + @EJB (lookup = "java:global/jjobs-ejb/openingTimes!org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote") + private OpeningTimeSessionBeanRemote openingTimesBean; + + /** + * A list of all opening times (globally) + */ + @Inject + @NamedCache (cacheName = "openingTimesCache") + private transient Cache openingTimesCache; + + /** + * Selected opening-time instance + */ + private OpeningTime selectedOpeningTime; + + /** + * Default constructor + */ + public JobsOpeningTimeListWebViewBean () { + // Call super constructor + super(); + + // Init list + this.allOpeningTimes = new LinkedList<>(); + } + + /** + * Observes events being thrown when a new opening time has been added + *

+ * @param event Event being fired + */ + public void afterOpeningTimeAddedEvent (@Observes final ObservableOpeningTimeAddedEvent event) { + // Validate parameter + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); + } else if (event.getOpeningTime() == null) { + // Throw it again + throw new NullPointerException("event.openingTime is null"); + } else if (event.getOpeningTime().getOpeningTimeId() == null) { + // Throw it again + throw new NullPointerException("event.openingTime.openingTimeId is null"); + } else if (event.getOpeningTime().getOpeningTimeId() < 1) { + // Throw it again + throw new NullPointerException(MessageFormat.format("event.openingTime.openingTimeId={0} is invalid", event.getOpeningTime().getOpeningTimeId())); + } + + // Add to cache and list + this.openingTimesCache.put(event.getOpeningTime().getOpeningTimeId(), event.getOpeningTime()); + this.getAllOpeningTimes().add(event.getOpeningTime()); + } + + @Override + public OpeningTime findOpeningTimeById (final Long openingTimeId) throws OpeningTimeNotFoundException { + // Validate parameter + if (null == openingTimeId) { + // Throw NPE + throw new NullPointerException("openingTimeId is null"); //NOI18N + } else if (openingTimeId < 1) { + // Throw IAE + throw new IllegalArgumentException("openingTimeId=" + openingTimeId + " is invalid"); //NOI18N + } else if (!this.openingTimesCache.containsKey(openingTimeId)) { + // Not found + throw new OpeningTimeNotFoundException(openingTimeId); + } + + // Get it from cache + final OpeningTime opening = this.openingTimesCache.get(openingTimeId); + + // Return it + return opening; + } + + /** + * Returns a list of all opening times + *

+ * @return A list of all opening times + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllOpeningTimes () { + return this.allOpeningTimes; + } + + /** + * Getter for a list of filtered opening times + *

+ * @return Filtered opening times + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredOpeningTimes () { + return this.filteredOpeningTimes; + } + + /** + * Setter for a list of filtered opening times + *

+ * @param filteredOpeningTimes Filtered opening times + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredOpeningTimes (final List filteredOpeningTimes) { + this.filteredOpeningTimes = filteredOpeningTimes; + } + + /** + * Getter for selected open-time instance + *

+ * @return Selected open-time instance + */ + public OpeningTime getSelectedOpeningTime () { + return this.selectedOpeningTime; + } + + /** + * Setter for selected open-time instance + *

+ * @param selectedOpeningTime Selected open-time instance + */ + public void setSelectedOpeningTime (final OpeningTime selectedOpeningTime) { + this.selectedOpeningTime = selectedOpeningTime; + } + + /** + * Initializer method + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.openingTimesCache.iterator().hasNext()) { + // Add all + for (final OpeningTime openingTime : this.openingTimesBean.fetchAllOpeningTimes()) { + // Add it to cache + this.openingTimesCache.put(openingTime.getOpeningTimeId(), openingTime); + } + } + + // Is the list empty, but filled cache? + if (this.getAllOpeningTimes().isEmpty() && this.openingTimesCache.iterator().hasNext()) { + // Build up list + for (final Cache.Entry currentEntry : this.openingTimesCache) { + // Add to list + this.getAllOpeningTimes().add(currentEntry.getValue()); + } + + // Sort list + this.getAllOpeningTimes().sort(new Comparator() { + @Override + public int compare (final OpeningTime openingTime1, final OpeningTime openingTime2) { + return openingTime1.getOpeningTimeId() > openingTime2.getOpeningTimeId() ? 1 : openingTime1.getOpeningTimeId() < openingTime2.getOpeningTimeId() ? -1 : 0; + } + } + ); + } + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewController.java new file mode 100644 index 00000000..016ea00d --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/business/opening_time/list/JobsOpeningTimeListWebViewController.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2017 - 2020 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.opening_time.list; + +import java.io.Serializable; +import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException; +import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; + +/** + * An interface for general opening times controller + *

+ * @author Roland Häder + */ +public interface JobsOpeningTimeListWebViewController extends Serializable { + + /** + * Retrieves a single opening-time entity for given id number or throws a + * proper exception if not found. + *

+ * @param openingTimeId Opening time id to lookup + *

+ * @return Company department instance + *

+ * @throws OpeningTimeNotFoundException If the id number could not be looked + * up and solved into an entity + */ + OpeningTime findOpeningTimeById (final Long openingTimeId) throws OpeningTimeNotFoundException; + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestBean.java deleted file mode 100644 index bde080e6..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestBean.java +++ /dev/null @@ -1,531 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.contact.mobile; - -import java.text.MessageFormat; -import java.util.Date; -import javax.ejb.EJB; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.event.Observes; -import javax.enterprise.inject.Any; -import javax.faces.application.FacesMessage; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; -import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent; -import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; -import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; -import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.phone.FinancialsAdminPhoneWebRequestController; -import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; -import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; -import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException; -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.events.user.add.ObservableAdminAddedUserEvent; - -/** - * An administrative contact mobile controller (bean) - *

- * @author Roland Häder - */ -@Named ("adminContactMobileController") -@RequestScoped -public class FinancialsAdminContactMobileWebRequestBean extends BaseFinancialsBean implements FinancialsAdminContactMobileWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_919L; - - /** - * Administrative EJB for phone number - */ - @EJB (lookup = "java:global/jfinancials-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote") - private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean; - - /** - * Event being fired when a mobile number has been linked - */ - @Inject - @Any - private Event adminLinkedMobileNumberEvent; - - /** - * Administrative phone controller - */ - @Inject - private FinancialsAdminPhoneWebRequestController adminPhoneController; - - /** - * Contact instance - */ - private Contact contact; - - /** - * When mobile number has been created - */ - private Date mobileEntryCreated; - - /** - * When mobile number has been updated - */ - private Date mobileEntryUpdated; - - /** - * Phone id (primary key) - */ - private Long mobileId; - - /** - * Mobile number - */ - private Long mobileNumber; - - /** - * Event being fired when administrator unlinks mobile from contact - */ - @Inject - @Any - private Event mobileNumberUnlinkedEvent; - - /** - * Mobile provider - */ - private MobileProvider mobileProvider; - - /** - * Default constructor - */ - public FinancialsAdminContactMobileWebRequestBean () { - // Call super constructor - super(); - - // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName()); - // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller)); - } - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { - // The event must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact() == null) { - // Throw again ... - throw new NullPointerException("event.addedContact is null"); //NOI18N - } else if (event.getAddedContact().getContactId() == null) { - // ... and again - throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N - } else if (event.getAddedContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N - } - - // Clear this bean - this.clear(); - } - - /** - * Event observer for newly added users by administrator - *

- * @param event Event being fired - */ - public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { - // Event and contained entity instance should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedUser() == null) { - // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - /** - * Event observer for updated contact data by administrators - *

- * @param event Updated contact data event - */ - public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { - // Event and contained entity instance should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedContact() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedContact is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() == null) { - // userId is null - throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - /** - * Observer for events being fired when a bean helper has successfully - * created a contact instance. - *

- * @param event Event being fired - */ - public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) { - // Log message - //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N - - // The event instance must be valid - if (null == event) { - // Throw NPE again - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getCreatedContact() == null) { - // Throw NPE again - throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N - } else if (event.getCreatedContact().getContactId() == null) { - // Throw NPE again - throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N - } else if (event.getCreatedContact().getContactId() < 1) { - // Not valid - throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N - } - - // Set it here - this.setContact(event.getCreatedContact()); - } - - /** - * Observes events being fired when a bean helper has successfully created a - * mobile number instance. - *

- * @param event Event being fired - */ - public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) { - // The event instance must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.mobileNumber is null"); //NOI18N - } else if (event.getMobileNumber().getMobileId() == null) { - // Throw NPE yet again - throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N - } else if (event.getMobileNumber().getMobileId() < 1) { - // Throw NPE yet again - throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N - } - - // Get fax number from event - final DialableMobileNumber number = event.getMobileNumber(); - - // Copy all data to this bean - this.setMobileId(number.getMobileId()); - this.setMobileProvider(number.getMobileProvider()); - this.setMobileNumber(number.getMobileNumber()); - this.setMobileEntryCreated(number.getMobileEntryCreated()); - this.setMobileEntryUpdated(number.getMobileEntryUpdated()); - } - - /** - * Links mobile number to contact from bean helper as "main mobile number". - *

- * @return Redirect outcome - */ - public String doLinkMainMobileNumber () { - // Get contact from helper - final Contact targetContact = this.getContact(); - - // Is all data properly set? - if (null == targetContact) { - // Throw NPE - throw new NullPointerException("targetContact is null"); //NOI18N - } else if (targetContact.getContactId() == null) { - // Throw it again - throw new NullPointerException("targetContact.contactId is null"); //NOI18N - } else if (targetContact.getContactId() < 1) { - // Is not valid - throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N - } else if (this.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("this.mobileProvider is null"); //NOI18N - } else if (this.getMobileProvider().getProviderId() == null) { - // Throw NPE - throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N - } else if (this.getMobileProvider().getProviderId() < 1) { - // Throw NPE - throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N - } else if (this.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("this.mobileNumber is null"); //NOI18N - } else if (this.getMobileNumber() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N - } - - // Init instance - final Contact updatedContact; - final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); - - // Try it again - try { - // Link it, too - updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number); - } catch (final PhoneNumberAlreadyLinkedException ex) { - // Throw again as cause - this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N - return ""; //NOI18N - } - - // Fire event - this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number)); - - // Return to contact profile - return "admin_show_contact"; //NOI18N - } - - /** - * Getter for contact instance - *

- * @return Contact instance - */ - public Contact getContact () { - return this.contact; - } - - /** - * Setter for contact instance - *

- * @param contact Contact instance - */ - public void setContact (final Contact contact) { - this.contact = contact; - } - - /** - * Setter for phone id - *

- * @return Phone id - */ - public Long getMobileId () { - return this.mobileId; - } - - /** - * Getter for phone id - *

- * @param mobileId Phone id - */ - public void setMobileId (final Long mobileId) { - this.mobileId = mobileId; - } - - /** - * 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 - *

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

- * @param mobileProvider Mobile provider - */ - public void setMobileProvider (final MobileProvider mobileProvider) { - this.mobileProvider = mobileProvider; - } - - /** - * Unlinks mobile data with current contact - *

- * @return Redirect outcome - */ - public String unlinkMobileContactData () { - // Create fax number instance - final DialableMobileNumber number = this.createMobileNumber(); - - // Is all data set - if (number == null) { - // Not set, throw NPE - throw new NullPointerException("number is null"); //NOI18N - } else if (number.getMobileId() == null) { - // Throw NPE again - throw new NullPointerException("number.phoneId is null"); //NOI18N - } else if (number.getMobileId() < 1) { - // Invalid number - throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getMobileId())); //NOI18N - } else if (number.getMobileProvider() == null) { - // Throw NPE - throw new NullPointerException("number.mobileProvider is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() == null) { - // ... throw again - throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N - } else if (number.getMobileProvider().getProviderId() < 1) { - // Id not valid - throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N - } else if (number.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("number.phoneNumber is null"); //NOI18N - } else if (number.getMobileNumber() < 1) { - // Throw it again ... - throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getMobileNumber())); //NOI18N - } else if (this.getContact() == null) { - // ... and throw again - throw new NullPointerException("this.contact is null"); //NOI18N - } else if (this.getContact().getContactId() == null) { - // ... and again ... - throw new NullPointerException("this.contact.contactId is null"); //NOI18N - } else if (this.getContact().getContactId() < 1) { - // Invalid id number - throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N - } - - // Init contact instance - final Contact updatedContact; - - try { - // Unlink it and return contact without mobile instance - updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number); - } catch (final PhoneNumberNotLinkedException ex) { - // Did not work - this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N - return ""; //NOI18N - } - - // Fire event - this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number)); - - // All fine here - return "admin_show_contact"; //NOI18N - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - } - - /** - * Returns an instance of a DialableMobileNumber from all fields stored in - * this bean. - *

- * @return An instance of a DialableMobileNumber class - */ - private DialableMobileNumber createMobileNumber () { - // Initialize it - final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); - - // Add all other data - number.setMobileEntryCreated(this.getMobileEntryCreated()); - number.setMobileEntryUpdated(this.getMobileEntryUpdated()); - - // Is id number set? - if (this.getMobileId() instanceof Long) { - // Set it - number.setMobileId(this.getMobileId()); - } - - // Return it - return number; - } - - /** - * Getter for mobile entry created - *

- * @return Mobile entry created - */ - @SuppressWarnings ("ReturnOfDateField") - private Date getMobileEntryCreated () { - return this.mobileEntryCreated; - } - - /** - * Setter for mobile entry created - *

- * @param mobileEntryCreated Mobile entry created - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - private void setMobileEntryCreated (final Date mobileEntryCreated) { - this.mobileEntryCreated = mobileEntryCreated; - } - - /** - * Getter for mobile entry updated - *

- * @return Mobile entry updated - */ - @SuppressWarnings ("ReturnOfDateField") - private Date getMobileEntryUpdated () { - return this.mobileEntryUpdated; - } - - /** - * Setter for mobile entry updated - *

- * @param mobileEntryUpdated Mobile entry updated - */ - @SuppressWarnings ("AssignmentToDateFieldFromParameter") - private void setMobileEntryUpdated (final Date mobileEntryUpdated) { - this.mobileEntryUpdated = mobileEntryUpdated; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestController.java deleted file mode 100644 index 0e0f0b20..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsAdminContactMobileWebRequestController.java +++ /dev/null @@ -1,30 +0,0 @@ - -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.contact.mobile; - -import org.mxchange.jfinancials.beans.contact.phone.*; -import java.io.Serializable; - -/** - * An interface for user beans - *

- * @author Roland Häder - */ -public interface FinancialsAdminContactMobileWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestBean.java deleted file mode 100644 index a3ef2762..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestBean.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.contact.mobile; - -import java.text.MessageFormat; -import java.util.LinkedList; -import java.util.List; -import java.util.Objects; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Observes; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; -import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.contact.list.FinancialsContactListWebViewController; -import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; -import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; -import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; - -/** - * A general contact bean (controller) - *

- * @author Roland Häder - */ -@Named ("contactMobileController") -@RequestScoped -public class FinancialsContactMobileWebRequestBean extends BaseFinancialsBean implements FinancialsContactMobileWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_916L; - - /** - * An instance of a contact-list controller - */ - @Inject - private FinancialsContactListWebViewController contactListController; - - /** - * Chosen mobile number - */ - private DialableMobileNumber mobileNumber; - - /** - * Default constructor - */ - public FinancialsContactMobileWebRequestBean () { - // Call super constructor - super(); - } - - /** - * Observes events being fired when an administrator has added a new - * contact. - *

- * @param event Event being fired - */ - public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { - // The event must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedContact() == null) { - // Throw again ... - throw new NullPointerException("event.addedContact is null"); //NOI18N - } else if (event.getAddedContact().getContactId() == null) { - // ... and again - throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N - } else if (event.getAddedContact().getContactId() < 1) { - // Not valid - throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N - } - - // Clear this bean - this.clear(); - } - - /** - * Event observer for newly added users by administrator - *

- * @param event Event being fired - */ - public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { - // Event and contained entity instance should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getAddedUser() == null) { - // Throw NPE again - throw new NullPointerException("event.addedUser is null"); //NOI18N - } else if (event.getAddedUser().getUserId() == null) { - // userId is null - throw new NullPointerException("event.addedUser.userId is null"); //NOI18N - } else if (event.getAddedUser().getUserId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - /** - * Event observer for updated contact data by administrators - *

- * @param event Updated contact data event - */ - public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { - // Event and contained entity instance should not be null - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getUpdatedContact() == null) { - // Throw NPE again - throw new NullPointerException("event.updatedContact is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() == null) { - // userId is null - throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N - } else if (event.getUpdatedContact().getContactId() < 1) { - // Not avalid id - throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N - } - - // Clear all data - this.clear(); - } - - /** - * Observes events being fired when a bean helper has successfully created a - * mobile number instance. - *

- * @param event Event being fired - */ - public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) { - // The event instance must be valid - if (null == event) { - // Throw NPE - throw new NullPointerException("event is null"); //NOI18N - } else if (event.getMobileNumber() == null) { - // Throw NPE again - throw new NullPointerException("event.mobileNumber is null"); //NOI18N - } else if (event.getMobileNumber().getMobileId() == null) { - // Throw NPE yet again - throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N - } else if (event.getMobileNumber().getMobileId() < 1) { - // Throw NPE yet again - throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N - } - - // Set it here - this.setMobileNumber(event.getMobileNumber()); - } - - /** - * Getter for all contacts having current mobile number linked - *

- * @return List of all linked contacts - */ - public List allCurrentMobileNumberContacts () { - // Get id - final DialableMobileNumber dialableMobileNumber = this.getMobileNumber(); - - // Init list - final List contacts = new LinkedList<>(); - - // "Walk" through all contacts - for (final Contact contact : this.contactListController.getAllContacts()) { - // Is mobile instance the same? - if (Objects.equals(contact.getContactMobileNumber(), dialableMobileNumber)) { - // Found one - contacts.add(contact); - } - } - - // Return now-cached list - return contacts; - } - - /** - * Getter for chosen mobile number - *

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

- * @param mobileNumber mobile number - */ - public void setMobileNumber (final DialableMobileNumber mobileNumber) { - this.mobileNumber = mobileNumber; - } - - /** - * Clears this bean - */ - private void clear () { - // Clear all data - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestController.java deleted file mode 100644 index 1501a46c..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/mobile/FinancialsContactMobileWebRequestController.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.contact.mobile; - -import org.mxchange.jfinancials.beans.contact.phone.*; -import java.io.Serializable; - -/** - * An interface for user beans - *

- * @author Roland Häder - */ -public interface FinancialsContactMobileWebRequestController extends Serializable { - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestBean.java new file mode 100644 index 00000000..5d5a4801 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestBean.java @@ -0,0 +1,524 @@ +/* + * Copyright (C) 2016 - 2020 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.contact.mobile; + +import java.text.MessageFormat; +import java.util.Date; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.event.Observes; +import javax.enterprise.inject.Any; +import javax.faces.application.FacesMessage; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.events.mobile.linked.AdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.AdminUnlinkedMobileNumberEvent; +import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; +import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException; +import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException; +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.events.user.add.ObservableAdminAddedUserEvent; + +/** + * An administrative contact mobile controller (bean) + *

+ * @author Roland Häder + */ +@Named ("adminContactMobileController") +@RequestScoped +public class JobsAdminContactMobileWebRequestBean extends BaseJobsBean implements JobsAdminContactMobileWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_919L; + + /** + * Administrative EJB for phone number + */ + @EJB (lookup = "java:global/jjobs-ejb/adminContactPhone!org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote") + private AdminContactsPhoneSessionBeanRemote adminContactPhoneBean; + + /** + * Event being fired when a mobile number has been linked + */ + @Inject + @Any + private Event adminLinkedMobileNumberEvent; + + /** + * Contact instance + */ + private Contact contact; + + /** + * When mobile number has been created + */ + private Date mobileEntryCreated; + + /** + * When mobile number has been updated + */ + private Date mobileEntryUpdated; + + /** + * Phone id (primary key) + */ + private Long mobileId; + + /** + * Mobile number + */ + private Long mobileNumber; + + /** + * Event being fired when administrator unlinks mobile from contact + */ + @Inject + @Any + private Event mobileNumberUnlinkedEvent; + + /** + * Mobile provider + */ + private MobileProvider mobileProvider; + + /** + * Default constructor + */ + public JobsAdminContactMobileWebRequestBean () { + // Call super constructor + super(); + + // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[3].getClassName(), Thread.currentThread().getStackTrace()[3].getMethodName()); + // System.out.println(MessageFormat.format("{0}: Constructed, caller: {1}", this.getClass().getSimpleName(), caller)); + } + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Clear this bean + this.clear(); + } + + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { + // Event and contained entity instance should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { + // Event and contained entity instance should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + /** + * Observer for events being fired when a bean helper has successfully + * created a contact instance. + *

+ * @param event Event being fired + */ + public void afterCreatedContactEvent (@Observes final ObservableCreatedContactEvent event) { + // Log message + //* NOISY-DEBUG: */ System.out.println(MessageFormat.format("AdminContactController::afterCreatedContactEvent(): contact={0} - CALLED!", contact)); //NOI18N + + // The event instance must be valid + if (null == event) { + // Throw NPE again + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getCreatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N + } else if (event.getCreatedContact().getContactId() == null) { + // Throw NPE again + throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N + } else if (event.getCreatedContact().getContactId() < 1) { + // Not valid + throw new IllegalStateException(MessageFormat.format("event.createdContact.contactId={0} is not valid.", event.getCreatedContact().getContactId())); //NOI18N + } + + // Set it here + this.setContact(event.getCreatedContact()); + } + + /** + * Observes events being fired when a bean helper has successfully created a + * mobile number instance. + *

+ * @param event Event being fired + */ + public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.mobileNumber is null"); //NOI18N + } else if (event.getMobileNumber().getMobileId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N + } else if (event.getMobileNumber().getMobileId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N + } + + // Get fax number from event + final DialableMobileNumber number = event.getMobileNumber(); + + // Copy all data to this bean + this.setMobileId(number.getMobileId()); + this.setMobileProvider(number.getMobileProvider()); + this.setMobileNumber(number.getMobileNumber()); + this.setMobileEntryCreated(number.getMobileEntryCreated()); + this.setMobileEntryUpdated(number.getMobileEntryUpdated()); + } + + /** + * Links mobile number to contact from bean helper as "main mobile number". + *

+ * @return Redirect outcome + */ + public String doLinkMainMobileNumber () { + // Get contact from helper + final Contact targetContact = this.getContact(); + + // Is all data properly set? + if (null == targetContact) { + // Throw NPE + throw new NullPointerException("targetContact is null"); //NOI18N + } else if (targetContact.getContactId() == null) { + // Throw it again + throw new NullPointerException("targetContact.contactId is null"); //NOI18N + } else if (targetContact.getContactId() < 1) { + // Is not valid + throw new IllegalArgumentException(MessageFormat.format("targetContact.contactId={0} is not valid", targetContact.getContactId())); //NOI18N + } else if (this.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("this.mobileProvider is null"); //NOI18N + } else if (this.getMobileProvider().getProviderId() == null) { + // Throw NPE + throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N + } else if (this.getMobileProvider().getProviderId() < 1) { + // Throw NPE + throw new NullPointerException(MessageFormat.format("this.mobileProvider.providerId={0} is invalid", this.getMobileProvider().getProviderId())); //NOI18N + } else if (this.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("this.mobileNumber is null"); //NOI18N + } else if (this.getMobileNumber() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber={0} is invalid", this.getMobileNumber())); //NOI18N + } + + // Init instance + final Contact updatedContact; + final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); + + // Try it again + try { + // Link it, too + updatedContact = this.adminContactPhoneBean.linkNewMobileNumberWithContact(targetContact, number); + } catch (final PhoneNumberAlreadyLinkedException ex) { + // Throw again as cause + this.showFacesMessage("form_add_contact_mobile:mobileNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.adminLinkedMobileNumberEvent.fire(new AdminLinkedMobileNumberEvent(updatedContact, number)); + + // Return to contact profile + return "admin_show_contact"; //NOI18N + } + + /** + * Getter for contact instance + *

+ * @return Contact instance + */ + public Contact getContact () { + return this.contact; + } + + /** + * Setter for contact instance + *

+ * @param contact Contact instance + */ + public void setContact (final Contact contact) { + this.contact = contact; + } + + /** + * Setter for phone id + *

+ * @return Phone id + */ + public Long getMobileId () { + return this.mobileId; + } + + /** + * Getter for phone id + *

+ * @param mobileId Phone id + */ + public void setMobileId (final Long mobileId) { + this.mobileId = mobileId; + } + + /** + * 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 + *

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

+ * @param mobileProvider Mobile provider + */ + public void setMobileProvider (final MobileProvider mobileProvider) { + this.mobileProvider = mobileProvider; + } + + /** + * Unlinks mobile data with current contact + *

+ * @return Redirect outcome + */ + public String unlinkMobileContactData () { + // Create fax number instance + final DialableMobileNumber number = this.createMobileNumber(); + + // Is all data set + if (number == null) { + // Not set, throw NPE + throw new NullPointerException("number is null"); //NOI18N + } else if (number.getMobileId() == null) { + // Throw NPE again + throw new NullPointerException("number.phoneId is null"); //NOI18N + } else if (number.getMobileId() < 1) { + // Invalid number + throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getMobileId())); //NOI18N + } else if (number.getMobileProvider() == null) { + // Throw NPE + throw new NullPointerException("number.mobileProvider is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() == null) { + // ... throw again + throw new NullPointerException("number.mobileProvider.providerId is null"); //NOI18N + } else if (number.getMobileProvider().getProviderId() < 1) { + // Id not valid + throw new IllegalArgumentException(MessageFormat.format("number.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N + } else if (number.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("number.phoneNumber is null"); //NOI18N + } else if (number.getMobileNumber() < 1) { + // Throw it again ... + throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getMobileNumber())); //NOI18N + } else if (this.getContact() == null) { + // ... and throw again + throw new NullPointerException("this.contact is null"); //NOI18N + } else if (this.getContact().getContactId() == null) { + // ... and again ... + throw new NullPointerException("this.contact.contactId is null"); //NOI18N + } else if (this.getContact().getContactId() < 1) { + // Invalid id number + throw new IllegalArgumentException(MessageFormat.format("this.contact.contactId={0} is invalid.", this.getContact().getContactId())); //NOI18N + } + + // Init contact instance + final Contact updatedContact; + + try { + // Unlink it and return contact without mobile instance + updatedContact = this.adminContactPhoneBean.unlinkMobileDataFromContact(this.getContact(), number); + } catch (final PhoneNumberNotLinkedException ex) { + // Did not work + this.showFacesMessage("form_unlink_contact_mobile:mobileNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N + return ""; //NOI18N + } + + // Fire event + this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number)); + + // All fine here + return "admin_show_contact"; //NOI18N + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + + /** + * Returns an instance of a DialableMobileNumber from all fields stored in + * this bean. + *

+ * @return An instance of a DialableMobileNumber class + */ + private DialableMobileNumber createMobileNumber () { + // Initialize it + final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber()); + + // Add all other data + number.setMobileEntryCreated(this.getMobileEntryCreated()); + number.setMobileEntryUpdated(this.getMobileEntryUpdated()); + + // Is id number set? + if (this.getMobileId() instanceof Long) { + // Set it + number.setMobileId(this.getMobileId()); + } + + // Return it + return number; + } + + /** + * Getter for mobile entry created + *

+ * @return Mobile entry created + */ + @SuppressWarnings ("ReturnOfDateField") + private Date getMobileEntryCreated () { + return this.mobileEntryCreated; + } + + /** + * Setter for mobile entry created + *

+ * @param mobileEntryCreated Mobile entry created + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + private void setMobileEntryCreated (final Date mobileEntryCreated) { + this.mobileEntryCreated = mobileEntryCreated; + } + + /** + * Getter for mobile entry updated + *

+ * @return Mobile entry updated + */ + @SuppressWarnings ("ReturnOfDateField") + private Date getMobileEntryUpdated () { + return this.mobileEntryUpdated; + } + + /** + * Setter for mobile entry updated + *

+ * @param mobileEntryUpdated Mobile entry updated + */ + @SuppressWarnings ("AssignmentToDateFieldFromParameter") + private void setMobileEntryUpdated (final Date mobileEntryUpdated) { + this.mobileEntryUpdated = mobileEntryUpdated; + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestController.java new file mode 100644 index 00000000..de54b875 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsAdminContactMobileWebRequestController.java @@ -0,0 +1,30 @@ + +/* + * Copyright (C) 2016 - 2020 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.contact.mobile; + +import org.mxchange.jjobs.beans.contact.phone.*; +import java.io.Serializable; + +/** + * An interface for user beans + *

+ * @author Roland Häder + */ +public interface JobsAdminContactMobileWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestBean.java new file mode 100644 index 00000000..25c0af4e --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestBean.java @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2016 - 2020 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.contact.mobile; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Observes; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent; +import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController; +import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; +import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; + +/** + * A general contact bean (controller) + *

+ * @author Roland Häder + */ +@Named ("contactMobileController") +@RequestScoped +public class JobsContactMobileWebRequestBean extends BaseJobsBean implements JobsContactMobileWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_916L; + + /** + * An instance of a contact-list controller + */ + @Inject + private JobsContactListWebViewController contactListController; + + /** + * Chosen mobile number + */ + private DialableMobileNumber mobileNumber; + + /** + * Default constructor + */ + public JobsContactMobileWebRequestBean () { + // Call super constructor + super(); + } + + /** + * Observes events being fired when an administrator has added a new + * contact. + *

+ * @param event Event being fired + */ + public void afterAdminAddedContactEvent (@Observes final ObservableAdminAddedContactEvent event) { + // The event must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedContact() == null) { + // Throw again ... + throw new NullPointerException("event.addedContact is null"); //NOI18N + } else if (event.getAddedContact().getContactId() == null) { + // ... and again + throw new NullPointerException("event.addedContact.contactId is null"); //NOI18N + } else if (event.getAddedContact().getContactId() < 1) { + // Not valid + throw new IllegalArgumentException(MessageFormat.format("event.addedContact.contactId={0} is not valid", event.getAddedContact().getContactId())); //NOI18N + } + + // Clear this bean + this.clear(); + } + + /** + * Event observer for newly added users by administrator + *

+ * @param event Event being fired + */ + public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) { + // Event and contained entity instance should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getAddedUser() == null) { + // Throw NPE again + throw new NullPointerException("event.addedUser is null"); //NOI18N + } else if (event.getAddedUser().getUserId() == null) { + // userId is null + throw new NullPointerException("event.addedUser.userId is null"); //NOI18N + } else if (event.getAddedUser().getUserId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getAddedUser(), event.getAddedUser().getUserId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + /** + * Event observer for updated contact data by administrators + *

+ * @param event Updated contact data event + */ + public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) { + // Event and contained entity instance should not be null + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getUpdatedContact() == null) { + // Throw NPE again + throw new NullPointerException("event.updatedContact is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() == null) { + // userId is null + throw new NullPointerException("event.updatedContact.contactId is null"); //NOI18N + } else if (event.getUpdatedContact().getContactId() < 1) { + // Not avalid id + throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N + } + + // Clear all data + this.clear(); + } + + /** + * Observes events being fired when a bean helper has successfully created a + * mobile number instance. + *

+ * @param event Event being fired + */ + public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) { + // The event instance must be valid + if (null == event) { + // Throw NPE + throw new NullPointerException("event is null"); //NOI18N + } else if (event.getMobileNumber() == null) { + // Throw NPE again + throw new NullPointerException("event.mobileNumber is null"); //NOI18N + } else if (event.getMobileNumber().getMobileId() == null) { + // Throw NPE yet again + throw new NullPointerException("event.mobileNumber.mobileId is null"); //NOI18N + } else if (event.getMobileNumber().getMobileId() < 1) { + // Throw NPE yet again + throw new NullPointerException(MessageFormat.format("event.mobileNumber.mobileId={0} is invalid", event.getMobileNumber().getMobileId())); //NOI18N + } + + // Set it here + this.setMobileNumber(event.getMobileNumber()); + } + + /** + * Getter for all contacts having current mobile number linked + *

+ * @return List of all linked contacts + */ + public List allCurrentMobileNumberContacts () { + // Get id + final DialableMobileNumber dialableMobileNumber = this.getMobileNumber(); + + // Init list + final List contacts = new LinkedList<>(); + + // "Walk" through all contacts + for (final Contact contact : this.contactListController.getAllContacts()) { + // Is mobile instance the same? + if (Objects.equals(contact.getContactMobileNumber(), dialableMobileNumber)) { + // Found one + contacts.add(contact); + } + } + + // Return now-cached list + return contacts; + } + + /** + * Getter for chosen mobile number + *

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

+ * @param mobileNumber mobile number + */ + public void setMobileNumber (final DialableMobileNumber mobileNumber) { + this.mobileNumber = mobileNumber; + } + + /** + * Clears this bean + */ + private void clear () { + // Clear all data + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestController.java new file mode 100644 index 00000000..696dfafe --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/contact/mobile/JobsContactMobileWebRequestController.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2016 - 2020 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.contact.mobile; + +import org.mxchange.jjobs.beans.contact.phone.*; +import java.io.Serializable; + +/** + * An interface for user beans + *

+ * @author Roland Häder + */ +public interface JobsContactMobileWebRequestController extends Serializable { + +} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestBean.java deleted file mode 100644 index effde46a..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestBean.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.user.action; - -import java.text.MessageFormat; -import javax.ejb.EJB; -import javax.enterprise.context.RequestScoped; -import javax.enterprise.event.Event; -import javax.enterprise.inject.Any; -import javax.faces.FacesException; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.contact.FinancialsContactWebRequestController; -import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController; -import org.mxchange.jfinancials.beans.user.login.FinancialsUserLoginWebSessionController; -import org.mxchange.jusercore.events.user.update.post.ObservablePostUserPersonalDataUpdatedEvent; -import org.mxchange.jusercore.events.user.update.post.PostUserPersonalDataUpdatedEvent; -import org.mxchange.jusercore.events.user.update.pre.ObservablePreUserPersonalDataUpdatedEvent; -import org.mxchange.jusercore.events.user.update.pre.PreUserPersonalDataUpdatedEvent; -import org.mxchange.jusercore.model.user.User; -import org.mxchange.jusercore.model.user.UserSessionBeanRemote; -import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; - -/** - * A user action bean (controller) - *

- * @author Roland Häder - */ -@Named ("userActionController") -@RequestScoped -public class FinancialsUserActionWebRequestBean extends BaseFinancialsBean implements FinancialsUserActionWebRequestController { - - /** - * Serial number - */ - private static final long serialVersionUID = 542_145_347_920L; - - /** - * General contact controller - */ - @Inject - private FinancialsContactWebRequestController contactController; - - /** - * Features controller - */ - @Inject - private FinancialsFeaturesWebApplicationController featureController; - - /** - * Event being fired when user updated personal data - */ - @Inject - @Any - private Event postUpdatedPersonalDataEvent; - - /** - * Event being fired when user updated personal data - */ - @Inject - @Any - private Event preUpdatedPersonalDataEvent; - - /** - * Remote user bean - */ - @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") - private UserSessionBeanRemote userBean; - - /** - * Login controller (bean) - */ - @Inject - private FinancialsUserLoginWebSessionController userLoginController; - - /** - * Default constructor - */ - public FinancialsUserActionWebRequestBean () { - // Call super constructor - super(); - } - - @Override - public String doChangePersonalData () { - // This method shall only be called if the user is logged-in - if (!this.userLoginController.isUserLoggedIn()) { - // Not logged-in - throw new IllegalStateException("User is not logged-in"); //NOI18N - } else if (!this.contactController.isRequiredChangePersonalDataSet()) { - // Not all required fields are set - throw new FacesException("Not all required fields are set."); //NOI18N - } else if (!this.userLoginController.ifCurrentPasswordMatches()) { - // Password not matching - throw new FacesException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); - } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) { //NOI18N - // Editing is not allowed - throw new IllegalStateException("User tried to edit personal data."); //NOI18N - } - - // Get user instance - final User user = this.userLoginController.getLoggedInUser(); - - // Fire pre-update event - this.preUpdatedPersonalDataEvent.fire(new PreUserPersonalDataUpdatedEvent(user)); - - // It should be there, so run some tests on it - assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N - assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N - assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N - assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N - assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N - assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N - - // Send it to the EJB - final User updatedUser = this.userBean.updateUserPersonalData(user); - - // Fire post-update event - this.postUpdatedPersonalDataEvent.fire(new PostUserPersonalDataUpdatedEvent(updatedUser)); - - // All fine - return "user_contact_data_saved"; //NOI18N - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestController.java deleted file mode 100644 index ed6cd2d9..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/action/FinancialsUserActionWebRequestController.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.user.action; - -import java.io.Serializable; - -/** - * An interface for user beans - *

- * @author Roland Häder - */ -public interface FinancialsUserActionWebRequestController extends Serializable { - - /** - * Minimum password length - *

- * @deprecated Better set as context parameter - */ - @Deprecated - public static final Integer MINIMUM_PASSWORD_LENGTH = 5; - - /** - * Changes logged-in user's personal data if the current password matches - * and TAC + privacy statement has been accepted. - *

- * @return New target page - */ - String doChangePersonalData (); - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewBean.java deleted file mode 100644 index 7c79cdf6..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewBean.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.user.email_address.list; - -import fish.payara.cdi.jsr107.impl.NamedCache; -import java.util.Comparator; -import java.util.LinkedList; -import java.util.List; -import javax.annotation.PostConstruct; -import javax.cache.Cache; -import javax.ejb.EJB; -import javax.faces.view.ViewScoped; -import javax.inject.Inject; -import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController; -import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; -import org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote; - -/** - * A view-scoped bean for listing email address changes - *

- * @author Roland Häder - */ -@Named ("emailChangeListController") -@ViewScoped -public class FinancialsEmailChangeListWebViewBean extends BaseFinancialsBean implements FinancialsEmailChangeListWebViewController { - - /** - * Serial number - */ - private static final long serialVersionUID = 186_078_724_659_154L; - - /** - * A list of all mobile numbers - */ - private final List allEmailAddressChanges; - - /** - * Remote email change bean - */ - @EJB (lookup = "java:global/jfinancials-ejb/userEmailChange!org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote") - private UserEmailChangeSessionBeanRemote emailChangeBean; - - /** - * Features controller - */ - @Inject - private FinancialsFeaturesWebApplicationController featureController; - - /** - * A list of filtered mobile numbers - */ - private List filteredEmailAddressChanges; - - /** - * Local list of already queued email addresses - */ - @Inject - @NamedCache (cacheName = "queuedEmailCache") - private transient Cache queuedEmailCache; - - /** - * Default constructor - */ - public FinancialsEmailChangeListWebViewBean () { - // Call super constructor - super(); - - // Initialize list - this.allEmailAddressChanges = new LinkedList<>(); - } - - @Override - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getAllEmailAddressChanges () { - return this.allEmailAddressChanges; - } - - /** - * Getter for filtered email address changed - *

- * @return Filtered email address changed - */ - @SuppressWarnings ("ReturnOfCollectionOrArrayField") - public List getFilteredEmailAddressChanges () { - return this.filteredEmailAddressChanges; - } - - /** - * Setter for filtered email address changed - *

- * @param filteredEmailAddressChanges Filtered email address changed - */ - @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") - public void setFilteredEmailAddressChanges (final List filteredEmailAddressChanges) { - this.filteredEmailAddressChanges = filteredEmailAddressChanges; - } - - /** - * Post-construction - */ - @PostConstruct - public void initializeList () { - // Is cache there? - if (!this.queuedEmailCache.iterator().hasNext()) { - // Add all - for (final ChangeableEmailAddress currentEmailAddress : this.emailChangeBean.fetchAllQueuedAddressChanges()) { - // Add it to cache - this.queuedEmailCache.put(currentEmailAddress.getEmailChangeId(), currentEmailAddress); - } - } - - // Is cache filled and list is empty - if ((this.queuedEmailCache.iterator().hasNext()) && (this.getAllEmailAddressChanges().isEmpty())) { - // Build up list - for (final Cache.Entry currentEntry : this.queuedEmailCache) { - // Add to list - this.getAllEmailAddressChanges().add(currentEntry.getValue()); - } - - // Sort list - this.getAllEmailAddressChanges().sort(new Comparator() { - @Override - public int compare (final ChangeableEmailAddress queuedEmail1, final ChangeableEmailAddress queuedEmail2) { - return queuedEmail1.getEmailChangeId() > queuedEmail2.getEmailChangeId() ? 1 : queuedEmail1.getEmailChangeId() < queuedEmail2.getEmailChangeId() ? -1 : 0; - } - }); - - // Set full list - this.setFilteredEmailAddressChanges(this.getAllEmailAddressChanges()); - } - } - - @Override - public boolean isEmailAddressQueued (final String emailAddress) { - // Check if parameter is valid - 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; - - // Iterate through whole list - for (final ChangeableEmailAddress address : this.getAllEmailAddressChanges()) { - // Does current match? - if (emailAddress.equals(address.getEmailAddress())) { - // Yes, set flag and abort iteration - isFound = true; - break; - } - } - - // Return flag - return isFound; - } - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewController.java deleted file mode 100644 index ca0fa540..00000000 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/email_address/list/FinancialsEmailChangeListWebViewController.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 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.jfinancials.beans.user.email_address.list; - -import java.io.Serializable; -import java.util.List; -import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; - -/** - * An interface for an email change controller - *

- * @author Roland Häder - */ -public interface FinancialsEmailChangeListWebViewController extends Serializable { - - /** - * Returns a list of all email address changes. For performance reasons, the - * controller (bean) should be view-scoped as from user to user nothing - * changes. And the controller's post-construct method should load all - * numbers and cache it in the controller. - *

- * @return List of all mobile numbers - */ - List getAllEmailAddressChanges (); - - /** - * Checks if given email address has already been queued. First a local list - * is being checked, if not found, the EJB is called. Only if found, the - * result is "cached" in the list. - *

- * @param emailAddress Email address to verify - *

- * @return Whether the email address in field emailAddress is already queued - */ - boolean isEmailAddressQueued (final String emailAddress); - -} diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewBean.java index 232cbf58..945c09c4 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewBean.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.user.list; +package org.mxchange.jjobs.beans.user.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; @@ -29,7 +29,7 @@ import javax.enterprise.event.Observes; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent; import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; @@ -77,7 +77,7 @@ public class JobsUserListWebViewBean extends BaseJobsBean implements JobsUserLis /** * Remote user bean */ - @EJB (lookup = "java:global/jfinancials-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") + @EJB (lookup = "java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") private UserSessionBeanRemote userBean; /** diff --git a/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewController.java b/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewController.java index 82ef7df7..b76a562c 100644 --- a/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewController.java +++ b/src/java/org/mxchange/jjobs/beans/contact/phone/list/JobsUserListWebViewController.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.user.list; +package org.mxchange.jjobs.beans.user.list; import java.io.Serializable; import java.util.List; diff --git a/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java b/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java index 0bfeb8b8..c8eed438 100644 --- a/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java +++ b/src/java/org/mxchange/jjobs/beans/data/JobsDataWebApplicationBean.java @@ -19,9 +19,8 @@ package org.mxchange.jjobs.beans.data; import javax.enterprise.context.ApplicationScoped; 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.jcoreee.dates.DayOfTheWeek; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jusercore.model.user.profilemodes.ProfileMode; import org.mxchange.jusercore.model.user.status.UserAccountStatus; @@ -69,6 +68,7 @@ public class JobsDataWebApplicationBean extends BaseJobsBean { * Returns an array of all profile modes

* @ * + * * return An array of all profile modes */ public ProfileMode[] getProfileModes () { diff --git a/src/java/org/mxchange/jjobs/beans/helper/JobsWebViewHelperBean.java b/src/java/org/mxchange/jjobs/beans/helper/JobsWebViewHelperBean.java index ac672e79..c811a424 100644 --- a/src/java/org/mxchange/jjobs/beans/helper/JobsWebViewHelperBean.java +++ b/src/java/org/mxchange/jjobs/beans/helper/JobsWebViewHelperBean.java @@ -32,8 +32,8 @@ import org.mxchange.jcontactsbusiness.model.employee.Employable; import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.contact.list.JobsContactListWebViewController; import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent; import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent; import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent; @@ -78,7 +78,7 @@ public class JobsWebViewHelperBean extends BaseJobsBean implements JobsWebViewHe * Regular user controller */ @Inject - private FinancialsContactListWebViewController contactListController; + private JobsContactListWebViewController contactListController; /** * Fax number diff --git a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java index 8851f632..e6cbd863 100644 --- a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobile; +package org.mxchange.jjobs.beans.mobile; import java.text.MessageFormat; import java.util.Date; @@ -28,8 +28,8 @@ import javax.enterprise.inject.Any; import javax.faces.application.FacesMessage; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; -import org.mxchange.jfinancials.beans.mobile.list.FinancialsMobileListWebViewController; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.mobile.list.FinancialsMobileListWebViewController; import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent; import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent; @@ -49,7 +49,7 @@ import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; */ @Named ("adminMobileController") @RequestScoped -public class FinancialsAdminMobileWebRequestBean extends BaseFinancialsBean implements FinancialsAdminMobileWebRequestController { +public class FinancialsAdminMobileWebRequestBean extends BaseJobsBean implements FinancialsAdminMobileWebRequestController { /** * Serial number @@ -59,7 +59,7 @@ public class FinancialsAdminMobileWebRequestBean extends BaseFinancialsBean impl /** * Remote EJB for phone number (administrative) */ - @EJB (lookup = "java:global/jfinancials-ejb/adminMobile!org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote") + @EJB (lookup = "java:global/jjobs-ejb/adminMobile!org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote") private AdminMobileSessionBeanRemote adminMobileBean; /** diff --git a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java index 3a5a8f7f..269629df 100644 --- a/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java +++ b/src/java/org/mxchange/jjobs/beans/mobile/FinancialsAdminMobileWebRequestController.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobile; +package org.mxchange.jjobs.beans.mobile; import java.io.Serializable; diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java index 5c6a03f0..fdc286b3 100644 --- a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobile.list; +package org.mxchange.jjobs.beans.mobile.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; @@ -33,7 +33,7 @@ import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEven import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent; import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent; import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent; import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent; import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException; @@ -48,7 +48,7 @@ import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; */ @Named ("mobileListController") @ViewScoped -public class FinancialsMobileListWebViewBean extends BaseFinancialsBean implements FinancialsMobileListWebViewController { +public class FinancialsMobileListWebViewBean extends BaseJobsBean implements FinancialsMobileListWebViewController { /** * Serial number @@ -68,7 +68,7 @@ public class FinancialsMobileListWebViewBean extends BaseFinancialsBean implemen /** * General EJB for mobile numbers */ - @EJB (lookup = "java:global/jfinancials-ejb/mobile!org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote") + @EJB (lookup = "java:global/jjobs-ejb/mobile!org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote") private MobileSessionBeanRemote mobileBean; /** diff --git a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java index 18a38fb6..1b45c3ab 100644 --- a/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java +++ b/src/java/org/mxchange/jjobs/beans/mobile/list/FinancialsMobileListWebViewController.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobile.list; +package org.mxchange.jjobs.beans.mobile.list; import java.io.Serializable; import java.util.List; diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java index cc7067a8..f8e4b262 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/JobsAdminMobileProviderWebRequestBean.java @@ -27,7 +27,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jfinancials.beans.mobileprovider.list.FinancialsMobileProviderListWebViewController; +import org.mxchange.jjobs.beans.mobileprovider.list.FinancialsMobileProviderListWebViewController; import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; import org.mxchange.jphone.events.mobileprovider.added.AdminMobileProviderAddedEvent; import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderAlreadyAddedException; diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java index 8a5e1f16..ab20ff88 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobileprovider.list; +package org.mxchange.jjobs.beans.mobileprovider.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; @@ -28,7 +28,7 @@ import javax.enterprise.event.Observes; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent; import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException; import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider; @@ -41,7 +41,7 @@ import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingl */ @Named ("mobileProviderListController") @ViewScoped -public class FinancialsMobileProviderListWebViewBean extends BaseFinancialsBean implements FinancialsMobileProviderListWebViewController { +public class FinancialsMobileProviderListWebViewBean extends BaseJobsBean implements FinancialsMobileProviderListWebViewController { /** * Serial number @@ -61,7 +61,7 @@ public class FinancialsMobileProviderListWebViewBean extends BaseFinancialsBean /** * Remote EJB for mobile providers (regular) */ - @EJB (lookup = "java:global/jfinancials-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote") + @EJB (lookup = "java:global/jjobs-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote") private MobileProviderSingletonBeanRemote mobileProviderBean; /** diff --git a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java index fa035528..f1e4568e 100644 --- a/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java +++ b/src/java/org/mxchange/jjobs/beans/mobileprovider/list/FinancialsMobileProviderListWebViewController.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.mobileprovider.list; +package org.mxchange.jjobs.beans.mobileprovider.list; import java.io.Serializable; import java.util.List; diff --git a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java index 9901d763..07edf159 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/JobsAdminPhoneWebRequestBean.java @@ -30,7 +30,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcountry.model.data.Country; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jfinancials.beans.phone.list.FinancialsPhoneListWebViewController; +import org.mxchange.jjobs.beans.phone.list.FinancialsPhoneListWebViewController; import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent; import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; import org.mxchange.jphone.events.fax.deleted.AdminFaxNumberDeletedEvent; diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java index 58642aed..8c68bcdb 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java +++ b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewBean.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.phone.list; +package org.mxchange.jjobs.beans.phone.list; import fish.payara.cdi.jsr107.impl.NamedCache; import java.text.MessageFormat; @@ -34,7 +34,7 @@ import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContac import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent; import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent; import org.mxchange.jcontacts.model.contact.Contact; -import org.mxchange.jfinancials.beans.BaseFinancialsBean; +import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent; import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent; import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent; @@ -51,7 +51,7 @@ import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote; */ @Named ("phoneListController") @ViewScoped -public class FinancialsPhoneListWebViewBean extends BaseFinancialsBean implements FinancialsPhoneListWebViewController { +public class FinancialsPhoneListWebViewBean extends BaseJobsBean implements FinancialsPhoneListWebViewController { /** * Serial number @@ -95,7 +95,7 @@ public class FinancialsPhoneListWebViewBean extends BaseFinancialsBean implement /** * General EJB for phone numbers */ - @EJB (lookup = "java:global/jfinancials-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote") + @EJB (lookup = "java:global/jjobs-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote") private PhoneSessionBeanRemote phoneBean; /** diff --git a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java index 24176e8f..421c5723 100644 --- a/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java +++ b/src/java/org/mxchange/jjobs/beans/phone/list/FinancialsPhoneListWebViewController.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -package org.mxchange.jfinancials.beans.phone.list; +package org.mxchange.jjobs.beans.phone.list; import java.io.Serializable; import java.util.List; diff --git a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java index fb901415..2e750756 100644 --- a/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/JobsAdminUserWebRequestBean.java @@ -27,7 +27,6 @@ import javax.enterprise.inject.Any; import javax.faces.FacesException; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; -import javax.faces.view.facelets.FaceletException; import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcontacts.model.contact.Contact; @@ -36,6 +35,7 @@ import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.contact.JobsAdminContactWebRequestController; import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent; import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; @@ -48,6 +48,7 @@ import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent; import org.mxchange.jusercore.events.user.unlocked.AdminUnlockedUserEvent; import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent; import org.mxchange.jusercore.events.user.update.post.AdminPostUserDataUpdatedEvent; +import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNotFoundException; @@ -64,7 +65,6 @@ import org.mxchange.juserlogincore.container.login.UserLoginContainer; import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent; import org.mxchange.juserlogincore.exceptions.UserPasswordRepeatMismatchException; import org.mxchange.juserlogincore.login.UserLoginUtils; -import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent; /** * A user controller (bean) diff --git a/src/java/org/mxchange/jjobs/beans/user/action/JobsUserActionWebRequestController.java b/src/java/org/mxchange/jjobs/beans/user/action/JobsUserActionWebRequestController.java new file mode 100644 index 00000000..788e7166 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/user/action/JobsUserActionWebRequestController.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016 - 2020 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.user.action; + +import java.io.Serializable; + +/** + * An interface for user beans + *

+ * @author Roland Häder + */ +public interface JobsUserActionWebRequestController extends Serializable { + + /** + * Minimum password length + *

+ * @deprecated Better set as context parameter + */ + @Deprecated + public static final Integer MINIMUM_PASSWORD_LENGTH = 5; + + /** + * Changes logged-in user's personal data if the current password matches + * and TAC + privacy statement has been accepted. + *

+ * @return New target page + */ + String doChangePersonalData (); + +} diff --git a/src/java/org/mxchange/jjobs/beans/user/action/JobssUserActionWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/action/JobssUserActionWebRequestBean.java new file mode 100644 index 00000000..faace205 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/user/action/JobssUserActionWebRequestBean.java @@ -0,0 +1,141 @@ +/* + * Copyright (C) 2016 - 2020 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.user.action; + +import java.text.MessageFormat; +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.enterprise.event.Event; +import javax.enterprise.inject.Any; +import javax.faces.FacesException; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jcontacts.model.contact.Contact; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController; +import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; +import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; +import org.mxchange.jusercore.events.user.update.post.ObservablePostUserPersonalDataUpdatedEvent; +import org.mxchange.jusercore.events.user.update.post.PostUserPersonalDataUpdatedEvent; +import org.mxchange.jusercore.events.user.update.pre.ObservablePreUserPersonalDataUpdatedEvent; +import org.mxchange.jusercore.events.user.update.pre.PreUserPersonalDataUpdatedEvent; +import org.mxchange.jusercore.model.user.User; +import org.mxchange.jusercore.model.user.UserSessionBeanRemote; +import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException; + +/** + * A user action bean (controller) + *

+ * @author Roland Häder + */ +@Named ("userActionController") +@RequestScoped +public class JobssUserActionWebRequestBean extends BaseJobsBean implements JobsUserActionWebRequestController { + + /** + * Serial number + */ + private static final long serialVersionUID = 542_145_347_920L; + + /** + * General contact controller + */ + @Inject + private JobsContactWebRequestController contactController; + + /** + * Features controller + */ + @Inject + private JobsFeaturesWebApplicationController featureController; + + /** + * Event being fired when user updated personal data + */ + @Inject + @Any + private Event postUpdatedPersonalDataEvent; + + /** + * Event being fired when user updated personal data + */ + @Inject + @Any + private Event preUpdatedPersonalDataEvent; + + /** + * Remote user bean + */ + @EJB (lookup = "java:global/jjobs-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote") + private UserSessionBeanRemote userBean; + + /** + * Login controller (bean) + */ + @Inject + private JobsUserLoginWebSessionController userLoginController; + + /** + * Default constructor + */ + public JobssUserActionWebRequestBean () { + // Call super constructor + super(); + } + + @Override + public String doChangePersonalData () { + // This method shall only be called if the user is logged-in + if (!this.userLoginController.isUserLoggedIn()) { + // Not logged-in + throw new IllegalStateException("User is not logged-in"); //NOI18N + } else if (!this.contactController.isRequiredChangePersonalDataSet()) { + // Not all required fields are set + throw new FacesException("Not all required fields are set."); //NOI18N + } else if (!this.userLoginController.ifCurrentPasswordMatches()) { + // Password not matching + throw new FacesException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); + } else if (!this.featureController.isFeatureEnabled("change_user_personal_data")) { //NOI18N + // Editing is not allowed + throw new IllegalStateException("User tried to edit personal data."); //NOI18N + } + + // Get user instance + final User user = this.userLoginController.getLoggedInUser(); + + // Fire pre-update event + this.preUpdatedPersonalDataEvent.fire(new PreUserPersonalDataUpdatedEvent(user)); + + // It should be there, so run some tests on it + assert (user instanceof User) : "Instance userLoginController.loggedInUser is null"; //NOI18N + assert (user.getUserId() instanceof Long) : "Instance userLoginController.loggedInUser.userId is null"; //NOI18N + assert (user.getUserId() > 0) : MessageFormat.format("userLoginController.loggedInUser.userId={0} is invalid", user.getUserId()); //NOI18N + assert (user.getUserContact() instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N + assert (user.getUserContact().getContactId() instanceof Long) : "Instance userLoginController.userContact.contactId is null"; //NOI18N + assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N + + // Send it to the EJB + final User updatedUser = this.userBean.updateUserPersonalData(user); + + // Fire post-update event + this.postUpdatedPersonalDataEvent.fire(new PostUserPersonalDataUpdatedEvent(updatedUser)); + + // All fine + return "user_contact_data_saved"; //NOI18N + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java index 34da8b17..c03ac3ca 100644 --- a/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/confirmlink/JobsConfirmationLinkWebRequestBean.java @@ -29,7 +29,7 @@ import org.mxchange.jcoreee.events.helper.clear.HelperCleanupEvent; import org.mxchange.jcoreee.events.helper.clear.ObservableHelperCleanupEvent; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsBean; -import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jusercore.events.user.created.CreatedUserEvent; import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; import org.mxchange.jusercore.exceptions.UserStatusConfirmedException; diff --git a/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java index 519a869a..89238fcb 100644 --- a/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/email_address/JobsEmailChangeWebRequestBean.java @@ -28,6 +28,7 @@ import org.mxchange.jcontacts.model.contact.Contact; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; +import org.mxchange.jjobs.beans.user.email_address.list.JobsEmailChangeListWebViewController; import org.mxchange.jjobs.beans.user.login.JobsUserLoginWebSessionController; import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; import org.mxchange.jusercore.model.email_address.EmailAddressChange; @@ -69,13 +70,13 @@ public class JobsEmailChangeWebRequestBean extends BaseJobsBean implements JobsE * Controller for listing email address changes */ @Inject - private FinancialsEmailChangeListWebViewController emailChangeListController; + private JobsEmailChangeListWebViewController emailChangeListController; /** * Features controller */ @Inject - private FinancialsFeaturesWebApplicationController featureController; + private JobsFeaturesWebApplicationController featureController; /** * Login controller (bean) diff --git a/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewBean.java b/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewBean.java new file mode 100644 index 00000000..a5691a17 --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewBean.java @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2016 - 2020 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.user.email_address.list; + +import fish.payara.cdi.jsr107.impl.NamedCache; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import javax.annotation.PostConstruct; +import javax.cache.Cache; +import javax.ejb.EJB; +import javax.faces.view.ViewScoped; +import javax.inject.Inject; +import javax.inject.Named; +import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; +import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; +import org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote; + +/** + * A view-scoped bean for listing email address changes + *

+ * @author Roland Häder + */ +@Named ("emailChangeListController") +@ViewScoped +public class JobsEmailChangeListWebViewBean extends BaseJobsBean implements JobsEmailChangeListWebViewController { + + /** + * Serial number + */ + private static final long serialVersionUID = 186_078_724_659_154L; + + /** + * A list of all mobile numbers + */ + private final List allEmailAddressChanges; + + /** + * Remote email change bean + */ + @EJB (lookup = "java:global/jjobs-ejb/userEmailChange!org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote") + private UserEmailChangeSessionBeanRemote emailChangeBean; + + /** + * Features controller + */ + @Inject + private JobsFeaturesWebApplicationController featureController; + + /** + * A list of filtered mobile numbers + */ + private List filteredEmailAddressChanges; + + /** + * Local list of already queued email addresses + */ + @Inject + @NamedCache (cacheName = "queuedEmailCache") + private transient Cache queuedEmailCache; + + /** + * Default constructor + */ + public JobsEmailChangeListWebViewBean () { + // Call super constructor + super(); + + // Initialize list + this.allEmailAddressChanges = new LinkedList<>(); + } + + @Override + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getAllEmailAddressChanges () { + return this.allEmailAddressChanges; + } + + /** + * Getter for filtered email address changed + *

+ * @return Filtered email address changed + */ + @SuppressWarnings ("ReturnOfCollectionOrArrayField") + public List getFilteredEmailAddressChanges () { + return this.filteredEmailAddressChanges; + } + + /** + * Setter for filtered email address changed + *

+ * @param filteredEmailAddressChanges Filtered email address changed + */ + @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter") + public void setFilteredEmailAddressChanges (final List filteredEmailAddressChanges) { + this.filteredEmailAddressChanges = filteredEmailAddressChanges; + } + + /** + * Post-construction + */ + @PostConstruct + public void initializeList () { + // Is cache there? + if (!this.queuedEmailCache.iterator().hasNext()) { + // Add all + for (final ChangeableEmailAddress currentEmailAddress : this.emailChangeBean.fetchAllQueuedAddressChanges()) { + // Add it to cache + this.queuedEmailCache.put(currentEmailAddress.getEmailChangeId(), currentEmailAddress); + } + } + + // Is cache filled and list is empty + if ((this.queuedEmailCache.iterator().hasNext()) && (this.getAllEmailAddressChanges().isEmpty())) { + // Build up list + for (final Cache.Entry currentEntry : this.queuedEmailCache) { + // Add to list + this.getAllEmailAddressChanges().add(currentEntry.getValue()); + } + + // Sort list + this.getAllEmailAddressChanges().sort(new Comparator() { + @Override + public int compare (final ChangeableEmailAddress queuedEmail1, final ChangeableEmailAddress queuedEmail2) { + return queuedEmail1.getEmailChangeId() > queuedEmail2.getEmailChangeId() ? 1 : queuedEmail1.getEmailChangeId() < queuedEmail2.getEmailChangeId() ? -1 : 0; + } + }); + + // Set full list + this.setFilteredEmailAddressChanges(this.getAllEmailAddressChanges()); + } + } + + @Override + public boolean isEmailAddressQueued (final String emailAddress) { + // Check if parameter is valid + 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; + + // Iterate through whole list + for (final ChangeableEmailAddress address : this.getAllEmailAddressChanges()) { + // Does current match? + if (emailAddress.equals(address.getEmailAddress())) { + // Yes, set flag and abort iteration + isFound = true; + break; + } + } + + // Return flag + return isFound; + } + +} diff --git a/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewController.java b/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewController.java new file mode 100644 index 00000000..9c90b24b --- /dev/null +++ b/src/java/org/mxchange/jjobs/beans/user/email_address/list/JobsEmailChangeListWebViewController.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016 - 2020 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.user.email_address.list; + +import java.io.Serializable; +import java.util.List; +import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress; + +/** + * An interface for an email change controller + *

+ * @author Roland Häder + */ +public interface JobsEmailChangeListWebViewController extends Serializable { + + /** + * Returns a list of all email address changes. For performance reasons, the + * controller (bean) should be view-scoped as from user to user nothing + * changes. And the controller's post-construct method should load all + * numbers and cache it in the controller. + *

+ * @return List of all mobile numbers + */ + List getAllEmailAddressChanges (); + + /** + * Checks if given email address has already been queued. First a local list + * is being checked, if not found, the EJB is called. Only if found, the + * result is "cached" in the list. + *

+ * @param emailAddress Email address to verify + *

+ * @return Whether the email address in field emailAddress is already queued + */ + boolean isEmailAddressQueued (final String emailAddress); + +} diff --git a/src/java/org/mxchange/jjobs/beans/user/login/JobsUserLoginWebSessionBean.java b/src/java/org/mxchange/jjobs/beans/user/login/JobsUserLoginWebSessionBean.java index 09aae448..b088ae80 100644 --- a/src/java/org/mxchange/jjobs/beans/user/login/JobsUserLoginWebSessionBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/login/JobsUserLoginWebSessionBean.java @@ -31,9 +31,10 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; -import org.mxchange.jusercore.exceptions.UserNotFoundException; -import org.mxchange.jusercore.exceptions.UserStatusLockedException; -import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; +import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent; +import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent; +import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent; import org.mxchange.jusercore.model.user.User; import org.mxchange.jusercore.model.user.password_history.PasswordHistory; import org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote; @@ -104,7 +105,7 @@ public class JobsUserLoginWebSessionBean extends BaseJobsBean implements JobsUse * Administrative user-list controller */ @Inject - private FinancialsUserListWebViewController userListController; + private JobsUserListWebViewController userListController; /** * Flag whether the user has logged-in, set only from inside diff --git a/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebRequestBean.java index fa9db991..114e0ec7 100644 --- a/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/register/JobsUserRegisterWebRequestBean.java @@ -32,11 +32,9 @@ import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsBean; import org.mxchange.jjobs.beans.contact.JobsContactWebRequestController; import org.mxchange.jjobs.beans.features.JobsFeaturesWebApplicationController; +import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; -import org.mxchange.jusercore.events.user.clear.password.ClearUserPasswordEvent; -import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent; -import org.mxchange.jusercore.events.user.clear.username.ClearUserNameEvent; -import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent; +import org.mxchange.jjobs.beans.user.list.JobsUserListWebViewController; import org.mxchange.jusercore.exceptions.DataRepeatMismatchException; import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException; import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException; @@ -84,7 +82,7 @@ public class JobsUserRegisterWebRequestBean extends BaseJobsBean implements Jobs * Localization controller */ @Inject - private FinancialsLocalizationSessionController localizationController; + private JobsLocalizationSessionController localizationController; /** * Remote register session-scoped bean @@ -96,7 +94,7 @@ public class JobsUserRegisterWebRequestBean extends BaseJobsBean implements Jobs * User list controller */ @Inject - private FinancialsUserListWebViewController userListController; + private JobsUserListWebViewController userListController; /** * User name @@ -328,7 +326,7 @@ public class JobsUserRegisterWebRequestBean extends BaseJobsBean implements Jobs return ""; //NOI18N } else if (this.ifBothPasswordsEmptyAllowed()) { // Both passwords are left empty and is allowed, then generate a random password - final String randomPassword = UserLoginUtils.createRandomPassword(FinancialsUserWebRequestController.MINIMUM_PASSWORD_LENGTH); + final String randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebRequestController.MINIMUM_PASSWORD_LENGTH); // Generate (ignored) password-history final PasswordHistory passwordHistory = new UserPasswordHistory(randomPassword, user); @@ -492,7 +490,7 @@ public class JobsUserRegisterWebRequestBean extends BaseJobsBean implements Jobs this.setUserProfileMode(ProfileMode.INVISIBLE); // Generate random password - final String randomPassword = UserLoginUtils.createRandomPassword(FinancialsUserWebRequestController.MINIMUM_PASSWORD_LENGTH); + final String randomPassword = UserLoginUtils.createRandomPassword(JobsUserWebRequestController.MINIMUM_PASSWORD_LENGTH); // Set random password this.setUserPassword(randomPassword); diff --git a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java index cb8626ec..0d8a6707 100644 --- a/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java +++ b/src/java/org/mxchange/jjobs/beans/user/resendlink/JobsResendLinkWebRequestBean.java @@ -25,6 +25,7 @@ import javax.inject.Inject; import javax.inject.Named; import org.mxchange.jcoreee.utils.FacesUtils; import org.mxchange.jjobs.beans.BaseJobsBean; +import org.mxchange.jjobs.beans.localization.JobsLocalizationSessionController; import org.mxchange.jjobs.beans.user.JobsUserWebRequestController; import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException; import org.mxchange.jusercore.exceptions.UserNotFoundException; 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 index 590cd203..19fdaa21 100644 --- a/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsEmployeeConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/company_employee/JobsEmployeeConverter.java @@ -24,8 +24,8 @@ 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; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewBean; +import org.mxchange.jjobs.beans.business.employee.list.JobsEmployeeListWebViewController; /** * Converter for converting company employee to and from id number @@ -38,7 +38,7 @@ public class JobsEmployeeConverter implements Converter { /** * Employable EJB */ - private static FinancialsEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER; + private static JobsEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER; @Override public Employable getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { @@ -58,7 +58,7 @@ public class JobsEmployeeConverter implements Converter { // Is the instance there? if (null == EMPLOYEE_LIST_CONTROLLER) { // Get bean from CDI directly - EMPLOYEE_LIST_CONTROLLER = CDI.current().select(FinancialsEmployeeListWebViewBean.class).get(); + EMPLOYEE_LIST_CONTROLLER = CDI.current().select(JobsEmployeeListWebViewBean.class).get(); } // Try to get user instance from it diff --git a/src/java/org/mxchange/jjobs/converter/business/opening_time/JobsCompanyOpeningTimeConverter.java b/src/java/org/mxchange/jjobs/converter/business/opening_time/JobsCompanyOpeningTimeConverter.java index 26e6db1b..2d0a0c32 100644 --- a/src/java/org/mxchange/jjobs/converter/business/opening_time/JobsCompanyOpeningTimeConverter.java +++ b/src/java/org/mxchange/jjobs/converter/business/opening_time/JobsCompanyOpeningTimeConverter.java @@ -24,8 +24,8 @@ import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException; import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime; -import org.mxchange.jjobs.beans.business.opening_time.JobsOpeningTimeWebRequestBean; -import org.mxchange.jjobs.beans.business.opening_time.JobsOpeningTimeWebRequestController; +import org.mxchange.jjobs.beans.business.opening_time.list.JobsOpeningTimeListWebViewBean; +import org.mxchange.jjobs.beans.business.opening_time.list.JobsOpeningTimeListWebViewController; /** * Converter for opening time id <-> instance @@ -38,7 +38,7 @@ public class JobsCompanyOpeningTimeConverter implements Converter { /** * Opening time backing bean */ - private static JobsOpeningTimeWebRequestController OPENING_TIMES_LIST_CONTROLLER; + private static JobsOpeningTimeListWebViewController OPENING_TIMES_LIST_CONTROLLER; @Override public OpeningTime getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { @@ -59,13 +59,13 @@ public class JobsCompanyOpeningTimeConverter implements Converter { final Long openingTimeId = Long.valueOf(submittedValue); // Is the instance there? - if (null == OPENING_TIME_LIST_CONTROLLER) { + if (null == OPENING_TIMES_LIST_CONTROLLER) { // Get bean from CDI directly - OPENING_TIME_LIST_CONTROLLER = CDI.current().select(FinancialsOpeningTimeListWebViewBean.class).get(); + OPENING_TIMES_LIST_CONTROLLER = CDI.current().select(JobsOpeningTimeListWebViewBean.class).get(); } // Try to get user instance from it - openingTime = OPENING_TIME_LIST_CONTROLLER.findOpeningTimeById(openingTimeId); + openingTime = OPENING_TIMES_LIST_CONTROLLER.findOpeningTimeById(openingTimeId); } catch (final NumberFormatException ex) { // Throw again throw new ConverterException(ex); diff --git a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java index b2e43c39..c5f3f1b9 100644 --- a/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/fax/JobsFaxNumberConverter.java @@ -22,8 +22,6 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestBean; -import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestController; import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber; @@ -38,7 +36,7 @@ public class JobsFaxNumberConverter implements Converter { /** * Phone EJB */ - private static JobsPhoneWebRequestController PHONE_LIST_CONTROLLER; + private static JobsPhoneListWebViewController PHONE_LIST_CONTROLLER; @Override public DialableFaxNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { @@ -58,7 +56,7 @@ public class JobsFaxNumberConverter implements Converter { // Is the instance there? if (null == PHONE_LIST_CONTROLLER) { // Get bean from CDI directly - PHONE_LIST_CONTROLLER = CDI.current().select(FinancialsPhoneListWebViewBean.class).get(); + PHONE_LIST_CONTROLLER = CDI.current().select(JobsPhoneListWebViewBean.class).get(); } // Try to get mobile instance from it diff --git a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java index 73ad9e16..2a64a37a 100644 --- a/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java +++ b/src/java/org/mxchange/jjobs/converter/landline/JobsLandLineNumberConverter.java @@ -22,8 +22,6 @@ import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; import javax.faces.convert.FacesConverter; -import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestBean; -import org.mxchange.jjobs.beans.phone.JobsPhoneWebRequestController; import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException; import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber; @@ -38,7 +36,7 @@ public class JobsLandLineNumberConverter implements Converter { /** * Mobile provider backing bean */ - private static JobsMobileProviderWebRequestController MOBILE_PROVIDER_LIST_CONTROLLER; + private static JobsMobileProviderListWebViewController MOBILE_PROVIDER_LIST_CONTROLLER; @Override public MobileProvider getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) { @@ -59,7 +57,7 @@ public class JobsMobileProviderConverter implements Converter { // Is the instance there? if (null == MOBILE_PROVIDER_LIST_CONTROLLER) { // Get bean from CDI directly - MOBILE_PROVIDER_LIST_CONTROLLER = CDI.current().select(FinancialsMobileProviderListWebViewBean.class).get(); + MOBILE_PROVIDER_LIST_CONTROLLER = CDI.current().select(JobsMobileProviderListWebViewBean.class).get(); } // Lookup of mobile provider diff --git a/src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java b/src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java deleted file mode 100644 index 5b4df983..00000000 --- a/src/java/org/mxchange/jjobs/validator/addressbook/JobsAddressbookIdValidator.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2016 - 2020 Free Software Foundation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jjobs.validator.addressbook; - -import java.text.MessageFormat; -import javax.faces.application.FacesMessage; -import javax.faces.component.UIComponent; -import javax.faces.context.FacesContext; -import javax.faces.validator.FacesValidator; -import javax.faces.validator.ValidatorException; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import org.mxchange.addressbook.model.addressbook.AddressbookSessionBeanRemote; -import org.mxchange.jaddressbook.exceptions.AddressbookNotFoundException; -import org.mxchange.jaddressbook.model.addressbook.Addressbook; -import org.mxchange.jcoreee.validator.number.BaseNumberValidator; -import org.mxchange.jcoreeelogger.beans.local.logger.Log; -import org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal; - -/** - * A validator for address book id verification - *

- * @author Roland Häder - */ -@FacesValidator ("AddressbookIdValidator") -public class JobsAddressbookIdValidator extends BaseNumberValidator { - - /** - * Serial number - */ - private static final long serialVersionUID = 158_768_467_186_951_809L; - - /** - * Remote bean - */ - private AddressbookSessionBeanRemote addressbookBean; - - /** - * Logger instance - */ - @Log - private LoggerBeanLocal loggerBeanLocal; - - /** - * Public consutructor - */ - public JobsAddressbookIdValidator () { - // Try to get it - try { - // Get initial context - Context context = new InitialContext(); - - // Lookup logger - this.loggerBeanLocal = (LoggerBeanLocal) context.lookup("java:global/jcore-logger-ejb/logger!org.mxchange.jcoreeelogger.beans.local.logger.LoggerBeanLocal"); //NOI18N - - // ... and user controller - this.addressbookBean = (AddressbookSessionBeanRemote) context.lookup("java:global/jjobs-ejb/jjobs-adr!org.mxchange.jjobs.model.addressbook.JobsAddressbookSessionBeanRemote"); //NOI18N - } catch (final NamingException ex) { - // Continue to throw it - throw new RuntimeException(MessageFormat.format("context.lookup() failed: {0}", ex.getMessage()), ex); //NOI18N - } - } - - @Override - public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException { - // Trace message - this.loggerBeanLocal.logTrace(MessageFormat.format("validate: context={0},component={1},value={2} - CALLED!", context, component, value)); //NOI18N - - // All accepted, required fields - String[] requiredFields = {"addressbookId"}; //NOI18N - - // Pre-validation (example: not null, not a string, empty string ...) - super.preValidate(context, component, value, requiredFields, false); - - // Cast to long - Long addressbookId = (Long) value; - - // Is the address book id valid? - if (!this.addressbookBean.isAddressbookIdUsed(addressbookId)) { - // Is not valid - throw new ValidatorException(new FacesMessage(MessageFormat.format("No address book found with id {0}. Please check your link.", addressbookId))); //NOI18N - } - - // Init variable - Addressbook addressbook; - - // Try it - try { - // Get full data - addressbook = this.addressbookBean.getAddressbookById(addressbookId); - - // Is it set? - if (null == addressbook) { - // Is null?! - throw new NullPointerException(MessageFormat.format("addressbook for id={0} is null", addressbookId)); //NOI18N - } - } catch (final AddressbookNotFoundException ex) { - // Continue to throw - throw new ValidatorException(new FacesMessage(MessageFormat.format("Cannot find address book with id {0}", addressbookId)), ex); //NOI18N - } - - // Trace message - this.loggerBeanLocal.logTrace("validate: EXIT!"); //NOI18N - } -}