2 * Copyright (C) 2016 - 2020 Free Software Foundation
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jfinancials.beans.user.email_address.list;
19 import fish.payara.cdi.jsr107.impl.NamedCache;
20 import java.util.Comparator;
21 import java.util.LinkedList;
22 import java.util.List;
23 import javax.annotation.PostConstruct;
24 import javax.cache.Cache;
26 import javax.faces.view.ViewScoped;
27 import javax.inject.Inject;
28 import javax.inject.Named;
29 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
30 import org.mxchange.jfinancials.beans.features.FinancialsFeaturesWebApplicationController;
31 import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
32 import org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote;
35 * A view-scoped bean for listing email address changes
37 * @author Roland Häder<roland@mxchange.org>
39 @Named ("emailChangeListController")
41 public class FinancialsEmailChangeListWebViewBean extends BaseFinancialsBean implements FinancialsEmailChangeListWebViewController {
46 private static final long serialVersionUID = 186_078_724_659_154L;
49 * A list of all mobile numbers
51 private final List<ChangeableEmailAddress> allEmailAddressChanges;
54 * Remote email change bean
56 @EJB (lookup = "java:global/jfinancials-ejb/userEmailChange!org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote")
57 private UserEmailChangeSessionBeanRemote emailChangeBean;
63 private FinancialsFeaturesWebApplicationController featureController;
66 * A list of filtered mobile numbers
68 private List<ChangeableEmailAddress> filteredEmailAddressChanges;
71 * Local list of already queued email addresses
74 @NamedCache (cacheName = "queuedEmailCache")
75 private transient Cache<Long, ChangeableEmailAddress> queuedEmailCache;
80 public FinancialsEmailChangeListWebViewBean () {
81 // Call super constructor
85 this.allEmailAddressChanges = new LinkedList<>();
89 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
90 public List<ChangeableEmailAddress> getAllEmailAddressChanges () {
91 return this.allEmailAddressChanges;
95 * Getter for filtered email address changed
97 * @return Filtered email address changed
99 @SuppressWarnings ("ReturnOfCollectionOrArrayField")
100 public List<ChangeableEmailAddress> getFilteredEmailAddressChanges () {
101 return this.filteredEmailAddressChanges;
105 * Setter for filtered email address changed
107 * @param filteredEmailAddressChanges Filtered email address changed
109 @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
110 public void setFilteredEmailAddressChanges (final List<ChangeableEmailAddress> filteredEmailAddressChanges) {
111 this.filteredEmailAddressChanges = filteredEmailAddressChanges;
118 public void initializeList () {
120 if (!this.queuedEmailCache.iterator().hasNext()) {
122 for (final ChangeableEmailAddress currentEmailAddress : this.emailChangeBean.fetchAllQueuedAddressChanges()) {
124 this.queuedEmailCache.put(currentEmailAddress.getEmailChangeId(), currentEmailAddress);
128 // Is cache filled and list is empty
129 if ((this.queuedEmailCache.iterator().hasNext()) && (this.getAllEmailAddressChanges().isEmpty())) {
131 for (final Cache.Entry<Long, ChangeableEmailAddress> currentEntry : this.queuedEmailCache) {
133 this.getAllEmailAddressChanges().add(currentEntry.getValue());
137 this.getAllEmailAddressChanges().sort(new Comparator<ChangeableEmailAddress>() {
139 public int compare (final ChangeableEmailAddress queuedEmail1, final ChangeableEmailAddress queuedEmail2) {
140 return queuedEmail1.getEmailChangeId() > queuedEmail2.getEmailChangeId() ? 1 : queuedEmail1.getEmailChangeId() < queuedEmail2.getEmailChangeId() ? -1 : 0;
145 this.setFilteredEmailAddressChanges(this.getAllEmailAddressChanges());
150 public boolean isEmailAddressQueued (final String emailAddress) {
151 // Check if parameter is valid
152 if (null == emailAddress) {
154 throw new NullPointerException("emailAddress is null"); //NOI18N
155 } else if (emailAddress.isEmpty()) {
157 throw new IllegalArgumentException("emailAddress is empty."); //NOI18N
160 // Default is not found
161 boolean isFound = false;
163 // Iterate through whole list
164 for (final ChangeableEmailAddress address : this.getAllEmailAddressChanges()) {
165 // Does current match?
166 if (emailAddress.equals(address.getEmailAddress())) {
167 // Yes, set flag and abort iteration