libs.apache_poi.classpath=\
- ${base}/poi/poi-3.15.jar:\
- ${base}/poi/poi-ooxml-3.15.jar
-libs.apache_poi.displayName=Apache POI 3.15
+ ${base}/poi/poi-4.1.1.jar:\
+ ${base}/poi/poi-ooxml-4.1.1.jar
+libs.apache_poi.displayName=Apache POI 4.1.1
libs.apache_poi.javadoc=\
https://poi.apache.org/apidocs/
libs.cache.classpath=\
+++ /dev/null
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
-
-APACHE POI SUBCOMPONENTS:
-
-Apache POI includes subcomponents with separate copyright notices and
-license terms. Your use of these subcomponents is subject to the terms
-and conditions of the following licenses:
-
-
-Office Open XML schemas (ooxml-schemas-1.*.jar)
-
- The Office Open XML schema definitions used by Apache POI are
- a part of the Office Open XML ECMA Specification (ECMA-376, [1]).
- As defined in section 9.4 of the ECMA bylaws [2], this specification
- is available to all interested parties without restriction:
-
- 9.4 All documents when approved shall be made available to
- all interested parties without restriction.
-
- Furthermore, both Microsoft and Adobe have granted patent licenses
- to this work [3,4,5].
-
- [1] http://www.ecma-international.org/publications/standards/Ecma-376.htm
- [2] http://www.ecma-international.org/memento/Ecmabylaws.htm
- [3] http://www.microsoft.com/openspecifications/en/us/programs/osp/default.aspx
- [4] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
- Patent%20statements%20ok/ECMA-376%20Edition%202%20Microsoft%20Patent%20Declaration.pdf
- [5] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
- Patent%20statements%20ok/ECMA-376%20Adobe%20Patent%20Declaration.pdf
-
-
-Bouncy Castle library (bcprov-*.jar, bcpg-*.jar, bcpkix-*.jar)
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to
- deal in the Software without restriction, including without limitation the
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- sell copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- IN THE SOFTWARE.
-
-JUnit test library (junit-4.*.jar) & JaCoCo (*jacoco*)
-
- Eclipse Public License - v 1.0
-
- THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
- LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
- CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
-
- 1. DEFINITIONS
-
- "Contribution" means:
-
- a) in the case of the initial Contributor, the initial code and documentation
- distributed under this Agreement, and
- b) in the case of each subsequent Contributor:
- i) changes to the Program, and
- ii) additions to the Program;
- where such changes and/or additions to the Program originate from and are
- distributed by that particular Contributor. A Contribution 'originates' from
- a Contributor if it was added to the Program by such Contributor itself or
- anyone acting on such Contributor's behalf. Contributions do not include
- additions to the Program which: (i) are separate modules of software
- distributed in conjunction with the Program under their own license agreement,
- and (ii) are not derivative works of the Program.
-
- "Contributor" means any person or entity that distributes the Program.
-
- "Licensed Patents" mean patent claims licensable by a Contributor which are
- necessarily infringed by the use or sale of its Contribution alone or when
- combined with the Program.
-
- "Program" means the Contributions distributed in accordance with this Agreement.
-
- "Recipient" means anyone who receives the Program under this Agreement,
- including all Contributors.
-
- 2. GRANT OF RIGHTS
-
- a) Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free copyright license to
- reproduce, prepare derivative works of, publicly display, publicly
- perform, distribute and sublicense the Contribution of such Contributor,
- if any, and such derivative works, in source code and object code form.
- b) Subject to the terms of this Agreement, each Contributor hereby grants
- Recipient a non-exclusive, worldwide, royalty-free patent license under
- Licensed Patents to make, use, sell, offer to sell, import and otherwise
- transfer the Contribution of such Contributor, if any, in source code
- and object code form. This patent license shall apply to the combination
- of the Contribution and the Program if, at the time the Contribution is
- added by the Contributor, such addition of the Contribution causes such
- combination to be covered by the Licensed Patents. The patent license
- shall not apply to any other combinations which include the Contribution.
- No hardware per se is licensed hereunder.
- c) Recipient understands that although each Contributor grants the licenses
- to its Contributions set forth herein, no assurances are provided by any
- Contributor that the Program does not infringe the patent or other
- intellectual property rights of any other entity. Each Contributor
- disclaims any liability to Recipient for claims brought by any other
- entity based on infringement of intellectual property rights or
- otherwise. As a condition to exercising the rights and licenses granted
- hereunder, each Recipient hereby assumes sole responsibility to secure
- any other intellectual property rights needed, if any. For example, if
- a third party patent license is required to allow Recipient to distribute
- the Program, it is Recipient's responsibility to acquire that license
- before distributing the Program.
- d) Each Contributor represents that to its knowledge it has sufficient
- copyright rights in its Contribution, if any, to grant the copyright
- license set forth in this Agreement.
-
- 3. REQUIREMENTS
-
- A Contributor may choose to distribute the Program in object code form under
- its own license agreement, provided that:
-
- a) it complies with the terms and conditions of this Agreement; and
- b) its license agreement:
- i) effectively disclaims on behalf of all Contributors all warranties and
- conditions, express and implied, including warranties or conditions of
- title and non-infringement, and implied warranties or conditions of
- merchantability and fitness for a particular purpose;
- ii) effectively excludes on behalf of all Contributors all liability for
- damages, including direct, indirect, special, incidental and
- consequential damages, such as lost profits;
- iii) states that any provisions which differ from this Agreement are
- offered by that Contributor alone and not by any other party; and
- iv) states that source code for the Program is available from such
- Contributor, and informs licensees how to obtain it in a reasonable
- manner on or through a medium customarily used for software exchange.
-
- When the Program is made available in source code form:
-
- a) it must be made available under this Agreement; and
- b) a copy of this Agreement must be included with each copy of the Program.
- Contributors may not remove or alter any copyright notices contained
- within the Program.
-
- Each Contributor must identify itself as the originator of its Contribution,
- if any, in a manner that reasonably allows subsequent Recipients to identify
- the originator of the Contribution.
-
- 4. COMMERCIAL DISTRIBUTION
-
- Commercial distributors of software may accept certain responsibilities with
- respect to end users, business partners and the like. While this license is
- intended to facilitate the commercial use of the Program, the Contributor
- who includes the Program in a commercial product offering should do so in a
- manner which does not create potential liability for other Contributors.
- Therefore, if a Contributor includes the Program in a commercial product
- offering, such Contributor ("Commercial Contributor") hereby agrees to
- defend and indemnify every other Contributor ("Indemnified Contributor")
- against any losses, damages and costs (collectively "Losses") arising from
- claims, lawsuits and other legal actions brought by a third party against
- the Indemnified Contributor to the extent caused by the acts or omissions
- of such Commercial Contributor in connection with its distribution of the
- Program in a commercial product offering. The obligations in this section
- do not apply to any claims or Losses relating to any actual or alleged
- intellectual property infringement. In order to qualify, an Indemnified
- Contributor must: a) promptly notify the Commercial Contributor in writing
- of such claim, and b) allow the Commercial Contributor to control, and
- cooperate with the Commercial Contributor in, the defense and any related
- settlement negotiations. The Indemnified Contributor may participate in any
- such claim at its own expense.
-
- For example, a Contributor might include the Program in a commercial product
- offering, Product X. That Contributor is then a Commercial Contributor. If
- that Commercial Contributor then makes performance claims, or offers
- warranties related to Product X, those performance claims and warranties are
- such Commercial Contributor's responsibility alone. Under this section, the
- Commercial Contributor would have to defend claims against the other
- Contributors related to those performance claims and warranties, and if a
- court requires any other Contributor to pay any damages as a result, the
- Commercial Contributor must pay those damages.
-
- 5. NO WARRANTY
-
- EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
- AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
- EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
- CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
- PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
- appropriateness of using and distributing the Program and assumes all risks
- associated with its exercise of rights under this Agreement , including but
- not limited to the risks and costs of program errors, compliance with
- applicable laws, damage to or loss of data, programs or equipment, and
- unavailability or interruption of operations.
-
- 6. DISCLAIMER OF LIABILITY
-
- EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
- CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
- LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
- EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
- OF SUCH DAMAGES.
-
- 7. GENERAL
-
- If any provision of this Agreement is invalid or unenforceable under
- applicable law, it shall not affect the validity or enforceability of the
- remainder of the terms of this Agreement, and without further action by the
- parties hereto, such provision shall be reformed to the minimum extent
- necessary to make such provision valid and enforceable.
-
- If Recipient institutes patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Program itself
- (excluding combinations of the Program with other software or hardware)
- infringes such Recipient's patent(s), then such Recipient's rights granted
- under Section 2(b) shall terminate as of the date such litigation is filed.
-
- All Recipient's rights under this Agreement shall terminate if it fails to
- comply with any of the material terms or conditions of this Agreement and
- does not cure such failure in a reasonable period of time after becoming
- aware of such noncompliance. If all Recipient's rights under this Agreement
- terminate, Recipient agrees to cease use and distribution of the Program as
- soon as reasonably practicable. However, Recipient's obligations under this
- Agreement and any licenses granted by Recipient relating to the Program
- shall continue and survive.
-
- Everyone is permitted to copy and distribute copies of this Agreement, but
- in order to avoid inconsistency the Agreement is copyrighted and may only
- be modified in the following manner. The Agreement Steward reserves the
- right to publish new versions (including revisions) of this Agreement from
- time to time. No one other than the Agreement Steward has the right to
- modify this Agreement. The Eclipse Foundation is the initial Agreement
- Steward. The Eclipse Foundation may assign the responsibility to serve as
- the Agreement Steward to a suitable separate entity. Each new version of
- the Agreement will be given a distinguishing version number. The Program
- (including Contributions) may always be distributed subject to the version
- of the Agreement under which it was received. In addition, after a new
- version of the Agreement is published, Contributor may elect to distribute
- the Program (including its Contributions) under the new version. Except as
- expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
- rights or licenses to the intellectual property of any Contributor under
- this Agreement, whether expressly, by implication, estoppel or otherwise.
- All rights in the Program not expressly granted under this Agreement are
- reserved.
-
- This Agreement is governed by the laws of the State of New York and the
- intellectual property laws of the United States of America. No party to this
- Agreement will bring a legal action under this Agreement more than one year
- after the cause of action arose. Each party waives its rights to a jury
- trial in any resulting litigation.
-
-Hamcrest library (hamcrest-*.jar) & CuvesAPI / Curve API
-
- BSD License
-
- Copyright (c) 2000-2006, www.hamcrest.org
- All rights reserved.
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions are met:
-
- Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer. Redistributions in binary
- form must reproduce the above copyright notice, this list of conditions and
- the following disclaimer in the documentation and/or other materials
- provided with the distribution.
-
- Neither the name of Hamcrest nor the names of its contributors may be used
- to endorse or promote products derived from this software without specific
- prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- POSSIBILITY OF SUCH DAMAGE.
-
-SLF4J library (slf4j-api-*.jar)
-
- Copyright (c) 2004-2013 QOS.ch
- All rights reserved.
-
- Permission is hereby granted, free of charge, to any person obtaining
- a copy of this software and associated documentation files (the
- "Software"), to deal in the Software without restriction, including
- without limitation the rights to use, copy, modify, merge, publish,
- distribute, sublicense, and/or sell copies of the Software, and to
- permit persons to whom the Software is furnished to do so, subject to
- the following conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
--- /dev/null
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+APACHE POI SUBCOMPONENTS:
+
+Apache POI includes subcomponents with separate copyright notices and
+license terms. Your use of these subcomponents is subject to the terms
+and conditions of the following licenses:
+
+
+Office Open XML schemas (ooxml-schemas-1.*.jar)
+
+ The Office Open XML schema definitions used by Apache POI are
+ a part of the Office Open XML ECMA Specification (ECMA-376, [1]).
+ As defined in section 9.4 of the ECMA bylaws [2], this specification
+ is available to all interested parties without restriction:
+
+ 9.4 All documents when approved shall be made available to
+ all interested parties without restriction.
+
+ Furthermore, both Microsoft and Adobe have granted patent licenses
+ to this work [3,4,5].
+
+ [1] http://www.ecma-international.org/publications/standards/Ecma-376.htm
+ [2] http://www.ecma-international.org/memento/Ecmabylaws.htm
+ [3] http://www.microsoft.com/openspecifications/en/us/programs/osp/default.aspx
+ [4] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
+ Patent%20statements%20ok/ECMA-376%20Edition%202%20Microsoft%20Patent%20Declaration.pdf
+ [5] http://www.ecma-international.org/publications/files/ECMA-ST/Ecma%20PATENT/
+ Patent%20statements%20ok/ECMA-376%20Adobe%20Patent%20Declaration.pdf
+
+
+Bouncy Castle library (bcprov-*.jar, bcpg-*.jar, bcpkix-*.jar)
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to
+ deal in the Software without restriction, including without limitation the
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ sell copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in
+ all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ IN THE SOFTWARE.
+
+JUnit test library (junit-4.*.jar) & JaCoCo (*jacoco*)
+
+ Eclipse Public License - v 1.0
+
+ THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
+ LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM
+ CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
+
+ 1. DEFINITIONS
+
+ "Contribution" means:
+
+ a) in the case of the initial Contributor, the initial code and documentation
+ distributed under this Agreement, and
+ b) in the case of each subsequent Contributor:
+ i) changes to the Program, and
+ ii) additions to the Program;
+ where such changes and/or additions to the Program originate from and are
+ distributed by that particular Contributor. A Contribution 'originates' from
+ a Contributor if it was added to the Program by such Contributor itself or
+ anyone acting on such Contributor's behalf. Contributions do not include
+ additions to the Program which: (i) are separate modules of software
+ distributed in conjunction with the Program under their own license agreement,
+ and (ii) are not derivative works of the Program.
+
+ "Contributor" means any person or entity that distributes the Program.
+
+ "Licensed Patents" mean patent claims licensable by a Contributor which are
+ necessarily infringed by the use or sale of its Contribution alone or when
+ combined with the Program.
+
+ "Program" means the Contributions distributed in accordance with this Agreement.
+
+ "Recipient" means anyone who receives the Program under this Agreement,
+ including all Contributors.
+
+ 2. GRANT OF RIGHTS
+
+ a) Subject to the terms of this Agreement, each Contributor hereby grants
+ Recipient a non-exclusive, worldwide, royalty-free copyright license to
+ reproduce, prepare derivative works of, publicly display, publicly
+ perform, distribute and sublicense the Contribution of such Contributor,
+ if any, and such derivative works, in source code and object code form.
+ b) Subject to the terms of this Agreement, each Contributor hereby grants
+ Recipient a non-exclusive, worldwide, royalty-free patent license under
+ Licensed Patents to make, use, sell, offer to sell, import and otherwise
+ transfer the Contribution of such Contributor, if any, in source code
+ and object code form. This patent license shall apply to the combination
+ of the Contribution and the Program if, at the time the Contribution is
+ added by the Contributor, such addition of the Contribution causes such
+ combination to be covered by the Licensed Patents. The patent license
+ shall not apply to any other combinations which include the Contribution.
+ No hardware per se is licensed hereunder.
+ c) Recipient understands that although each Contributor grants the licenses
+ to its Contributions set forth herein, no assurances are provided by any
+ Contributor that the Program does not infringe the patent or other
+ intellectual property rights of any other entity. Each Contributor
+ disclaims any liability to Recipient for claims brought by any other
+ entity based on infringement of intellectual property rights or
+ otherwise. As a condition to exercising the rights and licenses granted
+ hereunder, each Recipient hereby assumes sole responsibility to secure
+ any other intellectual property rights needed, if any. For example, if
+ a third party patent license is required to allow Recipient to distribute
+ the Program, it is Recipient's responsibility to acquire that license
+ before distributing the Program.
+ d) Each Contributor represents that to its knowledge it has sufficient
+ copyright rights in its Contribution, if any, to grant the copyright
+ license set forth in this Agreement.
+
+ 3. REQUIREMENTS
+
+ A Contributor may choose to distribute the Program in object code form under
+ its own license agreement, provided that:
+
+ a) it complies with the terms and conditions of this Agreement; and
+ b) its license agreement:
+ i) effectively disclaims on behalf of all Contributors all warranties and
+ conditions, express and implied, including warranties or conditions of
+ title and non-infringement, and implied warranties or conditions of
+ merchantability and fitness for a particular purpose;
+ ii) effectively excludes on behalf of all Contributors all liability for
+ damages, including direct, indirect, special, incidental and
+ consequential damages, such as lost profits;
+ iii) states that any provisions which differ from this Agreement are
+ offered by that Contributor alone and not by any other party; and
+ iv) states that source code for the Program is available from such
+ Contributor, and informs licensees how to obtain it in a reasonable
+ manner on or through a medium customarily used for software exchange.
+
+ When the Program is made available in source code form:
+
+ a) it must be made available under this Agreement; and
+ b) a copy of this Agreement must be included with each copy of the Program.
+ Contributors may not remove or alter any copyright notices contained
+ within the Program.
+
+ Each Contributor must identify itself as the originator of its Contribution,
+ if any, in a manner that reasonably allows subsequent Recipients to identify
+ the originator of the Contribution.
+
+ 4. COMMERCIAL DISTRIBUTION
+
+ Commercial distributors of software may accept certain responsibilities with
+ respect to end users, business partners and the like. While this license is
+ intended to facilitate the commercial use of the Program, the Contributor
+ who includes the Program in a commercial product offering should do so in a
+ manner which does not create potential liability for other Contributors.
+ Therefore, if a Contributor includes the Program in a commercial product
+ offering, such Contributor ("Commercial Contributor") hereby agrees to
+ defend and indemnify every other Contributor ("Indemnified Contributor")
+ against any losses, damages and costs (collectively "Losses") arising from
+ claims, lawsuits and other legal actions brought by a third party against
+ the Indemnified Contributor to the extent caused by the acts or omissions
+ of such Commercial Contributor in connection with its distribution of the
+ Program in a commercial product offering. The obligations in this section
+ do not apply to any claims or Losses relating to any actual or alleged
+ intellectual property infringement. In order to qualify, an Indemnified
+ Contributor must: a) promptly notify the Commercial Contributor in writing
+ of such claim, and b) allow the Commercial Contributor to control, and
+ cooperate with the Commercial Contributor in, the defense and any related
+ settlement negotiations. The Indemnified Contributor may participate in any
+ such claim at its own expense.
+
+ For example, a Contributor might include the Program in a commercial product
+ offering, Product X. That Contributor is then a Commercial Contributor. If
+ that Commercial Contributor then makes performance claims, or offers
+ warranties related to Product X, those performance claims and warranties are
+ such Commercial Contributor's responsibility alone. Under this section, the
+ Commercial Contributor would have to defend claims against the other
+ Contributors related to those performance claims and warranties, and if a
+ court requires any other Contributor to pay any damages as a result, the
+ Commercial Contributor must pay those damages.
+
+ 5. NO WARRANTY
+
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON
+ AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER
+ EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
+ CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A
+ PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the
+ appropriateness of using and distributing the Program and assumes all risks
+ associated with its exercise of rights under this Agreement , including but
+ not limited to the risks and costs of program errors, compliance with
+ applicable laws, damage to or loss of data, programs or equipment, and
+ unavailability or interruption of operations.
+
+ 6. DISCLAIMER OF LIABILITY
+
+ EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY
+ CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
+ LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE
+ EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY
+ OF SUCH DAMAGES.
+
+ 7. GENERAL
+
+ If any provision of this Agreement is invalid or unenforceable under
+ applicable law, it shall not affect the validity or enforceability of the
+ remainder of the terms of this Agreement, and without further action by the
+ parties hereto, such provision shall be reformed to the minimum extent
+ necessary to make such provision valid and enforceable.
+
+ If Recipient institutes patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Program itself
+ (excluding combinations of the Program with other software or hardware)
+ infringes such Recipient's patent(s), then such Recipient's rights granted
+ under Section 2(b) shall terminate as of the date such litigation is filed.
+
+ All Recipient's rights under this Agreement shall terminate if it fails to
+ comply with any of the material terms or conditions of this Agreement and
+ does not cure such failure in a reasonable period of time after becoming
+ aware of such noncompliance. If all Recipient's rights under this Agreement
+ terminate, Recipient agrees to cease use and distribution of the Program as
+ soon as reasonably practicable. However, Recipient's obligations under this
+ Agreement and any licenses granted by Recipient relating to the Program
+ shall continue and survive.
+
+ Everyone is permitted to copy and distribute copies of this Agreement, but
+ in order to avoid inconsistency the Agreement is copyrighted and may only
+ be modified in the following manner. The Agreement Steward reserves the
+ right to publish new versions (including revisions) of this Agreement from
+ time to time. No one other than the Agreement Steward has the right to
+ modify this Agreement. The Eclipse Foundation is the initial Agreement
+ Steward. The Eclipse Foundation may assign the responsibility to serve as
+ the Agreement Steward to a suitable separate entity. Each new version of
+ the Agreement will be given a distinguishing version number. The Program
+ (including Contributions) may always be distributed subject to the version
+ of the Agreement under which it was received. In addition, after a new
+ version of the Agreement is published, Contributor may elect to distribute
+ the Program (including its Contributions) under the new version. Except as
+ expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
+ rights or licenses to the intellectual property of any Contributor under
+ this Agreement, whether expressly, by implication, estoppel or otherwise.
+ All rights in the Program not expressly granted under this Agreement are
+ reserved.
+
+ This Agreement is governed by the laws of the State of New York and the
+ intellectual property laws of the United States of America. No party to this
+ Agreement will bring a legal action under this Agreement more than one year
+ after the cause of action arose. Each party waives its rights to a jury
+ trial in any resulting litigation.
+
+Hamcrest library (hamcrest-*.jar) & CuvesAPI / Curve API
+
+ BSD License
+
+ Copyright (c) 2000-2006, www.hamcrest.org
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer. Redistributions in binary
+ form must reproduce the above copyright notice, this list of conditions and
+ the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+ Neither the name of Hamcrest nor the names of its contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+SLF4J library (slf4j-api-*.jar)
+
+ Copyright (c) 2004-2013 QOS.ch
+ All rights reserved.
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+inbot-utils (https://github.com/Inbot/inbot-utils)
+
+ The MIT License (MIT)
+
+ Copyright (c) 2015 Inbot
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
<project default="-deploy-ant" basedir=".">
<target name="-init-cl-deployment-env" if="deploy.ant.enabled">
<property file="${deploy.ant.properties.file}" />
<tempfile prefix="gfv3" property="gfv3.password.file" destdir="${java.io.tmpdir}"/> <!-- do not forget to delete this! -->
<echo message="AS_ADMIN_PASSWORD=${gfv3.password}" file="${gfv3.password.file}"/>
</target>
-
+
<target name="-parse-sun-web" depends="-init-cl-deployment-env" if="sun.web.present">
<tempfile prefix="gfv3" property="temp.sun.web" destdir="${java.io.tmpdir}"/>
<copy file="${deploy.ant.docbase.dir}/WEB-INF/sun-web.xml" tofile="${temp.sun.web}"/>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<jvmarg value="-ea"/>
- <jvmarg line="${debug-args-line}"/>
- <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
<customize/>
</junit>
</sequential>
<formatter type="xml"/>
<jvmarg value="-ea"/>
<jvmarg line="${run.jvmargs.ide}"/>
- <jvmarg line="${debug-args-line}"/>
- <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
<customize/>
</junit>
</sequential>
</macrodef>
</target>
<target name="-init-debug-args">
- <property name="version-output" value="java version "${ant.java.version}"/>
- <condition property="have-jdk-older-than-1.4">
- <or>
- <contains string="${version-output}" substring="java version "1.0"/>
- <contains string="${version-output}" substring="java version "1.1"/>
- <contains string="${version-output}" substring="java version "1.2"/>
- <contains string="${version-output}" substring="java version "1.3"/>
- </or>
- </condition>
- <condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
- <istrue value="${have-jdk-older-than-1.4}"/>
- </condition>
<condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
<os family="windows"/>
</condition>
<sequential>
<java classname="@{classname}" fork="true">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
- <jvmarg line="${debug-args-line}"/>
- <jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
+ <jvmarg value="-agentlib:jdwp=transport=${debug-transport},address=${jpda.address}"/>
<jvmarg line="${runmain.jvmargs}"/>
<classpath>
<path path="@{classpath}"/>
</target>
<target depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
<target depends="init,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test-method" name="debug-test-method"/>
+ <target depends="debug-test-method" name="debug-single-method"/>
<target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
<webproject1:nbjpdareload dir="${build.test.classes.dir}"/>
</target>
j2ee.copy.static.files.on.save=true
j2ee.deploy.on.save=true
j2ee.platform=1.7-web
-j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar
+j2ee.platform.classpath=${j2ee.server.home}/modules/cdi-api.jar:${j2ee.server.home}/modules/endorsed/javax.annotation-api.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.batch-api.jar:${j2ee.server.home}/modules/javax.ejb-api.jar:${j2ee.server.home}/modules/javax.el.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent-api.jar:${j2ee.server.home}/modules/javax.enterprise.concurrent.jar:${j2ee.server.home}/modules/javax.enterprise.deploy-api.jar:${j2ee.server.home}/modules/javax.faces.jar:${j2ee.server.home}/modules/javax.inject.jar:${j2ee.server.home}/modules/javax.interceptor-api.jar:${j2ee.server.home}/modules/javax.jms-api.jar:${j2ee.server.home}/modules/javax.json.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.management.j2ee-api.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.resource-api.jar:${j2ee.server.home}/modules/javax.security.auth.message-api.jar:${j2ee.server.home}/modules/javax.security.enterprise-api.jar:${j2ee.server.home}/modules/javax.security.enterprise.jar:${j2ee.server.home}/modules/javax.security.jacc-api.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.transaction-api.jar:${j2ee.server.home}/modules/javax.websocket-api.jar:${j2ee.server.home}/modules/javax.ws.rs-api.jar:${j2ee.server.home}/modules/javax.xml.registry-api.jar:${j2ee.server.home}/modules/javax.xml.rpc-api.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar
j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar
j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar
j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api.jar
package org.mxchange.addressbook.beans;
import java.util.Locale;
+import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.mxchange.jcoreee.bean.faces.BaseFacesBean;
}
@Override
- protected ResourceBundle loadResourceBundle (final Locale locale) {
- // Load resource bundle
- ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.bundle", locale);
+ protected void loadResourceBundles (final Locale locale) {
+ // Is any locale loaded? (Will be 2)
+ if (BaseFacesBean.getBundles().isEmpty()) {
+ // Load resource bundles, so it will be loaded from this JAR"
+ // 1) Generic
+ ResourceBundle bundle = ResourceBundle.getBundle("org.mxchange.localization.generic", locale);
+ BaseFacesBean.getBundles().add(bundle);
- // Return it
- return bundle;
+ // 2) Project-specific
+ bundle = ResourceBundle.getBundle("org.mxchange.localization.project", locale);
+ BaseFacesBean.getBundles().add(bundle);
+
+ // Try the local file
+ try {
+ // 3) Local (not committed)
+ bundle = ResourceBundle.getBundle("org.mxchange.localization.local", locale);
+ BaseFacesBean.getBundles().add(bundle);
+ } catch (final MissingResourceException ex) {
+ // Cannot load it, it is okay here
+ }
+ }
}
}
package org.mxchange.addressbook.beans.addressbook;
import java.text.MessageFormat;
-import java.util.Calendar;
import java.util.Collections;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
/**
* When this address book has been created
*/
- private Calendar addressbookCreated;
+ private Date addressbookCreated;
/**
* Address book id number (from URL for example)
this.setAddressbookId(book.getAddressbookId());
this.setAddressbookName(book.getAddressbookName());
this.setAddressbookUser(book.getAddressbookUser());
- this.setAddressbookCreated(book.getAddressbookCreated());
+ this.setAddressbookCreated(book.getAddressbookEntryCreated());
// And instance ...
this.setAddressbook(book);
if (null == event) {
// Is null
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getLoggedInUser()== null) {
+ } else if (event.getLoggedInUser() == null) {
// user is null
throw new NullPointerException("event.user is null"); //NOI18N
} else if (!event.getLoggedInUser().equals(this.userLoginController.getLoggedInUser())) {
}
// Ask the bean
- return this.addressbookBean.allEntries(addressbook);
+ return this.addressbookBean.fetchAllAddressbookEntries(addressbook);
}
@Override
@Override
@SuppressWarnings ("ReturnOfDateField")
- public Calendar getAddressbookCreated () {
+ public Date getAddressbookCreated () {
return this.addressbookCreated;
}
@Override
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setAddressbookCreated (final Calendar addressbookCreated) {
+ public void setAddressbookCreated (final Date addressbookCreated) {
this.addressbookCreated = addressbookCreated;
}
try {
// Then try to look it up
- Addressbook a = this.addressbookBean.getAddressbookById(this.getAddressbookId());
+ Addressbook addressbook = this.addressbookBean.getAddressbookById(this.getAddressbookId());
// Fire event here
- this.loadedEvent.fire(new AddressbookLoadedEvent(a));
+ this.loadedEvent.fire(new AddressbookLoadedEvent(addressbook));
// Found it
isFound = true;
package org.mxchange.addressbook.beans.addressbook;
import java.io.Serializable;
-import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import org.mxchange.jaddressbook.model.addressbook.Addressbook;
import org.mxchange.jaddressbook.model.addressbook.entry.AddressbookEntry;
* <p>
* @return When the address book has been created
*/
- Calendar getAddressbookCreated ();
+ Date getAddressbookCreated ();
/**
* Setter for when the address book has been created
* <p>
* @param addressbookCreated When the address book has been created
*/
- void setAddressbookCreated (final Calendar addressbookCreated);
+ void setAddressbookCreated (final Date addressbookCreated);
/**
* Checks if the user is logged in and if so if it matches the current
* @return Whether the address book was found
*/
boolean loadAddressbook ();
+
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata;
+
+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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
+import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An administrative business contact bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminCompanyDataController")
+@RequestScoped
+public class AddressbookAdminBasicDataWebRequestBean extends BaseAddressbookBean implements AddressbookAdminBasicDataWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 56_189_028_928_374L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote")
+ private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
+
+ /**
+ * An event being fired when basic business data has been added
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
+
+ /**
+ * Comments for this company
+ */
+ private String companyComments;
+
+ /**
+ * An employee as contact person with this company
+ */
+ private Employable companyContactEmployee;
+
+ /**
+ * Companies (main) email address (example: info@company.example)
+ */
+ private String companyEmailAddress;
+
+ /**
+ * Company founder
+ */
+ private Employable companyFounder;
+
+ /**
+ * Headquarter data for this company
+ */
+ private Headquarter companyHeadQuarter;
+
+ /**
+ * Company name
+ */
+ private String companyName;
+
+ /**
+ * Company's road number
+ */
+ private String companyRoadNumber;
+
+ /**
+ * Company short name
+ */
+ private String companyShortName;
+
+ /**
+ * Tax number
+ */
+ private String companyTaxNumber;
+
+ /**
+ * Owning user instance (which this company is assigned to)
+ */
+ private User companyUserOwner;
+
+ /**
+ * Web site URL
+ */
+ private String companyWebsiteUrl;
+
+ /**
+ * Area code for fax number
+ */
+ private Integer faxAreaCode;
+
+ /**
+ * Country for fax number
+ */
+ private Country faxCountry;
+
+ /**
+ * Dial number for fax number
+ */
+ private Long faxNumber;
+
+ /**
+ * Area code for land-line number
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country for land-line number
+ */
+ private Country landLineCountry;
+
+ /**
+ * Dial number for land-line number
+ */
+ private Long landLineNumber;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminBasicDataWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Adds a basic business data entry, if not yet found.
+ */
+ public void addBusinessBasicData () {
+ // Check if company short name is set
+ if (this.getCompanyShortName() == null) {
+ // Is null
+ throw new NullPointerException("this.companyShortName is null"); //NOI18N
+ } else if (this.getCompanyShortName().isEmpty()) {
+ // Is null
+ throw new IllegalArgumentException("this.companyShortName is empty"); //NOI18N
+ } else if ((this.getCompanyName() != null) && (this.getCompanyName().isEmpty())) {
+ // Is null
+ throw new IllegalArgumentException("this.companyName is set empty"); //NOI18N
+ }
+
+ // Prepare entity
+ final BasicData basicData = new BusinessBasicData(this.getCompanyShortName());
+
+ // Set all opther remaining data
+ basicData.setCompanyComments(this.getCompanyComments());
+ basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
+ basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
+ basicData.setCompanyFounder(this.getCompanyFounder());
+ basicData.setCompanyHeadquarterData(this.getCompanyHeadQuarter());
+ basicData.setCompanyName(this.getCompanyName());
+ basicData.setCompanyRoadNumber(this.getCompanyRoadNumber());
+ basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
+ basicData.setCompanyUserOwner(this.getCompanyUserOwner());
+ basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
+
+ // Set logo instance
+ // @TODO basicData.setCompanyLogo();
+ // Init varibables
+ DialableLandLineNumber landLine = null;
+ DialableFaxNumber fax = null;
+
+ // Are all 3 fields set?
+ if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+ // Initialize land number number instance
+ landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ }
+
+ // Are all 3 fields set?
+ if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+ // Initialzie fax number instance
+ fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ }
+
+ // Don't set null or wrong references
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (landLine.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (landLine.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (landLine.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set phone number
+ basicData.setCompanyLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+ } else if (fax.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ } else if (fax.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+ } else if (fax.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set fax number
+ basicData.setCompanyFaxNumber(fax);
+ }
+
+ // Init variable
+ final BasicData updatedBasicData;
+
+ // Now try to send to EJB and get an updated version back
+ try {
+ // Try it
+ updatedBasicData = this.adminBasicCompanyDataBean.addBusinessBasicData(basicData);
+ } catch (final BasicDataAlreadyAddedException e) {
+ // Does already exist
+ throw new FacesException(e);
+ }
+
+ // Fire event
+ this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
+ }
+
+ /**
+ * Getter for comments
+ * <p>
+ * @return Comments
+ */
+ public String getCompanyComments () {
+ return this.companyComments;
+ }
+
+ /**
+ * Setter for comments
+ * <p>
+ * @param companyComments Comments
+ */
+ public void setCompanyComments (final String companyComments) {
+ this.companyComments = companyComments;
+ }
+
+ /**
+ * Getter for employee as contact person
+ * <p>
+ * @return Employable as contact person
+ */
+ public Employable getCompanyContactEmployee () {
+ return this.companyContactEmployee;
+ }
+
+ /**
+ * Setter for employee as contact person
+ * <p>
+ * @param companyContactEmployee Employable as contact person
+ */
+ public void setCompanyContactEmployee (final Employable companyContactEmployee) {
+ this.companyContactEmployee = companyContactEmployee;
+ }
+
+ /**
+ * Getter for company's (main) email address
+ * <p>
+ * @return Company's (main) email address
+ */
+ public String getCompanyEmailAddress () {
+ return this.companyEmailAddress;
+ }
+
+ /**
+ * Setter for company's (main) email address
+ * <p>
+ * @param companyEmailAddress Company's (main) email address
+ */
+ public void setCompanyEmailAddress (final String companyEmailAddress) {
+ this.companyEmailAddress = companyEmailAddress;
+ }
+
+ /**
+ * Getter for company founder
+ * <p>
+ * @return Company founder
+ */
+ public Employable getCompanyFounder () {
+ return this.companyFounder;
+ }
+
+ /**
+ * Setter for company founder
+ * <p>
+ * @param companyFounder Company founder
+ */
+ public void setCompanyFounder (final Employable companyFounder) {
+ this.companyFounder = companyFounder;
+ }
+
+ /**
+ * Getter for headquarter data
+ * <p>
+ * @return Headquarter data
+ */
+ public Headquarter getCompanyHeadQuarter () {
+ return this.companyHeadQuarter;
+ }
+
+ /**
+ * Setter for headquarter data
+ * <p>
+ * @param companyHeadQuarter Headquarter data
+ */
+ public void setCompanyHeadQuarter (final Headquarter companyHeadQuarter) {
+ this.companyHeadQuarter = companyHeadQuarter;
+ }
+
+ /**
+ * Getter for company name
+ * <p>
+ * @return Company name
+ */
+ public String getCompanyName () {
+ return this.companyName;
+ }
+
+ /**
+ * Setter for company name
+ * <p>
+ * @param companyName Company name
+ */
+ public void setCompanyName (final String companyName) {
+ this.companyName = companyName;
+ }
+
+ /**
+ * Getter for company's road number
+ * <p>
+ * @return Company's road number
+ */
+ public String getCompanyRoadNumber () {
+ return this.companyRoadNumber;
+ }
+
+ /**
+ * Setter for company's road number
+ * <p>
+ * @param companyRoadNumber Company's road number
+ */
+ public void setCompanyRoadNumber (final String companyRoadNumber) {
+ this.companyRoadNumber = companyRoadNumber;
+ }
+
+ /**
+ * Getter for company short name
+ * <p>
+ * @return Company short name
+ */
+ public String getCompanyShortName () {
+ return this.companyShortName;
+ }
+
+ /**
+ * Setter for company short name
+ * <p>
+ * @param companyShortName Company short name
+ */
+ public void setCompanyShortName (final String companyShortName) {
+ this.companyShortName = companyShortName;
+ }
+
+ /**
+ * Getter for company tax number
+ * <p>
+ * @return Company tax number
+ */
+ public String getCompanyTaxNumber () {
+ return this.companyTaxNumber;
+ }
+
+ /**
+ * Setter for company tax number
+ * <p>
+ * @param companyTaxNumber Company tax number
+ */
+ public void setCompanyTaxNumber (final String companyTaxNumber) {
+ this.companyTaxNumber = companyTaxNumber;
+ }
+
+ /**
+ * Getter for owning user instance
+ * <p>
+ * @return Owning user instance
+ */
+ public User getCompanyUserOwner () {
+ return this.companyUserOwner;
+ }
+
+ /**
+ * Setter for owning user instance
+ * <p>
+ * @param companyUserOwner Owning user instance
+ */
+ public void setCompanyUserOwner (final User companyUserOwner) {
+ this.companyUserOwner = companyUserOwner;
+ }
+
+ /**
+ * Getter for company web site URL
+ * <p>
+ * @return Company web site URL
+ */
+ public String getCompanyWebsiteUrl () {
+ return this.companyWebsiteUrl;
+ }
+
+ /**
+ * Getter for company web site URL
+ * <p>
+ * @param companyWebsiteUrl Company web site URL
+ */
+ public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
+ this.companyWebsiteUrl = companyWebsiteUrl;
+ }
+
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
+ public Integer getFaxAreaCode () {
+ return this.faxAreaCode;
+ }
+
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
+ public void setFaxAreaCode (final Integer faxAreaCode) {
+ this.faxAreaCode = faxAreaCode;
+ }
+
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
+ public Country getFaxCountry () {
+ return this.faxCountry;
+ }
+
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
+ public void setFaxCountry (final Country faxCountry) {
+ this.faxCountry = faxCountry;
+ }
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ public Long getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata;
+
+import java.io.Serializable;
+
+/**
+ * An interface for session-scoped financial controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminBasicDataWebRequestController extends Serializable {
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.basicdata;
-
-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.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontactsbusiness.events.basicdata.added.AdminAddedBusinessBasicDataEvent;
-import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
-import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataAlreadyAddedException;
-import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
-import org.mxchange.jcontactsbusiness.model.basicdata.CompanyBasicData;
-import org.mxchange.jcontactsbusiness.model.employee.Employee;
-import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
-import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An administrative business contact bean (controller)
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("adminCompanyDataController")
-@RequestScoped
-public class AddressbookAdminBusinessDataWebRequestBean extends BaseAddressbookBean implements AddressbookAdminBusinessDataWebRequestController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 56_189_028_928_374L;
-
- /**
- * EJB for administrative purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote")
- private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
-
- /**
- * An event being fired when basic business data has been added
- */
- @Inject
- @Any
- private Event<ObservableAdminAddedBusinessBasicDataEvent> businessDataAddedEvent;
-
- /**
- * Comments for this company
- */
- private String companyComments;
-
- /**
- * An employee as contact person with this company
- */
- private Employee companyContactEmployee;
-
- /**
- * Companies (main) email address (example: info@company.example)
- */
- private String companyEmailAddress;
-
- /**
- * Company founder
- */
- private Employee companyFounder;
-
- /**
- * Head quarter data for this company
- */
- private HeadquartersData companyHeadQuarters;
-
- /**
- * Company name
- */
- private String companyName;
-
- /**
- * Tax number
- */
- private String companyTaxNumber;
-
- /**
- * Owning user instance (which this company is assigned to)
- */
- private User companyUserOwner;
-
- /**
- * Web site URL
- */
- private String companyWebsiteUrl;
-
- /**
- * Area code for fax number
- */
- private Integer faxAreaCode;
-
- /**
- * Country for fax number
- */
- private Country faxCountry;
-
- /**
- * Dial number for fax number
- */
- private Long faxNumber;
-
- /**
- * Area code for land-line number
- */
- private Integer landLineAreaCode;
-
- /**
- * Country for land-line number
- */
- private Country landLineCountry;
-
- /**
- * Dial number for land-line number
- */
- private Long landLineNumber;
-
- /**
- * Default constructor
- */
- public AddressbookAdminBusinessDataWebRequestBean () {
- // Call super constructor
- super();
- }
-
- /**
- * Adds a basic business data entry, if not yet found.
- * <p>
- * @return Redirect outcome
- */
- public String addBusinessBasicData () {
- // First, validate all parameter
- if (this.getCompanyName() == null) {
- // Is null
- throw new NullPointerException("this.companyName is null"); //NOI18N
- } else if (this.getCompanyName().isEmpty()) {
- // Is null
- throw new IllegalArgumentException("this.companyName is empty"); //NOI18N
- }
-
- // Prepare entity
- BusinessBasicData basicData = new CompanyBasicData(this.getCompanyName());
-
- // Set all opther remaining data
- basicData.setCompanyComments(this.getCompanyComments());
- basicData.setCompanyContactEmployee(this.getCompanyContactEmployee());
- basicData.setCompanyEmailAddress(this.getCompanyEmailAddress());
- basicData.setCompanyFounder(this.getCompanyFounder());
- basicData.setCompanyHeadQuartersData(this.getCompanyHeadQuarters());
- basicData.setCompanyTaxNumber(this.getCompanyTaxNumber());
- basicData.setCompanyUserOwner(this.getCompanyUserOwner());
- basicData.setCompanyWebsiteUrl(this.getCompanyWebsiteUrl());
-
- // Set logo instance
- // @TODO basicData.setCompanyLogo();
- // Generate phone number
- DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
- DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
-
- // Don't set null or wrong references
- if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
- // Now the number must be given
- if (landLine.getPhoneAreaCode() == null) {
- // Is null
- throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
- } else if (landLine.getPhoneAreaCode() < 1) {
- // Abort here
- throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
- } else if (landLine.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
- } else if (landLine.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set phone number
- basicData.setCompanyLandLineNumber(landLine);
- }
-
- // Don't set null or wrong references
- if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
- // Now the number must be given
- if (fax.getPhoneAreaCode() == null) {
- // Is null
- throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
- } else if (fax.getPhoneAreaCode() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
- } else if (fax.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
- } else if (fax.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set fax number
- basicData.setCompanyFaxNumber(fax);
- }
-
- // Now try to send to EJB and get an updated version back
- try {
- // Try it
- BusinessBasicData updatedBasicData = this.adminBasicCompanyDataBean.addCompanyBasicData(basicData);
-
- // Fire event
- this.businessDataAddedEvent.fire(new AdminAddedBusinessBasicDataEvent(updatedBasicData));
- } catch (final BasicCompanyDataAlreadyAddedException e) {
- // Does already exist
- throw new FacesException(e);
- }
-
- // Continue to list again
- return "admin_list_basic_company_data"; //NOI18N
- }
-
- /**
- * Getter for comments
- * <p>
- * @return Comments
- */
- public String getCompanyComments () {
- return this.companyComments;
- }
-
- /**
- * Setter for comments
- * <p>
- * @param companyComments Comments
- */
- public void setCompanyComments (final String companyComments) {
- this.companyComments = companyComments;
- }
-
- /**
- * Getter for employee as contact person
- * <p>
- * @return Employee as contact person
- */
- public Employee getCompanyContactEmployee () {
- return this.companyContactEmployee;
- }
-
- /**
- * Setter for employee as contact person
- * <p>
- * @param companyContactEmployee Employee as contact person
- */
- public void setCompanyContactEmployee (final Employee companyContactEmployee) {
- this.companyContactEmployee = companyContactEmployee;
- }
-
- /**
- * Getter for company's (main) email address
- * <p>
- * @return Company's (main) email address
- */
- public String getCompanyEmailAddress () {
- return this.companyEmailAddress;
- }
-
- /**
- * Setter for company's (main) email address
- * <p>
- * @param companyEmailAddress Company's (main) email address
- */
- public void setCompanyEmailAddress (final String companyEmailAddress) {
- this.companyEmailAddress = companyEmailAddress;
- }
-
- /**
- * Getter for company founder
- * <p>
- * @return Company founder
- */
- public Employee getCompanyFounder () {
- return this.companyFounder;
- }
-
- /**
- * Setter for company founder
- * <p>
- * @param companyFounder Company founder
- */
- public void setCompanyFounder (final Employee companyFounder) {
- this.companyFounder = companyFounder;
- }
-
- /**
- * Getter for headquarters data
- * <p>
- * @return Headquarters data
- */
- public HeadquartersData getCompanyHeadQuarters () {
- return this.companyHeadQuarters;
- }
-
- /**
- * Setter for headquarters data
- * <p>
- * @param companyHeadQuarters Headquarters data
- */
- public void setCompanyHeadQuarters (final HeadquartersData companyHeadQuarters) {
- this.companyHeadQuarters = companyHeadQuarters;
- }
-
- /**
- * Getter for company name
- * <p>
- * @return Company name
- */
- public String getCompanyName () {
- return this.companyName;
- }
-
- /**
- * Setter for company name
- * <p>
- * @param companyName Company name
- */
- public void setCompanyName (final String companyName) {
- this.companyName = companyName;
- }
-
- /**
- * Getter for company tax number
- * <p>
- * @return Company tax number
- */
- public String getCompanyTaxNumber () {
- return this.companyTaxNumber;
- }
-
- /**
- * Setter for company tax number
- * <p>
- * @param companyTaxNumber Company tax number
- */
- public void setCompanyTaxNumber (final String companyTaxNumber) {
- this.companyTaxNumber = companyTaxNumber;
- }
-
- /**
- * Getter for owning user instance
- * <p>
- * @return Owning user instance
- */
- public User getCompanyUserOwner () {
- return this.companyUserOwner;
- }
-
- /**
- * Setter for owning user instance
- * <p>
- * @param companyUserOwner Owning user instance
- */
- public void setCompanyUserOwner (final User companyUserOwner) {
- this.companyUserOwner = companyUserOwner;
- }
-
- /**
- * Getter for company web site URL
- * <p>
- * @return Company web site URL
- */
- public String getCompanyWebsiteUrl () {
- return this.companyWebsiteUrl;
- }
-
- /**
- * Getter for company web site URL
- * <p>
- * @param companyWebsiteUrl Company web site URL
- */
- public void setCompanyWebsiteUrl (final String companyWebsiteUrl) {
- this.companyWebsiteUrl = companyWebsiteUrl;
- }
-
- /**
- * Getter for fax number's area code
- * <p>
- * @return Fax number's area code
- */
- public Integer getFaxAreaCode () {
- return this.faxAreaCode;
- }
-
- /**
- * Setter for fax number's area code
- * <p>
- * @param faxAreaCode Fax number's area code
- */
- public void setFaxAreaCode (final Integer faxAreaCode) {
- this.faxAreaCode = faxAreaCode;
- }
-
- /**
- * Getter for fax's country instance
- * <p>
- * @return Fax' country instance
- */
- public Country getFaxCountry () {
- return this.faxCountry;
- }
-
- /**
- * Setter for fax's country instance
- * <p>
- * @param faxCountry Fax' country instance
- */
- public void setFaxCountry (final Country faxCountry) {
- this.faxCountry = faxCountry;
- }
-
- /**
- * Getter for fax number
- * <p>
- * @return Fax number
- */
- public Long getFaxNumber () {
- return this.faxNumber;
- }
-
- /**
- * Setter for fax number
- * <p>
- * @param faxNumber Fax number
- */
- public void setFaxNumber (final Long faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- /**
- * Getter for land-line number's area code
- * <p>
- * @return Land-line number's area code
- */
- public Integer getLandLineAreaCode () {
- return this.landLineAreaCode;
- }
-
- /**
- * Setter for land-line number's area code
- * <p>
- * @param landLineAreaCode Land-line number's area code
- */
- public void setLandLineAreaCode (final Integer landLineAreaCode) {
- this.landLineAreaCode = landLineAreaCode;
- }
-
- /**
- * Getter for land-line number's country instance
- * <p>
- * @return Land-line number's country instance
- */
- public Country getLandLineCountry () {
- return this.landLineCountry;
- }
-
- /**
- * Setter for land-line number's country instance
- * <p>
- * @param landLineCountry Land-line number's country instance
- */
- public void setLandLineCountry (final Country landLineCountry) {
- this.landLineCountry = landLineCountry;
- }
-
- /**
- * Getter for land-line number
- * <p>
- * @return Land-line number
- */
- public Long getLandLineNumber () {
- return this.landLineNumber;
- }
-
- /**
- * Setter for land-line number
- * <p>
- * @param landLineNumber Land-line number
- */
- public void setLandLineNumber (final Long landLineNumber) {
- this.landLineNumber = landLineNumber;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.basicdata;
-
-import java.io.Serializable;
-
-/**
- * An interface for session-scoped financial controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookAdminBusinessDataWebRequestController extends Serializable {
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
+import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
+import org.mxchange.jcountry.model.data.Country;
+
+/**
+ * A business contact bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("basicDataController")
+@RequestScoped
+public class AddressbookBasicDataWebRequestBean extends BaseAddressbookBean implements AddressbookBasicDataWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 56_189_028_928_371L;
+
+ /**
+ * EJB for administrative basic business data purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
+ private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
+
+ /**
+ * Comments for this company
+ */
+ private String companyComments;
+
+ /**
+ * Companies (main) email address (example: info@company.example)
+ */
+ private String companyEmailAddress;
+
+ /**
+ * Company cacheName
+ */
+ private String companyName;
+
+ /**
+ * Area code for fax number
+ */
+ private Integer faxAreaCode;
+
+ /**
+ * Country for fax number
+ */
+ private Country faxCountry;
+
+ /**
+ * Dial number for fax number
+ */
+ private Long faxNumber;
+
+ /**
+ * Area code for land-line number
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country for land-line number
+ */
+ private Country landLineCountry;
+
+ /**
+ * Dial number for land-line number
+ */
+ private Long landLineNumber;
+
+ /**
+ * User instance
+ */
+ @Inject
+ private AddressbookUserLoginWebSessionController userLoginController;
+
+ /**
+ * Constructor
+ */
+ public AddressbookBasicDataWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Getter for comments
+ * <p>
+ * @return Comments
+ */
+ public String getCompanyComments () {
+ return this.companyComments;
+ }
+
+ /**
+ * Setter for comments
+ * <p>
+ * @param companyComments Comments
+ */
+ public void setCompanyComments (final String companyComments) {
+ this.companyComments = companyComments;
+ }
+
+ /**
+ * Getter for company's (main) email address
+ * <p>
+ * @return Company's (main) email address
+ */
+ public String getCompanyEmailAddress () {
+ return this.companyEmailAddress;
+ }
+
+ /**
+ * Setter for company's (main) email address
+ * <p>
+ * @param companyEmailAddress Company's (main) email address
+ */
+ public void setCompanyEmailAddress (final String companyEmailAddress) {
+ this.companyEmailAddress = companyEmailAddress;
+ }
+
+ /**
+ * Getter for company cacheName
+ * <p>
+ * @return Company cacheName
+ */
+ public String getCompanyName () {
+ return this.companyName;
+ }
+
+ /**
+ * Setter for company cacheName
+ * <p>
+ * @param companyName Company cacheName
+ */
+ public void setCompanyName (final String companyName) {
+ this.companyName = companyName;
+ }
+
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
+ public Integer getFaxAreaCode () {
+ return this.faxAreaCode;
+ }
+
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
+ public void setFaxAreaCode (final Integer faxAreaCode) {
+ this.faxAreaCode = faxAreaCode;
+ }
+
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
+ public Country getFaxCountry () {
+ return this.faxCountry;
+ }
+
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
+ public void setFaxCountry (final Country faxCountry) {
+ this.faxCountry = faxCountry;
+ }
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ public Long getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data:
+ this.setCompanyComments(null);
+ this.setCompanyEmailAddress(null);
+ this.setCompanyName(null);
+ this.setFaxAreaCode(null);
+ this.setFaxCountry(null);
+ this.setFaxNumber(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineCountry(null);
+ this.setLandLineNumber(null);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata;
+
+import java.io.Serializable;
+
+/**
+ * An interface for session-scoped financial controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookBasicDataWebRequestController extends Serializable {
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.basicdata;
-
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
-import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
-import org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
-import org.mxchange.jcountry.model.data.Country;
-
-/**
- * A business contact bean (controller)
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("basicDataController")
-@RequestScoped
-public class AddressbookBusinessDataWebRequestBean extends BaseAddressbookBean implements AddressbookBusinessDataWebRequestController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 56_189_028_928_371L;
-
- /**
- * EJB for administrative basic business data purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/adminBasicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.AdminBasicCompanyDataSessionBeanRemote", description = "A stateless session bean for administrative purposes.")
- private AdminBasicCompanyDataSessionBeanRemote adminBasicCompanyDataBean;
-
- /**
- * A list of all registered companies (globally)
- */
- @Inject
- @NamedCache (cacheName = "basicDataCache")
- private Cache<Long, BusinessBasicData> basicDataCache;
-
- /**
- * EJB for general basic business data purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
- private BasicCompanyDataSessionBeanRemote businessDataBean;
-
- /**
- * Comments for this company
- */
- private String companyComments;
-
- /**
- * Companies (main) email address (example: info@company.example)
- */
- private String companyEmailAddress;
-
- /**
- * Company cacheName
- */
- private String companyName;
-
- /**
- * Area code for fax number
- */
- private Integer faxAreaCode;
-
- /**
- * Country for fax number
- */
- private Country faxCountry;
-
- /**
- * Dial number for fax number
- */
- private Long faxNumber;
-
- /**
- * Area code for land-line number
- */
- private Integer landLineAreaCode;
-
- /**
- * Country for land-line number
- */
- private Country landLineCountry;
-
- /**
- * Dial number for land-line number
- */
- private Long landLineNumber;
-
- /**
- * User instance
- */
- @Inject
- private AddressbookUserLoginWebSessionController userLoginController;
-
- /**
- * Constructor
- */
- public AddressbookBusinessDataWebRequestBean () {
- // Call super constructor
- super();
- }
-
- /**
- * Observers events being fired when an administrator has added company
- * basic data.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
- // Is the parameter valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- } else if (event.getBasicData() == null) {
- // Throw NPE again
- throw new NullPointerException("event.basicData is null");
- } else if (event.getBasicData().getBasicDataId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.basicData.basicDataId is null");
- } else if (event.getBasicData().getBasicDataId() < 1) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("event.basicData.basicDataId={0} is invalid", event.getBasicData().getBasicDataId()));
- } else if (event.getBasicData().getCompanyName() == null) {
- // Throw NPE again
- throw new NullPointerException("event.basicData.companyName is null");
- } else if (event.getBasicData().getCompanyName().isEmpty()) {
- // Throw IAE again
- throw new IllegalArgumentException("event.basicData.companyName is empty");
- }
-
- // Add it to list
- this.basicDataCache.put(event.getBasicData().getBasicDataId(), event.getBasicData());
- }
-
- /**
- * Returns a list of all business contacts
- * <p>
- * @return A list of all business contacts
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<BusinessBasicData> allCompanyBasicData () {
- // Init list
- final List<BusinessBasicData> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, BusinessBasicData>> iterator = this.basicDataCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, BusinessBasicData> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- /**
- * Getter for comments
- * <p>
- * @return Comments
- */
- public String getCompanyComments () {
- return this.companyComments;
- }
-
- /**
- * Setter for comments
- * <p>
- * @param companyComments Comments
- */
- public void setCompanyComments (final String companyComments) {
- this.companyComments = companyComments;
- }
-
- /**
- * Getter for company's (main) email address
- * <p>
- * @return Company's (main) email address
- */
- public String getCompanyEmailAddress () {
- return this.companyEmailAddress;
- }
-
- /**
- * Setter for company's (main) email address
- * <p>
- * @param companyEmailAddress Company's (main) email address
- */
- public void setCompanyEmailAddress (final String companyEmailAddress) {
- this.companyEmailAddress = companyEmailAddress;
- }
-
- /**
- * Getter for company cacheName
- * <p>
- * @return Company cacheName
- */
- public String getCompanyName () {
- return this.companyName;
- }
-
- /**
- * Setter for company cacheName
- * <p>
- * @param companyName Company cacheName
- */
- public void setCompanyName (final String companyName) {
- this.companyName = companyName;
- }
-
- /**
- * Getter for fax number's area code
- * <p>
- * @return Fax number's area code
- */
- public Integer getFaxAreaCode () {
- return this.faxAreaCode;
- }
-
- /**
- * Setter for fax number's area code
- * <p>
- * @param faxAreaCode Fax number's area code
- */
- public void setFaxAreaCode (final Integer faxAreaCode) {
- this.faxAreaCode = faxAreaCode;
- }
-
- /**
- * Getter for fax's country instance
- * <p>
- * @return Fax' country instance
- */
- public Country getFaxCountry () {
- return this.faxCountry;
- }
-
- /**
- * Setter for fax's country instance
- * <p>
- * @param faxCountry Fax' country instance
- */
- public void setFaxCountry (final Country faxCountry) {
- this.faxCountry = faxCountry;
- }
-
- /**
- * Getter for fax number
- * <p>
- * @return Fax number
- */
- public Long getFaxNumber () {
- return this.faxNumber;
- }
-
- /**
- * Setter for fax number
- * <p>
- * @param faxNumber Fax number
- */
- public void setFaxNumber (final Long faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- /**
- * Getter for land-line number's area code
- * <p>
- * @return Land-line number's area code
- */
- public Integer getLandLineAreaCode () {
- return this.landLineAreaCode;
- }
-
- /**
- * Setter for land-line number's area code
- * <p>
- * @param landLineAreaCode Land-line number's area code
- */
- public void setLandLineAreaCode (final Integer landLineAreaCode) {
- this.landLineAreaCode = landLineAreaCode;
- }
-
- /**
- * Getter for land-line number's country instance
- * <p>
- * @return Land-line number's country instance
- */
- public Country getLandLineCountry () {
- return this.landLineCountry;
- }
-
- /**
- * Setter for land-line number's country instance
- * <p>
- * @param landLineCountry Land-line number's country instance
- */
- public void setLandLineCountry (final Country landLineCountry) {
- this.landLineCountry = landLineCountry;
- }
-
- /**
- * Getter for land-line number
- * <p>
- * @return Land-line number
- */
- public Long getLandLineNumber () {
- return this.landLineNumber;
- }
-
- /**
- * Setter for land-line number
- * <p>
- * @param landLineNumber Land-line number
- */
- public void setLandLineNumber (final Long landLineNumber) {
- this.landLineNumber = landLineNumber;
- }
-
- /**
- * Initializer method
- */
- @PostConstruct
- public void initializeList () {
- // Is cache there?
- if (!this.basicDataCache.iterator().hasNext()) {
- // Get whole list
- final List<BusinessBasicData> list = this.businessDataBean.allCompanyBasicData();
-
- // Add all
- for (final Iterator<BusinessBasicData> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final BusinessBasicData next = iterator.next();
-
- // Add it to cache
- this.basicDataCache.put(next.getBasicDataId(), next);
- }
- }
- }
-
- /**
- * Clears this bean
- */
- private void clear () {
- // Clear all data:
- this.setCompanyComments(null);
- this.setCompanyEmailAddress(null);
- this.setCompanyName(null);
- this.setFaxAreaCode(null);
- this.setFaxCountry(null);
- this.setFaxNumber(null);
- this.setLandLineAreaCode(null);
- this.setLandLineCountry(null);
- this.setLandLineNumber(null);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.basicdata;
-
-import java.io.Serializable;
-
-/**
- * An interface for session-scoped financial controller
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookBusinessDataWebRequestController extends Serializable {
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontactsbusiness.events.basicdata.added.ObservableAdminAddedBusinessBasicDataEvent;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataNotFoundException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+
+/**
+ * A view-scoped bean for product lists
+ * <p>
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Named ("basicDataListController")
+@ViewScoped
+public class AddressbookBasicDataListWebViewBean extends BaseAddressbookBean implements AddressbookBasicDataListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 34_869_872_672_645L;
+
+ /**
+ * List of all basic company data
+ */
+ private final List<BasicData> allBasicData;
+
+ /**
+ * EJB for general basic business data purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote", description = "A stateless session bean for general purposes.")
+ private BasicCompanyDataSessionBeanRemote basicDataBean;
+
+ /**
+ * A list of all registered companies (globally)
+ */
+ @Inject
+ @NamedCache (cacheName = "basicDataCache")
+ private transient Cache<Long, BasicData> basicDataCache;
+
+ /**
+ * List of filtered basic company data
+ */
+ private List<BasicData> filteredBasicData;
+
+ /**
+ * Selected basic data
+ */
+ private BasicData selectedBasicData;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookBasicDataListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allBasicData = new LinkedList<>();
+ }
+
+ /**
+ * Observers events being fired when an administrator has added company
+ * basic data.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedBasicCompanyDataEvent (@Observes final ObservableAdminAddedBusinessBasicDataEvent event) {
+ // Is the parameter valid?
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getBasicData() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.basicData is null"); //NOI18N
+ } else if (event.getBasicData().getBasicDataId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.basicData.basicDataId is null"); //NOI18N
+ } else if (event.getBasicData().getBasicDataId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.basicData.basicDataId={0} is invalid", event.getBasicData().getBasicDataId())); //NOI18N
+ } else if (event.getBasicData().getCompanyShortName() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.basicData.companyName is null"); //NOI18N
+ } else if (event.getBasicData().getCompanyShortName().isEmpty()) {
+ // Throw IAE again
+ throw new IllegalArgumentException("event.basicData.companyName is empty"); //NOI18N
+ }
+
+ // Add it to list
+ this.basicDataCache.put(event.getBasicData().getBasicDataId(), event.getBasicData());
+ this.getAllBasicData().add(event.getBasicData());
+ }
+
+ @Override
+ public BasicData findBasicDataById (final Long basicDataId) throws BasicDataNotFoundException {
+ // Validate parameter
+ if (null == basicDataId) {
+ // Throw NPE
+ throw new NullPointerException("basicDataId is null"); //NOI18N
+ } else if (basicDataId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("basicDataId={0} is invalid", basicDataId)); //NOI18N
+ } else if (!this.basicDataCache.containsKey(basicDataId)) {
+ // Not found
+ throw new BasicDataNotFoundException(basicDataId);
+ }
+
+ // Get it from cache
+ final BasicData basicData = this.basicDataCache.get(basicDataId);
+
+ // Return it
+ return basicData;
+ }
+
+ /**
+ * Getter for a list of all business contacts
+ * <p>
+ * @return A list of all business contacts
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BasicData> getAllBasicData () {
+ return this.allBasicData;
+ }
+
+ /**
+ * Getter for filtered basic company data
+ * <p>
+ * @return Filtered basic company data
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BasicData> getFilteredBasicData () {
+ return this.filteredBasicData;
+ }
+
+ /**
+ * Setter for filtered basic company data
+ * <p>
+ * @param filteredBasicData Filtered basic company data
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredBasicData (final List<BasicData> filteredBasicData) {
+ this.filteredBasicData = filteredBasicData;
+ }
+
+ /**
+ * Getter for selected basic data
+ * <p>
+ * @return Selected basic data
+ */
+ public BasicData getSelectedBasicData () {
+ return this.selectedBasicData;
+ }
+
+ /**
+ * Setter for selected basic data
+ * <p>
+ * @param selectedBasicData Selected basic data
+ */
+ public void setSelectedBasicData (final BasicData selectedBasicData) {
+ this.selectedBasicData = selectedBasicData;
+ }
+
+ /**
+ * Initializer method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.basicDataCache.iterator().hasNext()) {
+ // Add all
+ for (final BasicData basicData : this.basicDataBean.fetchAllBusinessBasicData()) {
+ // Add it to cache
+ this.basicDataCache.put(basicData.getBasicDataId(), basicData);
+ }
+ }
+
+ // Is cache there and list is not full?
+ if ((this.getAllBasicData().isEmpty()) && (this.basicDataCache.iterator().hasNext())) {
+ // Build up list
+ for (final Cache.Entry<Long, BasicData> currentEntry : this.basicDataCache) {
+ // Add to list
+ this.getAllBasicData().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllBasicData().sort(new Comparator<BasicData>() {
+ @Override
+ public int compare (final BasicData basicData1, final BasicData basicData2) {
+ return basicData1.getBasicDataId() > basicData2.getBasicDataId() ? 1 : basicData1.getBasicDataId() < basicData2.getBasicDataId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredBasicData(this.getAllBasicData());
+ }
+ }
+
+ @Override
+ public Boolean isCompanyNameUsed (final String companyName) {
+ // Validate parameter
+ if (null == companyName) {
+ // Throw NPE
+ throw new NullPointerException("companyName is null"); //NOI18N
+ } else if (companyName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("companyName is empty"); //NOI18N
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all entries
+ for (final BasicData basicData : this.getAllBasicData()) {
+ // Is same company name?
+ if (Objects.equals(basicData.getCompanyName(), companyName)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ @Override
+ public boolean isCompanyRoadNumberUsed (final String companyRoadNumber) {
+ // Validate parameter
+ if (null == companyRoadNumber) {
+ // Throw NPE
+ throw new NullPointerException("companyRoadNumber is null"); //NOI18N
+ } else if (companyRoadNumber.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("companyRoadNumber is empty"); //NOI18N
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all entries
+ for (final BasicData basicData : this.getAllBasicData()) {
+ // Is same company name?
+ if (Objects.equals(basicData.getCompanyRoadNumber(), companyRoadNumber)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ @Override
+ public Boolean isCompanyShortNameUsed (final String companyShortName) {
+ // Validate parameter
+ if (null == companyShortName) {
+ // Throw NPE
+ throw new NullPointerException("companyShortName is null"); //NOI18N
+ } else if (companyShortName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("companyShortName is empty"); //NOI18N
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all entries
+ for (final BasicData basicData : this.getAllBasicData()) {
+ // Is same company name?
+ if (Objects.equals(basicData.getCompanyShortName(), companyShortName)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ @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 BasicData basicData : this.getAllBasicData()) {
+ // Is email address used?
+ if (Objects.equals(basicData.getCompanyEmailAddress(), emailAddress)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.basicdata.list;
+
+import java.io.Serializable;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataNotFoundException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+
+/**
+ * An interface of basic data list backing beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookBasicDataListWebViewController extends Serializable {
+
+ /**
+ * Checks whether given company's road number is already used.
+ * <p>
+ * @param companyRoadNumber Company's road number
+ * <p>
+ * @return Whether it is already in use
+ */
+ boolean isCompanyRoadNumberUsed (final String companyRoadNumber);
+
+ /**
+ * Retrieves a single business data entity for given id number or throws a
+ * proper exception if not found.
+ * <p>
+ * @param basicDataId Company basic data id to lookup
+ * <p>
+ * @return Business contact instance
+ * <p>
+ * @throws BasicDataNotFoundException If the id number could not be looked
+ * up and solved into an entity
+ */
+ BasicData findBasicDataById (final Long basicDataId) throws BasicDataNotFoundException;
+
+ /**
+ * Checks if given email address is already registered by other basic
+ * company data
+ * <p>
+ * @param emailAddress Email address
+ * <p>
+ * @return Whether the email address has been already registered
+ */
+ Boolean isEmailAddressRegistered (final String emailAddress);
+
+ /**
+ * Checks whether given company name already exists
+ * <p>
+ * @param companyName Company name to check
+ * <p>
+ * @return Whether the company name exists
+ */
+ Boolean isCompanyNameUsed (final String companyName);
+
+ /**
+ * Checks whether given company short name already exists
+ * <p>
+ * @param companyShortName Company short name to check
+ * <p>
+ * @return Whether the company short name exists
+ */
+ Boolean isCompanyShortNameUsed (final String companyShortName);
+
+}
*/
package org.mxchange.addressbook.beans.business.branchoffice;
-import java.util.List;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontactsbusiness.events.branchoffice.added.BranchOfficeAddedEvent;
-import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableBranchOfficeAddedEvent;
-import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
-import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
-import org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffices;
-import org.mxchange.jcontactsbusiness.model.branchoffice.CompanyBranchOffice;
-import org.mxchange.jcontactsbusiness.model.employee.Employee;
-import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
-import org.mxchange.jusercore.model.user.User;
/**
* An administrative bean for branch offices
*/
private static final long serialVersionUID = 5_028_697_360_461L;
- /**
- * EJB for administrative purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/adminBranchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote")
- private AdminBranchOfficeSessionBeanRemote adminBranchOfficeBean;
-
- /**
- * City
- */
- private String branchCity;
-
- /**
- * Assigned company for this branch office
- */
- private BusinessBasicData branchCompany;
-
- /**
- * Contact person in branch office
- */
- private Employee branchContactEmployee;
-
- /**
- * Country
- */
- private Country branchCountry;
-
- /**
- * Email address
- */
- private String branchEmailAddress;
-
- /**
- * House number
- */
- private Short branchHouseNumber;
-
- /**
- * Number of branch office
- */
- private Long branchNumber;
-
- /**
- * An event being fired when a branch office has been successfully added
- */
- @Inject
- @Any
- private Event<ObservableBranchOfficeAddedEvent> branchOfficeAddedEvent;
-
- /**
- * A general branch office controller (backing bean)
- */
- @Inject
- private AddressbookBranchOfficeWebRequestController branchOfficeController;
-
- /**
- * Store
- */
- private Short branchStore;
-
- /**
- * Branch office street name
- */
- private String branchStreet;
-
- /**
- * Suite number
- */
- private Short branchSuiteNumber;
-
- /**
- * Owning user instance (which this branch office is assigned to)
- */
- private User branchUserOwner;
-
- /**
- * ZIP code
- */
- private Integer branchZipCode;
-
- /**
- * Area code for fax number
- */
- private Integer faxAreaCode;
-
- /**
- * Country for fax number
- */
- private Country faxCountry;
-
- /**
- * Dial number for fax number
- */
- private Long faxNumber;
-
- /**
- * Area code for land-line number
- */
- private Integer landLineAreaCode;
-
- /**
- * Country for land-line number
- */
- private Country landLineCountry;
-
- /**
- * Dial number for land-line number
- */
- private Long landLineNumber;
-
/**
* Default constructor
*/
super();
}
- /**
- * Adds branch office with all data from this backing bean. First this
- * action method will validate if the branch office's address is already
- * registered and if found, it will output a proper faces message.
- * <p>
- * @return Redirect outcome
- */
- public String addBranchOffice () {
- // Get instance
- final BranchOffice branchOffice = this.createBranchOffice();
-
- // Is the branch office not created yet?
- if (this.isBranchOfficeCreatedByRequiredData(branchOffice)) {
- // Then show proper faces message
- this.showFacesMessage("form_admin_add_branch_office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N
- return ""; //NOI18N
- }
-
- // Delcare updated instance
- final BranchOffice updatedOffice;
-
- try {
- // Try to call EJB
- updatedOffice = this.adminBranchOfficeBean.addBranchOffice(branchOffice);
- } catch (final BranchOfficeAlreadyAddedException ex) {
- // Output message
- this.showFacesMessage("form_admin_add_branch_office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED"); //NOI18N
- return ""; //NOI18N
- }
-
- // Fire event
- this.branchOfficeAddedEvent.fire(new BranchOfficeAddedEvent(updatedOffice));
-
- // Redirect to list
- return "admin_list_branch_offices"; //NOI18N
- }
-
- /**
- * Getter for city
- * <p>
- * @return City
- */
- public String getBranchCity () {
- return this.branchCity;
- }
-
- /**
- * Setter for city
- * <p>
- * @param branchCity City
- */
- public void setBranchCity (final String branchCity) {
- this.branchCity = branchCity;
- }
-
- /**
- * Getter for basic company data
- * <p>
- * @return Basic company data
- */
- public BusinessBasicData getBranchCompany () {
- return this.branchCompany;
- }
-
- /**
- * Setter for basic company data
- * <p>
- * @param branchCompany Basic company data
- */
- public void setBranchCompany (final BusinessBasicData branchCompany) {
- this.branchCompany = branchCompany;
- }
-
- /**
- * Getter for branch office contact person
- * <p>
- * @return Branch office contact person
- */
- public Employee getBranchContactEmployee () {
- return this.branchContactEmployee;
- }
-
- /**
- * Setter for branch office contact person
- * <p>
- * @param branchContactEmployee Branch office contact person
- */
- public void setBranchContactEmployee (final Employee branchContactEmployee) {
- this.branchContactEmployee = branchContactEmployee;
- }
-
- /**
- * Getter for country
- * <p>
- * @return Country
- */
- public Country getBranchCountry () {
- return this.branchCountry;
- }
-
- /**
- * Setter for country
- * <p>
- * @param branchCountry Country
- */
- public void setBranchCountry (final Country branchCountry) {
- this.branchCountry = branchCountry;
- }
-
- /**
- * Getter for email address
- * <p>
- * @return Email address
- */
- public String getBranchEmailAddress () {
- return this.branchEmailAddress;
- }
-
- /**
- * Getter for email address
- * <p>
- * @param branchEmailAddress Email address
- */
- public void setBranchEmailAddress (final String branchEmailAddress) {
- this.branchEmailAddress = branchEmailAddress;
- }
-
- /**
- * Getter for house number
- * <p>
- * @return House number
- */
- public Short getBranchHouseNumber () {
- return this.branchHouseNumber;
- }
-
- /**
- * Setter for house number
- * <p>
- * @param branchHouseNumber House number
- */
- public void setBranchHouseNumber (final Short branchHouseNumber) {
- this.branchHouseNumber = branchHouseNumber;
- }
-
- /**
- * Getter for branch office number
- * <p>
- * @return Branch office number
- */
- public Long getBranchNumber () {
- return this.branchNumber;
- }
-
- /**
- * Setter for branch office number
- * <p>
- * @param branchNumber Branch office number
- */
- public void setBranchNumber (final Long branchNumber) {
- this.branchNumber = branchNumber;
- }
-
- /**
- * Getter for store
- * <p>
- * @return Store
- */
- public Short getBranchStore () {
- return this.branchStore;
- }
-
- /**
- * Setter for store
- * <p>
- * @param branchStore Store
- */
- public void setBranchStore (final Short branchStore) {
- this.branchStore = branchStore;
- }
-
- /**
- * Getter for street name
- * <p>
- * @return Street name
- */
- public String getBranchStreet () {
- return this.branchStreet;
- }
-
- /**
- * Setter for street name
- * <p>
- * @param branchStreet Street name
- */
- public void setBranchStreet (final String branchStreet) {
- this.branchStreet = branchStreet;
- }
-
- /**
- * Getter for suite number
- * <p>
- * @return Suite number
- */
- public Short getBranchSuiteNumber () {
- return this.branchSuiteNumber;
- }
-
- /**
- * Setter for suite number
- * <p>
- * @param branchSuiteNumber Suite number
- */
- public void setBranchSuiteNumber (final Short branchSuiteNumber) {
- this.branchSuiteNumber = branchSuiteNumber;
- }
-
- /**
- * Getter for owning user instance
- * <p>
- * @return Owning user instance
- */
- public User getBranchUserOwner () {
- return this.branchUserOwner;
- }
-
- /**
- * Setter for owning user instance
- * <p>
- * @param branchUserOwner Owning user instance
- */
- public void setBranchUserOwner (final User branchUserOwner) {
- this.branchUserOwner = branchUserOwner;
- }
-
- /**
- * Getter for ZIP code\
- * <p>
- * @return ZIP code
- */
- public Integer getBranchZipCode () {
- return this.branchZipCode;
- }
-
- /**
- * Setter for ZIP code\
- * <p>
- * @param branchZipCode ZIP code
- */
- public void setBranchZipCode (final Integer branchZipCode) {
- this.branchZipCode = branchZipCode;
- }
-
- /**
- * Getter for fax number's area code
- * <p>
- * @return Fax number's area code
- */
- public Integer getFaxAreaCode () {
- return this.faxAreaCode;
- }
-
- /**
- * Setter for fax number's area code
- * <p>
- * @param faxAreaCode Fax number's area code
- */
- public void setFaxAreaCode (final Integer faxAreaCode) {
- this.faxAreaCode = faxAreaCode;
- }
-
- /**
- * Getter for fax's country instance
- * <p>
- * @return Fax' country instance
- */
- public Country getFaxCountry () {
- return this.faxCountry;
- }
-
- /**
- * Setter for fax's country instance
- * <p>
- * @param faxCountry Fax' country instance
- */
- public void setFaxCountry (final Country faxCountry) {
- this.faxCountry = faxCountry;
- }
-
- /**
- * Getter for fax number
- * <p>
- * @return Fax number
- */
- public Long getFaxNumber () {
- return this.faxNumber;
- }
-
- /**
- * Setter for fax number
- * <p>
- * @param faxNumber Fax number
- */
- public void setFaxNumber (final Long faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- /**
- * Getter for land-line number's area code
- * <p>
- * @return Land-line number's area code
- */
- public Integer getLandLineAreaCode () {
- return this.landLineAreaCode;
- }
-
- /**
- * Setter for land-line number's area code
- * <p>
- * @param landLineAreaCode Land-line number's area code
- */
- public void setLandLineAreaCode (final Integer landLineAreaCode) {
- this.landLineAreaCode = landLineAreaCode;
- }
-
- /**
- * Getter for land-line number's country instance
- * <p>
- * @return Land-line number's country instance
- */
- public Country getLandLineCountry () {
- return this.landLineCountry;
- }
-
- /**
- * Setter for land-line number's country instance
- * <p>
- * @param landLineCountry Land-line number's country instance
- */
- public void setLandLineCountry (final Country landLineCountry) {
- this.landLineCountry = landLineCountry;
- }
-
- /**
- * Getter for land-line number
- * <p>
- * @return Land-line number
- */
- public Long getLandLineNumber () {
- return this.landLineNumber;
- }
-
- /**
- * Setter for land-line number
- * <p>
- * @param landLineNumber Land-line number
- */
- public void setLandLineNumber (final Long landLineNumber) {
- this.landLineNumber = landLineNumber;
- }
-
- /**
- * Prepares an instance of a BranchOffice object (entity) with all data from
- * this bean. If a complete fax number or land-line number was provided, it
- * will be set in the instance as well.
- * <p>
- * @return An instance of a BranchOffice class (entity)
- */
- private BranchOffice createBranchOffice () {
- // Create new branch office instance
- final BranchOffice branchOffice = new CompanyBranchOffice(this.getBranchCity(), this.getBranchCompany(), this.getBranchCountry(), this.getBranchStreet(), this.getBranchZipCode(), this.getBranchHouseNumber());
-
- // Add all other fields, too
- branchOffice.setBranchContactEmployee(this.getBranchContactEmployee());
- branchOffice.setBranchEmailAddress(this.getBranchEmailAddress());
- branchOffice.setBranchNumber(this.getBranchNumber());
- branchOffice.setBranchStore(this.getBranchStore());
- branchOffice.setBranchSuiteNumber(this.getBranchSuiteNumber());
- branchOffice.setBranchUserOwner(this.getBranchUserOwner());
-
- // Generate phone number
- final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
- final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
-
- // Don't set null or wrong references
- if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
- // Now the number must be given
- if (landLine.getPhoneAreaCode() == null) {
- // Is null
- throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
- } else if (landLine.getPhoneAreaCode() < 1) {
- // Abort here
- throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
- } else if (landLine.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
- } else if (landLine.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set phone number
- branchOffice.setBranchLandLineNumber(landLine);
- }
-
- // Don't set null or wrong references
- if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
- // Now the number must be given
- if (fax.getPhoneAreaCode() == null) {
- // Is null
- throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
- } else if (fax.getPhoneAreaCode() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
- } else if (fax.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
- } else if (fax.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set fax number
- branchOffice.setBranchFaxNumber(fax);
- }
-
- // Return fully prepared instance
- return branchOffice;
- }
-
- /**
- * Checks whether the given branch office's address is already found in
- * local cache. Please note that this method fully relies on the cache, so
- * you must always fire proper events that add/update/delete entries in
- * cache.
- * <p>
- * @param branchOffice Branch office to check it's address
- * <p>
- * @return Whether the address has been found
- */
- private boolean isBranchOfficeCreatedByRequiredData (final BranchOffice branchOffice) {
- // Get full list from other bean
- final List<BranchOffice> branchOffices = this.branchOfficeController.allBranchOffices();
-
- // Default is not found
- boolean isFound = false;
-
- // Now check each entry
- for (final BranchOffice bo : branchOffices) {
- // Is same address?
- if (BranchOffices.isSameAddress(bo, branchOffice)) {
- // Found one
- isFound = true;
- break;
- }
- }
-
- // Return flag
- return isFound;
- }
-
}
*/
package org.mxchange.addressbook.beans.business.branchoffice;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableBranchOfficeAddedEvent;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
/**
* A general bean for branch offices
*/
private static final long serialVersionUID = 5_028_697_360_461L;
- /**
- * A list of all branch offices
- */
- private final List<BranchOffice> allBranchOffices;
-
- /**
- * EJB for administrative purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote")
- private BranchOfficeSessionBeanRemote branchOfficeBean;
-
- /**
- * A list of all branch offices (globally)
- */
- @Inject
- @NamedCache (cacheName = "branchOfficeCache")
- private Cache<Long, BranchOffice> branchOfficeCache;
-
- /**
- * A list of filtered branch offices
- */
- private List<BranchOffice> filteredBranchOffices;
-
/**
* Default constructor
*/
public AddressbookBranchOfficeWebRequestBean () {
// Call super constructor
super();
-
- // Init list
- this.allBranchOffices = new LinkedList<>();
- }
-
- /**
- * Observes events being fired when a branch office has been added.
- * <p>
- * @param event Event being fired
- * <p>
- * @throws NullPointerException If the parameter or it's carried instance is
- * null
- * @throws IllegalArgumentException If the branchId is zero or lower
- */
- public void afterBranchOfficeAddedEvent (@Observes final ObservableBranchOfficeAddedEvent event) {
- // Validate parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getBranchOffice() == null) {
- // Throw NPE again
- throw new NullPointerException("event.branchOffice is null"); //NOI18N
- } else if (event.getBranchOffice().getBranchId() == null) {
- // Throw it again
- throw new NullPointerException("event.branchOffice.branchId is null"); //NOI18N
- } else if (event.getBranchOffice().getBranchId() < 1) {
- // Throw IAE
- throw new IllegalArgumentException(MessageFormat.format("event.branchOffice.branchId={0} is not valid", event.getBranchOffice().getBranchId())); //NOI18N
- }
-
- // Add instance to cache
- this.branchOfficeCache.put(event.getBranchOffice().getBranchId(), event.getBranchOffice());
- this.allBranchOffices.add(event.getBranchOffice());
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<BranchOffice> allBranchOffices () {
- return this.allBranchOffices;
- }
-
- /**
- * Getter for a list of filtered branch offices
- * <p>
- * @return Filtered branch offices
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<BranchOffice> getFilteredBranchOffices () {
- return this.filteredBranchOffices;
- }
-
- /**
- * Setter for a list of filtered branch offices
- * <p>
- * @param filteredBranchOffices Filtered branch offices
- */
- @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
- public void setFilteredBranchOffices (final List<BranchOffice> filteredBranchOffices) {
- this.filteredBranchOffices = filteredBranchOffices;
- }
-
- /**
- * Initializer method
- */
- @PostConstruct
- public void initializeList () {
- // Is cache there?
- if (!this.branchOfficeCache.iterator().hasNext()) {
- // Get whole list
- final List<BranchOffice> list = this.branchOfficeBean.allBranchOffices();
-
- // Add all
- for (final Iterator<BranchOffice> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final BranchOffice next = iterator.next();
-
- // Add it to cache
- this.branchOfficeCache.put(next.getBranchId(), next);
- }
- }
-
- // Is the list empty, but filled cache?
- if (this.allBranchOffices.isEmpty() && this.branchOfficeCache.iterator().hasNext()) {
- // Get iterator
- final Iterator<Cache.Entry<Long, BranchOffice>> iterator = this.branchOfficeCache.iterator();
-
- // Build up list
- while (iterator.hasNext()) {
- // GEt next element
- final Cache.Entry<Long, BranchOffice> next = iterator.next();
-
- // Add to list
- this.allBranchOffices.add(next.getValue());
- }
-
- // Sort list
- this.allBranchOffices.sort(new Comparator<BranchOffice>() {
- @Override
- public int compare (final BranchOffice o1, final BranchOffice o2) {
- return o1.getBranchId() > o2.getBranchId() ? 1 : o1.getBranchId() < o2.getBranchId() ? -1 : 0;
- }
- }
- );
- }
}
}
package org.mxchange.addressbook.beans.business.branchoffice;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
/**
* An interface for general branch office controller
*/
public interface AddressbookBranchOfficeWebRequestController extends Serializable {
- /**
- * Returns a list of all branch offices
- * <p>
- * @return A list of all branch offices
- */
- List<BranchOffice> allBranchOffices ();
-
}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.branchoffice.action;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+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.faces.application.FacesMessage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewController;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.events.branchoffice.added.AdminBranchOfficeAddedEvent;
+import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableAdminBranchOfficeAddedEvent;
+import org.mxchange.jcontactsbusiness.events.branchoffice.updated.AdminBranchOfficeUpdatedEvent;
+import org.mxchange.jcontactsbusiness.events.branchoffice.updated.ObservableAdminBranchOfficeUpdatedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BusinessBranchOffice;
+import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcontactsbusiness.model.utils.BranchOfficeUtils;
+import org.mxchange.jcoreee.dates.DayOfTheWeek;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An administrative bean for branch offices
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminBranchOfficeActionController")
+@RequestScoped
+public class AddressbookAdminBranchOfficeActionWebRequestBean extends BaseAddressbookBean implements AddressbookAdminBranchOfficeActionWebRequestController {
+
+ /**
+ * Opening times of this branch office
+ */
+ private static List<OpeningTime> BRANCH_OPENING_TIMES;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_471L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminBranchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.AdminBranchOfficeSessionBeanRemote")
+ private AdminBranchOfficeSessionBeanRemote adminBranchOfficeBean;
+
+ /**
+ * City
+ */
+ private String branchCity;
+
+ /**
+ * Assigned company for this branch office
+ */
+ private BasicData branchCompany;
+
+ /**
+ * Contact person in branch office
+ */
+ private Contact branchContactEmployee;
+
+ /**
+ * Country
+ */
+ private Country branchCountry;
+
+ /**
+ * Email address
+ */
+ private String branchEmailAddress;
+
+ /**
+ * House number
+ */
+ private Short branchHouseNumber;
+
+ /**
+ * House number's extension (a,b,c,...)
+ */
+ private String branchHouseNumberExtension;
+
+ /**
+ * Branch office's id number
+ */
+ private Long branchId;
+
+ /**
+ * Last house number
+ */
+ private Short branchLastHouseNumber;
+
+ /**
+ * Number of branch office
+ */
+ private Long branchNumber;
+
+ /**
+ * An event being fired when a branch office has been successfully added
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminBranchOfficeAddedEvent> branchOfficeAddedEvent;
+
+ /**
+ * A list branch office controller (backing bean)
+ */
+ @Inject
+ private AddressbookBranchOfficeListWebViewController branchOfficeListController;
+
+ /**
+ * Owner/leader of branch office
+ */
+ private Contact branchOwnerEmployee;
+
+ /**
+ * Store
+ */
+ private Short branchStore;
+
+ /**
+ * Branch office street name
+ */
+ private String branchStreet;
+
+ /**
+ * Suite number
+ */
+ private Short branchSuiteNumber;
+
+ /**
+ * Owning user instance (which this branch office is assigned to)
+ */
+ private User branchUserOwner;
+
+ /**
+ * ZIP code
+ */
+ private Integer branchZipCode;
+
+ /**
+ * Currently worked on branch office
+ */
+ private BranchOffice currentBranchOffice;
+
+ /**
+ * Area code for fax number
+ */
+ private Integer faxAreaCode;
+
+ /**
+ * Country for fax number
+ */
+ private Country faxCountry;
+
+ /**
+ * Dial number for fax number
+ */
+ private Long faxNumber;
+
+ /**
+ * Area code for land-line number
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country for land-line number
+ */
+ private Country landLineCountry;
+
+ /**
+ * Dial number for land-line number
+ */
+ private Long landLineNumber;
+
+ /**
+ * Ending week day
+ */
+ private DayOfTheWeek openingEndDay;
+
+ /**
+ * Ending time
+ */
+ private Date openingEndTime;
+
+ /**
+ * Starting week day
+ */
+ private DayOfTheWeek openingStartDay;
+
+ /**
+ * Starting time
+ */
+ private Date openingStartTime;
+
+ /**
+ * Event being fired when an administrator has updated a branch office
+ */
+ @Any
+ @Inject
+ private Event<ObservableAdminBranchOfficeUpdatedEvent> updatedBranchOfficeEvent;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminBranchOfficeActionWebRequestBean () {
+ // Call super constructor
+ super();
+
+ // Is the opening times list there?
+ if (null == BRANCH_OPENING_TIMES) {
+ // Init list
+ BRANCH_OPENING_TIMES = new ArrayList<>(1);
+ }
+ }
+
+ /**
+ * Adds branch office with all data from this backing bean. First this
+ * action method will validate if the branch office's address is already
+ * registered and if found, it will output a proper faces message.
+ */
+ public void addBranchOffice () {
+ // Get instance
+ final BranchOffice branchOffice = this.createBranchOffice();
+
+ // Is the branch office not created yet?
+ if (this.isBranchOfficeCreatedBySameAddress(branchOffice)) {
+ // Then show proper faces message
+ this.showFacesMessage("form-admin-add-branch-office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Delcare updated instance
+ final BranchOffice updatedOffice;
+
+ try {
+ // Try to call EJB
+ updatedOffice = this.adminBranchOfficeBean.addBranchOffice(branchOffice);
+ } catch (final BranchOfficeAlreadyAddedException ex) {
+ // Output message
+ this.showFacesMessage("form-admin-add-branch-office:branchStreet", "ADMIN_BRANCH_OFFICE_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
+ return;
+ }
+
+ // Fire event
+ this.branchOfficeAddedEvent.fire(new AdminBranchOfficeAddedEvent(updatedOffice));
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Adds opening time to temporary list which will be sent along with the
+ * branch office data to the EJB.
+ */
+ public void addOpeningTime () {
+ // Validate all required fields
+ if (this.getOpeningEndDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndDay is null"); //NOI18N
+ } else if (this.getOpeningEndTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndTime is null"); //NOI18N
+ } else if (this.getOpeningStartDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartDay is null"); //NOI18N
+ } else if (this.getOpeningStartTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartTime is null"); //NOI18N
+ }
+
+ // Get opening time instance
+ final OpeningTime openingTime = this.createOpeningTimes();
+
+ // Is same found?
+ if (this.isOpeningTimeFound(openingTime)) {
+ // Yes then abort here
+ this.showFacesMessage("form-admin-add-branch-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Add to temporary list
+ getBranchOpeningTimes().add(openingTime);
+
+ // Clear opening time fields
+ this.clearOpeningTime();
+ }
+
+ /**
+ * Copies all current branch office's properties back to this bean.
+ */
+ public void copyAllBranchOfficeProperties () {
+ // Validate current product instance
+ if (this.getCurrentBranchOffice() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.product is null"); //NOI18N
+ } else if (this.getCurrentBranchOffice().getBranchId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.product.branchId is null"); //NOI18N
+ } else if (this.getCurrentBranchOffice().getBranchId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.product.branchId={0} is not valid.", this.getCurrentBranchOffice().getBranchId())); //NOI18N
+ }
+
+ // Now copy all fields
+ this.setBranchCity(this.getCurrentBranchOffice().getBranchCity());
+ this.setBranchCompany(this.getCurrentBranchOffice().getBranchCompany());
+ this.setBranchContactEmployee(this.getCurrentBranchOffice().getBranchContactEmployee());
+ this.setBranchCountry(this.getCurrentBranchOffice().getBranchCountry());
+ this.setBranchEmailAddress(this.getCurrentBranchOffice().getBranchEmailAddress());
+ this.setBranchHouseNumber(this.getCurrentBranchOffice().getBranchHouseNumber());
+ this.setBranchHouseNumberExtension(this.getCurrentBranchOffice().getBranchHouseNumberExtension());
+ this.setBranchId(this.getCurrentBranchOffice().getBranchId());
+ this.setBranchLastHouseNumber(this.getCurrentBranchOffice().getBranchLastHouseNumber());
+ this.setBranchNumber(this.getCurrentBranchOffice().getBranchNumber());
+ this.setBranchOpeningTimes(this.getCurrentBranchOffice().getBranchOpeningTimes());
+ this.setBranchOwnerEmployee(this.getCurrentBranchOffice().getBranchOwnerEmployee());
+ this.setBranchStore(this.getCurrentBranchOffice().getBranchStore());
+ this.setBranchStreet(this.getCurrentBranchOffice().getBranchStreet());
+ this.setBranchSuiteNumber(this.getCurrentBranchOffice().getBranchSuiteNumber());
+ this.setBranchUserOwner(this.getCurrentBranchOffice().getBranchUserOwner());
+ this.setBranchZipCode(this.getCurrentBranchOffice().getBranchZipCode());
+ }
+
+ /**
+ * Getter for city
+ * <p>
+ * @return City
+ */
+ public String getBranchCity () {
+ return this.branchCity;
+ }
+
+ /**
+ * Setter for city
+ * <p>
+ * @param branchCity City
+ */
+ public void setBranchCity (final String branchCity) {
+ this.branchCity = branchCity;
+ }
+
+ /**
+ * Getter for basic company data
+ * <p>
+ * @return Basic company data
+ */
+ public BasicData getBranchCompany () {
+ return this.branchCompany;
+ }
+
+ /**
+ * Setter for basic company data
+ * <p>
+ * @param branchCompany Basic company data
+ */
+ public void setBranchCompany (final BasicData branchCompany) {
+ this.branchCompany = branchCompany;
+ }
+
+ /**
+ * Getter for branch office contact person
+ * <p>
+ * @return Branch office contact person
+ */
+ public Contact getBranchContactEmployee () {
+ return this.branchContactEmployee;
+ }
+
+ /**
+ * Setter for branch office contact person
+ * <p>
+ * @param branchContactEmployee Branch office contact person
+ */
+ public void setBranchContactEmployee (final Contact branchContactEmployee) {
+ this.branchContactEmployee = branchContactEmployee;
+ }
+
+ /**
+ * Getter for country
+ * <p>
+ * @return Country
+ */
+ public Country getBranchCountry () {
+ return this.branchCountry;
+ }
+
+ /**
+ * Setter for country
+ * <p>
+ * @param branchCountry Country
+ */
+ public void setBranchCountry (final Country branchCountry) {
+ this.branchCountry = branchCountry;
+ }
+
+ /**
+ * Getter for email address
+ * <p>
+ * @return Email address
+ */
+ public String getBranchEmailAddress () {
+ return this.branchEmailAddress;
+ }
+
+ /**
+ * Getter for email address
+ * <p>
+ * @param branchEmailAddress Email address
+ */
+ public void setBranchEmailAddress (final String branchEmailAddress) {
+ this.branchEmailAddress = branchEmailAddress;
+ }
+
+ /**
+ * Getter for house number
+ * <p>
+ * @return House number
+ */
+ public Short getBranchHouseNumber () {
+ return this.branchHouseNumber;
+ }
+
+ /**
+ * Setter for house number
+ * <p>
+ * @param branchHouseNumber House number
+ */
+ public void setBranchHouseNumber (final Short branchHouseNumber) {
+ this.branchHouseNumber = branchHouseNumber;
+ }
+
+ /**
+ * Getter for house number's extension
+ * <p>
+ * @return House number's extension
+ */
+ public String getBranchHouseNumberExtension () {
+ return this.branchHouseNumberExtension;
+ }
+
+ /**
+ * Setter for house number's extension
+ * <p>
+ * @param branchHouseNumberExtension House number's extension
+ */
+ public void setBranchHouseNumberExtension (final String branchHouseNumberExtension) {
+ this.branchHouseNumberExtension = branchHouseNumberExtension;
+ }
+
+ /**
+ * Getter for branch office's id number
+ * <p>
+ * @return Branch office's id number
+ */
+ public Long getBranchId () {
+ return this.branchId;
+ }
+
+ /**
+ * Setter for branch office's id number
+ * <p>
+ * @param branchId Branch office's id number
+ */
+ public void setBranchId (final Long branchId) {
+ this.branchId = branchId;
+ }
+
+ /**
+ * Getter for last house number
+ * <p>
+ * @return Last house number
+ */
+ public Short getBranchLastHouseNumber () {
+ return this.branchLastHouseNumber;
+ }
+
+ /**
+ * Setter for last house number
+ * <p>
+ * @param branchLastHouseNumber Last house number
+ */
+ public void setBranchLastHouseNumber (final Short branchLastHouseNumber) {
+ this.branchLastHouseNumber = branchLastHouseNumber;
+ }
+
+ /**
+ * Getter for branch office number
+ * <p>
+ * @return Branch office number
+ */
+ public Long getBranchNumber () {
+ return this.branchNumber;
+ }
+
+ /**
+ * Setter for branch office number
+ * <p>
+ * @param branchNumber Branch office number
+ */
+ public void setBranchNumber (final Long branchNumber) {
+ this.branchNumber = branchNumber;
+ }
+
+ /**
+ * Getter for opening times of this branch office
+ * <p>
+ * @return Opening times
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<OpeningTime> getBranchOpeningTimes () {
+ return BRANCH_OPENING_TIMES;
+ }
+
+ /**
+ * Setter for opening times of this branch office
+ * <p>
+ * @param branchOpeningTimes Opening times
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setBranchOpeningTimes (final List<OpeningTime> branchOpeningTimes) {
+ BRANCH_OPENING_TIMES = branchOpeningTimes;
+ }
+
+ /**
+ * Getter for branch office contact person
+ * <p>
+ * @return Branch office contact person
+ */
+ public Contact getBranchOwnerEmployee () {
+ return this.branchOwnerEmployee;
+ }
+
+ /**
+ * Setter for branch office contact person
+ * <p>
+ * @param branchOwnerEmployee Branch office contact person
+ */
+ public void setBranchOwnerEmployee (final Contact branchOwnerEmployee) {
+ this.branchOwnerEmployee = branchOwnerEmployee;
+ }
+
+ /**
+ * Getter for store
+ * <p>
+ * @return Store
+ */
+ public Short getBranchStore () {
+ return this.branchStore;
+ }
+
+ /**
+ * Setter for store
+ * <p>
+ * @param branchStore Store
+ */
+ public void setBranchStore (final Short branchStore) {
+ this.branchStore = branchStore;
+ }
+
+ /**
+ * Getter for street name
+ * <p>
+ * @return Street name
+ */
+ public String getBranchStreet () {
+ return this.branchStreet;
+ }
+
+ /**
+ * Setter for street name
+ * <p>
+ * @param branchStreet Street name
+ */
+ public void setBranchStreet (final String branchStreet) {
+ this.branchStreet = branchStreet;
+ }
+
+ /**
+ * Getter for suite number
+ * <p>
+ * @return Suite number
+ */
+ public Short getBranchSuiteNumber () {
+ return this.branchSuiteNumber;
+ }
+
+ /**
+ * Setter for suite number
+ * <p>
+ * @param branchSuiteNumber Suite number
+ */
+ public void setBranchSuiteNumber (final Short branchSuiteNumber) {
+ this.branchSuiteNumber = branchSuiteNumber;
+ }
+
+ /**
+ * Getter for owning user instance
+ * <p>
+ * @return Owning user instance
+ */
+ public User getBranchUserOwner () {
+ return this.branchUserOwner;
+ }
+
+ /**
+ * Setter for owning user instance
+ * <p>
+ * @param branchUserOwner Owning user instance
+ */
+ public void setBranchUserOwner (final User branchUserOwner) {
+ this.branchUserOwner = branchUserOwner;
+ }
+
+ /**
+ * Getter for ZIP code\
+ * <p>
+ * @return ZIP code
+ */
+ public Integer getBranchZipCode () {
+ return this.branchZipCode;
+ }
+
+ /**
+ * Setter for ZIP code\
+ * <p>
+ * @param branchZipCode ZIP code
+ */
+ public void setBranchZipCode (final Integer branchZipCode) {
+ this.branchZipCode = branchZipCode;
+ }
+
+ /**
+ * Getter for current branch office
+ * <p>
+ * @return Current branch office
+ */
+ public BranchOffice getCurrentBranchOffice () {
+ return this.currentBranchOffice;
+ }
+
+ /**
+ * Setter for current branch office
+ * <p>
+ * @param currentBranchOffice Current branch office
+ */
+ public void setCurrentBranchOffice (final BranchOffice currentBranchOffice) {
+ this.currentBranchOffice = currentBranchOffice;
+ }
+
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
+ public Integer getFaxAreaCode () {
+ return this.faxAreaCode;
+ }
+
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
+ public void setFaxAreaCode (final Integer faxAreaCode) {
+ this.faxAreaCode = faxAreaCode;
+ }
+
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
+ public Country getFaxCountry () {
+ return this.faxCountry;
+ }
+
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
+ public void setFaxCountry (final Country faxCountry) {
+ this.faxCountry = faxCountry;
+ }
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ public Long getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Getter for ending week day
+ * <p>
+ * @return Ending week day
+ */
+ public DayOfTheWeek getOpeningEndDay () {
+ return this.openingEndDay;
+ }
+
+ /**
+ * Setter for ending week day
+ * <p>
+ * @param openingEndDay Ending week day
+ */
+ public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
+ this.openingEndDay = openingEndDay;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @return Ending time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningEndTime () {
+ return this.openingEndTime;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @param openingEndTime Ending time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningEndTime (final Date openingEndTime) {
+ this.openingEndTime = openingEndTime;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @return Starting week day
+ */
+ public DayOfTheWeek getOpeningStartDay () {
+ return this.openingStartDay;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @param openingStartDay Starting week day
+ */
+ public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
+ this.openingStartDay = openingStartDay;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @return Starting time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningStartTime () {
+ return this.openingStartTime;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @param openingStartTime Starting time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningStartTime (final Date openingStartTime) {
+ this.openingStartTime = openingStartTime;
+ }
+
+ /**
+ * Updates currently worked on branch office data
+ * <p>
+ * @return Redirection outcome
+ */
+ public String updateBranchOffice () {
+ // Validate current product instance and id
+ if (this.getCurrentBranchOffice() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.product is null"); //NOI18N
+ } else if (this.getCurrentBranchOffice().getBranchId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.product.branchId is null"); //NOI18N
+ } else if (this.getCurrentBranchOffice().getBranchId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.product.branchId={0} is not valid.", this.getCurrentBranchOffice().getBranchId())); //NOI18N
+ } else if (this.getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.branchId is null"); //NOI18N
+ } else if (this.getBranchId() < 1) {
+ // Throw ISE
+ throw new IllegalStateException(MessageFormat.format("this.branchId={0} is not valid.", this.getBranchId())); //NOI18N
+ }
+
+ // Init instance with fresh data
+ final BranchOffice branchOffice = this.createBranchOffice();
+
+ // Does current (not updated) and just created (maybe updated) match?
+ if (Objects.equals(this.getCurrentBranchOffice(), branchOffice)) {
+ // Yes, then output message
+ this.showFacesMessage("form-admin-edit-branch-office:branchCompany", "ADMIN_BRANCH_OFFICE_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N
+
+ // Skip below code
+ return ""; //NOI18N
+ }
+
+ // Initialize updated instance
+ final BranchOffice updatedBranchOffice;
+
+ // Try it
+ try {
+ // Invoke EJB
+ updatedBranchOffice = this.adminBranchOfficeBean.updateBranchOffice(branchOffice);
+ } catch (final BranchOfficeNotFoundException ex) {
+ // Throw as a cause
+ throw new FacesException(ex);
+ }
+
+ // Fire event
+ this.updatedBranchOfficeEvent.fire(new AdminBranchOfficeUpdatedEvent(updatedBranchOffice));
+
+ // Redirect to list view
+ return "admin_list_branch_offices"; //NOI18N
+ }
+
+ /**
+ * Clears this bean data
+ */
+ private void clear () {
+ // Clear all branch office data
+ this.setBranchCity(null);
+ this.setBranchCompany(null);
+ this.setBranchContactEmployee(null);
+ this.setBranchCountry(null);
+ this.setBranchEmailAddress(null);
+ this.setBranchHouseNumber(null);
+ this.setBranchHouseNumberExtension(null);
+ this.setBranchLastHouseNumber(null);
+ this.setBranchNumber(null);
+ this.setBranchOwnerEmployee(null);
+ this.setBranchStore(null);
+ this.setBranchStreet(null);
+ this.setBranchSuiteNumber(null);
+ this.setBranchUserOwner(null);
+ this.setBranchZipCode(null);
+
+ // Opening times list
+ this.setBranchOpeningTimes(new ArrayList<OpeningTime>(1));
+
+ // Fax and land-line number
+ this.setFaxAreaCode(null);
+ this.setFaxCountry(null);
+ this.setFaxNumber(null);
+ this.setLandLineAreaCode(null);
+ this.setLandLineCountry(null);
+ this.setLandLineNumber(null);
+
+ // Extra-clear opening time
+ this.clearOpeningTime();
+ }
+
+ /**
+ * Clears all opening time fields
+ */
+ private void clearOpeningTime () {
+ // Clear all opening time fields
+ this.setOpeningEndDay(null);
+ this.setOpeningEndTime(null);
+ this.setOpeningStartDay(null);
+ this.setOpeningStartTime(null);
+ }
+
+ /**
+ * Prepares an instance of a BranchOffice object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a BranchOffice class (entity)
+ */
+ private BranchOffice createBranchOffice () {
+ // Create new branch office instance
+ final BranchOffice branchOffice = new BusinessBranchOffice(
+ this.getBranchCity(),
+ this.getBranchCompany(),
+ this.getBranchCountry(),
+ this.getBranchStreet(),
+ this.getBranchZipCode(),
+ this.getBranchHouseNumber()
+ );
+
+ // Add all other fields, too
+ branchOffice.setBranchId(this.getBranchId());
+ branchOffice.setBranchContactEmployee(this.getBranchContactEmployee());
+ branchOffice.setBranchEmailAddress(this.getBranchEmailAddress());
+ branchOffice.setBranchHouseNumberExtension(this.getBranchHouseNumberExtension());
+ branchOffice.setBranchLastHouseNumber(this.getBranchLastHouseNumber());
+ branchOffice.setBranchNumber(this.getBranchNumber());
+ branchOffice.setBranchOwnerEmployee(this.getBranchOwnerEmployee());
+ branchOffice.setBranchStore(this.getBranchStore());
+ branchOffice.setBranchSuiteNumber(this.getBranchSuiteNumber());
+ branchOffice.setBranchUserOwner(this.getBranchUserOwner());
+
+ // Init variables
+ DialableLandLineNumber landLine = null;
+ DialableFaxNumber fax = null;
+
+ // Are all required fields set?
+ if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+ // Initialize land-line instance
+ landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ }
+
+ // Are all required fields set?
+ if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+ // Initialize fax instance
+ fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ }
+
+ // Don't set null or wrong references
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (landLine.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (landLine.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (landLine.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set phone number
+ branchOffice.setBranchLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+ } else if (fax.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ } else if (fax.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+ } else if (fax.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set fax number
+ branchOffice.setBranchFaxNumber(fax);
+ }
+ // Is the opening times list filled?
+ if (!this.getBranchOpeningTimes().isEmpty()) {
+ // Yes, then set in branch office, too
+ branchOffice.setBranchOpeningTimes(this.getBranchOpeningTimes());
+ }
+
+ // Return fully prepared instance
+ return branchOffice;
+ }
+
+ /**
+ * Prepares an instance of a OpeningTimes object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a OpeningTimes class (entity)
+ */
+ private OpeningTime createOpeningTimes () {
+ // Create new openingTime instance
+ final OpeningTime openingTime = new BusinessOpeningTime(
+ this.getOpeningEndDay(),
+ this.getOpeningEndTime(),
+ this.getOpeningStartDay(),
+ this.getOpeningStartTime()
+ );
+
+ // Return fully prepared instance
+ return openingTime;
+ }
+
+ /**
+ * Checks whether the given branch office's address is already found in
+ * local cache. Please note that this method fully relies on the cache, so
+ * you must always fire proper events that add/update/delete entries in
+ * cache.
+ * <p>
+ * @param branchOffice Branch office to check it's address
+ * <p>
+ * @return Whether the address has been found
+ */
+ private boolean isBranchOfficeCreatedBySameAddress (final BranchOffice branchOffice) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Now check each entry
+ for (final BranchOffice bo : this.branchOfficeListController.getAllBranchOffices()) {
+ // Is same address?
+ if (BranchOfficeUtils.isSameAddress(bo, branchOffice)) {
+ // Found one
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ /**
+ * Checks if given opening time is already added
+ * <p>
+ * @param openingTime Opening time to be checked
+ * <p>
+ * @return Whether it has been added already
+ */
+ private boolean isOpeningTimeFound (final OpeningTime openingTime) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Loop through list
+ for (final OpeningTime ot : this.getBranchOpeningTimes()) {
+ // Check it
+ if (Objects.equals(ot, openingTime)) {
+ // Found same match
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return it
+ return isFound;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.branchoffice.action;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative branch office controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminBranchOfficeActionWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.branchoffice.list;
+
+import fish.payara.cdi.jsr107.impl.NamedCache;
+import java.text.MessageFormat;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.cache.Cache;
+import javax.ejb.EJB;
+import javax.enterprise.event.Observes;
+import javax.faces.view.ViewScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontactsbusiness.events.branchoffice.added.ObservableAdminBranchOfficeAddedEvent;
+import org.mxchange.jcontactsbusiness.events.branchoffice.updated.ObservableAdminBranchOfficeUpdatedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
+
+/**
+ * A list bean for branch offices
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("branchOfficeListController")
+@ViewScoped
+public class AddressbookBranchOfficeListWebViewBean extends BaseAddressbookBean implements AddressbookBranchOfficeListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_468L;
+
+ /**
+ * A list of all branch offices
+ */
+ private final List<BranchOffice> allBranchOffices;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote")
+ private BranchOfficeSessionBeanRemote branchOfficeBean;
+
+ /**
+ * A list of all branch offices (globally)
+ */
+ @Inject
+ @NamedCache (cacheName = "branchOfficeCache")
+ private transient Cache<Long, BranchOffice> branchOfficeCache;
+
+ /**
+ * A list of filtered branch offices
+ */
+ private List<BranchOffice> filteredBranchOffices;
+
+ /**
+ * Selected branch office instance
+ */
+ private BranchOffice selectedBranchOffice;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookBranchOfficeListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allBranchOffices = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when a branch office has been added by an
+ * administrator.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminBranchOfficeAddedEvent (@Observes final ObservableAdminBranchOfficeAddedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedBranchOffice() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addedBranchOffice is null"); //NOI18N
+ } else if (event.getAddedBranchOffice().getBranchId() == null) {
+ // Throw it again
+ throw new NullPointerException("event.addedBranchOffice .branchId is null"); //NOI18N
+ } else if (event.getAddedBranchOffice().getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.addedBranchOffice .branchId={0} is not valid", event.getAddedBranchOffice().getBranchId())); //NOI18N
+ }
+
+ // Uniquely add branch office
+ this.uniqueAddBranchOffice(event.getAddedBranchOffice());
+ }
+
+ /**
+ * Observes events being fired when a branch office has been updated by an
+ * administrator.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminBranchOfficeUpdatedEvent (@Observes final ObservableAdminBranchOfficeUpdatedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedBranchOffice() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedBranchOffice is null"); //NOI18N
+ } else if (event.getUpdatedBranchOffice().getBranchId() == null) {
+ // Throw it again
+ throw new NullPointerException("event.updatedBranchOffice .branchId is null"); //NOI18N
+ } else if (event.getUpdatedBranchOffice().getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.updatedBranchOffice .branchId={0} is not valid", event.getUpdatedBranchOffice().getBranchId())); //NOI18N
+ }
+
+ // Uniquely update branch office
+ this.uniqueAddBranchOffice(event.getUpdatedBranchOffice());
+ }
+
+ @Override
+ public BranchOffice findBranchOfficeById (final Long branchId) throws BranchOfficeNotFoundException {
+ // Validate parameter
+ if (null == branchId) {
+ // Throw NPE
+ throw new NullPointerException("branchId is null"); //NOI18N
+ } else if (branchId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("branchId={0} is invalid", branchId)); //NOI18N
+ } else if (!this.branchOfficeCache.containsKey(branchId)) {
+ // Not found
+ throw new BranchOfficeNotFoundException(branchId);
+ }
+
+ // Get it from cache
+ final BranchOffice branchOffice = this.branchOfficeCache.get(branchId);
+
+ // Return it
+ return branchOffice;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BranchOffice> getAllBranchOffices () {
+ return this.allBranchOffices;
+ }
+
+ /**
+ * Getter for a list of filtered branch offices
+ * <p>
+ * @return Filtered branch offices
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<BranchOffice> getFilteredBranchOffices () {
+ return this.filteredBranchOffices;
+ }
+
+ /**
+ * Setter for a list of filtered branch offices
+ * <p>
+ * @param filteredBranchOffices Filtered branch offices
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredBranchOffices (final List<BranchOffice> filteredBranchOffices) {
+ this.filteredBranchOffices = filteredBranchOffices;
+ }
+
+ /**
+ * Getter for selected branch office
+ * <p>
+ * @return Selected branch office
+ */
+ public BranchOffice getSelectedBranchOffice () {
+ return this.selectedBranchOffice;
+ }
+
+ /**
+ * Setter for selected branch office
+ * <p>
+ * @param selectedBranchOffice Selected branch office
+ */
+ public void setSelectedBranchOffice (final BranchOffice selectedBranchOffice) {
+ this.selectedBranchOffice = selectedBranchOffice;
+ }
+
+ /**
+ * Initializer method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.branchOfficeCache.iterator().hasNext()) {
+ // Add all
+ for (final BranchOffice branchOffice : this.branchOfficeBean.fetchAllBranchOffices()) {
+ // Add it to cache
+ this.branchOfficeCache.put(branchOffice.getBranchId(), branchOffice);
+ }
+ }
+
+ // Is the list empty, but filled cache?
+ if (this.getAllBranchOffices().isEmpty() && this.branchOfficeCache.iterator().hasNext()) {
+ // Build up list
+ for (final Cache.Entry<Long, BranchOffice> currentEntry : this.branchOfficeCache) {
+ // Add to list
+ this.getAllBranchOffices().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllBranchOffices().sort(new Comparator<BranchOffice>() {
+ @Override
+ public int compare (final BranchOffice branchOffice1, final BranchOffice branchOffice2) {
+ return branchOffice1.getBranchId() > branchOffice2.getBranchId() ? 1 : branchOffice1.getBranchId() < branchOffice2.getBranchId() ? -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 BranchOffice branchOffice : this.getAllBranchOffices()) {
+ // Is email address used?
+ if (Objects.equals(branchOffice.getBranchEmailAddress(), emailAddress)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ /**
+ * Uniquely add branch office instance to allBranchOffices property
+ * <p>
+ * @param branchOffice Branch office being added
+ */
+ private void uniqueAddBranchOffice (final BranchOffice branchOffice) {
+ // Add instance to cache
+ this.branchOfficeCache.put(branchOffice.getBranchId(), branchOffice);
+
+ // Get iterator
+ final Iterator<BranchOffice> iterator = this.getAllBranchOffices().iterator();
+
+ // Iterate over all
+ while (iterator.hasNext()) {
+ // Get current element
+ final BranchOffice currentBranchOffice = iterator.next();
+
+ // Does primary key match?
+ if (Objects.equals(branchOffice.getBranchId(), currentBranchOffice.getBranchId())) {
+ // Yes then remove this one
+ iterator.remove();
+
+ // Re-add maybe updated version
+ this.getAllBranchOffices().add(branchOffice);
+
+ // Stop iteration
+ break;
+ }
+ }
+ }
+
+ @Override
+ protected Object clone () throws CloneNotSupportedException {
+ return super.clone(); //To change body of generated methods, choose Tools | Templates.
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.branchoffice.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+
+/**
+ * An interface for general branch office controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookBranchOfficeListWebViewController extends Serializable {
+
+ /**
+ * Checks if given email address is already registered by an other branch
+ * office
+ * <p>
+ * @param emailAddress Email address
+ * <p>
+ * @return Whether the email address has been already registered
+ */
+ Boolean isEmailAddressRegistered (final String emailAddress);
+
+ /**
+ * Returns a list of all branch offices
+ * <p>
+ * @return A list of all branch offices
+ */
+ List<BranchOffice> getAllBranchOffices ();
+
+ /**
+ * Tries to find a branch office with given id number
+ * <p>
+ * @param branchId Branch office id
+ * <p>
+ * @return A branch office instance
+ * <p>
+ * @throws BranchOfficeNotFoundException If the branch office was not found
+ */
+ BranchOffice findBranchOfficeById (final Long branchId) throws BranchOfficeNotFoundException;
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * An administrative bean for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminDepartmentController")
+@RequestScoped
+public class AddressbookAdminDepartmentWebRequestBean extends BaseAddressbookBean implements AddressbookAdminDepartmentWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_464L;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminDepartmentWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative department controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminDepartmentWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote;
+
+/**
+ * A general bean for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("departmentController")
+@RequestScoped
+public class AddressbookDepartmentWebRequestBean extends BaseAddressbookBean implements AddressbookDepartmentWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_461L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/department!org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote")
+ private DepartmentSessionBeanRemote departmentBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookDepartmentWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department;
+
+import java.io.Serializable;
+
+/**
+ * An interface for general department controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookDepartmentWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department.action;
+
+import java.text.MessageFormat;
+import java.util.Objects;
+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.faces.application.FacesMessage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.business.department.list.AddressbookDepartmentListWebViewController;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.events.department.added.AdminDepartmentAddedEvent;
+import org.mxchange.jcontactsbusiness.events.department.added.ObservableAdminDepartmentAddedEvent;
+import org.mxchange.jcontactsbusiness.events.department.updated.AdminDepartmentUpdatedEvent;
+import org.mxchange.jcontactsbusiness.events.department.updated.ObservableAdminDepartmentUpdatedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.department.AdminDepartmentSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.department.BusinessDepartment;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An administrative action bean for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminDepartmentActionController")
+@RequestScoped
+public class AddressbookAdminDepartmentActionWebRequestBean extends BaseAddressbookBean implements AddressbookAdminDepartmentActionWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_473L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminDepartment!org.mxchange.jcontactsbusiness.model.department.AdminDepartmentSessionBeanRemote")
+ private AdminDepartmentSessionBeanRemote adminDepartmentBean;
+
+ /**
+ * Currently worked on department
+ */
+ private Department currentDepartment;
+
+ /**
+ * An event being fired when a department has been successfully added
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminDepartmentAddedEvent> departmentAddedEvent;
+
+ /**
+ * Assigned branch office (if apply-able)
+ */
+ private BranchOffice departmentBranchOffice;
+
+ /**
+ * Assigned company for this department
+ */
+ private BasicData departmentCompany;
+
+ /**
+ * Assigned headquarter (if apply-able)
+ */
+ private Headquarter departmentHeadquarter;
+
+ /**
+ * Department name
+ */
+ private String departmentI18nKey;
+
+ /**
+ * Primary key of department
+ */
+ private Long departmentId;
+
+ /**
+ * Lead person of this department
+ */
+ private Contact departmentLead;
+
+ /**
+ * A general department controller (backing bean)
+ */
+ @Inject
+ private AddressbookDepartmentListWebViewController departmentListController;
+
+ /**
+ * Owning user instance (which this department is assigned to)
+ */
+ private User departmentUserOwner;
+
+ /**
+ * Event being fired when a department has been updated
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminDepartmentUpdatedEvent> updatedDepartmentEvent;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminDepartmentActionWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Adds department with all data from this backing bean. First this action
+ * method will validate if the department's address is already registered
+ * and if found, it will output a proper faces message.
+ */
+ public void addDepartment () {
+ // Get instance
+ final Department department = this.createDepartment();
+
+ // Is the department not created yet?
+ if (this.departmentListController.isDepartmentAlreadyAdded(department)) {
+ // Then show proper faces message
+ this.showFacesMessage("form-admin-add-department:branchStreet", "ADMIN_DEPARTMENT_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Delcare updated instance
+ final Department updatedDepartment;
+
+ try {
+ // Try to call EJB
+ updatedDepartment = this.adminDepartmentBean.addDepartment(department);
+ } catch (final DepartmentAlreadyAddedException ex) {
+ // Output message
+ this.showFacesMessage("form-admin-add-department:departmentI18nKey", "ADMIN_DEPARTMENT_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
+ return;
+ }
+
+ // Fire event
+ this.departmentAddedEvent.fire(new AdminDepartmentAddedEvent(updatedDepartment));
+ }
+
+ /**
+ * Copies all properties from current department to this bean.
+ */
+ public void copyAllDepartmentProperties () {
+ // Is current department set?
+ if (this.getCurrentDepartment() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.currentDepartment is null"); //NOI18N
+ } else if (this.getCurrentDepartment().getDepartmentId() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.currentDepartment.departmentId is null"); //NOI18N
+ } else if (this.getCurrentDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("this.currentDepartment.departmentId={0} is not valid", this.getCurrentDepartment().getDepartmentId())); //NOI18N
+ }
+
+ // Copy all fields
+ this.setDepartmentBranchOffice(this.getCurrentDepartment().getDepartmentBranchOffice());
+ this.setDepartmentCompany(this.getCurrentDepartment().getDepartmentCompany());
+ this.setDepartmentHeadquarter(this.getCurrentDepartment().getDepartmentHeadquarter());
+ this.setDepartmentI18nKey(this.getCurrentDepartment().getDepartmentI18nKey());
+ this.setDepartmentId(this.getCurrentDepartment().getDepartmentId());
+ this.setDepartmentLead(this.getCurrentDepartment().getDepartmentLead());
+ this.setDepartmentUserOwner(this.getCurrentDepartment().getDepartmentUserOwner());
+ }
+
+ /**
+ * Getter for current department
+ * <p>
+ * @return Current department
+ */
+ public Department getCurrentDepartment () {
+ return this.currentDepartment;
+ }
+
+ /**
+ * Setter for current department
+ * <p>
+ * @param currentDepartment Current department
+ */
+ public void setCurrentDepartment (final Department currentDepartment) {
+ this.currentDepartment = currentDepartment;
+ }
+
+ /**
+ * Getter for assigned branch office
+ * <p>
+ * @return Branch office
+ */
+ public BranchOffice getDepartmentBranchOffice () {
+ return this.departmentBranchOffice;
+ }
+
+ /**
+ * Setter for assigned branch office
+ * <p>
+ * @param departmentDepartment Branch office
+ */
+ public void setDepartmentBranchOffice (final BranchOffice departmentDepartment) {
+ this.departmentBranchOffice = departmentDepartment;
+ }
+
+ /**
+ * Getter for basic company data
+ * <p>
+ * @return Basic company data
+ */
+ public BasicData getDepartmentCompany () {
+ return this.departmentCompany;
+ }
+
+ /**
+ * Setter for basic company data
+ * <p>
+ * @param departmentCompany Basic company data
+ */
+ public void setDepartmentCompany (final BasicData departmentCompany) {
+ this.departmentCompany = departmentCompany;
+ }
+
+ /**
+ * Getter for assigned headquarter data
+ * <p>
+ * @return Headquarter data
+ */
+ public Headquarter getDepartmentHeadquarter () {
+ return this.departmentHeadquarter;
+ }
+
+ /**
+ * Setter for assigned headquarter data
+ * <p>
+ * @param departmentHeadquarter Headquarter data
+ */
+ public void setDepartmentHeadquarter (final Headquarter departmentHeadquarter) {
+ this.departmentHeadquarter = departmentHeadquarter;
+ }
+
+ /**
+ * Getter for department name
+ * <p>
+ * @return Department name
+ */
+ public String getDepartmentI18nKey () {
+ return this.departmentI18nKey;
+ }
+
+ /**
+ * Setter for department name
+ * <p>
+ * @param departmentI18nKey Department name
+ */
+ public void setDepartmentI18nKey (final String departmentI18nKey) {
+ this.departmentI18nKey = departmentI18nKey;
+ }
+
+ /**
+ * Getter for primary key
+ * <p>
+ * @return Primary key
+ */
+ public Long getDepartmentId () {
+ return this.departmentId;
+ }
+
+ /**
+ * Setter for primary key
+ * <p>
+ * @param departmentId Primary key
+ */
+ public void setDepartmentId (final Long departmentId) {
+ this.departmentId = departmentId;
+ }
+
+ /**
+ * Getter for department contact person
+ * <p>
+ * @return Department contact person
+ */
+ public Contact getDepartmentLead () {
+ return this.departmentLead;
+ }
+
+ /**
+ * Setter for department contact person
+ * <p>
+ * @param departmentLead Department contact person
+ */
+ public void setDepartmentLead (final Contact departmentLead) {
+ this.departmentLead = departmentLead;
+ }
+
+ /**
+ * Getter for owning user instance
+ * <p>
+ * @return Owning user instance
+ */
+ public User getDepartmentUserOwner () {
+ return this.departmentUserOwner;
+ }
+
+ /**
+ * Setter for owning user instance
+ * <p>
+ * @param departmentUserOwner Owning user instance
+ */
+ public void setDepartmentUserOwner (final User departmentUserOwner) {
+ this.departmentUserOwner = departmentUserOwner;
+ }
+
+ /**
+ * Updates department record with data from this bean.
+ * <p>
+ * @return Redirection outcome
+ */
+ public String updateDepartment () {
+ // Is current department set?
+ if (this.getCurrentDepartment() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.currentDepartment is null"); //NOI18N
+ } else if (this.getCurrentDepartment().getDepartmentId() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.currentDepartment.departmentId is null"); //NOI18N
+ } else if (this.getCurrentDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("this.currentDepartment.departmentId={0} is not valid", this.getCurrentDepartment().getDepartmentId())); //NOI18N
+ }
+
+ // Init instance with current data
+ final Department department = this.createDepartment();
+
+ // Does current (not updated) and just created (maybe updated) match?
+ if (Objects.equals(this.getCurrentDepartment(), department)) {
+ // Yes, then output message
+ this.showFacesMessage("form-admin-edit-department:departmentI18nKey", "ADMIN_DEPARTMENT_NOT_UPDATED", FacesMessage.SEVERITY_WARN); //NOI18N
+
+ // Skip below code
+ return ""; //NOI18N
+ }
+
+ // Copy all fields
+ DepartmentUtils.copyDepartmentData(department, this.getCurrentDepartment());
+
+ // Initialize updated instance
+ final Department updatedDepartment;
+
+ // Try it
+ try {
+ // Invoke EJB
+ updatedDepartment = this.adminDepartmentBean.updateDepartment(this.getCurrentDepartment());
+ } catch (final DepartmentNotFoundException ex) {
+ // Throw as a cause
+ throw new FacesException(ex);
+ }
+
+ // Fire event
+ this.updatedDepartmentEvent.fire(new AdminDepartmentUpdatedEvent(updatedDepartment));
+
+ // Return to list view
+ return "admin_list_departments"; //NOI18N
+ }
+
+ /**
+ * Prepares an instance of a Department object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a Department class (entity)
+ */
+ private Department createDepartment () {
+ // Create new department instance
+ final Department department = new BusinessDepartment(this.getDepartmentCompany(), this.getDepartmentI18nKey());
+
+ // Add all optional fields
+ department.setDepartmentBranchOffice(this.getDepartmentBranchOffice());
+ department.setDepartmentHeadquarter(this.getDepartmentHeadquarter());
+ department.setDepartmentId(this.getDepartmentId());
+ department.setDepartmentLead(this.getDepartmentLead());
+ department.setDepartmentUserOwner(this.getDepartmentUserOwner());
+
+ // Return fully prepared instance
+ return department;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department.action;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative action department controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminDepartmentActionWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department.list;
+
+import fish.payara.cdi.jsr107.impl.NamedCache;
+import java.text.MessageFormat;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import javax.annotation.PostConstruct;
+import javax.cache.Cache;
+import javax.ejb.EJB;
+import javax.enterprise.event.Observes;
+import javax.faces.view.ViewScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontactsbusiness.events.department.added.ObservableAdminDepartmentAddedEvent;
+import org.mxchange.jcontactsbusiness.events.department.updated.ObservableAdminDepartmentUpdatedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.utils.DepartmentUtils;
+
+/**
+ * A list bean for departments
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("departmentListController")
+@ViewScoped
+public class AddressbookDepartmentListWebViewBean extends BaseAddressbookBean implements AddressbookDepartmentListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_469L;
+
+ /**
+ * A list of all departments
+ */
+ private final List<Department> allDepartments;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/department!org.mxchange.jcontactsbusiness.model.department.DepartmentSessionBeanRemote")
+ private DepartmentSessionBeanRemote departmentBean;
+
+ /**
+ * A list of all departments (globally)
+ */
+ @Inject
+ @NamedCache (cacheName = "departmentCache")
+ private transient Cache<Long, Department> departmentCache;
+
+ /**
+ * A list of filtered departments
+ */
+ private List<Department> filteredDepartments;
+
+ /**
+ * Currently selected department
+ */
+ private Department selectedDepartment;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookDepartmentListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allDepartments = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when a department has been added by an
+ * administrator.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDepartmentAddedEvent (@Observes final ObservableAdminDepartmentAddedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedDepartment() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.addedDepartment is null"); //NOI18N
+ } else if (event.getAddedDepartment().getDepartmentId() == null) {
+ // Throw it again
+ throw new NullPointerException("event.addedDepartment.branchId is null"); //NOI18N
+ } else if (event.getAddedDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.addedDepartment.branchId={0} is not valid", event.getAddedDepartment().getDepartmentId())); //NOI18N
+ }
+
+ // Uniquely add department
+ this.uniqueAddDepartment(event.getAddedDepartment());
+ }
+
+ /**
+ * Observes events being fired when a department has been updated by an
+ * administrator.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDepartmentUpdatedEvent (@Observes final ObservableAdminDepartmentUpdatedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedDepartment() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedDepartment is null"); //NOI18N
+ } else if (event.getUpdatedDepartment().getDepartmentId() == null) {
+ // Throw it again
+ throw new NullPointerException("event.updatedDepartment.branchId is null"); //NOI18N
+ } else if (event.getUpdatedDepartment().getDepartmentId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.updatedDepartment.branchId={0} is not valid", event.getUpdatedDepartment().getDepartmentId())); //NOI18N
+ }
+
+ // Uniquely add (update) instance
+ this.uniqueAddDepartment(event.getUpdatedDepartment());
+ }
+
+ @Override
+ public Department findDepartmentById (final Long departmentId) throws DepartmentNotFoundException {
+ // Validate parameter
+ if (null == departmentId) {
+ // Throw NPE
+ throw new NullPointerException("departmentId is null"); //NOI18N
+ } else if (departmentId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("departmentId=" + departmentId + " is invalid"); //NOI18N
+ } else if (!this.departmentCache.containsKey(departmentId)) {
+ // Not found
+ throw new DepartmentNotFoundException(departmentId);
+ }
+
+ // Get it from cache
+ final Department department = this.departmentCache.get(departmentId);
+
+ // Return it
+ return department;
+ }
+
+ /**
+ * Returns a list of all departments
+ * <p>
+ * @return A list of all departments
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Department> getAllDepartments () {
+ return this.allDepartments;
+ }
+
+ /**
+ * Getter for a list of filtered departments
+ * <p>
+ * @return Filtered departments
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Department> getFilteredDepartments () {
+ return this.filteredDepartments;
+ }
+
+ /**
+ * Setter for a list of filtered departments
+ * <p>
+ * @param filteredDepartments Filtered departments
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredDepartments (final List<Department> filteredDepartments) {
+ this.filteredDepartments = filteredDepartments;
+ }
+
+ /**
+ * Getter for selected department
+ * <p>
+ * @return Selected department
+ */
+ public Department getSelectedDepartment () {
+ return this.selectedDepartment;
+ }
+
+ /**
+ * Setter for selected department
+ * <p>
+ * @param selectedDepartment Selected department
+ */
+ public void setSelectedDepartment (final Department selectedDepartment) {
+ this.selectedDepartment = selectedDepartment;
+ }
+
+ /**
+ * Initializer method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.departmentCache.iterator().hasNext()) {
+ // Add all
+ for (final Department department : this.departmentBean.fetchAllDepartments()) {
+ // Add it to cache
+ this.departmentCache.put(department.getDepartmentId(), department);
+ }
+ }
+
+ // Is the list empty, but filled cache?
+ if (this.getAllDepartments().isEmpty() && this.departmentCache.iterator().hasNext()) {
+ // Build up list
+ for (final Cache.Entry<Long, Department> currentEntry : this.departmentCache) {
+ // Add to list
+ this.getAllDepartments().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllDepartments().sort(new Comparator<Department>() {
+ @Override
+ public int compare (final Department department1, final Department department2) {
+ return department1.getDepartmentId() > department2.getDepartmentId() ? 1 : department1.getDepartmentId() < department2.getDepartmentId() ? -1 : 0;
+ }
+ });
+ }
+ }
+
+ @Override
+ public boolean isDepartmentAlreadyAdded (final Department department) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Now check each entry
+ for (final Department currentDepartment : this.getAllDepartments()) {
+ // Is same address?
+ if (DepartmentUtils.isSameDepartment(currentDepartment, department)) {
+ // Found one
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ /**
+ * Uniquely adds given department instance to full list and updates cache.
+ * <p>
+ * @param department Department being uniquely added
+ */
+ private void uniqueAddDepartment (final Department department) {
+ // Add instance to cache
+ this.departmentCache.put(department.getDepartmentId(), department);
+
+ // Get iterator
+ final Iterator<Department> iterator = this.getAllDepartments().iterator();
+
+ // Loop through all
+ while (iterator.hasNext()) {
+ // Get current entry
+ final Department currentDepartment = iterator.next();
+
+ // Does the primary key match?
+ if (Objects.equals(department.getDepartmentId(), currentDepartment.getDepartmentId())) {
+ // Yes, remove it and abort iteration
+ iterator.remove();
+ break;
+ }
+ }
+
+ // (Re-) Add department
+ this.getAllDepartments().add(department);
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.department.list;
+
+import java.io.Serializable;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * An interface for general department controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookDepartmentListWebViewController extends Serializable {
+
+ /**
+ * Retrieves a single company department entity for given id number or
+ * throws a proper exception if not found.
+ * <p>
+ * @param departmentId Company department id to lookup
+ * <p>
+ * @return Company department instance
+ * <p>
+ * @throws DepartmentNotFoundException If the id number could not be looked
+ * up and solved into an entity
+ */
+ Department findDepartmentById (final Long departmentId) throws DepartmentNotFoundException;
+
+ /**
+ * Checks whether the given department is already found in local cache.
+ * Please note that this method fully relies on the cache, so you must
+ * always fire proper events that add/update/delete entries in cache.
+ * <p>
+ * @param department Department to check it's address
+ * <p>
+ * @return Whether the address has been found
+ */
+ boolean isDepartmentAlreadyAdded (final Department department);
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2017 RRoland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.employee;
-
-import javax.ejb.EJB;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontactsbusiness.model.employee.AdminCompanyEmployeeSessionBeanRemote;
-
-/**
- * A request-scoped bean for administrative purposes for company employees.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("adminCompanyEmployeeController")
-@RequestScoped
-public class AddressbookAdminCompanyEmployeeWebRequestBean extends BaseAddressbookBean implements AddressbookAdminCompanyEmployeeWebRequestController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 12_886_968_547_360L;
-
- /**
- * EJB for administrative company employee purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/adminCompanyEmployee!org.mxchange.jcontactsbusiness.model.employee.AdminCompanyEmployeeSessionBeanRemote")
- private AdminCompanyEmployeeSessionBeanRemote adminCompanyEmployeeBean;
-
- /**
- * Default constructor
- */
- public AddressbookAdminCompanyEmployeeWebRequestBean () {
- // Call super constructor
- super();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.employee;
-
-import java.io.Serializable;
-
-/**
- * An interface for request-scoped administrative company employee beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookAdminCompanyEmployeeWebRequestController extends Serializable {
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2017 RRoland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.employee;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.application.FacesMessage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.business.employee.list.AddressbookEmployeeListWebViewController;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.events.employee.added.EmployeeAddedEvent;
+import org.mxchange.jcontactsbusiness.events.employee.added.ObservableEmployeeAddedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.employee.BusinessEmployee;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.utils.EmployeeUtils;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A request-scoped bean for administrative purposes for company employees.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminEmployeeController")
+@RequestScoped
+public class AddressbookAdminEmployeeWebRequestBean extends BaseAddressbookBean implements AddressbookAdminEmployeeWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 12_886_968_547_360L;
+
+ /**
+ * An event being fired when an employee has been added
+ */
+ @Inject
+ @Any
+ private Event<ObservableEmployeeAddedEvent> addedEmployeeEvent;
+
+ /**
+ * EJB for administrative company employee purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminEmployee!org.mxchange.jcontactsbusiness.model.employee.AdminEmployeeSessionBeanRemote")
+ private AdminEmployeeSessionBeanRemote adminEmployeeBean;
+
+ /**
+ * Administrative list-all-employees controller
+ */
+ @Inject
+ private AddressbookEmployeeListWebViewController adminEmployeeListController;
+
+ /**
+ * Assigned basic data instance
+ */
+ private BasicData employeeBasicData;
+
+ /**
+ * Assigned branch office
+ */
+ private BranchOffice employeeBranchOffice;
+
+ /**
+ * General employee controller
+ */
+ @Inject
+ private AddressbookEmployeeWebRequestController employeeController;
+
+ /**
+ * Department where employee works (alternative to headquarter)
+ */
+ private Department employeeDepartment;
+
+ /**
+ * Employee's business email address
+ */
+ private String employeeEmailAddress;
+
+ /**
+ * Employee's Headquarter data, if he is working there
+ */
+ private Headquarter employeeHeadquarter;
+
+ /**
+ * Employee's staff number
+ */
+ private String employeeNumber;
+
+ /**
+ * Assigned personal data of the employee
+ */
+ private Contact employeePersonalData;
+
+ /**
+ * Employee's phone extension (on top of a "main number")
+ */
+ private Integer employeePhoneExtension;
+
+ /**
+ * Assigned user account
+ */
+ private User employeeUserOwner;
+
+ /**
+ * Mobile number for employee's business mobile
+ */
+ private Long mobileNumber;
+
+ /**
+ * Mobile provider instance for employee's business mobile
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminEmployeeWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Adds branch office with all data from this backing bean. First this
+ * action method will validate if the branch office's address is already
+ * registered and if found, it will output a proper faces message.
+ */
+ public void addEmployee () {
+ // Get instance
+ final Employable employee = this.createEmployee();
+
+ // Is the branch office not created yet?
+ if (this.isEmployeeCreatedByRequiredData(employee)) {
+ // Then show proper faces message
+ this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Delcare updated instance
+ final Employable updatedOffice;
+
+ try {
+ // Try to call EJB
+ updatedOffice = this.adminEmployeeBean.addEmployee(employee);
+ } catch (final EmployeeAlreadyAddedException ex) {
+ // Output message
+ this.showFacesMessage("form-admin-add-employee:employeeNumber", "ADMIN_EMPLOYEE_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
+ return;
+ }
+
+ // Fire event
+ this.addedEmployeeEvent.fire(new EmployeeAddedEvent(updatedOffice));
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Getter for employee's assigned basic company data
+ * <p>
+ * @return Employee's assigned basic company data
+ */
+ public BasicData getEmployeeBasicData () {
+ return this.employeeBasicData;
+ }
+
+ /**
+ * Setter for employee's assigned basic company data
+ * <p>
+ * @param employeeBasicData Employee's assigned basic company data
+ */
+ public void setEmployeeBasicData (final BasicData employeeBasicData) {
+ this.employeeBasicData = employeeBasicData;
+ }
+
+ /**
+ * Getter for employee's assigned branch office
+ * <p>
+ * @return Employee's assigned branch office
+ */
+ public BranchOffice getEmployeeBranchOffice () {
+ return this.employeeBranchOffice;
+ }
+
+ /**
+ * Setter for employee's assigned branch office
+ * <p>
+ * @param employeeBranchOffice Employee's assigned branch office
+ */
+ public void setEmployeeBranchOffice (final BranchOffice employeeBranchOffice) {
+ this.employeeBranchOffice = employeeBranchOffice;
+ }
+
+ /**
+ * Getter for employee's assigned department
+ * <p>
+ * @return Employee's assigned department
+ */
+ public Department getEmployeeDepartment () {
+ return this.employeeDepartment;
+ }
+
+ /**
+ * Setter for employee's assigned department
+ * <p>
+ * @param employeeDepartment Employee's assigned department
+ */
+ public void setEmployeeDepartment (final Department employeeDepartment) {
+ this.employeeDepartment = employeeDepartment;
+ }
+
+ /**
+ * Getter for employee's business email address
+ * <p>
+ * @return Employee's business email address
+ */
+ public String getEmployeeEmailAddress () {
+ return this.employeeEmailAddress;
+ }
+
+ /**
+ * Setter for employee's business email address
+ * <p>
+ * @param employeeEmailAddress Employee's business email address
+ */
+ public void setEmployeeEmailAddress (final String employeeEmailAddress) {
+ this.employeeEmailAddress = employeeEmailAddress;
+ }
+
+ /**
+ * Getter for employee's assigned headquarter (if no branch office)
+ * <p>
+ * @return Employee's assigned headquarter
+ */
+ public Headquarter getEmployeeHeadquarter () {
+ return this.employeeHeadquarter;
+ }
+
+ /**
+ * Setter for employee's assigned headquarter (if no branch office)
+ * <p>
+ * @param employeeHeadquarter Employee's assigned headquarter
+ */
+ public void setEmployeeHeadquarter (final Headquarter employeeHeadquarter) {
+ this.employeeHeadquarter = employeeHeadquarter;
+ }
+
+ /**
+ * Getter for employee's staff number
+ * <p>
+ * @return Employee's staff number
+ */
+ public String getEmployeeNumber () {
+ return this.employeeNumber;
+ }
+
+ /**
+ * Setter for employee's staff number
+ * <p>
+ * @param employeeNumber Employee's staff number
+ */
+ public void setEmployeeNumber (final String employeeNumber) {
+ this.employeeNumber = employeeNumber;
+ }
+
+ /**
+ * Getter for employee's personal contact data
+ * <p>
+ * @return Employee's personal contact data
+ */
+ public Contact getEmployeePersonalData () {
+ return this.employeePersonalData;
+ }
+
+ /**
+ * Setter for employee's personal contact data
+ * <p>
+ * @param employeePersonalData Employee's personal contact data
+ */
+ public void setEmployeePersonalData (final Contact employeePersonalData) {
+ this.employeePersonalData = employeePersonalData;
+ }
+
+ /**
+ * Getter for employee's phone extension
+ * <p>
+ * @return Employee's phone extension
+ */
+ public Integer getEmployeePhoneExtension () {
+ return this.employeePhoneExtension;
+ }
+
+ /**
+ * Getter for employee's phone extension
+ * <p>
+ * @param employeePhoneExtension Employee's phone extension
+ */
+ public void setEmployeePhoneExtension (final Integer employeePhoneExtension) {
+ this.employeePhoneExtension = employeePhoneExtension;
+ }
+
+ /**
+ * Getter for employee's user "owner"
+ * <p>
+ * @return Employee's user "owner"
+ */
+ public User getEmployeeUserOwner () {
+ return this.employeeUserOwner;
+ }
+
+ /**
+ * Setter for employee's user "owner"
+ * <p>
+ * @param employeeUserOwner Employee's user "owner"
+ */
+ public void setEmployeeUserOwner (final User employeeUserOwner) {
+ this.employeeUserOwner = employeeUserOwner;
+ }
+
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
+ public Long getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for mobile number
+ * <p>
+ * @param mobileNumber Mobile number
+ */
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Getter for mobile provider instance
+ * <p>
+ * @return Mobile provider instance
+ */
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ /**
+ * Setter for mobile provider instance
+ * <p>
+ * @param mobileProvider Mobile provider instance
+ */
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ /**
+ * Clears all bean fields
+ */
+ private void clear () {
+ // Clear all fields
+ this.setEmployeeBranchOffice(null);
+ this.setEmployeeBasicData(null);
+ this.setEmployeeDepartment(null);
+ this.setEmployeeEmailAddress(null);
+ this.setEmployeeHeadquarter(null);
+ this.setEmployeePersonalData(null);
+ this.setEmployeePhoneExtension(null);
+ this.setEmployeeNumber(null);
+ this.setEmployeeUserOwner(null);
+ }
+
+ /**
+ * Creates employee instance with all data from this bean
+ * <p>
+ * @return Employee instance
+ */
+ private Employable createEmployee () {
+ // Init instance
+ final Employable employee = new BusinessEmployee(this.getEmployeeBasicData(), this.getEmployeeNumber(), this.getEmployeePersonalData());
+
+ // Set all othewr data
+ employee.setEmployeeBranchOffice(this.getEmployeeBranchOffice());
+ employee.setEmployeeDepartment(this.getEmployeeDepartment());
+ employee.setEmployeeHeadquarter(this.getEmployeeHeadquarter());
+ employee.setEmployeePhoneExtension(this.getEmployeePhoneExtension());
+ // @TODO employee.setEmployeePosition(this.getEmployeePosition());
+ employee.setEmployeeUserOwner(this.getEmployeeUserOwner());
+
+ // Is mobile provider and number set?
+ if ((this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+ // Init mobile number instance
+ final DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+
+ // Set it in employee
+ employee.setEmployeeMobileNumber(number);
+ }
+
+ // Return it
+ return employee;
+ }
+
+ /**
+ * Checks whether given employee is already added
+ * <p>
+ * @param employee Employee to be checked
+ * <p>
+ * @return Whether the employee has already been added
+ */
+ private boolean isEmployeeCreatedByRequiredData (final Employable employee) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all employees
+ for (final Employable otherEmployee : this.adminEmployeeListController.getAllEmployees()) {
+ // Is same found?
+ if (EmployeeUtils.isSameEmployeeFound(employee, otherEmployee)) {
+ // Okay, found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return it
+ return isFound;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.employee;
+
+import java.io.Serializable;
+
+/**
+ * An interface for request-scoped administrative company employee beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminEmployeeWebRequestController extends Serializable {
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2017 RRoland Häder
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.employee;
-
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.employee.Employee;
-
-/**
- * A request-scoped bean for general purposes for company employees.
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("companyEmployeeController")
-@RequestScoped
-public class AddressbookCompanyEmployeeWebRequestBean extends BaseAddressbookBean implements AddressbookCompanyEmployeeWebRequestController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 12_886_968_547_361L;
-
- /**
- * EJB for general company employee purposes
- */
- @EJB (lookup = "java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote")
- private CompanyEmployeeSessionBeanRemote companyEmployeeBean;
-
- /**
- * List of all company employees
- */
- @Inject
- @NamedCache (cacheName = "companyEmployeeCache")
- private Cache<Long, Employee> companyEmployeeCache;
-
- /**
- * Default constructor
- */
- public AddressbookCompanyEmployeeWebRequestBean () {
- // Call super constructor
- super();
- }
-
- /**
- * Returns a list of all company employees
- * <p>
- * @return List of all company employees
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<Employee> allCompanyEmployees () {
- // Init list
- final List<Employee> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, Employee>> iterator = this.companyEmployeeCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, Employee> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- /**
- * Initialization method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.companyEmployeeCache.iterator().hasNext()) {
- // Get whole list
- final List<Employee> list = this.companyEmployeeBean.allCompanyEmployees();
-
- // Add all
- for (final Iterator<Employee> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final Employee next = iterator.next();
-
- // Add it to cache
- this.companyEmployeeCache.put(next.getEmployeeId(), next);
- }
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.business.employee;
-
-import java.io.Serializable;
-
-/**
- * An interface for request-scoped general company employee beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookCompanyEmployeeWebRequestController extends Serializable {
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2017 RRoland Häder
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.employee;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * A request-scoped bean for general purposes for company employees.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("employeeController")
+@RequestScoped
+public class AddressbookEmployeeWebRequestBean extends BaseAddressbookBean implements AddressbookEmployeeWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 12_886_968_547_361L;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookEmployeeWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.employee;
+
+import java.io.Serializable;
+
+/**
+ * An interface for request-scoped general company employee beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookEmployeeWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+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;
+
+/**
+ * A view-scoped bean for listing purposes for e.g. administrative employee
+ * purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("employeeListController")
+@ViewScoped
+public class AddressbookEmployeeListWebViewBean extends BaseAddressbookBean implements AddressbookEmployeeListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 12_886_968_547_362L;
+
+ /**
+ * List of all employees
+ */
+ private final List<Employable> allEmployees;
+
+ /**
+ * EJB for general company employee purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/employee!org.mxchange.jcontactsbusiness.model.employee.EmployeeSessionBeanRemote")
+ private EmployeeSessionBeanRemote employeeBean;
+
+ /**
+ * List of all company employees
+ */
+ @Inject
+ @NamedCache (cacheName = "companyEmployeeCache")
+ private transient Cache<Long, Employable> employeeCache;
+
+ /**
+ * A list of filtered employees
+ */
+ private List<Employable> filteredEmployees;
+
+ /**
+ * Currently selected employee
+ */
+ private Employable selectedEmployee;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookEmployeeListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allEmployees = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when an employee has been added
+ * <p>
+ * @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<Employable> getAllEmployees () {
+ return this.allEmployees;
+ }
+
+ /**
+ * Getter for filtered list of employees
+ * <p>
+ * @return Filtered list of employees
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Employable> getFilteredEmployees () {
+ return this.filteredEmployees;
+ }
+
+ /**
+ * Getter for filtered list of employees
+ * <p>
+ * @param filteredEmployees Filtered list of employees
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredEmployees (final List<Employable> filteredEmployees) {
+ this.filteredEmployees = filteredEmployees;
+ }
+
+ /**
+ * Getter for currently selected employee
+ * <p>
+ * @return Currently selected employee
+ */
+ public Employable getSelectedEmployee () {
+ return this.selectedEmployee;
+ }
+
+ /**
+ * Setter for currently selected employee
+ * <p>
+ * @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<Long, Employable> currentEntry : this.employeeCache) {
+ // Add to list
+ this.getAllEmployees().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllEmployees().sort(new Comparator<Employable>() {
+ @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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookEmployeeListWebViewController extends Serializable {
+
+ /**
+ * Returns a list of all company employees
+ * <p>
+ * @return List of all company employees
+ */
+ List<Employable> getAllEmployees ();
+
+ /**
+ * Validates if given email address is already in use by an employee
+ * <p>
+ * @param emailAddress Email address to be validated
+ * <p>
+ * @return Whether the email address is already used
+ */
+ Boolean isEmailAddressRegistered (final String emailAddress);
+
+ /**
+ * Finds a company employee by given employee id
+ * <p>
+ * @param employeeId Employable id to find company employee instance for
+ * <p>
+ * @return Company employee instance
+ * <p>
+ * @throws EmployeeNotFoundException If the company employee was not found
+ */
+ Employable findEmployeeById (final Long employeeId) throws EmployeeNotFoundException;
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter;
+
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * An administrative bean for headquarter
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminHeadquarterController")
+@RequestScoped
+public class AddressbookAdminHeadquarterWebRequestBean extends BaseAddressbookBean implements AddressbookAdminHeadquarterWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_470L;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminHeadquarterWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative headquarter controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminHeadquarterWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * A general bean for headquarter
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("headquarterController")
+@RequestScoped
+public class AddressbookHeadquarterWebRequestBean extends BaseAddressbookBean implements AddressbookHeadquarterWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_465L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote")
+ private HeadquarterSessionBeanRemote headquarterBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookHeadquarterWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter;
+
+import java.io.Serializable;
+
+/**
+ * An interface for general Headquarter controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookHeadquarterWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter.action;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.faces.application.FacesMessage;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.events.headquarter.added.HeadquarterAddedEvent;
+import org.mxchange.jcontactsbusiness.events.headquarter.added.ObservableHeadquarterAddedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterAlreadyAddedException;
+import org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.headquarter.BusinessHeadquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcoreee.dates.DayOfTheWeek;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewController;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An administrative action bean for headquarter
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminHeadquarterActionController")
+@RequestScoped
+public class AddressbookAdminHeadquarterActionWebRequestBean extends BaseAddressbookBean implements AddressbookAdminHeadquarterActionWebRequestController {
+
+ /**
+ * Opening times of this headquarter
+ */
+ private static List<OpeningTime> headquarterOpeningTimes;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_472L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminHeadquarter!org.mxchange.jcontactsbusiness.model.headquarter.AdminHeadquarterSessionBeanRemote")
+ private AdminHeadquarterSessionBeanRemote adminHeadquarterBean;
+
+ /**
+ * Area code for fax number
+ */
+ private Integer faxAreaCode;
+
+ /**
+ * Country for fax number
+ */
+ private Country faxCountry;
+
+ /**
+ * Dial number for fax number
+ */
+ private Long faxNumber;
+
+ /**
+ * An event being fired when a headquarter has been successfully added
+ */
+ @Inject
+ @Any
+ private Event<ObservableHeadquarterAddedEvent> headquarterAddedEvent;
+
+ /**
+ * City
+ */
+ private String headquarterCity;
+
+ /**
+ * Headquarter's company name
+ */
+ private String headquarterCompanyName;
+
+ /**
+ * Contact person in headquarter
+ */
+ private Contact headquarterContactEmployee;
+
+ /**
+ * Country
+ */
+ private Country headquarterCountry;
+
+ /**
+ * Email address
+ */
+ private String headquarterEmailAddress;
+
+ /**
+ * House number
+ */
+ private Short headquarterHouseNumber;
+
+ /**
+ * House number's extension
+ */
+ private String headquarterHouseNumberExtension;
+
+ /**
+ * Last house number
+ */
+ private Short headquarterLastHouseNumber;
+
+ /**
+ * A general headquarter controller (backing bean)
+ */
+ @Inject
+ private AddressbookHeadquarterListWebViewController headquarterListController;
+
+ /**
+ * Store
+ */
+ private Short headquarterStore;
+
+ /**
+ * Headquarter street name
+ */
+ private String headquarterStreet;
+
+ /**
+ * Suite number
+ */
+ private Short headquarterSuiteNumber;
+
+ /**
+ * Owning user instance (which this headquarter is assigned to)
+ */
+ private User headquarterUserOwner;
+
+ /**
+ * ZIP code
+ */
+ private Integer headquarterZipCode;
+
+ /**
+ * Area code for land-line number
+ */
+ private Integer landLineAreaCode;
+
+ /**
+ * Country for land-line number
+ */
+ private Country landLineCountry;
+
+ /**
+ * Dial number for land-line number
+ */
+ private Long landLineNumber;
+
+ /**
+ * Ending week day
+ */
+ private DayOfTheWeek openingEndDay;
+
+ /**
+ * Ending time
+ */
+ private Date openingEndTime;
+
+ /**
+ * Starting week day
+ */
+ private DayOfTheWeek openingStartDay;
+
+ /**
+ * Starting time
+ */
+ private Date openingStartTime;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminHeadquarterActionWebRequestBean () {
+ // Call super constructor
+ super();
+
+ // Is the opening times list there?
+ if (null == headquarterOpeningTimes) {
+ // Init list
+ headquarterOpeningTimes = new ArrayList<>(1);
+ }
+ }
+
+ /**
+ * Adds headquarter with all data from this backing bean. First this action
+ * method will validate if the headquarter's address is already registered
+ * and if found, it will output a proper faces message.
+ */
+ public void addHeadquarter () {
+ // Get instance
+ final Headquarter headquarter = this.createHeadquarter();
+
+ // Is the headquarter not created yet?
+ if (this.headquarterListController.isHeadquarterCreatedByRequiredData(headquarter)) {
+ // Then show proper faces message
+ this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Delcare updated instance
+ final Headquarter updatedHeadquarter;
+
+ try {
+ // Try to call EJB
+ updatedHeadquarter = this.adminHeadquarterBean.addHeadquarter(headquarter);
+ } catch (final HeadquarterAlreadyAddedException ex) {
+ // Output message
+ this.showFacesMessage("form-admin-add-headquarter-office:headquarterStreet", "ADMIN_HEADQUARTER_ALREADY_CREATED", FacesMessage.SEVERITY_ERROR); //NOI18N
+ return;
+ }
+
+ // Fire event
+ this.headquarterAddedEvent.fire(new HeadquarterAddedEvent(updatedHeadquarter));
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Adds opening time to temporary list which will be sent along with the
+ * headquarter data to the EJB.
+ */
+ public void addOpeningTime () {
+ // Validate all required fields
+ if (this.getOpeningEndDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndDay is null"); //NOI18N
+ } else if (this.getOpeningEndTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingEndTime is null"); //NOI18N
+ } else if (this.getOpeningStartDay() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartDay is null"); //NOI18N
+ } else if (this.getOpeningStartTime() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.openingStartTime is null"); //NOI18N
+ }
+
+ // Get opening time instance
+ final OpeningTime openingTime = this.createOpeningTimes();
+
+ // Is same found?
+ if (this.isSameOpeningTimeFound(openingTime)) {
+ // Yes then abort here
+ this.showFacesMessage("form-admin-add-headquarter-opening-time:openingStartDay", "ADMIN_OPENING_TIME_ALREADY_CREATED", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
+ }
+
+ // Add to temporary list
+ headquarterOpeningTimes.add(openingTime);
+
+ // Clear opening time fields
+ this.clearOpeningTime();
+ }
+
+ /**
+ * Getter for fax number's area code
+ * <p>
+ * @return Fax number's area code
+ */
+ public Integer getFaxAreaCode () {
+ return this.faxAreaCode;
+ }
+
+ /**
+ * Setter for fax number's area code
+ * <p>
+ * @param faxAreaCode Fax number's area code
+ */
+ public void setFaxAreaCode (final Integer faxAreaCode) {
+ this.faxAreaCode = faxAreaCode;
+ }
+
+ /**
+ * Getter for fax's country instance
+ * <p>
+ * @return Fax' country instance
+ */
+ public Country getFaxCountry () {
+ return this.faxCountry;
+ }
+
+ /**
+ * Setter for fax's country instance
+ * <p>
+ * @param faxCountry Fax' country instance
+ */
+ public void setFaxCountry (final Country faxCountry) {
+ this.faxCountry = faxCountry;
+ }
+
+ /**
+ * Getter for fax number
+ * <p>
+ * @return Fax number
+ */
+ public Long getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for fax number
+ * <p>
+ * @param faxNumber Fax number
+ */
+ public void setFaxNumber (final Long faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for city
+ * <p>
+ * @return City
+ */
+ public String getHeadquarterCity () {
+ return this.headquarterCity;
+ }
+
+ /**
+ * Setter for city
+ * <p>
+ * @param headquarterCity City
+ */
+ public void setHeadquarterCity (final String headquarterCity) {
+ this.headquarterCity = headquarterCity;
+ }
+
+ /**
+ * Getter for headquarter's company name
+ * <p>
+ * @return Headquarter's company name
+ */
+ public String getHeadquarterCompanyName () {
+ return this.headquarterCompanyName;
+ }
+
+ /**
+ * Setter for headquarter's company name
+ * <p>
+ * @param headquarterCompanyName Headquarter's company name
+ */
+ public void setHeadquarterCompanyName (final String headquarterCompanyName) {
+ this.headquarterCompanyName = headquarterCompanyName;
+ }
+
+ /**
+ * Getter for headquarter contact person
+ * <p>
+ * @return Headquarter contact person
+ */
+ public Contact getHeadquarterContactEmployee () {
+ return this.headquarterContactEmployee;
+ }
+
+ /**
+ * Setter for headquarter contact person
+ * <p>
+ * @param headquarterContactEmployee Headquarter contact person
+ */
+ public void setHeadquarterContactEmployee (final Contact headquarterContactEmployee) {
+ this.headquarterContactEmployee = headquarterContactEmployee;
+ }
+
+ /**
+ * Getter for country
+ * <p>
+ * @return Country
+ */
+ public Country getHeadquarterCountry () {
+ return this.headquarterCountry;
+ }
+
+ /**
+ * Setter for country
+ * <p>
+ * @param headquarterCountry Country
+ */
+ public void setHeadquarterCountry (final Country headquarterCountry) {
+ this.headquarterCountry = headquarterCountry;
+ }
+
+ /**
+ * Getter for email address
+ * <p>
+ * @return Email address
+ */
+ public String getHeadquarterEmailAddress () {
+ return this.headquarterEmailAddress;
+ }
+
+ /**
+ * Getter for email address
+ * <p>
+ * @param headquarterEmailAddress Email address
+ */
+ public void setHeadquarterEmailAddress (final String headquarterEmailAddress) {
+ this.headquarterEmailAddress = headquarterEmailAddress;
+ }
+
+ /**
+ * Getter for house number
+ * <p>
+ * @return House number
+ */
+ public Short getHeadquarterHouseNumber () {
+ return this.headquarterHouseNumber;
+ }
+
+ /**
+ * Setter for house number
+ * <p>
+ * @param headquarterHouseNumber House number
+ */
+ public void setHeadquarterHouseNumber (final Short headquarterHouseNumber) {
+ this.headquarterHouseNumber = headquarterHouseNumber;
+ }
+
+ /**
+ * Getter for house number's extension
+ * <p>
+ * @return House number's extension
+ */
+ public String getHeadquarterHouseNumberExtension () {
+ return this.headquarterHouseNumberExtension;
+ }
+
+ /**
+ * Setter for house number's extension
+ * <p>
+ * @param headquarterHouseNumberExtension House number's extension
+ */
+ public void setHeadquarterHouseNumberExtension (final String headquarterHouseNumberExtension) {
+ this.headquarterHouseNumberExtension = headquarterHouseNumberExtension;
+ }
+
+ /**
+ * Getter for last house number
+ * <p>
+ * @return Last house number
+ */
+ public Short getHeadquarterLastHouseNumber () {
+ return this.headquarterLastHouseNumber;
+ }
+
+ /**
+ * Setter for last house number
+ * <p>
+ * @param headquarterLastHouseNumber Last house number
+ */
+ public void setHeadquarterLastHouseNumber (final Short headquarterLastHouseNumber) {
+ this.headquarterLastHouseNumber = headquarterLastHouseNumber;
+ }
+
+ /**
+ * Getter for opening times of this headquarter
+ * <p>
+ * @return Opening times
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<OpeningTime> getHeadquarterOpeningTimes () {
+ return headquarterOpeningTimes;
+ }
+
+ /**
+ * Setter for opening times of this headquarter
+ * <p>
+ * @param headquarterOpeningTimes Opening times
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setHeadquarterOpeningTimes (final List<OpeningTime> headquarterOpeningTimes) {
+ AddressbookAdminHeadquarterActionWebRequestBean.headquarterOpeningTimes = headquarterOpeningTimes;
+ }
+
+ /**
+ * Getter for store
+ * <p>
+ * @return Store
+ */
+ public Short getHeadquarterStore () {
+ return this.headquarterStore;
+ }
+
+ /**
+ * Setter for store
+ * <p>
+ * @param headquarterStore Store
+ */
+ public void setHeadquarterStore (final Short headquarterStore) {
+ this.headquarterStore = headquarterStore;
+ }
+
+ /**
+ * Getter for street name
+ * <p>
+ * @return Street name
+ */
+ public String getHeadquarterStreet () {
+ return this.headquarterStreet;
+ }
+
+ /**
+ * Setter for street name
+ * <p>
+ * @param headquarterStreet Street name
+ */
+ public void setHeadquarterStreet (final String headquarterStreet) {
+ this.headquarterStreet = headquarterStreet;
+ }
+
+ /**
+ * Getter for suite number
+ * <p>
+ * @return Suite number
+ */
+ public Short getHeadquarterSuiteNumber () {
+ return this.headquarterSuiteNumber;
+ }
+
+ /**
+ * Setter for suite number
+ * <p>
+ * @param headquarterSuiteNumber Suite number
+ */
+ public void setHeadquarterSuiteNumber (final Short headquarterSuiteNumber) {
+ this.headquarterSuiteNumber = headquarterSuiteNumber;
+ }
+
+ /**
+ * Getter for owning user instance
+ * <p>
+ * @return Owning user instance
+ */
+ public User getHeadquarterUserOwner () {
+ return this.headquarterUserOwner;
+ }
+
+ /**
+ * Setter for owning user instance
+ * <p>
+ * @param headquarterUserOwner Owning user instance
+ */
+ public void setHeadquarterUserOwner (final User headquarterUserOwner) {
+ this.headquarterUserOwner = headquarterUserOwner;
+ }
+
+ /**
+ * Getter for ZIP code\
+ * <p>
+ * @return ZIP code
+ */
+ public Integer getHeadquarterZipCode () {
+ return this.headquarterZipCode;
+ }
+
+ /**
+ * Setter for ZIP code\
+ * <p>
+ * @param headquarterZipCode ZIP code
+ */
+ public void setHeadquarterZipCode (final Integer headquarterZipCode) {
+ this.headquarterZipCode = headquarterZipCode;
+ }
+
+ /**
+ * Getter for land-line number's area code
+ * <p>
+ * @return Land-line number's area code
+ */
+ public Integer getLandLineAreaCode () {
+ return this.landLineAreaCode;
+ }
+
+ /**
+ * Setter for land-line number's area code
+ * <p>
+ * @param landLineAreaCode Land-line number's area code
+ */
+ public void setLandLineAreaCode (final Integer landLineAreaCode) {
+ this.landLineAreaCode = landLineAreaCode;
+ }
+
+ /**
+ * Getter for land-line number's country instance
+ * <p>
+ * @return Land-line number's country instance
+ */
+ public Country getLandLineCountry () {
+ return this.landLineCountry;
+ }
+
+ /**
+ * Setter for land-line number's country instance
+ * <p>
+ * @param landLineCountry Land-line number's country instance
+ */
+ public void setLandLineCountry (final Country landLineCountry) {
+ this.landLineCountry = landLineCountry;
+ }
+
+ /**
+ * Getter for land-line number
+ * <p>
+ * @return Land-line number
+ */
+ public Long getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for land-line number
+ * <p>
+ * @param landLineNumber Land-line number
+ */
+ public void setLandLineNumber (final Long landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Getter for ending week day
+ * <p>
+ * @return Ending week day
+ */
+ public DayOfTheWeek getOpeningEndDay () {
+ return this.openingEndDay;
+ }
+
+ /**
+ * Setter for ending week day
+ * <p>
+ * @param openingEndDay Ending week day
+ */
+ public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
+ this.openingEndDay = openingEndDay;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @return Ending time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningEndTime () {
+ return this.openingEndTime;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @param openingEndTime Ending time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningEndTime (final Date openingEndTime) {
+ this.openingEndTime = openingEndTime;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @return Starting week day
+ */
+ public DayOfTheWeek getOpeningStartDay () {
+ return this.openingStartDay;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @param openingStartDay Starting week day
+ */
+ public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
+ this.openingStartDay = openingStartDay;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @return Starting time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningStartTime () {
+ return this.openingStartTime;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @param openingStartTime Starting time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningStartTime (final Date openingStartTime) {
+ this.openingStartTime = openingStartTime;
+ }
+
+ /**
+ * Clears this bean data
+ */
+ private void clear () {
+ // Clear all headquarter data
+ this.setHeadquarterCity(null);
+ this.setHeadquarterCompanyName(null);
+ this.setHeadquarterContactEmployee(null);
+ this.setHeadquarterCountry(null);
+ this.setHeadquarterEmailAddress(null);
+ this.setHeadquarterHouseNumber(null);
+ this.setHeadquarterHouseNumberExtension(null);
+ this.setHeadquarterLastHouseNumber(null);
+ this.setHeadquarterStore(null);
+ this.setHeadquarterStreet(null);
+ this.setHeadquarterSuiteNumber(null);
+ this.setHeadquarterUserOwner(null);
+ this.setHeadquarterZipCode(null);
+ this.setHeadquarterOpeningTimes(null);
+
+ // Extra-clear opening time
+ this.clearOpeningTime();
+ }
+
+ /**
+ * Clears all opening time fields
+ */
+ private void clearOpeningTime () {
+ // Clear all opening time fields
+ this.setOpeningEndDay(null);
+ this.setOpeningEndTime(null);
+ this.setOpeningStartDay(null);
+ this.setOpeningStartTime(null);
+ }
+
+ /**
+ * Prepares an instance of a Headquarter object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a Headquarter class (entity)
+ */
+ private Headquarter createHeadquarter () {
+ // Create new headquarter instance
+ final Headquarter headquarter = new BusinessHeadquarter(
+ this.getHeadquarterCompanyName(),
+ this.getHeadquarterCity(),
+ this.getHeadquarterCountry(),
+ this.getHeadquarterStreet(),
+ this.getHeadquarterZipCode(),
+ this.getHeadquarterHouseNumber()
+ );
+
+ // Add all other fields, too
+ headquarter.setHeadquarterContactEmployee(this.getHeadquarterContactEmployee());
+ headquarter.setHeadquarterEmailAddress(this.getHeadquarterEmailAddress());
+ headquarter.setHeadquarterHouseNumberExtension(this.getHeadquarterHouseNumberExtension());
+ headquarter.setHeadquarterLastHouseNumber(this.getHeadquarterLastHouseNumber());
+ headquarter.setHeadquarterStore(this.getHeadquarterStore());
+ headquarter.setHeadquarterSuiteNumber(this.getHeadquarterSuiteNumber());
+ headquarter.setHeadquarterUserOwner(this.getHeadquarterUserOwner());
+
+ // Initialize variables
+ DialableLandLineNumber landLine = null;
+ DialableFaxNumber fax = null;
+
+ // Are all fields set?
+ if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+ // Initialize instance
+ landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ }
+
+ // Are all fields set?
+ if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+ // Initialize instance
+ fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ }
+
+ // Don't set null or wrong references
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (landLine.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (landLine.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (landLine.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set phone number
+ headquarter.setHeadquarterLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+ } else if (fax.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ } else if (fax.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+ } else if (fax.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set fax number
+ headquarter.setHeadquarterFaxNumber(fax);
+ }
+ // Is the opening times list filled?
+ if (!this.getHeadquarterOpeningTimes().isEmpty()) {
+ // Yes, then set in headquarter, too
+ headquarter.setHeadquarterOpeningTimes(this.getHeadquarterOpeningTimes());
+ }
+
+ // Return fully prepared instance
+ return headquarter;
+ }
+
+ /**
+ * Prepares an instance of a OpeningTimes object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a OpeningTimes class (entity)
+ */
+ private OpeningTime createOpeningTimes () {
+ // Create new openingTime instance
+ final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
+
+ // Return fully prepared instance
+ return openingTime;
+ }
+
+ /**
+ * Checks if given opening time is already added
+ * <p>
+ * @param openingTime Opening time to be checked
+ * <p>
+ * @return Whether it has been added already
+ */
+ private boolean isSameOpeningTimeFound (final OpeningTime openingTime) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Loop through list
+ for (final OpeningTime ot : this.getHeadquarterOpeningTimes()) {
+ // Check it
+ if (Objects.equals(ot, openingTime)) {
+ // Found same match
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return it
+ return isFound;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter.action;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative headquarter action controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminHeadquarterActionWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter.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.headquarter.added.ObservableHeadquarterAddedEvent;
+import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.utils.HeadquarterUtils;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * A list bean for headquarter
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("headquarterListController")
+@ViewScoped
+public class AddressbookHeadquarterListWebViewBean extends BaseAddressbookBean implements AddressbookHeadquarterListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_466L;
+
+ /**
+ * A list of all headquarter
+ */
+ private final List<Headquarter> allHeadquarters;
+
+ /**
+ * A list of filtered headquarter
+ */
+ private List<Headquarter> filteredHeadquarters;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/headquarter!org.mxchange.jcontactsbusiness.model.headquarter.HeadquarterSessionBeanRemote")
+ private HeadquarterSessionBeanRemote headquarterBean;
+
+ /**
+ * A list of all headquarter (globally)
+ */
+ @Inject
+ @NamedCache (cacheName = "headquarterCache")
+ private transient Cache<Long, Headquarter> headquarterCache;
+
+ /**
+ * Currently selected headquarter
+ */
+ private Headquarter selectedHeadquarter;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookHeadquarterListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allHeadquarters = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when a branch office has been added.
+ * <p>
+ * @param event Event being fired
+ * <p>
+ * @throws NullPointerException If the parameter or it's carried instance is
+ * null
+ * @throws IllegalArgumentException If the branchId is zero or lower
+ */
+ public void afterHeadquarterAddedEvent (@Observes final ObservableHeadquarterAddedEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getHeadquarter() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.headquarter is null"); //NOI18N
+ } else if (event.getHeadquarter().getHeadquarterId() == null) {
+ // Throw it again
+ throw new NullPointerException("event.headquarter.branchId is null"); //NOI18N
+ } else if (event.getHeadquarter().getHeadquarterId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.headquarter.branchId={0} is not valid", event.getHeadquarter().getHeadquarterId())); //NOI18N
+ }
+
+ // Add instance to cache
+ this.headquarterCache.put(event.getHeadquarter().getHeadquarterId(), event.getHeadquarter());
+ this.getAllHeadquarters().add(event.getHeadquarter());
+ }
+
+ @Override
+ public Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException {
+ // Validate parameter
+ if (null == headquarterId) {
+ // Throw NPE
+ throw new NullPointerException("headquarterId is null"); //NOI18N
+ } else if (headquarterId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("headquarterId={0} is invalid", headquarterId)); //NOI18N
+ } else if (!this.headquarterCache.containsKey(headquarterId)) {
+ // Not found
+ throw new HeadquarterNotFoundException(headquarterId);
+ }
+
+ // Get it from cache
+ final Headquarter headquarter = this.headquarterCache.get(headquarterId);
+
+ // Return it
+ return headquarter;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Headquarter> getAllHeadquarters () {
+ return this.allHeadquarters;
+ }
+
+ /**
+ * Getter for a list of filtered headquarter
+ * <p>
+ * @return Filtered headquarter
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Headquarter> getFilteredHeadquarters () {
+ return this.filteredHeadquarters;
+ }
+
+ /**
+ * Setter for a list of filtered headquarter
+ * <p>
+ * @param filteredHeadquarters Filtered headquarter
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredHeadquarters (final List<Headquarter> filteredHeadquarters) {
+ this.filteredHeadquarters = filteredHeadquarters;
+ }
+
+ /**
+ * Getter for selected headquarter
+ * <p>
+ * @return Selected headquarter
+ */
+ public Headquarter getSelectedHeadquarter () {
+ return this.selectedHeadquarter;
+ }
+
+ /**
+ * Setter for selected headquarter
+ * <p>
+ * @param selectedHeadquarter Selected headquarter
+ */
+ public void setSelectedHeadquarter (final Headquarter selectedHeadquarter) {
+ this.selectedHeadquarter = selectedHeadquarter;
+ }
+
+ /**
+ * Initializer method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.headquarterCache.iterator().hasNext()) {
+ // Add all
+ for (final Headquarter headquarter : this.headquarterBean.fetchAllHeadquarters()) {
+ // Add it to cache
+ this.headquarterCache.put(headquarter.getHeadquarterId(), headquarter);
+ }
+ }
+
+ // Is the list empty, but filled cache?
+ if (this.getAllHeadquarters().isEmpty() && this.headquarterCache.iterator().hasNext()) {
+ // Build up list
+ for (final Cache.Entry<Long, Headquarter> currentEntry : this.headquarterCache) {
+ // Add to list
+ this.getAllHeadquarters().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllHeadquarters().sort(new Comparator<Headquarter>() {
+ @Override
+ public int compare (final Headquarter headquarter1, final Headquarter headquarter2) {
+ return headquarter1.getHeadquarterId() > headquarter2.getHeadquarterId() ? 1 : headquarter1.getHeadquarterId() < headquarter2.getHeadquarterId() ? -1 : 0;
+ }
+ });
+ }
+ }
+
+ @Override
+ public Boolean isCompanyNameUsed (final String companyName) {
+ // Validate parameter
+ if (null == companyName) {
+ // Throw NPE
+ throw new NullPointerException("companyName is null"); //NOI18N
+ } else if (companyName.isEmpty()) {
+ // Throw IAE
+ throw new IllegalArgumentException("companyName is empty"); //NOI18N
+ }
+
+ // Default is not found
+ boolean isFound = false;
+
+ // Check all entries
+ for (final Headquarter headquarter : this.getAllHeadquarters()) {
+ // Is same company name?
+ if (Objects.equals(headquarter.getHeadquarterCompanyName(), companyName)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ @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 Headquarter headquarter : this.getAllHeadquarters()) {
+ // Is email address used?
+ if (Objects.equals(headquarter.getHeadquarterEmailAddress(), emailAddress)) {
+ // Found it
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ /**
+ * Checks whether the given headquarter' address is already found in local
+ * cache. Please note that this method fully relies on the cache, so you
+ * must always fire proper events that add/update/delete entries in cache.
+ * <p>
+ * @param headquarter Headquarter to check it's address
+ * <p>
+ * @return Whether the address has been found
+ */
+ @Override
+ public boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Now check each entry
+ for (final Headquarter hq : this.getAllHeadquarters()) {
+ // Is same address?
+ if (HeadquarterUtils.isSameAddress(hq, headquarter)) {
+ // Found one
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.headquarter.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+
+/**
+ * An interface for general Headquarter controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookHeadquarterListWebViewController extends Serializable {
+
+ /**
+ * Checks whether given company name already exists
+ * <p>
+ * @param companyName Company name to check
+ * <p>
+ * @return Whether the company name exists
+ */
+ Boolean isCompanyNameUsed (final String companyName);
+
+ /**
+ * Checks if given email address is already registered by an other
+ * headquarter
+ * <p>
+ * @param emailAddress Email address
+ * <p>
+ * @return Whether the email address has been already registered
+ */
+ Boolean isEmailAddressRegistered (final String emailAddress);
+
+ /**
+ * Returns a list of all headquarter
+ * <p>
+ * @return A list of all headquarter
+ */
+ List<Headquarter> getAllHeadquarters ();
+
+ /**
+ * Tries to find a headquarter with given id number
+ * <p>
+ * @param headquarterId Headquarter id
+ * <p>
+ * @return A headquarter instance
+ * <p>
+ * @throws HeadquarterNotFoundException If the headquarter was not found
+ */
+ Headquarter findHeadquarterById (final Long headquarterId) throws HeadquarterNotFoundException;
+
+ /**
+ * Checks whether the given headquarter' address is already found in local
+ * cache. Please note that this method fully relies on the cache, so you
+ * must always fire proper events that add/update/delete entries in cache.
+ * <p>
+ * @param headquarter Headquarter to check it's address
+ * <p>
+ * @return Whether the address has been found
+ */
+ boolean isHeadquarterCreatedByRequiredData (final Headquarter headquarter);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.opening_time;
+
+import java.util.Date;
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.jcontactsbusiness.events.opening_time.added.ObservableOpeningTimeAddedEvent;
+import org.mxchange.jcontactsbusiness.events.opening_time.added.OpeningTimeAddedEvent;
+import org.mxchange.jcontactsbusiness.model.opening_time.AdminOpeningTimeSessionBeanRemote;
+import org.mxchange.jcontactsbusiness.model.opening_time.BusinessOpeningTime;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+import org.mxchange.jcoreee.dates.DayOfTheWeek;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * An administrative bean for openingTimes
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminOpeningTimeController")
+@RequestScoped
+public class AddressbookAdminOpeningTimeWebRequestBean extends BaseAddressbookBean implements AddressbookAdminOpeningTimeWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_463L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminOpeningTimes!org.mxchange.jcontactsbusiness.model.opening_time.AdminOpeningTimeSessionBeanRemote")
+ private AdminOpeningTimeSessionBeanRemote adminOpeningTimeBean;
+
+ /**
+ * Ending week day
+ */
+ private DayOfTheWeek openingEndDay;
+
+ /**
+ * Ending time
+ */
+ private Date openingEndTime;
+
+ /**
+ * Starting week day
+ */
+ private DayOfTheWeek openingStartDay;
+
+ /**
+ * Starting time
+ */
+ private Date openingStartTime;
+
+ /**
+ * An event being fired when a openingTime has been successfully added
+ */
+ @Inject
+ @Any
+ private Event<ObservableOpeningTimeAddedEvent> openingTimeAddedEvent;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminOpeningTimeWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Adds openingTime with all data from this backing bean. First this action
+ * method will validate if the openingTime's address is already registered
+ * and if found, it will output a proper faces message.
+ */
+ public void addOpeningTime () {
+ // Get instance
+ final OpeningTime openingTime = this.createOpeningTimes();
+
+ // Call EJB and return updated instance
+ final OpeningTime updatedOpeningTimes = this.adminOpeningTimeBean.addOpeningTime(openingTime);
+
+ // Fire event
+ this.openingTimeAddedEvent.fire(new OpeningTimeAddedEvent(updatedOpeningTimes));
+ }
+
+ /**
+ * Getter for ending week day
+ * <p>
+ * @return Ending week day
+ */
+ public DayOfTheWeek getOpeningEndDay () {
+ return this.openingEndDay;
+ }
+
+ /**
+ * Setter for ending week day
+ * <p>
+ * @param openingEndDay Ending week day
+ */
+ public void setOpeningEndDay (final DayOfTheWeek openingEndDay) {
+ this.openingEndDay = openingEndDay;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @return Ending time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningEndTime () {
+ return this.openingEndTime;
+ }
+
+ /**
+ * Getter for ending time
+ * <p>
+ * @param openingEndTime Ending time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningEndTime (final Date openingEndTime) {
+ this.openingEndTime = openingEndTime;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @return Starting week day
+ */
+ public DayOfTheWeek getOpeningStartDay () {
+ return this.openingStartDay;
+ }
+
+ /**
+ * Getter for starting week day
+ * <p>
+ * @param openingStartDay Starting week day
+ */
+ public void setOpeningStartDay (final DayOfTheWeek openingStartDay) {
+ this.openingStartDay = openingStartDay;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @return Starting time
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getOpeningStartTime () {
+ return this.openingStartTime;
+ }
+
+ /**
+ * Getter for starting time
+ * <p>
+ * @param openingStartTime Starting time
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setOpeningStartTime (final Date openingStartTime) {
+ this.openingStartTime = openingStartTime;
+ }
+
+ /**
+ * Prepares an instance of a OpeningTimes object (entity) with all data from
+ * this bean. If a complete fax number or land-line number was provided, it
+ * will be set in the instance as well.
+ * <p>
+ * @return An instance of a OpeningTimes class (entity)
+ */
+ private OpeningTime createOpeningTimes () {
+ // Create new openingTime instance
+ final OpeningTime openingTime = new BusinessOpeningTime(this.getOpeningEndDay(), this.getOpeningEndTime(), this.getOpeningStartDay(), this.getOpeningStartTime());
+
+ // Return fully prepared instance
+ return openingTime;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.opening_time;
+
+import java.io.Serializable;
+
+/**
+ * An interface for administrative opening time controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminOpeningTimeWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.opening_time;
+
+import javax.ejb.EJB;
+import javax.enterprise.context.RequestScoped;
+import javax.inject.Named;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * A general bean for opening times
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("openingTimeController")
+@RequestScoped
+public class AddressbookOpeningTimeWebRequestBean extends BaseAddressbookBean implements AddressbookOpeningTimeWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_462L;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/openingTimes!org.mxchange.jcontactsbusiness.model.opening_time.OpeningTimeSessionBeanRemote")
+ private OpeningTimeSessionBeanRemote openingTimesBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookOpeningTimeWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.business.opening_time;
+
+import java.io.Serializable;
+
+/**
+ * An interface for general opening times controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookOpeningTimeWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+
+/**
+ * A general bean for opening times
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("openingTimeListController")
+@ViewScoped
+public class AddressbookOpeningTimeListWebViewBean extends BaseAddressbookBean implements AddressbookOpeningTimeListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 5_028_697_360_467L;
+
+ /**
+ * A list of all opening times
+ */
+ private final List<OpeningTime> allOpeningTimes;
+
+ /**
+ * A list of filtered opening times
+ */
+ private List<OpeningTime> filteredOpeningTimes;
+
+ /**
+ * EJB for administrative purposes
+ */
+ @EJB (lookup = "java:global/addressbook-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<Long, OpeningTime> openingTimesCache;
+
+ /**
+ * Selected opening-time instance
+ */
+ private OpeningTime selectedOpeningTime;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookOpeningTimeListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allOpeningTimes = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being thrown when a new opening time has been added
+ * <p>
+ * @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
+ * <p>
+ * @return A list of all opening times
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<OpeningTime> getAllOpeningTimes () {
+ return this.allOpeningTimes;
+ }
+
+ /**
+ * Getter for a list of filtered opening times
+ * <p>
+ * @return Filtered opening times
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<OpeningTime> getFilteredOpeningTimes () {
+ return this.filteredOpeningTimes;
+ }
+
+ /**
+ * Setter for a list of filtered opening times
+ * <p>
+ * @param filteredOpeningTimes Filtered opening times
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredOpeningTimes (final List<OpeningTime> filteredOpeningTimes) {
+ this.filteredOpeningTimes = filteredOpeningTimes;
+ }
+
+ /**
+ * Getter for selected open-time instance
+ * <p>
+ * @return Selected open-time instance
+ */
+ public OpeningTime getSelectedOpeningTime () {
+ return this.selectedOpeningTime;
+ }
+
+ /**
+ * Setter for selected open-time instance
+ * <p>
+ * @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<Long, OpeningTime> currentEntry : this.openingTimesCache) {
+ // Add to list
+ this.getAllOpeningTimes().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllOpeningTimes().sort(new Comparator<OpeningTime>() {
+ @Override
+ public int compare (final OpeningTime openingTime1, final OpeningTime openingTime2) {
+ return openingTime1.getOpeningTimeId() > openingTime2.getOpeningTimeId() ? 1 : openingTime1.getOpeningTimeId() < openingTime2.getOpeningTimeId() ? -1 : 0;
+ }
+ }
+ );
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookOpeningTimeListWebViewController extends Serializable {
+
+ /**
+ * Retrieves a single opening-time entity for given id number or throws a
+ * proper exception if not found.
+ * <p>
+ * @param openingTimeId Opening time id to lookup
+ * <p>
+ * @return Company department instance
+ * <p>
+ * @throws OpeningTimeNotFoundException If the id number could not be looked
+ * up and solved into an entity
+ */
+ OpeningTime findOpeningTimeById (final Long openingTimeId) throws OpeningTimeNotFoundException;
+
+}
import java.text.MessageFormat;
import java.util.Date;
-import java.util.Iterator;
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.view.facelets.FaceletException;
+import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
import org.mxchange.jcontacts.events.contact.add.AdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.AdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
import org.mxchange.jcontacts.events.contact.update.AdminUpdatedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
import org.mxchange.jcontacts.exceptions.ContactAlreadyAddedException;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.AdminContactSessionBeanRemote;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
private String comment;
/**
- * EJB for general contact purposes
+ * Current contact instance
*/
- @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
- private ContactSessionBeanRemote contactBean;
+ private Contact contact;
/**
- * General contact controller
+ * EJB for general contact purposes
*/
- @Inject
- private AddressbookContactWebRequestController contactController;
+ @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+ private ContactSessionBeanRemote contactBean;
/**
* Country instance
*/
private Long contactId;
+ /**
+ * An instance of a contact list controller
+ */
+ @Inject
+ private AddressbookContactListWebViewController contactListController;
+
+ /**
+ * Event being fired when an administrator has deleted a contact
+ */
+ @Any
+ @Inject
+ private Event<ObservableAdminDeletedContactEvent> deletedContactEvent;
+
/**
* Email address
*/
/**
* Adds contact data to database and redirects on success. If the contact is
* already found, a proper exception is thrown.
- * <p>
- * @return Redirect outcome
*/
- public String addContact () {
+ public void addContact () {
// Are all minimum fields set?
if (this.getPersonalTitle() == null) {
// Throw NPE
}
// Create new contact instance
- final Contact contact = this.createContactInstance();
+ final Contact createdContact = this.createContactInstance();
// Default is not same contact
- if (this.isSameContactFound(contact)) {
+ if (this.contactListController.isContactFound(createdContact)) {
// Already registered
- throw new FaceletException(new ContactAlreadyAddedException(contact));
+ throw new FacesException(new ContactAlreadyAddedException(createdContact));
}
// Init contact
// Try to call EJB
try {
// Call EJB
- updatedContact = this.adminContactBean.addContact(contact);
+ updatedContact = this.adminContactBean.addContact(createdContact);
} catch (final ContactAlreadyAddedException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
// Clear this bean
this.clear();
-
- // Return outcome
- return "admin_list_contact"; //NOI18N
}
/**
throw new NullPointerException("event is null"); //NOI18N
} else if (event.getCreatedContact() == null) {
// Throw NPE again
- throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
+ throw new NullPointerException("event.createdContact is null"); //NOI18N
} else if (event.getCreatedContact().getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("event.createdContact.contactId is null"); //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 contact for e.g. delete method
+ this.setContact(event.getCreatedContact());
+
// Get contact instance from event
- final Contact contact = event.getCreatedContact();
+ final Contact createdContact = event.getCreatedContact();
// Set all fields: contact
- this.setContactId(contact.getContactId());
- this.setAcademicTitle(contact.getContactTitle());
- this.setBirthday(contact.getContactBirthday());
- this.setCity(contact.getContactCity());
- this.setComment(contact.getContactComment());
- this.setContactCountry(contact.getContactCountry());
- this.setEmailAddress(contact.getContactEmailAddress());
- this.setFamilyName(contact.getContactFamilyName());
- this.setFirstName(contact.getContactFirstName());
- this.setPersonalTitle(contact.getContactPersonalTitle());
- this.setHouseNumber(contact.getContactHouseNumber());
- this.setHouseNumberExtension(contact.getContactHouseNumberExtension());
- this.setStreet(contact.getContactStreet());
- this.setZipCode(contact.getContactZipCode());
+ this.setContactId(createdContact.getContactId());
+ this.setAcademicTitle(createdContact.getContactTitle());
+ this.setBirthday(createdContact.getContactBirthday());
+ this.setCity(createdContact.getContactCity());
+ this.setComment(createdContact.getContactComment());
+ this.setContactCountry(createdContact.getContactCountry());
+ this.setEmailAddress(createdContact.getContactEmailAddress());
+ this.setFamilyName(createdContact.getContactFamilyName());
+ this.setFirstName(createdContact.getContactFirstName());
+ this.setPersonalTitle(createdContact.getContactPersonalTitle());
+ this.setHouseNumber(createdContact.getContactHouseNumber());
+ this.setHouseNumberExtension(createdContact.getContactHouseNumberExtension());
+ this.setStreet(createdContact.getContactStreet());
+ this.setZipCode(createdContact.getContactZipCode());
// Is the cell phone set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ if (createdContact.getContactMobileNumber() instanceof DialableMobileNumber) {
// ... cmobile data
- this.setMobileId(contact.getContactMobileNumber().getPhoneId());
- this.setMobileProvider(contact.getContactMobileNumber().getMobileProvider());
- this.setMobileNumber(contact.getContactMobileNumber().getPhoneNumber());
+ this.setMobileId(createdContact.getContactMobileNumber().getMobileId());
+ this.setMobileProvider(createdContact.getContactMobileNumber().getMobileProvider());
+ this.setMobileNumber(createdContact.getContactMobileNumber().getMobileNumber());
}
// Is the fax set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ if (createdContact.getContactFaxNumber() instanceof DialableFaxNumber) {
// ... fax data
- this.setFaxId(contact.getContactFaxNumber().getPhoneId());
- this.setFaxAreaCode(contact.getContactFaxNumber().getPhoneAreaCode());
- this.setFaxCountry(contact.getContactFaxNumber().getPhoneCountry());
- this.setFaxNumber(contact.getContactFaxNumber().getPhoneNumber());
+ this.setFaxId(createdContact.getContactFaxNumber().getPhoneId());
+ this.setFaxAreaCode(createdContact.getContactFaxNumber().getPhoneAreaCode());
+ this.setFaxCountry(createdContact.getContactFaxNumber().getPhoneCountry());
+ this.setFaxNumber(createdContact.getContactFaxNumber().getPhoneNumber());
}
// Is the land-line number set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ if (createdContact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
// .. land-line data
- this.setLandLineId(contact.getContactLandLineNumber().getPhoneId());
- this.setLandLineAreaCode(contact.getContactLandLineNumber().getPhoneAreaCode());
- this.setLandLineCountry(contact.getContactLandLineNumber().getPhoneCountry());
- this.setLandLineNumber(contact.getContactLandLineNumber().getPhoneNumber());
+ this.setLandLineId(createdContact.getContactLandLineNumber().getPhoneId());
+ this.setLandLineAreaCode(createdContact.getContactLandLineNumber().getPhoneAreaCode());
+ this.setLandLineCountry(createdContact.getContactLandLineNumber().getPhoneCountry());
+ this.setLandLineNumber(createdContact.getContactLandLineNumber().getPhoneNumber());
}
// Log message
}
// Generate phone number
- final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
- final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
- final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ DialableLandLineNumber landLine = null;
+ DialableMobileNumber mobile = null;
+ DialableFaxNumber fax = null;
+
+ // Are all fields set?
+ if (this.getLandLineAreaCode() != null && this.getLandLineCountry() instanceof Country && this.getLandLineNumber() != null) {
+ // Init instance
+ landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ }
- // Create new instance
- final Contact contact = new UserContact(this.getPersonalTitle(), this.getFirstName(), this.getFamilyName());
+ // Are all fields set?
+ if (this.getMobileProvider() instanceof MobileProvider && this.getMobileNumber() != null) {
+ // Initialize instance
+ mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ }
- // Is contact id set?
- if (this.getContactId() instanceof Long) {
- // Set it, too
- contact.setContactId(this.getContactId());
+ // Are all fields set?
+ if (this.getFaxAreaCode() != null && this.getFaxCountry() instanceof Country && this.getFaxNumber() != null) {
+ // Initialize instance
+ fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
}
// Create new instance
}
// Set phone number
- contact.setContactLandLineNumber(landLine);
+ localContact.setContactLandLineNumber(landLine);
}
// Don't set null or wrong references
}
// Set fax number
- contact.setContactFaxNumber(fax);
+ localContact.setContactFaxNumber(fax);
}
// Is the provider set?
if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
// Is the number set?
- if (mobile.getPhoneNumber() == null) {
+ if (mobile.getMobileNumber() == null) {
// Is null
throw new NullPointerException("cmobile.phoneNumber is null"); //NOI18N
- } else if (mobile.getPhoneNumber() < 1) {
+ } else if (mobile.getMobileNumber() < 1) {
// Abort here
throw new IllegalStateException("cmobile.phoneNumber is zero or below."); //NOI18N
}
// Set cmobile number
- contact.setContactMobileNumber(mobile);
+ localContact.setContactMobileNumber(mobile);
}
// Return it
- return contact;
+ return localContact;
+ }
+
+ /**
+ * Deletes currently chosen contact and returns to list view
+ *
+ * @return
+ */
+ public String deleteContactData () {
+ // Is contact set?
+ if (this.getContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.contact is null");
+ } else if (this.getContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.contact.contactId is null");
+ } else if (this.getContact().getContactId() < 1) {
+ // Throw IAE
+ throw new NullPointerException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId()));
+ }
+
+ try {
+ // Invoke EJB
+ this.adminContactBean.deleteContactData(this.getContact());
+ } catch (final ContactNotFoundException ex) {
+ // Throw it again
+ throw new FacesException(ex);
+ }
+
+ // Fire event
+ this.deletedContactEvent.fire(new AdminDeletedContactEvent(this.getContact()));
+
+ // Return to list view
+ return "admin_list_contacts";
}
/**
* Edits currently loaded contact's data in database.
- * <p>
- * @return Redirect outcome
*/
- public String editContactData () {
+ public void editContactData () {
// Get contact instance
- final Contact contact = this.createContactInstance();
+ final Contact createdContact = this.createContactInstance();
// Check if contact instance is in helper and valid
- if (null == contact) {
+ if (null == createdContact) {
// Throw NPE
throw new NullPointerException("beanHelper.contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
+ } else if (createdContact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N //NOI18N
- } else if (contact.getContactId() < 1) {
+ throw new NullPointerException("beanHelper.contact.contactId is null"); //NOI18N
+ } else if (createdContact.getContactId() < 1) {
// Invalid id
- throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
+ throw new IllegalStateException(MessageFormat.format("beanHelper.contact.contactId={0} is invalid", createdContact.getContactId())); //NOI18N
}
// Update all data in contact
- this.updateContactData(contact);
+ this.updateContactData(createdContact);
+
+ // Init updated contact instance
+ final Contact updatedContact;
- // Call EJB for updating contact data
- final Contact updatedContact = this.contactBean.updateContactData(contact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ try {
+ // Call EJB for updating contact data
+ updatedContact = this.contactBean.updateContactData(createdContact, this.isMobileNumberUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ } catch (final ContactNotFoundException ex) {
+ // Throw as a cause
+ throw new FacesException(ex);
+ }
// Fire event
this.updatedContactEvent.fire(new AdminUpdatedContactEvent(updatedContact));
// Clear bean
this.clear();
-
- // Return to contact list (for now)
- return "admin_list_contact"; //NOI18N
}
/**
"%s%d%d", //NOI18N
mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
mobileNumber.getMobileProvider().getProviderDialPrefix(),
- mobileNumber.getPhoneNumber()
+ mobileNumber.getMobileNumber()
);
// Return it
this.comment = comment;
}
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
/**
* Getter for contactCountry instance
* <p>
return "admin"; //NOI18N
}
- @Override
- @Deprecated
- public void setControllerType (final String controllerType) {
- throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
- }
-
/**
* Getter for email address
* <p>
*/
private void clear () {
// Clear all data
+ this.setContact(null);
+
// - personal data
this.setAcademicTitle(null);
this.setFirstName(null);
this.setComment(null);
}
- /**
- * Checks whether the given contact is found
- * <p>
- * @param contact Contact instance
- *
- * @return Whether contact has been found
- */
- private boolean isSameContactFound (final Contact contact) {
- // Default is not found
- boolean IsFound = false;
-
- // Get iterator
- final Iterator<Contact> iterator = this.contactController.allContacts().iterator();
-
- // Loop through all
- while (iterator.hasNext()) {
- // Get next contact
- final Contact next = iterator.next();
-
- // Is the same?
- if (ContactUtils.isSameContact(contact, next)) {
- // Yes, then abort loop
- IsFound = false;
- break;
- }
- }
-
- // Return status
- return IsFound;
- }
-
/**
* Updates all data in contact instance.
* <p>
throw new NullPointerException("contact is null"); //NOI18N
} else if (contact.getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("contact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
} else if (contact.getContactId() < 1) {
// Invalid id
throw new IllegalStateException(MessageFormat.format("contact.contactId={0} is invalid", contact.getContactId())); //NOI18N
*/
String getControllerType ();
- /**
- * Setter for controller type
- * <p>
- * @param controllerType Controller type
- * <p>
- * @deprecated Don't use this method
- */
- @Deprecated
- void setControllerType (final String controllerType);
-
}
*/
package org.mxchange.addressbook.beans.contact;
-import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
import java.util.Date;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
-import javax.faces.view.facelets.FaceletException;
+import javax.enterprise.inject.Any;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.UpdatedContactEvent;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
import org.mxchange.jcontacts.model.contact.UserContact;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.jusercore.events.user.update.pre.ObservablePreUserPersonalDataUpdatedEvent;
import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
/**
private ContactSessionBeanRemote contactBean;
/**
- * Contact list
+ * An instance of a contact-list backing bean
*/
+ private AddressbookContactListWebViewController contactListController;
+
+ /**
+ * Event being fired when a user has updated his contact data
+ */
+ @Any
@Inject
- @NamedCache (cacheName = "contactsCache")
- private Cache<Long, Contact> contactsCache;
+ private Event<ObservableUpdatedContactEvent> contactUpdatedEvent;
/**
* Country instance
*/
private String emailAddress;
- /**
- * Email address list
- */
- @Inject
- @NamedCache (cacheName = "emailAddressCache")
- private Cache<Long, String> emailAddressCache;
-
/**
* Email address repeated
*/
*/
private String houseNumberExtension;
- /**
- * Whether a fax entry has been unlinked
- */
- private boolean isFaxUnlinked;
-
- /**
- * Whether a land-line number has been unlinked
- */
- private boolean isLandLineUnlinked;
-
- /**
- * Whether a mobile entry has been unlinked
- */
- private boolean isMobileUnlinked;
-
/**
* Phone number area code
*/
*/
private PersonalTitle personalTitle;
- /**
- * A list of all selectable contacts
- */
- @Inject
- @NamedCache (cacheName = "selectableContactsCache")
- private Cache<Long, Contact> selectableContactsCache;
-
/**
* Street
*/
private String street;
- /**
- * Regular user controller
- */
- @Inject
- private AddressbookUserWebRequestController userController;
-
/**
* Login bean (controller)
*/
super();
}
- /**
- * Observes events being fired when an administrator has added a new
- * contact.
- * <p>
- * @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 //NOI18N
- }
-
- // Clear this bean
- this.clear();
-
- // Call other method
- this.uniqueAddContact(event.getAddedContact());
-
- // Add to selectable contacts
- this.selectableContactsCache.put(event.getAddedContact().getContactId(), event.getAddedContact());
- }
-
/**
* Event observer for newly added users by administrator
* <p>
* @param event Event being fired
*/
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserContact().getContactId())); //NOI18N
}
- // Remove contact from list available contacts list
- this.selectableContactsCache.remove(event.getLinkedUser().getUserContact().getContactId());
-
// Clear all data
this.clear();
}
- /**
- * Event observer for updated contact data by administrators
- * <p>
- * @param event Updated contact data event
- */
- public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // event 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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
- }
-
- // Add contact instance only once
- this.uniqueAddContact(event.getUpdatedContact());
-
- // Add email address to list
- this.emailAddressCache.put(event.getUpdatedContact().getContactId(), event.getUpdatedContact().getContactEmailAddress());
- }
-
- /**
- * Event observer when user confirmed account.
- * <p>
- * @param event Event being fired
- */
- public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getConfirmedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.confirmedUser is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
- }
-
- // Add contact instance only once
- this.uniqueAddContact(event.getConfirmedUser().getUserContact());
- }
-
/**
* Event observer for logged-in user
* <p>
* @param event Event instance
*/
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
}
// Copy all data to this bean
- this.copyContact(event.getLoggedInUser().getUserContact());
+ this.copyFromContact(event.getLoggedInUser().getUserContact());
}
/**
- * Event observer for new user registrations
+ * Observes events being fired before an updated of personal data done by a
+ * user has started.
* <p>
- * @param event User registration event
+ * @param event Event being observed
*/
- public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // event should not be null
+ public void beforeUserUpdatedPersonalDataEvent (@Observes final ObservablePreUserPersonalDataUpdatedEvent event) {
+ // Is the instance valid?
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
- }
-
- // Get user instance
- final Contact registeredContact = event.getRegisteredUser().getUserContact();
-
- // Copy all data from registered->user
- this.copyContact(registeredContact);
-
- // Add contact instance only once
- this.uniqueAddContact(registeredContact);
-
- // Add user name and email address
- this.addUserNameEmailAddress(registeredContact);
-
- // Clear all data
- this.clear();
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<Contact> allContacts () {
- // Init list
- final List<Contact> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
+ } else if (event.getUpdatedUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("event.updatedUser is null"); //NOI18N
}
- // Return it
- return list;
+ // Set all
+ this.copyToContact(event.getUpdatedUser().getUserContact());
}
@Override
// Is all required data set?
if (!this.isRequiredPersonalDataSet()) {
// No, then abort here
- throw new FaceletException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
+ throw new FacesException(new IllegalArgumentException("Not all personal data is set, but createContactInstance() is called.")); //NOI18N
}
// Create new contact
Boolean.FALSE
);
- // Don't set null or wrong references
- if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
- // Now the number must be given
- if (fax.getPhoneAreaCode() == null) {
- // Is null
- throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
- } else if (fax.getPhoneAreaCode() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
- } else if (fax.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
- } else if (fax.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set fax number
- contact.setContactFaxNumber(fax);
- }
-
- // Is the provider set?
- if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
- // Is the number set?
- if (mobile.getPhoneNumber() == null) {
- // Is null
- throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
- } else if (mobile.getPhoneNumber() < 1) {
- // Abort here
- throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
- }
-
- // Set mobile number
- contact.setContactMobileNumber(mobile);
- }
-
- // Return it
+ // Return instance
return contact;
}
throw new IllegalStateException("User is not logged-in"); //NOI18N
} else if (!this.isRequiredChangePersonalDataSet()) {
// Not all required fields are set
- throw new FaceletException("Not all required fields are set."); //NOI18N
+ throw new FacesException("Not all required fields are set."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_change_personal:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
// Get contact instance
- Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
+ final Contact contact = this.userLoginController.getLoggedInUser().getUserContact();
// It should be there, so run some tests on it
assert (contact instanceof Contact) : "Instance userLoginController.loggedInUser.userContact is null"; //NOI18N
contact.setContactCountry(this.getCountry());
// Update contact's mobile number
- this.isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
+ final boolean isMobileUnlinked = ContactUtils.updateMobileNumber(contact, this.getMobileProvider(), this.getMobileNumber());
// Update contact's land-line number
- this.isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ final boolean isLandLineUnlinked = ContactUtils.updateLandLineNumber(contact, this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
// Update contact's fax number
- this.isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+ final boolean isFaxUnlinked = ContactUtils.updateFaxNumber(contact, this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
+
+ // Init updated contact instance
+ final Contact updatedContact;
+
+ try {
+ // Send it to the EJB
+ updatedContact = this.contactBean.updateContactData(contact, isMobileUnlinked, isLandLineUnlinked, isFaxUnlinked);
+ } catch (final ContactNotFoundException ex) {
+ // Throw as cause
+ throw new FacesException(ex);
+ }
- // Send it to the EJB
- this.contactBean.updateContactData(contact, this.isMobileUnlinked, this.isLandLineUnlinked, this.isFaxUnlinked);
+ // Fire event
+ this.contactUpdatedEvent.fire(new UpdatedContactEvent(updatedContact));
// All fine
return "contact_data_saved"; //NOI18N
this.comment = comment;
}
- @Override
- public String getControllerType () {
- return "general"; //NOI18N
- }
-
- @Override
- @Deprecated
- public void setControllerType (final String controllerType) {
- throw new UnsupportedOperationException("Setting controller type is not supported."); //NOI18N
- }
-
/**
* Getter for country instance
* <p>
this.zipCode = zipCode;
}
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.contactsCache.iterator().hasNext()) {
- // Get whole list
- final List<Contact> contacts = this.contactBean.allContacts();
-
- // Add all
- for (final Contact contact : contacts) {
- // Add it to cache
- this.contactsCache.put(contact.getContactId(), contact);
- this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
- }
- } else if (this.selectableContactsCache.iterator().hasNext()) {
- // Has already entries, avoid executing below code
- return;
- }
-
- // Get all users
- final List<User> allUsers = this.userController.allUsers();
-
- // Get iterator from contacts cache
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
- // Loop through all contacts
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Default is not found
- boolean isFound = false;
-
- // User list is not empty, check each entry, if contact is found
- for (final User user : allUsers) {
- // Is the contact the same?
- if (Objects.equals(user.getUserContact(), next.getValue())) {
- // Found one
- isFound = true;
- break;
- }
- }
-
- // Is contact not found?
- if (!isFound) {
- // Add it as selectable
- this.selectableContactsCache.put(next.getKey(), next.getValue());
- }
- }
- }
-
@Override
public boolean isEmailAddressRegistered (final Contact contact) {
// Cherck parameter
throw new IllegalArgumentException("contact.contactEmailAddress is empty."); //NOI18N
}
+ // Default is not registered
+ boolean isRegistered = false;
+
// Determine it
- return ((this.emailAddressCache instanceof List) && (this.emailAddressCache.containsKey(contact.getContactId())));
+ for (final Contact currentContact : this.contactListController.getAllContacts()) {
+ // Is same contact found?
+ if (currentContact.getContactEmailAddress().equals(contact.getContactEmailAddress())) {
+ // Found same email address
+ isRegistered = true;
+
+ // Skipp further iterations
+ break;
+ }
+ }
+
+ // Return status
+ return isRegistered;
+ }
+
+ @Override
+ public boolean isEmailAddressRegistered (final String emailAddress) {
+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
return (Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat()));
}
- /**
- * Returns a list of all selectable contacts for user creation. Contacts
- * from already existing users are excluded in this list.
- * <p>
- * @return A list of all selectable contacts
- */
- public List<Contact> selectableContacts () {
- // Init list
- final List<Contact> selectableContacts = new LinkedList<>();
-
- // Get iterator from cache
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
-
- // Loop through all contacts
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
-
- // Add entry's value to list
- selectableContacts.add(next.getValue());
- }
-
- // Return list
- return selectableContacts;
- }
-
- @Override
- public void updateContactDataFromController (final Contact contact) {
- // Is the instance valid?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- }
-
- // Set all
- this.copyContact(contact);
- }
-
- /**
- * Adds email address to bean's internal list.
- * <p>
- * @param contact Contact instance
- */
- private void addUserNameEmailAddress (final Contact contact) {
- // Make sure the entry is not added yet
- if (this.emailAddressCache.containsKey(contact.getContactId())) {
- // Already added
- throw new IllegalArgumentException(MessageFormat.format("Email address {0} already added.", contact.getContactEmailAddress())); //NOI18N
- }
-
- // Add email addres
- this.emailAddressCache.put(contact.getContactId(), contact.getContactEmailAddress());
- }
-
/**
* Clears this bean
*/
}
/**
- * Copies given contact into the controller
+ * Copies given contact data into the controller
* <p>
* @param contact Contact instance
*/
- private void copyContact (final Contact contact) {
- // Is the instance valid?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- }
-
+ private void copyFromContact (final Contact contact) {
// Copy all fields:
// - base data
this.setPersonalTitle(contact.getContactPersonalTitle());
this.setComment(contact.getContactComment());
// Get mobile, phone and fax instance
- DialableMobileNumber mobile = contact.getContactMobileNumber();
- DialableFaxNumber fax = contact.getContactFaxNumber();
- DialableLandLineNumber phone = contact.getContactLandLineNumber();
-
- // - contact data
- if ((phone instanceof DialableLandLineNumber) && (phone.getPhoneAreaCode() > 0)) {
- this.setLandLineCountry(phone.getPhoneCountry());
- this.setLandLineAreaCode(phone.getPhoneAreaCode());
- this.setLandLineNumber(phone.getPhoneNumber());
- }
-
- if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
- this.setMobileProvider(mobile.getMobileProvider());
- this.setMobileNumber(mobile.getPhoneNumber());
- }
+ final DialableFaxNumber fax = contact.getContactFaxNumber();
+ final DialableLandLineNumber landLine = contact.getContactLandLineNumber();
+ final DialableMobileNumber mobile = contact.getContactMobileNumber();
+ // Is a fax number set?
if ((fax instanceof DialableFaxNumber) && (fax.getPhoneAreaCode() > 0)) {
+ // Copy elements
this.setFaxCountry(fax.getPhoneCountry());
this.setFaxAreaCode(fax.getPhoneAreaCode());
this.setFaxNumber(fax.getPhoneNumber());
}
- }
- /**
- * Removes given contact from all lists
- * <p>
- * @param contact Contact instance to remove
- */
- private void removeContact (final Contact contact) {
- // Is the instance valid?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
+ // Is a land-line number set?
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneAreaCode() > 0)) {
+ // Copy elements
+ this.setLandLineCountry(landLine.getPhoneCountry());
+ this.setLandLineAreaCode(landLine.getPhoneAreaCode());
+ this.setLandLineNumber(landLine.getPhoneNumber());
}
- // Remove from general list
- if (!this.contactsCache.remove(contact.getContactId())) {
- // Did not remove contact
- throw new IllegalStateException(MessageFormat.format("contact {0} was not removed.", contact.getContactId())); //NOI18N
+ // Is a mobile number set?
+ if ((mobile instanceof DialableMobileNumber) && (mobile.getMobileProvider() instanceof MobileProvider)) {
+ // Copy elements
+ this.setMobileProvider(mobile.getMobileProvider());
+ this.setMobileNumber(mobile.getMobileNumber());
}
-
- // Remove from other lists
- this.emailAddressCache.remove(contact.getContactId());
}
/**
- * Adds unique instance to contact list. First any existing instance is
- * being removed, then the new instance is added.
+ * Copies all fields from this backing bean into given instance.
* <p>
- * @param contact Contact instance to add uniquely
+ * @param contact An instance of a Contact class
*/
- private void uniqueAddContact (final Contact contact) {
- // Is the instance valid?
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw NPE
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid id number
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid.", contact.getContactId())); //NOI18N
- }
+ private void copyToContact (final Contact contact) {
+ // Set other elements
+ contact.setContactStreet(this.getStreet());
+ contact.setContactHouseNumber(this.getHouseNumber());
+ contact.setContactHouseNumberExtension(this.getHouseNumberExtension());
+ contact.setContactZipCode(this.getZipCode());
+ contact.setContactCity(this.getCity());
+ contact.setContactCountry(this.getCountry());
+ contact.setContactEmailAddress(this.getEmailAddress());
+ contact.setContactBirthday(this.getBirthday());
+ contact.setContactComment(this.getComment());
- // Get iterator from list
- final Iterator<Cache.Entry<Long, Contact>> iterator = this.contactsCache.iterator();
+ // Generate phone number
+ final DialableLandLineNumber landLine = new LandLineNumber(this.getLandLineCountry(), this.getLandLineAreaCode(), this.getLandLineNumber());
+ final DialableMobileNumber mobile = new MobileNumber(this.getMobileProvider(), this.getMobileNumber());
+ final DialableFaxNumber fax = new FaxNumber(this.getFaxCountry(), this.getFaxAreaCode(), this.getFaxNumber());
- // "Walk" through all entries
- while (iterator.hasNext()) {
- // Get next element
- final Cache.Entry<Long, Contact> next = iterator.next();
+ // Don't set null or wrong references
+ if ((landLine instanceof DialableLandLineNumber) && (landLine.getPhoneCountry() instanceof Country) && (this.getLandLineAreaCode() != null) && (this.getLandLineNumber() != null) && (this.getLandLineAreaCode() > 0) && (this.getLandLineNumber() > 0)) {
+ // Now the number must be given
+ if (landLine.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneAreaCode is null"); //NOI18N
+ } else if (landLine.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneAreaCode is zero or below."); //NOI18N
+ } else if (landLine.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("phone.phoneNumber is null"); //NOI18N
+ } else if (landLine.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("phone.phoneNumber is zero or below."); //NOI18N
+ }
- // Is id number the same?
- if (Objects.equals(contact.getContactId(), next.getKey())) {
- // Found entry, so remove it and abort
- this.removeContact(next.getValue());
- break;
+ // Set phone number
+ contact.setContactLandLineNumber(landLine);
+ }
+
+ // Don't set null or wrong references
+ if ((fax instanceof DialableFaxNumber) && (fax.getPhoneCountry() instanceof Country) && (this.getFaxAreaCode() != null) && (this.getFaxNumber() != null) && (this.getFaxAreaCode() > 0) && (this.getFaxNumber() > 0)) {
+ // Now the number must be given
+ if (fax.getPhoneAreaCode() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneAreaCode is null"); //NOI18N
+ } else if (fax.getPhoneAreaCode() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneAreaCode is zero or below."); //NOI18N
+ } else if (fax.getPhoneNumber() == null) {
+ // Is null
+ throw new NullPointerException("fax.phoneNumber is null"); //NOI18N
+ } else if (fax.getPhoneNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("fax.phoneNumber is zero or below."); //NOI18N
}
+
+ // Set fax number
+ contact.setContactFaxNumber(fax);
}
- // Add contact to list
- this.contactsCache.put(contact.getContactId(), contact);
+ // Is the provider set?
+ if ((mobile instanceof DialableMobileNumber) && (this.getMobileProvider() instanceof MobileProvider) && (this.getMobileNumber() != null) && (this.getMobileNumber() > 0)) {
+ // Is the number set?
+ if (mobile.getMobileNumber() == null) {
+ // Is null
+ throw new NullPointerException("mobile.phoneNumber is null"); //NOI18N
+ } else if (mobile.getMobileNumber() < 1) {
+ // Abort here
+ throw new IllegalArgumentException("mobile.phoneNumber is zero or below."); //NOI18N
+ }
+
+ // Set mobile number
+ contact.setContactMobileNumber(mobile);
+ }
}
}
package org.mxchange.addressbook.beans.contact;
import java.io.Serializable;
-import java.util.List;
import org.mxchange.jcontacts.model.contact.Contact;
/**
*/
void clearEmailAddresses ();
- /**
- * Returns a list of all found contacts
- * <p>
- * @return A list of all contacts.
- */
- List<Contact> allContacts ();
-
- /**
- * Updates all data from bean in given contact instance
- * <p>
- * @param userContact Contact instance to update
- */
- void updateContactDataFromController (final Contact userContact);
-
/**
* Creates an instance from all properties
* <p>
*/
Contact createContactInstance ();
- /**
- * Getter for controller type
- * <p>
- * @return controller type
- */
- String getControllerType ();
-
- /**
- * Setter for controller type
- * <p>
- * @param controllerType Controller type
- * <p>
- * @deprecated Don't use this method.
- */
- @Deprecated
- void setControllerType (final String controllerType);
-
/**
* Checks whether contact instance's email address is used
* <p>
*/
String doChangePersonalContactData ();
+ /**
+ * Checks whether the given email address is already registered. The email
+ * address should be validated by EmailAddressValidator before calling this
+ * method.
+ * <p>
+ * @param emailAddress Email address to check
+ * <p>
+ * @return Whether the email address is already registered
+ */
+ boolean isEmailAddressRegistered (final String emailAddress);
+
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.contact.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.deleted.ObservableAdminDeletedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
+import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
+import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.jcontacts.model.utils.ContactUtils;
+import org.mxchange.jphone.model.phonenumbers.DialableNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+
+/**
+ * A regular contact list bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("contactListController")
+@ViewScoped
+public class AddressbookContactListWebViewBean extends BaseAddressbookBean implements AddressbookContactListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_917L;
+
+ /**
+ * All contacts
+ */
+ private final List<Contact> allContacts;
+
+ /**
+ * Administrative contact EJB
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote")
+ private ContactSessionBeanRemote contactBean;
+
+ /**
+ * Contact list
+ */
+ @Inject
+ @NamedCache (cacheName = "contactCache")
+ private transient Cache<Long, Contact> contactCache;
+
+ /**
+ * A list of filtered contacts
+ */
+ private List<Contact> filteredContacts;
+
+ /**
+ * Current selected contact
+ */
+ private Contact selectedContact;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookContactListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allContacts = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @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
+ }
+
+ // Call other method
+ this.uniqueAddContact(event.getAddedContact());
+ }
+
+ /**
+ * Event observer for when an administrator has deleted a contact
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedContactEvent (@Observes final ObservableAdminDeletedContactEvent event) {
+ // Validate parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getDeletedContact() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedContact is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedContact.contactId is null"); //NOI18N
+ } else if (event.getDeletedContact().getContactId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("event.deletedContact.contactId={0} is not valid.", event.getDeletedContact().getContactId())); //NOI18N
+ }
+
+ // Delete from cache and list
+ this.contactCache.remove(event.getDeletedContact().getContactId());
+ this.getAllContacts().remove(event.getDeletedContact());
+ }
+
+ /**
+ * Event observer for unlinked fax contact by administrators
+ * <p>
+ * @param event Unlinked fax contact event
+ */
+ public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent 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.getUnlinkedFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from any entry
+ for (final Cache.Entry<Long, Contact> entry : this.contactCache) {
+ // Get contact instance from it
+ final Contact contact = entry.getValue();
+
+ // Is the number matching?
+ if (Objects.equals(event.getUnlinkedFaxNumber(), contact.getContactFaxNumber())) {
+ // Yes, then unset it
+ contact.setContactFaxNumber(null);
+ }
+ }
+ }
+
+ /**
+ * Event observer for unlinked land-line contact by administrators
+ * <p>
+ * @param event Unlinked land-line contact event
+ */
+ public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent 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.getUnlinkedLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Remove it from any entry
+ for (final Cache.Entry<Long, Contact> entry : this.contactCache) {
+ // Get contact instance from it
+ final Contact contact = entry.getValue();
+
+ // Is the number matching?
+ if (Objects.equals(event.getUnlinkedLandLineNumber(), contact.getContactLandLineNumber())) {
+ // Yes, then unset it
+ contact.setContactLandLineNumber(null);
+ }
+ }
+ }
+
+ /**
+ * Event observer for unlinked mobile contact by administrators
+ * <p>
+ * @param event Unlinked mobile contact event
+ */
+ public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent 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.getUnlinkedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getMobileId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
+ } else if (event.getUnlinkedMobileNumber().getMobileId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getMobileId())); //NOI18N
+ }
+
+ // Remove it from any entry
+ for (final Cache.Entry<Long, Contact> entry : this.contactCache) {
+ // Get contact instance from it
+ final Contact contact = entry.getValue();
+
+ // Is the number matching?
+ if (Objects.equals(event.getUnlinkedMobileNumber(), contact.getContactMobileNumber())) {
+ // Yes, then unset it
+ contact.setContactMobileNumber(null);
+ }
+ }
+ }
+
+ /**
+ * Event observer for updated contact data by administrators
+ * <p>
+ * @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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getUpdatedContact());
+ }
+
+ /**
+ * Event observer for updated contact data by the user
+ * <p>
+ * @param event Updated contact data event
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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("userId of user={0} is not valid: {1}", event.getUpdatedContact(), event.getUpdatedContact().getContactId())); //NOI18N
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getUpdatedContact());
+ }
+
+ /**
+ * Event observer when user confirmed account.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserConfirmedAccount (@Observes final ObservableUserConfirmedAccountEvent 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.getConfirmedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
+ }
+
+ // Add contact instance only once
+ this.uniqueAddContact(event.getConfirmedUser().getUserContact());
+ }
+
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent 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.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Get user instance
+ final Contact registeredContact = event.getRegisteredUser().getUserContact();
+
+ // Add contact instance only once
+ this.uniqueAddContact(registeredContact);
+ }
+
+ @Override
+ public Contact findContactById (final Long contactId) throws ContactNotFoundException {
+ // Validate parameter
+ if (null == contactId) {
+ // Throw NPE
+ throw new NullPointerException("contactId is null"); //NOI18N
+ } else if (contactId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("contactId={0} is invalid", contactId)); //NOI18N
+ } else if (!this.contactCache.containsKey(contactId)) {
+ // Not found
+ throw new ContactNotFoundException(contactId);
+ }
+
+ // Get it from cache
+ final Contact contact = this.contactCache.get(contactId);
+
+ // Return it
+ return contact;
+ }
+
+ /**
+ * Returns a text representation of given mobile number or null if not set.
+ * <p>
+ * @param mobileNumber Mobile number
+ * <p>
+ * @return Text representation or null
+ */
+ public String generateMobileNumber (final DialableMobileNumber mobileNumber) {
+ // Is it null?
+ if (null == mobileNumber) {
+ // Return null
+ return null;
+ }
+
+ // Get all data
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ mobileNumber.getMobileProvider().getProviderCountry().getCountryExternalDialPrefix(),
+ mobileNumber.getMobileProvider().getProviderDialPrefix(),
+ mobileNumber.getMobileNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
+ /**
+ * Returns a text representation of given land-line or fax number or null if
+ * not set.
+ * <p>
+ * @param phoneNumber Land-line or fax number
+ * <p>
+ * @return Text representation or null
+ */
+ public String generatePhoneNumber (final DialableNumber phoneNumber) {
+ // Is it null?
+ if (null == phoneNumber) {
+ // Return null
+ return null;
+ }
+
+ // Generate it
+ final String number = String.format(
+ "%s%d%d", //NOI18N
+ phoneNumber.getPhoneCountry().getCountryExternalDialPrefix(),
+ phoneNumber.getPhoneAreaCode(),
+ phoneNumber.getPhoneNumber()
+ );
+
+ // Return it
+ return number;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Contact> getAllContacts () {
+ return this.allContacts;
+ }
+
+ /**
+ * Getter for filtered contacts
+ * <p>
+ * @return
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Contact> getFilteredContacts () {
+ return this.filteredContacts;
+ }
+
+ /**
+ * Setter for filtered contacts
+ * <p>
+ * @param filteredContacts Filtered contacts list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredContacts (final List<Contact> filteredContacts) {
+ this.filteredContacts = filteredContacts;
+ }
+
+ /**
+ * Getter for selected contact
+ * <p>
+ * @return Selected Contact instance
+ */
+ public Contact getSelectedContact () {
+ return this.selectedContact;
+ }
+
+ /**
+ * Setter for selected contact
+ * <p>
+ * @param selectedContact
+ */
+ public void setSelectedContact (final Contact selectedContact) {
+ this.selectedContact = selectedContact;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.contactCache.iterator().hasNext()) {
+ // Add all
+ for (final Contact contact : this.contactBean.fetchAllContacts()) {
+ // Add it to cache
+ this.contactCache.put(contact.getContactId(), contact);
+ }
+ }
+
+ // Is cache there and list is not full?
+ if ((this.getAllContacts().isEmpty()) && (this.contactCache.iterator().hasNext())) {
+ // Build up list
+ for (final Cache.Entry<Long, Contact> currentEntry : this.contactCache) {
+ // Add to list
+ this.getAllContacts().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllContacts().sort(new Comparator<Contact>() {
+ @Override
+ public int compare (final Contact contact1, final Contact contact2) {
+ return contact1.getContactId() > contact2.getContactId() ? 1 : contact1.getContactId() < contact2.getContactId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredContacts(this.getAllContacts());
+ }
+ }
+
+ @Override
+ public boolean isContactFound (final Contact contact) {
+ // Default is not found
+ boolean IsFound = false;
+
+ // Loop through all
+ for (final Contact currentContact : this.getAllContacts()) {
+ // Is the same?
+ if (ContactUtils.isSameContact(contact, currentContact)) {
+ // Yes, then abort loop
+ IsFound = false;
+ break;
+ }
+ }
+
+ // Return status
+ return IsFound;
+ }
+
+ /**
+ * Removes given contact from all lists
+ * <p>
+ * @param contact Contact instance to remove
+ */
+ private void removeContact (final Contact contact) {
+ // Remove from general list
+ this.contactCache.remove(contact.getContactId());
+ }
+
+ /**
+ * Adds unique instance to contact list. First any existing instance is
+ * being removed, then the new instance is added.
+ * <p>
+ * @param contact Contact instance to add uniquely
+ */
+ private void uniqueAddContact (final Contact contact) {
+ // "Walk" through all entries
+ for (final Cache.Entry<Long, Contact> currentEntry : this.contactCache) {
+ // Is id number the same?
+ if (Objects.equals(contact.getContactId(), currentEntry.getKey())) {
+ // Found entry, so remove it and abort
+ this.removeContact(currentEntry.getValue());
+ break;
+ }
+ }
+
+ // Add contact to list
+ this.contactCache.put(contact.getContactId(), contact);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.contact.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+
+/**
+ * An administrative interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookContactListWebViewController extends Serializable {
+
+ /**
+ * Returns a contact instance which has the given id number.
+ * <p>
+ * @param contactId Contact id
+ * <p>
+ * @return Contact instance
+ * <p>
+ * @throws ContactNotFoundException If the contact was not found
+ */
+ Contact findContactById (final Long contactId) throws ContactNotFoundException;
+
+ /**
+ * Checks whether the given contact is found
+ * <p>
+ * @param contact Contact instance
+ *
+ * @return Whether contact has been found
+ */
+ boolean isContactFound (final Contact contact);
+
+ /**
+ * Getter for all contacts
+ *
+ * @return All contact
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ List<Contact> getAllContacts ();
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+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.contact.update.ObservableUpdatedContactEvent;
+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.exceptions.ContactNotFoundException;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.mobile.AdminContactsMobileSessionBeanRemote;
+import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
+import org.mxchange.jphone.exceptions.mobile.MobileNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.mobile.MobileNumberNotLinkedException;
+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)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminContactMobileController")
+@RequestScoped
+public class AddressbookAdminContactMobileWebRequestBean extends BaseAddressbookBean implements AddressbookAdminContactMobileWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_919L;
+
+ /**
+ * Administrative EJB for phone number
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminContactMobile!org.mxchange.jcontacts.model.mobile.AdminContactsMobileSessionBeanRemote")
+ private AdminContactsMobileSessionBeanRemote adminContactMobileBean;
+
+ /**
+ * Event being fired when a mobile number has been linked
+ */
+ @Inject
+ @Any
+ private Event<ObservableAdminLinkedMobileNumberEvent> 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<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminContactMobileWebRequestBean () {
+ // 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.
+ * <p>
+ * @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
+ * <p>
+ * @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
+ * <p>
+ * @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.
+ * <p>
+ * @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
+ } else if (event.getCreatedContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.createdContact.contactId is null"); //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.
+ * <p>
+ * @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());
+ }
+
+ /**
+ * Event observer for updated contact data by the user
+ * <p>
+ * @param event Updated contact data event
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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();
+ }
+
+ /**
+ * Links mobile number to contact from bean helper as "main mobile number".
+ * <p>
+ * @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.adminContactMobileBean.linkNewMobileNumberWithContact(targetContact, number);
+ } catch (final MobileNumberAlreadyLinkedException | ContactNotFoundException 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
+ * <p>
+ * @return Contact instance
+ */
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Setter for phone id
+ * <p>
+ * @return Phone id
+ */
+ public Long getMobileId () {
+ return this.mobileId;
+ }
+
+ /**
+ * Getter for phone id
+ * <p>
+ * @param mobileId Phone id
+ */
+ public void setMobileId (final Long mobileId) {
+ this.mobileId = mobileId;
+ }
+
+ /**
+ * Getter for mobile number
+ * <p>
+ * @return Mobile number
+ */
+ public Long getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for mobile number
+ * <p>
+ * @param mobileNumber Mobile number
+ */
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Getter for mobile provider
+ * <p>
+ * @return Mobile provider
+ */
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ /**
+ * Setter for mobile provider
+ * <p>
+ * @param mobileProvider Mobile provider
+ */
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ /**
+ * Unlinks mobile data with current contact
+ * <p>
+ * @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.adminContactMobileBean.unlinkMobileDataFromContact(this.getContact(), number);
+ } catch (final MobileNumberNotLinkedException | ContactNotFoundException 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.
+ * <p>
+ * @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
+ * <p>
+ * @return Mobile entry created
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ private Date getMobileEntryCreated () {
+ return this.mobileEntryCreated;
+ }
+
+ /**
+ * Setter for mobile entry created
+ * <p>
+ * @param mobileEntryCreated Mobile entry created
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ private void setMobileEntryCreated (final Date mobileEntryCreated) {
+ this.mobileEntryCreated = mobileEntryCreated;
+ }
+
+ /**
+ * Getter for mobile entry updated
+ * <p>
+ * @return Mobile entry updated
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ private Date getMobileEntryUpdated () {
+ return this.mobileEntryUpdated;
+ }
+
+ /**
+ * Setter for mobile entry updated
+ * <p>
+ * @param mobileEntryUpdated Mobile entry updated
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ private void setMobileEntryUpdated (final Date mobileEntryUpdated) {
+ this.mobileEntryUpdated = mobileEntryUpdated;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+import org.mxchange.jcontacts.model.contact.Contact;
+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)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("contactMobileController")
+@RequestScoped
+public class AddressbookContactMobileWebRequestBean extends BaseAddressbookBean implements AddressbookContactMobileWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_916L;
+
+ /**
+ * An instance of a contact-list controller
+ */
+ @Inject
+ private AddressbookContactListWebViewController contactListController;
+
+ /**
+ * Chosen mobile number
+ */
+ private DialableMobileNumber mobileNumber;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookContactMobileWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @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
+ * <p>
+ * @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
+ * <p>
+ * @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.
+ * <p>
+ * @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());
+ }
+
+ /**
+ * Event observer for updated contact data by the user
+ * <p>
+ * @param event Updated contact data event
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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();
+ }
+
+ /**
+ * Getter for all contacts having current mobile number linked
+ * <p>
+ * @return List of all linked contacts
+ */
+ public List<Contact> allCurrentMobileNumberContacts () {
+ // Get id
+ final DialableMobileNumber dialableMobileNumber = this.getMobileNumber();
+
+ // Init list
+ final List<Contact> 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
+ * <p>
+ * @return mobile number
+ */
+ public DialableMobileNumber getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for chosen mobile number
+ * <p>
+ * @param mobileNumber mobile number
+ */
+ public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+}
package org.mxchange.addressbook.beans.contact.phone;
import java.text.MessageFormat;
-import java.util.Calendar;
+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.addressbook.beans.BaseAddressbookBean;
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.contact.update.ObservableUpdatedContactEvent;
import org.mxchange.jcontacts.events.fax.linked.AdminLinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.fax.unlinked.AdminUnlinkedFaxNumberEvent;
import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.landline.unlinked.AdminUnlinkedLandLineNumberEvent;
import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
-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.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcontacts.model.phone.AdminContactsPhoneSessionBeanRemote;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
-import org.mxchange.jphone.exceptions.PhoneNumberAlreadyLinkedException;
-import org.mxchange.jphone.exceptions.PhoneNumberNotLinkedException;
+import org.mxchange.jphone.exceptions.phone.PhoneNumberAlreadyLinkedException;
+import org.mxchange.jphone.exceptions.phone.PhoneNumberNotLinkedException;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
-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;
/**
@Any
private Event<ObservableAdminLinkedLandLineNumberEvent> adminLinkedLandLineNumberEvent;
- /**
- * Event being fired when a mobile number has been linked
- */
- @Inject
- @Any
- private Event<ObservableAdminLinkedMobileNumberEvent> adminLinkedMobileNumberEvent;
-
/**
* Administrative phone controller
*/
private Event<ObservableAdminUnlinkedLandLineNumberEvent> landLineNumberUnlinkedEvent;
/**
- * Mobile number
+ * When phone number has been created
*/
- private Long mobileNumber;
+ private Date phoneEntryCreated;
/**
- * Event being fired when administrator unlinks mobile from contact
+ * When phone number has been updated
*/
- @Inject
- @Any
- private Event<ObservableAdminUnlinkedMobileNumberEvent> mobileNumberUnlinkedEvent;
-
- /**
- * Mobile provider
- */
- private MobileProvider mobileProvider;
-
- /**
- * When fax number has been created
- */
- private Calendar phoneEntryCreated;
-
- /**
- * When fax number has been updated
- */
- private Calendar phoneEntryUpdated;
+ private Date phoneEntryUpdated;
/**
* Phone id (primary key)
* @param event Event being fired
*/
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Updated contact data event
*/
public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
throw new NullPointerException("event is null"); //NOI18N
} else if (event.getCreatedContact() == null) {
// Throw NPE again
- throw new NullPointerException("event.createdContact is null"); //NOI18N //NOI18N
+ throw new NullPointerException("event.createdContact is null"); //NOI18N
} else if (event.getCreatedContact().getContactId() == null) {
// Throw NPE again
- throw new NullPointerException("event.createdContact.contactId is null"); //NOI18N //NOI18N
+ throw new NullPointerException("event.createdContact.contactId is null"); //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
}
/**
- * Observes events being fired when a bean helper has successfully created a
- * mobile number instance.
+ * Event observer for updated contact data by the user
* <p>
- * @param event Event being fired
+ * @param event Updated contact data event
*/
- public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
- // The event instance must be valid
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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.getMobileNumber() == null) {
+ } else if (event.getUpdatedContact() == null) {
// Throw NPE again
- throw new NullPointerException("event.mobileNumber is null"); //NOI18N
- } else if (event.getMobileNumber().getPhoneId() == null) {
- // Throw NPE yet again
- throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
- } else if (event.getMobileNumber().getPhoneId() < 1) {
- // Throw NPE yet again
- throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
+ 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
}
- // Get fax number from event
- final DialableMobileNumber number = event.getMobileNumber();
-
- // Copy all data to this bean
- this.setPhoneId(number.getPhoneId());
- this.setMobileProvider(number.getMobileProvider());
- this.setMobileNumber(number.getPhoneNumber());
- this.setPhoneEntryCreated(number.getPhoneEntryCreated());
- this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
+ // Clear all data
+ this.clear();
}
/**
try {
// Link it, too
updatedContact = this.adminContactPhoneBean.linkNewFaxNumberWithContact(targetContact, number);
- } catch (final PhoneNumberAlreadyLinkedException ex) {
+ } catch (final PhoneNumberAlreadyLinkedException | ContactNotFoundException ex) {
// Throw again as cause
- this.showFacesMessage("form_add_contact_fax:faxNumber", ex); //NOI18N
+ this.showFacesMessage("form_add_contact_fax:faxNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
try {
// Link it, too
updatedContact = this.adminContactPhoneBean.linkNewLandLineNumberWithContact(targetContact, number);
- } catch (final PhoneNumberAlreadyLinkedException ex) {
+ } catch (final PhoneNumberAlreadyLinkedException | ContactNotFoundException ex) {
// Throw again as cause
- this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex); //NOI18N
+ this.showFacesMessage("form_add_contact_landLine:landLineNumber", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
return "admin_show_contact"; //NOI18N
}
- /**
- * Links mobile number to contact from bean helper as "main mobile number".
- * <p>
- * @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); //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
* <p>
this.landLineNumber = landLineNumber;
}
- /**
- * Getter for mobile number
- * <p>
- * @return Mobile number
- */
- public Long getMobileNumber () {
- return this.mobileNumber;
- }
-
- /**
- * Setter for mobile number
- * <p>
- * @param mobileNumber Mobile number
- */
- public void setMobileNumber (final Long mobileNumber) {
- this.mobileNumber = mobileNumber;
- }
-
- /**
- * Getter for mobile provider
- * <p>
- * @return Mobile provider
- */
- public MobileProvider getMobileProvider () {
- return this.mobileProvider;
- }
-
- /**
- * Setter for mobile provider
- * <p>
- * @param mobileProvider Mobile provider
- */
- public void setMobileProvider (final MobileProvider mobileProvider) {
- this.mobileProvider = mobileProvider;
- }
-
/**
* Setter for phone id
* <p>
try {
// Unlink it and return contact without fax instance
updatedContact = this.adminContactPhoneBean.unlinkFaxDataFromContact(this.getContact(), number);
- } catch (final PhoneNumberNotLinkedException ex) {
+ } catch (final PhoneNumberNotLinkedException | ContactNotFoundException ex) {
// Did not work
- this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex); //NOI18N
+ this.showFacesMessage("form_unlink_contact_fax:faxNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
try {
// Unlink it and return contact without landLine instance
updatedContact = this.adminContactPhoneBean.unlinkLandLineDataFromContact(this.getContact(), number);
- } catch (final PhoneNumberNotLinkedException ex) {
+ } catch (final PhoneNumberNotLinkedException | ContactNotFoundException ex) {
// Did not work
- this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex); //NOI18N
+ this.showFacesMessage("form_unlink_contact_landLine:landLineNumberId", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
return "admin_show_contact"; //NOI18N
}
- /**
- * Unlinks mobile data with current contact
- * <p>
- * @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.getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("number.phoneId is null"); //NOI18N
- } else if (number.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("number.phoneId={0} is not valid", number.getPhoneId())); //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.getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("number.phoneNumber is null"); //NOI18N
- } else if (number.getPhoneNumber() < 1) {
- // Throw it again ...
- throw new NullPointerException(MessageFormat.format("number.phoneNumber={0} is not valid.", number.getPhoneNumber())); //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); //NOI18N
- return ""; //NOI18N
- }
-
- // Fire event
- this.mobileNumberUnlinkedEvent.fire(new AdminUnlinkedMobileNumberEvent(updatedContact, number));
-
- // All fine here
- return "admin_show_contact"; //NOI18N
- }
-
/**
* Clears this bean
*/
// Set all other fields
number.setPhoneEntryCreated(this.getPhoneEntryCreated());
number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
-
- // Is id number there?
- if (this.getPhoneId() instanceof Long) {
- // Set it
- number.setPhoneId(this.getPhoneId());
- }
+ number.setPhoneId(this.getPhoneId());
// Return it
return number;
// Add all other data
number.setPhoneEntryCreated(this.getPhoneEntryCreated());
number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
-
- // Is id number set?
- if (this.getPhoneId() instanceof Long) {
- // Set it
- number.setPhoneId(this.getPhoneId());
- }
-
- // Return it
- return number;
- }
-
- /**
- * Returns an instance of a DialableMobileNumber from all fields stored in
- * this bean.
- * <p>
- * @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.setPhoneEntryCreated(this.getPhoneEntryCreated());
- number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
-
- // Is id number set?
- if (this.getPhoneId() instanceof Long) {
- // Set it
- number.setPhoneId(this.getPhoneId());
- }
+ number.setPhoneId(this.getPhoneId());
// Return it
return number;
/**
* Getter for phone entry created
* <p>
- * @param faxNumberEntryCreated Phone entry created
+ * @return Phone entry created
*/
@SuppressWarnings ("ReturnOfDateField")
- private Calendar getPhoneEntryCreated () {
+ private Date getPhoneEntryCreated () {
return this.phoneEntryCreated;
}
* @param phoneEntryCreated Phone entry created
*/
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- private void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
+ private void setPhoneEntryCreated (final Date phoneEntryCreated) {
this.phoneEntryCreated = phoneEntryCreated;
}
* @return Phone entry updated
*/
@SuppressWarnings ("ReturnOfDateField")
- private Calendar getPhoneEntryUpdated () {
+ private Date getPhoneEntryUpdated () {
return this.phoneEntryUpdated;
}
* @param phoneEntryUpdated Phone entry updated
*/
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- private void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
+ private void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
this.phoneEntryUpdated = phoneEntryUpdated;
}
*/
package org.mxchange.addressbook.beans.contact.phone;
-import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
-import javax.cache.Cache;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
-import org.mxchange.jcontacts.events.fax.unlinked.ObservableAdminUnlinkedFaxNumberEvent;
-import org.mxchange.jcontacts.events.landline.unlinked.ObservableAdminUnlinkedLandLineNumberEvent;
-import org.mxchange.jcontacts.events.mobile.unlinked.ObservableAdminUnlinkedMobileNumberEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
-import org.mxchange.jphone.model.phonenumbers.DialableNumber;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
/**
private static final long serialVersionUID = 542_145_347_916L;
/**
- * General contact controller
+ * An instance of a contact-list controller
*/
@Inject
- private AddressbookContactWebRequestController contactController;
-
- /**
- * "Cache" for contact's mobile, land-line and fax numbers. Currently one
- * per each type is supported. Maybe later this will change into a OneToMany
- * relationship (one contact, many numbers).
- */
- @Inject
- @NamedCache (cacheName = "contactsPhoneCache")
- private Cache<DialableNumber, List<Contact>> contactsPhoneCache;
+ private AddressbookContactListWebViewController contactListController;
/**
* fax number
*/
private DialableLandLineNumber landLineNumber;
- /**
- * Chosen mobile number
- */
- private DialableMobileNumber mobileNumber;
-
/**
* Default constructor
*/
* @param event Event being fired
*/
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
this.clear();
}
- /**
- * Event observer for unlinked fax contact by administrators
- * <p>
- * @param event Unlinked fax contact event
- */
- public void afterAdminUnlinkedFaxContactDataEvent (@Observes final ObservableAdminUnlinkedFaxNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUnlinkedFaxNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.unlinkedFaxNumber is null"); //NOI18N
- } else if (event.getUnlinkedFaxNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.unlinkedFaxNumber.contactId is null"); //NOI18N
- } else if (event.getUnlinkedFaxNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedFaxNumber(), event.getUnlinkedFaxNumber().getPhoneId())); //NOI18N
- }
-
- // Remove it from list
- this.contactsPhoneCache.remove(event.getUnlinkedFaxNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Event observer for unlinked land-line contact by administrators
- * <p>
- * @param event Unlinked land-line contact event
- */
- public void afterAdminUnlinkedLandLineContactDataEvent (@Observes final ObservableAdminUnlinkedLandLineNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUnlinkedLandLineNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.unlinkedLandLineNumber is null"); //NOI18N
- } else if (event.getUnlinkedLandLineNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.unlinkedLandLineNumber.contactId is null"); //NOI18N
- } else if (event.getUnlinkedLandLineNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedLandLineNumber(), event.getUnlinkedLandLineNumber().getPhoneId())); //NOI18N
- }
-
- // Remove it from list
- this.contactsPhoneCache.remove(event.getUnlinkedLandLineNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Event observer for unlinked mobile contact by administrators
- * <p>
- * @param event Unlinked mobile contact event
- */
- public void afterAdminUnlinkedMobileContactDataEvent (@Observes final ObservableAdminUnlinkedMobileNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUnlinkedMobileNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.unlinkedMobileNumber is null"); //NOI18N
- } else if (event.getUnlinkedMobileNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.unlinkedMobileNumber.contactId is null"); //NOI18N
- } else if (event.getUnlinkedMobileNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("contactId of contact={0} is not valid: {1}", event.getUnlinkedMobileNumber(), event.getUnlinkedMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Remove it from list
- this.contactsPhoneCache.remove(event.getUnlinkedMobileNumber());
-
- // Clear all data
- this.clear();
- }
-
/**
* Event observer for updated contact data by administrators
* <p>
* @param event Updated contact data event
*/
public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
}
/**
- * Observes events being fired when a bean helper has successfully created a
- * mobile number instance.
+ * Event observer for updated contact data by the user
* <p>
- * @param event Event being fired
+ * @param event Updated contact data event
*/
- public void afterCreatedMobileNumberEvent (@Observes final ObservableCreatedMobileNumberEvent event) {
- // The event instance must be valid
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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.getMobileNumber() == null) {
+ } else if (event.getUpdatedContact() == null) {
// Throw NPE again
- throw new NullPointerException("event.mobileNumber is null"); //NOI18N
- } else if (event.getMobileNumber().getPhoneId() == null) {
- // Throw NPE yet again
- throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
- } else if (event.getMobileNumber().getPhoneId() < 1) {
- // Throw NPE yet again
- throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
+ 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
}
- // Set it here
- this.setMobileNumber(event.getMobileNumber());
+ // Clear all data
+ this.clear();
}
/**
// Get id
final DialableFaxNumber number = this.getFaxNumber();
- // Is cache there?
- if (this.contactsPhoneCache.containsKey(number)) {
- // Return cached version
- return this.contactsPhoneCache.get(number);
- } else {
- // Ask bean
- final List<Contact> list = new LinkedList<>();
-
- // "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
- // Is mobile instance the same?
- if (Objects.equals(contact.getContactFaxNumber(), number)) {
- // Found one
- list.add(contact);
- }
- }
-
- // Store result in cache
- this.contactsPhoneCache.put(number, list);
+ // Init list
+ final List<Contact> contacts = new LinkedList<>();
- // Return now-cached list
- return list;
+ // "Walk" through all contacts
+ for (final Contact contact : this.contactListController.getAllContacts()) {
+ // Is mobile instance the same?
+ if (Objects.equals(contact.getContactFaxNumber(), number)) {
+ // Found one
+ contacts.add(contact);
+ }
}
+
+ // Return now-cached list
+ return contacts;
}
/**
* @return List of all linked contacts
*/
public List<Contact> allCurrentLandLineNumberContacts () {
- // Get id
+ // Get it locally
final DialableLandLineNumber number = this.getLandLineNumber();
- // Is cache there?
- if (this.contactsPhoneCache.containsKey(number)) {
- // Return cached version
- return this.contactsPhoneCache.get(number);
- } else {
- // Ask bean
- final List<Contact> list = new LinkedList<>();
-
- // "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
- // Is mobile instance the same?
- if (Objects.equals(contact.getContactLandLineNumber(), number)) {
- // Found one
- list.add(contact);
- }
- }
-
- // Store result in cache
- this.contactsPhoneCache.put(number, list);
-
- // Return now-cached list
- return list;
- }
- }
+ // Init list
+ final List<Contact> contacts = new LinkedList<>();
- /**
- * Getter for all contacts having current mobile number linked
- * <p>
- * @return List of all linked contacts
- */
- public List<Contact> allCurrentMobileNumberContacts () {
- // Get id
- final DialableMobileNumber number = this.getMobileNumber();
-
- // Is cache there?
- if (this.contactsPhoneCache.containsKey(number)) {
- // Return cached version
- return this.contactsPhoneCache.get(number);
- } else {
- // Ask bean
- final List<Contact> list = new LinkedList<>();
-
- // "Walk" through all contacts
- for (final Contact contact : this.contactController.allContacts()) {
- // Is mobile instance the same?
- if (Objects.equals(contact.getContactMobileNumber(), number)) {
- // Found one
- list.add(contact);
- }
+ // "Walk" through all contacts
+ for (final Contact contact : this.contactListController.getAllContacts()) {
+ // Is mobile instance the same?
+ if (Objects.equals(contact.getContactLandLineNumber(), number)) {
+ // Found one
+ contacts.add(contact);
}
-
- // Store result in cache
- this.contactsPhoneCache.put(number, list);
-
- // Return now-cached list
- return list;
}
+
+ // Return now-cached list
+ return contacts;
}
/**
this.landLineNumber = landLineNumber;
}
- /**
- * Getter for chosen mobile number
- * <p>
- * @return mobile number
- */
- public DialableMobileNumber getMobileNumber () {
- return this.mobileNumber;
- }
-
- /**
- * Setter for chosen mobile number
- * <p>
- * @param mobileNumber mobile number
- */
- public void setMobileNumber (final DialableMobileNumber mobileNumber) {
- this.mobileNumber = mobileNumber;
- }
-
/**
* Clears this bean
*/
*/
package org.mxchange.addressbook.beans.country;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcountry.events.AdminAddedCountryEvent;
-import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
+import org.mxchange.addressbook.beans.country.list.AddressbookCountryListWebViewController;
+import org.mxchange.jcountry.events.added.AdminAddedCountryEvent;
+import org.mxchange.jcountry.events.added.ObservableAdminAddedCountryEvent;
import org.mxchange.jcountry.exceptions.CountryAlreadyAddedException;
+import org.mxchange.jcountry.model.data.AdminCountrySessionBeanRemote;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jcountry.model.data.CountryData;
-import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
/**
* An administrative country bean
private Event<ObservableAdminAddedCountryEvent> addedCountryEvent;
/**
- * Abroad dial prefix
+ * Remote country EJB
*/
- private String countryAbroadDialPrefix;
+ @EJB (lookup = "java:global/addressbook-ejb/adminCountry!org.mxchange.jcountry.model.data.AdminCountrySessionBeanRemote")
+ private AdminCountrySessionBeanRemote adminCountryBean;
/**
- * Remote country EJB
+ * Abroad dial prefix
*/
- @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote")
- private CountrySingletonBeanRemote countryBean;
+ private String countryAbroadDialPrefix;
/**
* 2-letter country code
*/
private String countryCode;
- /**
- * Regular country controller
- */
- @Inject
- private AddressbookCountryWebRequestController countryController;
-
/**
* Local dial prefix
*/
*/
private Boolean countryIsLocalPrefixRequired;
+ /**
+ * Regular country controller
+ */
+ @Inject
+ private AddressbookCountryListWebViewController countryListController;
+
/**
* Phone code
*/
* Adds country to all relevant beans and sends it to the EJB. A redirect
* should happen after successful creation.
* <p>
- * @return Redirect outcome
- * <p>
* @todo Add field validation
*/
- public String addCountry () {
+ public void addCountry () {
// Create new country object
final Country country = new CountryData(
this.getCountryAbroadDialPrefix(),
// Does it already exist?
if (this.isCountryAdded(country)) {
// Yes, then abort here
- throw new FaceletException(new CountryAlreadyAddedException(country));
+ throw new FacesException(new CountryAlreadyAddedException(country));
}
// Init variable
try {
// Send country to bean
- updatedCountry = this.countryBean.addCountry(country);
+ updatedCountry = this.adminCountryBean.addCountry(country);
} catch (final CountryAlreadyAddedException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
// Clear this bean
this.clear();
-
- // Redirect to list
- return "admin_list_country"; //NOI18N
}
/**
// Default is not found
boolean isAdded = false;
- // Now get whole ist
- final List<Country> countries = this.countryController.allCountries();
-
- // Get iterator from it
- final Iterator<Country> iterator = countries.iterator();
-
// Check whole list
- while (iterator.hasNext()) {
- // Get next country
- final Country next = iterator.next();
-
+ for (final Country currentCountry : this.countryListController.getAllCountries()) {
// Is country code or i18n the same?
- if ((Objects.equals(country.getCountryCode(), next.getCountryCode())) || (Objects.equals(country.getCountryI18nKey(), next.getCountryI18nKey()))) {
+ if ((Objects.equals(country.getCountryCode(), currentCountry.getCountryCode())) || (Objects.equals(country.getCountryI18nKey(), currentCountry.getCountryI18nKey()))) {
// Yes, then abort search
isAdded = true;
break;
*/
package org.mxchange.addressbook.beans.country;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
-import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
-import org.mxchange.jcountry.events.ObservableAdminAddedCountryEvent;
/**
* A country bean
*/
private static final long serialVersionUID = 176_985_298_681_742_960L;
- /**
- * Remote country EJB
- */
- @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote")
- private CountrySingletonBeanRemote countryBean;
-
- /**
- * List of all countries
- */
- @Inject
- @NamedCache (cacheName = "countryCache")
- private Cache<Long, Country> countryCache;
-
/**
* Default constructor
*/
super();
}
- /**
- * Observing method when the event is fired that an administrator added a
- * new country
- * <p>
- * @param event Event instance
- */
- public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent event) {
- // Is all valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getAddedCountry() == null) {
- // Throw again ...
- throw new NullPointerException("event.addedCountry is null"); //NOI18N
- } else if (event.getAddedCountry().getCountryId() == null) {
- // And again ...
- throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N
- } else if (event.getAddedCountry().getCountryId() < 1) {
- // Id is invalid
- throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N
- }
-
- // Add the event
- this.countryCache.put(event.getAddedCountry().getCountryId(), event.getAddedCountry());
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<Country> allCountries () {
- // Init list
- final List<Country> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, Country>> iterator = this.countryCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, Country> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.countryCache.iterator().hasNext()) {
- // Get whole list
- final List<Country> list = this.countryBean.allCountries();
-
- // Add all
- for (final Iterator<Country> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final Country next = iterator.next();
-
- // Add it to cache
- this.countryCache.put(next.getCountryId(), next);
- }
- }
- }
-
}
package org.mxchange.addressbook.beans.country;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcountry.model.data.Country;
/**
* An interface for country beans
*/
public interface AddressbookCountryWebRequestController extends Serializable {
- /**
- * A list of all countries
- * <p>
- * @return All countries
- */
- List<Country> allCountries ();
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.country.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcountry.events.added.ObservableAdminAddedCountryEvent;
+import org.mxchange.jcountry.exceptions.CountryNotFoundException;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
+
+/**
+ * A country-list bean
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("countryListController")
+@ViewScoped
+public class AddressbookCountryListWebViewBean extends BaseAddressbookBean implements AddressbookCountryListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 176_985_298_681_742_961L;
+
+ /**
+ * A list of all countries
+ */
+ private final List<Country> allCountries;
+
+ /**
+ * Remote country EJB
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote")
+ private CountrySingletonBeanRemote countryBean;
+
+ /**
+ * List of all countries
+ */
+ @Inject
+ @NamedCache (cacheName = "countryCache")
+ private transient Cache<Long, Country> countryCache;
+
+ /**
+ * A list of filtered countries
+ */
+ private List<Country> filteredCountries;
+
+ /**
+ * Selected country
+ */
+ private Country selectedCountry;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookCountryListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allCountries = new LinkedList<>();
+ }
+
+ /**
+ * Observing method when the event is fired that an administrator added a
+ * new country
+ * <p>
+ * @param event Event instance
+ */
+ public void afterAdminAddedCountryEvent (@Observes final ObservableAdminAddedCountryEvent event) {
+ // Is all valid?
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedCountry() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.addedCountry is null"); //NOI18N
+ } else if (event.getAddedCountry().getCountryId() == null) {
+ // And again ...
+ throw new NullPointerException("event.addedCountry.countryId is null"); //NOI18N
+ } else if (event.getAddedCountry().getCountryId() < 1) {
+ // Id is invalid
+ throw new IllegalArgumentException(MessageFormat.format("event.addedCountry.countryId={0} is not valid.", event.getAddedCountry().getCountryId())); //NOI18N
+ }
+
+ // Add the event
+ this.countryCache.put(event.getAddedCountry().getCountryId(), event.getAddedCountry());
+ }
+
+ @Override
+ public Country findCountryById (final Long countryId) throws CountryNotFoundException {
+ // Validate parameter
+ if (null == countryId) {
+ // Throw NPE
+ throw new NullPointerException("countryId is null"); //NOI18N
+ } else if (countryId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("countryId=" + countryId + " is invalid"); //NOI18N
+ } else if (!this.countryCache.containsKey(countryId)) {
+ // Not found
+ throw new CountryNotFoundException(countryId);
+ }
+
+ // Get it from cache
+ final Country country = this.countryCache.get(countryId);
+
+ // Return it
+ return country;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Country> getAllCountries () {
+ return this.allCountries;
+ }
+
+ /**
+ * Getter for filtered country list
+ * <p>
+ * @return Filtered country list
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<Country> getFilteredCountries () {
+ return this.filteredCountries;
+ }
+
+ /**
+ * Setter for filtered countries list
+ * <p>
+ * @param filteredCountries Filtered countries list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredCountries (final List<Country> filteredCountries) {
+ this.filteredCountries = filteredCountries;
+ }
+
+ /**
+ * Getter for selected country
+ * <p>
+ * @return Selected country
+ */
+ public Country getSelectedCountry () {
+ return this.selectedCountry;
+ }
+
+ /**
+ * Setter for selected country
+ * <p>
+ * @param selectedCountry Selected country
+ */
+ public void setSelectedCountry (final Country selectedCountry) {
+ this.selectedCountry = selectedCountry;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.countryCache.iterator().hasNext()) {
+ // Add all
+ for (final Country country : this.countryBean.fetchAllCountries()) {
+ // Add it to cache
+ this.countryCache.put(country.getCountryId(), country);
+ }
+ }
+
+ // Is cache there and list is not full?
+ if ((this.getAllCountries().isEmpty()) && (this.countryCache.iterator().hasNext())) {
+ // Build up list
+ for (final Cache.Entry<Long, Country> currentEntry : this.countryCache) {
+ // Add to list
+ this.getAllCountries().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllCountries().sort(new Comparator<Country>() {
+ @Override
+ public int compare (final Country country1, final Country country2) {
+ return country1.getCountryId() > country2.getCountryId() ? 1 : country1.getCountryId() < country2.getCountryId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredCountries(this.getAllCountries());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.country.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jcountry.exceptions.CountryNotFoundException;
+import org.mxchange.jcountry.model.data.Country;
+
+/**
+ * An interface for country-list beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookCountryListWebViewController extends Serializable {
+
+ /**
+ * A list of all countries
+ * <p>
+ * @return All countries
+ */
+ List<Country> getAllCountries ();
+
+ /**
+ * Returns a country instance found by given primary key. If not found, a
+ * proper exception is thrown.
+ * <p>
+ * @param countryId Primary key
+ * <p>
+ * @return Country data instance
+ * <p>
+ * @throws CountryNotFoundException If the primary key was not found
+ */
+ public Country findCountryById (final Long countryId) throws CountryNotFoundException;
+
+}
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jproduct.model.payment.PaymentType;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+import org.mxchange.jcoreee.dates.DayOfTheWeek;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
/**
* An application-scoped data bean for any kind of static data
}
/**
- * Returns a list of all payment types
+ * Returns an array of all days of the week
* <p>
- * @return A list of all payment types
+ * @return An array of all days of the week
*/
- public PaymentType[] getPaymentTypes () {
- return PaymentType.values();
+ public DayOfTheWeek[] getDayOfTheWeek () {
+ return DayOfTheWeek.values();
+ }
+
+ /**
+ * Returns an array of all personal titles
+ * <p>
+ * @return An array of all personal titles
+ */
+ public PersonalTitle[] getPersonalTitles () {
+ return PersonalTitle.values();
+ }
+
+ /**
+ * Returns an array of all profile modes
+ * <p>
+ * @return An array of all profile modes
+ */
+ public ProfileMode[] getProfileModes () {
+ return ProfileMode.values();
+ }
+
+ /**
+ * Returns an array of all user account statuses
+ * <p>
+ * @return An array of all user account statuses
+ */
+ public UserAccountStatus[] getUserAccountStatuses () {
+ return UserAccountStatus.values();
}
}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.helper;
-
-import java.text.MessageFormat;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.inject.Any;
-import javax.inject.Inject;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
-import org.mxchange.addressbook.beans.phone.AddressbookAdminPhoneWebRequestController;
-import org.mxchange.addressbook.beans.user.AddressbookAdminUserWebRequestController;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
-import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent;
-import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent;
-import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
-import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.created.CreatedMobileNumberEvent;
-import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
-import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * A general helper for beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("beanHelper")
-@RequestScoped
-public class AddressbookWebRequestHelperBean implements AddressbookWebRequestHelperController {
-
- /**
- * Call-stack instance (5 may show BeanELResolver.getValue as caller)
- */
- private static final short THREAD_STACK = 5;
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 17_258_793_567_145_701L;
-
- /**
- * Administrative contact controller
- */
- @Inject
- private AddressbookAdminContactWebRequestController adminContactController;
-
- /**
- * Administrative phone controller
- */
- @Inject
- private AddressbookAdminPhoneWebRequestController adminPhoneController;
-
- /**
- * Administrative user controller
- */
- @Inject
- private AddressbookAdminUserWebRequestController adminUserController;
-
- /**
- * Contact instance
- */
- private Contact contact;
-
- /**
- * Event for when a contact instance was created
- */
- @Any
- @Inject
- private Event<ObservableCreatedContactEvent> contactCreatedEvent;
-
- /**
- * Fax number
- */
- private DialableFaxNumber faxNumber;
-
- /**
- * Event for when a fax number instance was created
- */
- @Any
- @Inject
- private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
-
- /**
- * Land-line number
- */
- private DialableLandLineNumber landLineNumber;
-
- /**
- * Event for when a land-line number instance was created
- */
- @Any
- @Inject
- private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
-
- /**
- * Mobile number
- */
- private DialableMobileNumber mobileNumber;
-
- /**
- * Event for when a mobile number instance was created
- */
- @Any
- @Inject
- private Event<ObservableCreatedMobileNumberEvent> mobileNumberCreatedEvent;
-
- /**
- * User instance
- */
- private User user;
-
- /**
- * Regular user controller
- */
- @Inject
- private AddressbookUserWebRequestController userController;
-
- /**
- * Event for when a user instance was created
- */
- @Any
- @Inject
- private Event<ObservableCreatedUserEvent> userCreatedEvent;
-
- /**
- * Default constructor
- */
- public AddressbookWebRequestHelperBean () {
- // 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));
- }
-
- /**
- * Getter for contact instance
- * <p>
- * @return Contact instance
- */
- @Override
- public Contact getContact () {
- return this.contact;
- }
-
- /**
- * Setter for contact instance
- * <p>
- * @param contact Contact instance
- */
- public void setContact (final Contact contact) {
- // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
- // System.out.println(MessageFormat.format("{0}: Setting contact={1}, previous: {2}, caller: {3}", this.getClass().getSimpleName(), contact, this.contact, caller));
- this.contact = contact;
- }
-
- /**
- * Returns a message key depending on if this contact is a user and/or a
- * contact. If this contact is unused, a default key is returned.
- * <p>
- * @param contact Contact instance to check
- * <p>
- * @return Message key
- */
- public String getContactUsageMessageKey (final Contact contact) {
- // The contact must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- }
-
- // Default key is "unused"
- String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
-
- // Check user first
- if (this.userController.isContactFound(contact)) {
- // Only user
- messageKey = "CONTACT_IS_USER"; //NOI18N
- }
-
- // Return message key
- return messageKey;
- }
-
- /**
- * Getter for dialable fax number
- * <p>
- * @return Dialable fax number
- */
- @Override
- public DialableFaxNumber getFaxNumber () {
- return this.faxNumber;
- }
-
- /**
- * Setter for dialable fax number
- * <p>
- * @param faxNumber Dialable fax number
- */
- public void setFaxNumber (final DialableFaxNumber faxNumber) {
- this.faxNumber = faxNumber;
- }
-
- /**
- * Getter for dialable land-line number
- * <p>
- * @return Dialable land-line number
- */
- @Override
- public DialableLandLineNumber getLandLineNumber () {
- return this.landLineNumber;
- }
-
- /**
- * Setter for dialable land-line number
- * <p>
- * @param landLineNumber Dialable land-line number
- */
- public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
- this.landLineNumber = landLineNumber;
- }
-
- /**
- * Getter for dialable mobile number
- * <p>
- * @return Dialable mobile number
- */
- @Override
- public DialableMobileNumber getMobileNumber () {
- return this.mobileNumber;
- }
-
- /**
- * Setter for dialable mobile number
- * <p>
- * @param mobileNumber Dialable mobile number
- */
- public void setMobileNumber (final DialableMobileNumber mobileNumber) {
- this.mobileNumber = mobileNumber;
- }
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- @Override
- public User getUser () {
- return this.user;
- }
-
- /**
- * Setter for user instance
- * <p>
- * @param user User instance
- */
- public void setUser (final User user) {
- this.user = user;
- }
-
- /**
- * Notifies other controllers (backing beans) if a contact id has been
- * successfully converted to a Contact instance.
- */
- public void notifyControllerContactConverted () {
- // String caller = MessageFormat.format("{0}.{1}", Thread.currentThread().getStackTrace()[THREAD_STACK].getClassName(), Thread.currentThread().getStackTrace()[THREAD_STACK].getMethodName());
- // System.out.println(MessageFormat.format("{0}.notifyControllerContactConverted: CALLED, caller: {2}", this.getClass().getSimpleName(), this.contact, caller));
-
- // Validate contact instance
- if (this.getContact() == null) {
- // Throw NPE
- throw new NullPointerException("this.contact is null"); //NOI18N
- } else if (this.getContact().getContactId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.contact.contactId is null"); //NOI18N
- } else if (this.getContact().getContactId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
- }
-
- // Set all phone instances
- this.setPhoneInstances(this.getContact());
-
- // Set all fields: user
- this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
- }
-
- /**
- * Notifies other controllers (backing beans) if a phone id has been
- * successfully converted to a DialableFaxNumber instance.
- */
- public void notifyControllerFaxNumberConverted () {
- // Validate fax instance
- if (this.getFaxNumber() == null) {
- // Throw NPE
- throw new NullPointerException("this.faxNumber is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneId() == null) {
- // Throw again
- throw new NullPointerException("this.faxNumber.phoneId is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); //NOI18N
- } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
- // Throw again
- throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
- } else if (this.getFaxNumber().getPhoneCountry() == null) {
- // Throw NPE again
- throw new NullPointerException("this.faxNumber.phoneCountry is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
- // ... throw again
- throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId())); //NOI18N
- } else if (this.getFaxNumber().getPhoneNumber() == null) {
- // Throw NPE again ...
- throw new NullPointerException("this.faxNumber.phoneNumber is null"); //NOI18N
- } else if (this.getFaxNumber().getPhoneNumber() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); //NOI18N
- }
-
- // Fire event
- this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
- }
-
- /**
- * Notifies other controllers (backing beans) if a phone id has been
- * successfully converted to a DialableLandLineNumber instance.
- */
- public void notifyControllerLandLineNumberConverted () {
- // Validate land-line instance
- if (this.getLandLineNumber() == null) {
- // Throw NPE
- throw new NullPointerException("this.landLineNumber is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneId() == null) {
- // Throw again
- throw new NullPointerException("this.landLineNumber.phoneId is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); //NOI18N
- } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
- // Throw again
- throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
- } else if (this.getLandLineNumber().getPhoneCountry() == null) {
- // Throw NPE again
- throw new NullPointerException("this.landLineNumber.phoneCountry is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
- // ... throw again
- throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId())); //NOI18N
- } else if (this.getLandLineNumber().getPhoneNumber() == null) {
- // Throw NPE again ...
- throw new NullPointerException("this.landLineNumber.phoneNumber is null"); //NOI18N
- } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); //NOI18N
- }
-
- // Fire event
- this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
- }
-
- /**
- * Notifies other controllers (backing beans) if a phone id has been
- * successfully converted to a DialableMobileNumber instance.
- */
- public void notifyControllerMobileNumberConverted () {
- // Validate mobile instance
- if (this.getMobileNumber() == null) {
- // Throw NPE
- throw new NullPointerException("this.mobileNumber is null"); //NOI18N
- } else if (this.getMobileNumber().getPhoneId() == null) {
- // Throw again
- throw new NullPointerException("this.mobileNumber.phoneId is null"); //NOI18N
- } else if (this.getMobileNumber().getPhoneId() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneId={0} is not valid", this.getMobileNumber().getPhoneId())); //NOI18N
- } else if (this.getMobileNumber().getMobileProvider() == null) {
- // Throw NPE again
- throw new NullPointerException("this.mobileNumber.mobileProvider is null"); //NOI18N
- } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
- } else if (this.getMobileNumber().getPhoneNumber() == null) {
- // Throw NPE again ...
- throw new NullPointerException("this.mobileNumber.phoneNumber is null"); //NOI18N
- } else if (this.getMobileNumber().getPhoneNumber() < 1) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.phoneNumber={0} is not valid", this.getMobileNumber().getPhoneNumber())); //NOI18N
- }
-
- // Fire event
- this.mobileNumberCreatedEvent.fire(new CreatedMobileNumberEvent(this.getMobileNumber()));
- }
-
- /**
- * Notifies other controllers (backing beans) if a user id has been
- * successfully converted to a User instance.
- */
- public void notifyControllerUserConverted () {
- // Log message
- //* NOISY-DEBUG: */ System.out.println("AdminHelper::notifyControllerUserConverted - CALLED!"); //NOI18N
-
- // Validate user instance
- if (this.getUser() == null) {
- // Throw NPE
- throw new NullPointerException("this.user is null"); //NOI18N
- } else if (this.getUser().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("this.user.userId is null"); //NOI18N
- } else if (this.getUser().getUserId() < 1) {
- // Not valid
- throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
- }
-
- // Get contact
- final Contact userContact = this.getUser().getUserContact();
-
- // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
- this.setContact(userContact);
-
- // Set all phone instances
- this.setPhoneInstances(userContact);
-
- // Fire event
- this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
- }
-
- /**
- * Set's all given contact's phone instances: land-line, mobile and
- * faxNumber
- * <p>
- * @param contact Contact to set phone instances for
- */
- private void setPhoneInstances (final Contact contact) {
- // The contact must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- }
-
- // Is mobile set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Yes, then set it in admin controller
- this.setMobileNumber(contact.getContactMobileNumber());
- }
-
- // Is land-line set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
- // Yes, then set it in admin controller
- this.setLandLineNumber(contact.getContactLandLineNumber());
- }
-
- // Is faxNumber set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- // Yes, then set it in admin controller
- this.setFaxNumber(contact.getContactFaxNumber());
- }
- }
-
-}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.helper;
-
-import java.io.Serializable;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jusercore.model.user.User;
-
-/**
- * An interface for general bean helper
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookWebRequestHelperController extends Serializable {
-
- /**
- * Getter for contact instance
- * <p>
- * @return Contact instance
- */
- Contact getContact ();
-
- /**
- * Getter for dialable fax number
- * <p>
- * @return Dialable fax number
- */
- DialableFaxNumber getFaxNumber ();
-
- /**
- * Getter for dialable land-line number
- * <p>
- * @return Dialable land-line number
- */
- DialableLandLineNumber getLandLineNumber ();
-
- /**
- * Getter for dialable mobile number
- * <p>
- * @return Dialable mobile number
- */
- DialableMobileNumber getMobileNumber ();
-
- /**
- * Getter for user instance
- * <p>
- * @return User instance
- */
- User getUser ();
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.helper;
+
+import java.text.MessageFormat;
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.event.Event;
+import javax.enterprise.inject.Any;
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
+import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
+import org.mxchange.jcontacts.events.contact.created.CreatedContactEvent;
+import org.mxchange.jcontacts.events.contact.created.ObservableCreatedContactEvent;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+import org.mxchange.jcountry.model.data.Country;
+import org.mxchange.jphone.events.fax.created.CreatedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.created.CreatedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.created.ObservableCreatedLandLineNumberEvent;
+import org.mxchange.jphone.events.mobile.created.CreatedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
+import org.mxchange.jphone.model.phonenumbers.DialableNumber;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.events.user.created.CreatedUserEvent;
+import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * A general helper for beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("beanHelper")
+@RequestScoped
+public class AddressbookWebViewHelperBean extends BaseAddressbookBean implements AddressbookWebViewHelperController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 17_258_793_567_145_701L;
+
+ /**
+ * Contact instance
+ */
+ private Contact contact;
+
+ /**
+ * Event for when a contact instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedContactEvent> contactCreatedEvent;
+
+ /**
+ * Regular user controller
+ */
+ @Inject
+ private AddressbookContactListWebViewController contactListController;
+
+ /**
+ * Fax number
+ */
+ private DialableFaxNumber faxNumber;
+
+ /**
+ * Event for when a fax number instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedFaxNumberEvent> faxNumberCreatedEvent;
+
+ /**
+ * Land-line number
+ */
+ private DialableLandLineNumber landLineNumber;
+
+ /**
+ * Event for when a land-line number instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedLandLineNumberEvent> landLineNumberCreatedEvent;
+
+ /**
+ * Localization controller
+ */
+ @Inject
+ private AddressbookLocalizationSessionController localizationController;
+
+ /**
+ * Mobile number
+ */
+ private DialableMobileNumber mobileNumber;
+
+ /**
+ * Event for when a mobile number instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedMobileNumberEvent> mobileNumberCreatedEvent;
+
+ /**
+ * User instance
+ */
+ private User user;
+
+ /**
+ * Event for when a user instance was created
+ */
+ @Any
+ @Inject
+ private Event<ObservableCreatedUserEvent> userCreatedEvent;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookWebViewHelperBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ @Override
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ /**
+ * Setter for contact instance
+ * <p>
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact) {
+ this.contact = contact;
+ }
+
+ /**
+ * Returns a message key depending on if this contact is a user and/or a
+ * contact. If this contact is unused, a default key is returned.
+ * <p>
+ * @param contact Contact instance to check
+ * <p>
+ * @return Message key
+ */
+ public String getContactUsageMessageKey (final Contact contact) {
+ // The contact must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ }
+
+ // Default key is "unused"
+ String messageKey = "CONTACT_IS_UNUSED"; //NOI18N
+
+ // Check user first
+ if (this.contactListController.isContactFound(contact)) {
+ // Only user
+ messageKey = "CONTACT_IS_USER"; //NOI18N
+ }
+
+ // Return message key
+ return messageKey;
+ }
+
+ /**
+ * Getter for dialable fax number
+ * <p>
+ * @return Dialable fax number
+ */
+ @Override
+ public DialableFaxNumber getFaxNumber () {
+ return this.faxNumber;
+ }
+
+ /**
+ * Setter for dialable fax number
+ * <p>
+ * @param faxNumber Dialable fax number
+ */
+ public void setFaxNumber (final DialableFaxNumber faxNumber) {
+ this.faxNumber = faxNumber;
+ }
+
+ /**
+ * Getter for dialable land-line number
+ * <p>
+ * @return Dialable land-line number
+ */
+ @Override
+ public DialableLandLineNumber getLandLineNumber () {
+ return this.landLineNumber;
+ }
+
+ /**
+ * Setter for dialable land-line number
+ * <p>
+ * @param landLineNumber Dialable land-line number
+ */
+ public void setLandLineNumber (final DialableLandLineNumber landLineNumber) {
+ this.landLineNumber = landLineNumber;
+ }
+
+ /**
+ * Getter for dialable mobile number
+ * <p>
+ * @return Dialable mobile number
+ */
+ @Override
+ public DialableMobileNumber getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for dialable mobile number
+ * <p>
+ * @param mobileNumber Dialable mobile number
+ */
+ public void setMobileNumber (final DialableMobileNumber mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Getter for user instance
+ * <p>
+ * @return User instance
+ */
+ @Override
+ public User getUser () {
+ return this.user;
+ }
+
+ /**
+ * Setter for user instance
+ * <p>
+ * @param user User instance
+ */
+ public void setUser (final User user) {
+ this.user = user;
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a contact id has been
+ * successfully converted to a Contact instance.
+ */
+ public void notifyControllerContactConverted () {
+ // Validate contact instance
+ if (this.getContact() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.contact is null"); //NOI18N
+ } else if (this.getContact().getContactId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.contact.contactId is null"); //NOI18N
+ } else if (this.getContact().getContactId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.contact.contactId={0} is not valid.", this.getContact().getContactId())); //NOI18N
+ }
+
+ // Set all phone instances
+ this.setPhoneInstances(this.getContact());
+
+ // Set all fields: user
+ this.contactCreatedEvent.fire(new CreatedContactEvent(this.getContact()));
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a phone id has been
+ * successfully converted to a DialableFaxNumber instance.
+ */
+ public void notifyControllerFaxNumberConverted () {
+ // Validate fax instance
+ if (this.getFaxNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.faxNumber is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneId() == null) {
+ // Throw again
+ throw new NullPointerException("this.faxNumber.phoneId is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneId={0} is not valid", this.getFaxNumber().getPhoneId())); //NOI18N
+ } else if (this.getFaxNumber().getPhoneAreaCode() == null) {
+ // Throw again
+ throw new NullPointerException("this.faxNumber.phoneAreaCode is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
+ } else if (this.getFaxNumber().getPhoneCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.faxNumber.phoneCountry is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneCountry().getCountryId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.faxNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneCountry().getCountryId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneCountry.countryId={0} is invalid", this.getFaxNumber().getPhoneCountry().getCountryId())); //NOI18N
+ } else if (this.getFaxNumber().getPhoneNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.faxNumber.phoneNumber is null"); //NOI18N
+ } else if (this.getFaxNumber().getPhoneNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.faxNumber.phoneNumber={0} is not valid", this.getFaxNumber().getPhoneNumber())); //NOI18N
+ }
+
+ // Fire event
+ this.faxNumberCreatedEvent.fire(new CreatedFaxNumberEvent(this.getFaxNumber()));
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a phone id has been
+ * successfully converted to a DialableLandLineNumber instance.
+ */
+ public void notifyControllerLandLineNumberConverted () {
+ // Validate land-line instance
+ if (this.getLandLineNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.landLineNumber is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneId() == null) {
+ // Throw again
+ throw new NullPointerException("this.landLineNumber.phoneId is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneId={0} is not valid", this.getLandLineNumber().getPhoneId())); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneAreaCode() == null) {
+ // Throw again
+ throw new NullPointerException("this.landLineNumber.phoneAreaCode is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneAreaCode() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneAreaCode={0} is not valid", this.getFaxNumber().getPhoneAreaCode())); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.landLineNumber.phoneCountry is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.landLineNumber.phoneCountry.countryId is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneCountry().getCountryId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneCountry.countryId={0} is invalid", this.getLandLineNumber().getPhoneCountry().getCountryId())); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.landLineNumber.phoneNumber is null"); //NOI18N
+ } else if (this.getLandLineNumber().getPhoneNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.landLineNumber.phoneNumber={0} is not valid", this.getLandLineNumber().getPhoneNumber())); //NOI18N
+ }
+
+ // Fire event
+ this.landLineNumberCreatedEvent.fire(new CreatedLandLineNumberEvent(this.getLandLineNumber()));
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a phone id has been
+ * successfully converted to a DialableMobileNumber instance.
+ */
+ public void notifyControllerMobileNumberConverted () {
+ // Validate mobile instance
+ if (this.getMobileNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.mobileNumber is null"); //NOI18N
+ } else if (this.getMobileNumber().getMobileId() == null) {
+ // Throw again
+ throw new NullPointerException("this.mobileNumber.mobileId is null"); //NOI18N
+ } else if (this.getMobileNumber().getMobileId() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileId={0} is not valid", this.getMobileNumber().getMobileId())); //NOI18N
+ } else if (this.getMobileNumber().getMobileProvider() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (this.getMobileNumber().getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("this.mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (this.getMobileNumber().getMobileProvider().getProviderId() < 1) {
+ // Invalid id
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileProvider.providerId={0} is invalid", this.getMobileNumber().getMobileProvider().getProviderId())); //NOI18N
+ } else if (this.getMobileNumber().getMobileNumber() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.mobileNumber.mobileNumber is null"); //NOI18N
+ } else if (this.getMobileNumber().getMobileNumber() < 1) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileNumber.mobileNumber={0} is not valid", this.getMobileNumber().getMobileNumber())); //NOI18N
+ }
+
+ // Fire event
+ this.mobileNumberCreatedEvent.fire(new CreatedMobileNumberEvent(this.getMobileNumber()));
+ }
+
+ /**
+ * Notifies other controllers (backing beans) if a user id has been
+ * successfully converted to a User instance.
+ */
+ public void notifyControllerUserConverted () {
+ // Validate user instance
+ if (this.getUser() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.user is null"); //NOI18N
+ } else if (this.getUser().getUserId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.user.userId is null"); //NOI18N
+ } else if (this.getUser().getUserId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("this.user.userId={0} is not valid.", this.getUser().getUserId())); //NOI18N
+ }
+
+ // Get contact
+ final Contact userContact = this.getUser().getUserContact();
+
+ // Set contact here, too. This avoids parameters that cannot auto-complete in IDEs.
+ this.setContact(userContact);
+
+ // Set all phone instances
+ this.setPhoneInstances(userContact);
+
+ // Fire event
+ this.userCreatedEvent.fire(new CreatedUserEvent(this.getUser()));
+ }
+
+ /**
+ * Renders data of basic company data
+ * <p>
+ * @param basicData Basic company data instance
+ * @param useShortName Whether to use short name or long name of company
+ * @param showEmailAddress Whether render email address
+ * <p>
+ * @return Basic company data as string
+ */
+ public String renderBasicData (final BasicData basicData, final boolean useShortName, final boolean showEmailAddress) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(30);
+
+ // Is basic company data set?
+ if (basicData instanceof BasicData) {
+ // Short or long name?
+ if (useShortName || basicData.getCompanyName() == null) {
+ // Add company's long name
+ sb.append(basicData.getCompanyShortName()); //NOI18N
+ } else {
+ // Add company's long name
+ sb.append(basicData.getCompanyName()); //NOI18N
+ }
+
+ // Is email address set?
+ if (showEmailAddress && basicData.getCompanyEmailAddress() != null) {
+ // Add it
+ sb.append(", ").append(basicData.getCompanyEmailAddress()); //NOI18N
+ }
+
+ // Is tax number set?
+ if (basicData.getCompanyTaxNumber() != null) {
+ // Add it
+ sb.append(", ").append(basicData.getCompanyTaxNumber()); //NOI18N
+ }
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the branch office's full address. If null is provided, an empty
+ * string is returned.
+ * <p>
+ * @param branchOffice Branch office instance
+ * @param showEmailAddress Whether render email address
+ * <p>
+ * @return Branch office's address
+ */
+ public String renderBranchOffice (final BranchOffice branchOffice, final boolean showEmailAddress) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(30);
+
+ // Is a branch office instance given?
+ if (branchOffice instanceof BranchOffice) {
+ // This should not happen:
+ if (branchOffice.getBranchId() == null) {
+ // Throw NPE
+ throw new NullPointerException("branchOffice.branchId is null"); //NOI18N
+ } else if (branchOffice.getBranchId() < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("branchOffice.branchId={0} is invalid.", branchOffice.getBranchId())); //NOI18N
+ } else if (branchOffice.getBranchCompany() == null) {
+ // Throw NPE
+ throw new NullPointerException("branchOffice.branchCompany is null"); //NOI18N
+ } else if (branchOffice.getBranchCountry() == null) {
+ // Throw NPE again
+ throw new NullPointerException("branchOffice.branchCountry is null"); //NOI18N
+ }
+
+ // Yes, then append all data
+ sb.append(this.renderBasicData(branchOffice.getBranchCompany(), true, showEmailAddress));
+ sb.append(", "); //NOI18N
+ sb.append(branchOffice.getBranchStreet());
+ sb.append(" "); //NOI18N
+ sb.append(branchOffice.getBranchHouseNumber());
+ sb.append(", "); //NOI18N
+ sb.append(branchOffice.getBranchCountry().getCountryCode());
+ sb.append(" "); //NOI18N
+ sb.append(branchOffice.getBranchZipCode());
+ sb.append(" "); //NOI18N
+ sb.append(branchOffice.getBranchCity());
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the contact's personal title, family name and name. If null is
+ * provided, an empty string is returned.
+ * <p>
+ * @param contact Contact instance
+ * <p>
+ * @return Contact's full name
+ */
+ public String renderContact (final Contact contact) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is contact set?
+ if (contact instanceof Contact) {
+ // Then create name
+ sb.append(this.getMessageFromBundle(contact.getContactPersonalTitle().getMessageKey()));
+ sb.append(" "); //NOI18N
+ sb.append(contact.getContactFirstName());
+ sb.append(" "); //NOI18N
+ sb.append(contact.getContactFamilyName());
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the text representation of given country. If null is provided, an
+ * empty string is returned.
+ * <p>
+ * @param country Country instance
+ * <p>
+ * @return Country's text representation
+ */
+ public String renderCountry (final Country country) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is a country given?
+ if (country instanceof Country) {
+ // Yes, then render it
+ sb.append(this.getMessageFromBundle(country.getCountryI18nKey()));
+ sb.append(" ("); //NOI18N
+ sb.append(country.getCountryCode());
+ sb.append(")"); //NOI18N
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the department's name and name of assigned company. If null is
+ * provided, an empty string is returned.
+ * <p>
+ * @param department Department instance
+ * @param showEmailAddress Whether to render email address
+ * <p>
+ * @return Department's full name
+ */
+ public String renderDepartment (final Department department, final boolean showEmailAddress) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(10);
+
+ // Is a department set?
+ if (department instanceof Department) {
+ // Then create name
+ sb.append(this.getMessageFromBundle(department.getDepartmentI18nKey()));
+ sb.append(" ("); //NOI18N
+ sb.append(this.renderBasicData(department.getDepartmentCompany(), true, showEmailAddress));
+ sb.append(")"); //NOI18N
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the employee's number, personal title, family name and name if
+ * available. If null is provided, an empty string is returned.
+ * <p>
+ * @param employee Employable instance
+ * @param showEmailAddress Whether to show email address of employee
+ * <p>
+ * @return A string representing an employee
+ */
+ public String renderEmployee (final Employable employee, final boolean showEmailAddress) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is employee set?
+ if (employee instanceof Employable) {
+ // Is the number given?
+ if (employee.getEmployeeNumber() != null) {
+ // Then create name
+ sb.append(employee.getEmployeeNumber());
+ }
+
+ // Is contact data found?
+ if (employee.getEmployeePersonalData() instanceof Contact) {
+ // Yes, then render it
+ final String contactName = this.renderContact(employee.getEmployeePersonalData());
+
+ // Is it given?
+ if (contactName != null && !contactName.isEmpty()) {
+ // Only add braces when employee number is given
+ if (employee.getEmployeeNumber() != null) {
+ sb.append(" ("); //NOI18N
+ }
+
+ // Then add it
+ sb.append(contactName);
+
+ // Only add braces when employee number is given
+ if (employee.getEmployeeNumber() != null) {
+ sb.append(")"); //NOI18N
+ }
+ }
+ }
+
+ // Is a department found?
+ if (employee.getEmployeeDepartment() instanceof Department) {
+ // Only add braces when employee number is given
+ if (employee.getEmployeeNumber() != null || employee.getEmployeePersonalData() instanceof Contact) {
+ sb.append(" ("); //NOI18N
+ }
+
+ // Add department name
+ sb.append(this.renderDepartment(employee.getEmployeeDepartment(), showEmailAddress));
+
+ // Only add braces when employee number is given
+ if (employee.getEmployeeNumber() != null || employee.getEmployeePersonalData() instanceof Contact) {
+ sb.append(")"); //NOI18N
+ }
+ }
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the headquarter address. If null is provided, an empty string is
+ * returned.
+ * <p>
+ * @param headquarter Headquarter instance
+ * <p>
+ * @return Headquarter address
+ */
+ public String renderHeadquarter (final Headquarter headquarter) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(10);
+
+ // Is a headquarter set?
+ if (headquarter instanceof Headquarter) {
+ // Then create name
+ sb.append(headquarter.getHeadquarterStreet());
+ sb.append(" "); //NOI18N
+ sb.append(headquarter.getHeadquarterHouseNumber());
+
+ // Is store/suite number set?
+ if (headquarter.getHeadquarterStore() instanceof Short) {
+ sb.append(" ("); //NOI18N
+ sb.append(this.getMessageFromBundle("DATA_STORE")); //NOI18N
+ sb.append(" "); //NOI18N
+ sb.append(headquarter.getHeadquarterStore());
+ sb.append(", "); //NOI18N
+ sb.append(this.getMessageFromBundle("DATA_SUITE_NUMBER")); //NOI18N
+ sb.append(" "); //NOI18N
+ sb.append(headquarter.getHeadquarterSuiteNumber());
+ sb.append(")"); //NOI18N
+ }
+
+ // Continue with country, ZIP code and city
+ sb.append(", "); //NOI18N
+ sb.append(headquarter.getHeadquarterCountry().getCountryCode());
+ sb.append(" "); //NOI18N
+ sb.append(headquarter.getHeadquarterZipCode());
+ sb.append(" "); //NOI18N
+ sb.append(headquarter.getHeadquarterCity());
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Renders given mobile number (land-line and fax number). If null is
+ * provided, an empty string is returned.
+ * <p>
+ * @param mobileNumber Mobile number to render
+ * <p>
+ * @return Mobile number
+ */
+ public String renderMobileNumber (final DialableMobileNumber mobileNumber) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is a phone number given?
+ if (mobileNumber instanceof DialableMobileNumber) {
+ // Yes, then render it
+ sb.append(mobileNumber.getMobileProvider().getProviderCountry().getCountryAbroadDialPrefix());
+ sb.append(mobileNumber.getMobileProvider().getProviderCountry().getCountryPhoneCode());
+ sb.append(" ("); //NOI18N
+ sb.append(mobileNumber.getMobileProvider().getProviderDialPrefix());
+ sb.append(") "); //NOI18N
+ sb.append(mobileNumber.getMobileNumber());
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Renders given phone number (land-line and fax number). If null is
+ * provided, an empty string is returned.
+ * <p>
+ * @param number Phone number to render
+ * <p>
+ * @return Phone number
+ * <p>
+ * @throws IllegalArgumentException If a mobile number is provided
+ */
+ public String renderPhoneNumber (final DialableNumber number) {
+ // Validate parameter
+ if (number instanceof DialableMobileNumber) {
+ // Not allowed here
+ throw new IllegalArgumentException("Mobile numbers cannot be rendered with this method. Please use renderMobileNumber() instead."); //NOI18N
+ }
+
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is a phone number given?
+ if (number instanceof DialableNumber) {
+ // Yes, then render it
+ sb.append(number.getPhoneCountry().getCountryAbroadDialPrefix());
+ sb.append(number.getPhoneCountry().getCountryPhoneCode());
+ sb.append(" ("); //NOI18N
+ sb.append(number.getPhoneAreaCode());
+ sb.append(") "); //NOI18N
+ sb.append(number.getPhoneNumber());
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Returns the user's personal title, family name and name. If null is
+ * provided, an empty string is returned.
+ * <p>
+ * @param user User instance
+ * <p>
+ * @return User's full name
+ */
+ public String renderUser (final User user) {
+ // Default is empty string, so let's get started
+ final StringBuilder sb = new StringBuilder(20);
+
+ // Is user given?
+ if (user instanceof User) {
+ // Add user name first
+ sb.append(user.getUserName());
+ sb.append(" ("); //NOI18N
+
+ // Add contact data
+ sb.append(this.renderContact(user.getUserContact()));
+
+ // Close brace
+ sb.append(")"); //NOI18N
+ }
+
+ // Return it
+ return sb.toString();
+ }
+
+ /**
+ * Set's all given contact's phone instances: land-line, mobile and
+ * faxNumber
+ * <p>
+ * @param contact Contact to set phone instances for
+ */
+ private void setPhoneInstances (final Contact contact) {
+ // The contact must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
+ }
+
+ // Is mobile set?
+ if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Yes, then set it in admin controller
+ this.setMobileNumber(contact.getContactMobileNumber());
+ }
+
+ // Is land-line set?
+ if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Yes, then set it in admin controller
+ this.setLandLineNumber(contact.getContactLandLineNumber());
+ }
+
+ // Is faxNumber set?
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Yes, then set it in admin controller
+ this.setFaxNumber(contact.getContactFaxNumber());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.helper;
+
+import java.io.Serializable;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An interface for general bean helper
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookWebViewHelperController extends Serializable {
+
+ /**
+ * Getter for contact instance
+ * <p>
+ * @return Contact instance
+ */
+ Contact getContact ();
+
+ /**
+ * Getter for dialable fax number
+ * <p>
+ * @return Dialable fax number
+ */
+ DialableFaxNumber getFaxNumber ();
+
+ /**
+ * Getter for dialable land-line number
+ * <p>
+ * @return Dialable land-line number
+ */
+ DialableLandLineNumber getLandLineNumber ();
+
+ /**
+ * Getter for dialable mobile number
+ * <p>
+ * @return Dialable mobile number
+ */
+ DialableMobileNumber getMobileNumber ();
+
+ /**
+ * Getter for user instance
+ * <p>
+ * @return User instance
+ */
+ User getUser ();
+
+}
package org.mxchange.addressbook.beans.localization;
import java.text.MessageFormat;
+import java.text.NumberFormat;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Locale;
@SessionScoped
public class AddressbookLocalizationSessionBean extends BaseAddressbookBean implements AddressbookLocalizationSessionController {
+ /**
+ * Number format
+ */
+ private static NumberFormat NUMBER_FORMAT;
+
/**
* Serial number
*/
// Call super constructor
super();
- // Init list
+ // Init locale list
this.supportedLocales = new LinkedHashMap<>(2);
}
* @param event Event instance
*/
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event instance
*/
public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
// Has a matching locale
if (null == newLocale) {
// Throw NPE
- throw new NullPointerException("this.localeCode=" + this.getLocaleCode() + " cannot be found."); //NOI18N
+ throw new NullPointerException(MessageFormat.format("this.localeCode={0} cannot be found.", this.getLocaleCode())); //NOI18N
}
// Then change it
this.changeLocale(newLocale, Boolean.TRUE);
+
+ // Change formatting
+ NUMBER_FORMAT = NumberFormat.getNumberInstance(newLocale);
}
- /**
- * Getter for locale
- * <p>
- * @return Locale
- */
+ @Override
+ public String formatFloatNumber (final Float amount) {
+ // Is parameter valid?
+ if (null == amount) {
+ // Throw NPE
+ throw new NullPointerException("amount is null"); //NOI18N
+ }
+
+ // Format amount
+ return NUMBER_FORMAT.format(amount);
+ }
+
+ @Override
public Locale getLocale () {
return this.locale;
}
* Initializer for this bean
*/
@PostConstruct
- public void init () {
+ public void inititializeList () {
// Get default locale
final Locale defaultLocale = FacesContext.getCurrentInstance().getApplication().getDefaultLocale();
// Add all locales
while (iterator.hasNext()) {
// Get next locale
- Locale supportedLocale = iterator.next();
+ final Locale supportedLocale = iterator.next();
// Add it
this.getSupportedLocales().put(supportedLocale.toString(), supportedLocale);
// Change locale, may set same back in faces context, but triggers event
this.changeLocale(requestLocale, Boolean.FALSE);
+
+ // Initial formatting, may change when user chooses other locale
+ NUMBER_FORMAT = NumberFormat.getNumberInstance(this.locale);
}
/**
package org.mxchange.addressbook.beans.localization;
import java.io.Serializable;
+import java.util.Locale;
/**
* An interface for localization change beans
*/
public interface AddressbookLocalizationSessionController extends Serializable {
+ /**
+ * Formats a float into a currency, depending on current locale
+ * <p>
+ * @param amount Amount (price) to format
+ * <p>
+ * @return Formatted string
+ */
+ String formatFloatNumber (final Float amount);
+
+ /**
+ * Getter for locale
+ * <p>
+ * @return Locale
+ */
+ Locale getLocale ();
+
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobile;
+
+import java.text.MessageFormat;
+import java.util.Date;
+import java.util.List;
+import java.util.Objects;
+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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.mobile.list.AddressbookMobileListWebViewController;
+import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
+import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.MobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+
+/**
+ * Administrative bean (controller) for mobile numbers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("adminMobileController")
+@RequestScoped
+public class AddressbookAdminMobileWebRequestBean extends BaseAddressbookBean implements AddressbookAdminMobileWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 184_598_175_371_269_017L;
+
+ /**
+ * Remote EJB for phone number (administrative)
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/adminMobile!org.mxchange.jphone.model.phonenumbers.mobile.AdminMobileSessionBeanRemote")
+ private AdminMobileSessionBeanRemote adminMobileBean;
+
+ /**
+ * When the phone entry has been created (persisted)
+ */
+ private Date mobileEntryCreated;
+
+ /**
+ * When the phone entry has been updated
+ */
+ private Date mobileEntryUpdated;
+
+ /**
+ * Mobile id (aka primary key)
+ */
+ private Long mobileId;
+
+ /**
+ * Generic hone controller
+ */
+ @Inject
+ private AddressbookMobileListWebViewController mobileListController;
+
+ /**
+ * Mobile number
+ */
+ private Long mobileNumber;
+
+ /**
+ * Event being fired when an administrator has deleted mobile number
+ */
+ @Inject
+ @Any
+ private Event<AdminDeletedMobileNumberEvent> mobileNumberDeletedEvent;
+
+ /**
+ * Event being fired when an administrator has updated land-line number
+ */
+ @Inject
+ @Any
+ private Event<AdminUpdatedMobileNumberEvent> mobileNumberUpdatedEvent;
+
+ /**
+ * Mobile provider
+ */
+ private MobileProvider mobileProvider;
+
+ /**
+ * Event being fired when a list of all unused mobile numbers is being
+ * created.
+ */
+ @Inject
+ @Any
+ private Event<AdminRemoveMobileNumberFromListEvent> removeLinkedMobileNumbersEvent;
+
+ /**
+ * Chosen mobile number
+ */
+ private DialableMobileNumber selectedMobileNumber;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookAdminMobileWebRequestBean () {
+ // Call super constructor
+ super();
+ }
+
+ /**
+ * Observes events being fired when a bean helper has successfully created a
+ * mobile number instance.
+ * <p>
+ * @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());
+ }
+
+ /**
+ * Returns a list of all unused ("non-linked") mobile numbers
+ * <p>
+ * @return List with all unused mobile numbers
+ */
+ public List<DialableMobileNumber> allNonLinkedMobileNumbers () {
+ // Get list of all mobile numbers
+ final List<DialableMobileNumber> numbers = this.mobileListController.getAllMobileNumbers();
+
+ // Visit all controllers to reduce the list
+ this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(numbers));
+
+ // Return it
+ return numbers;
+ }
+
+ /**
+ * Deletes given mobile entry data
+ */
+ public void deleteMobileData () {
+ // Get mobile number from helper
+ final DialableMobileNumber number = this.createMobileNumber();
+
+ // Is all data set
+ if (number == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (number.getMobileId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N
+ } else if (number.getMobileId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N
+ } else if (number.getMobileProvider() == null) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (number.getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (number.getMobileProvider().getProviderId() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
+ } else if (number.getMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N
+ } else if (number.getMobileNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N
+ }
+
+ // Call EJB
+ this.adminMobileBean.deleteMobileData(number);
+
+ // Fire event
+ this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(number));
+ }
+
+ /**
+ * Changes mobile entry data
+ * <p>
+ * @return Redirect outcome
+ */
+ public String doUpdateMobileNumber () {
+ // Get mobile number from helper
+ final DialableMobileNumber number = this.createMobileNumber();
+
+ // Is all data set
+ if (number == null) {
+ // Not set, throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (number.getMobileId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N
+ } else if (number.getMobileId() < 1) {
+ // Invalid number
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid", number.getMobileId())); //NOI18N
+ } else if (number.getMobileProvider() == null) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
+ } else if (number.getMobileProvider().getProviderId() == null) {
+ // ... throw again
+ throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
+ } else if (number.getMobileProvider().getProviderId() < 1) {
+ // Id not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
+ } else if (number.getMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("mobileNumber.mobileNumber is null"); //NOI18N
+ } else if (number.getMobileNumber() < 1) {
+ // Throw NPE again
+ throw new NullPointerException(MessageFormat.format("mobileNumber.mobileNumber={0} is not valid.", number.getMobileNumber())); //NOI18N
+ } else if (this.getMobileProvider() == null) {
+ // Throw NPE again
+ throw new NullPointerException("this.mobileProvider is null"); //NOI18N
+ } else if (this.getMobileProvider().getProviderId() == null) {
+ // Throw NPE again ...
+ throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
+ } else if (this.getMobileProvider().getProviderId() < 0) {
+ // Invalid id number
+ throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N
+ } else if (this.getMobileNumber() == null) {
+ // Throw NPE
+ throw new NullPointerException("this.phoneNumber is null"); //NOI18N
+ }
+
+ // Is the mobile provider and number the same?
+ if ((Objects.equals(this.getMobileProvider(), number.getMobileProvider())) && (Objects.equals(this.getMobileNumber(), number.getMobileNumber()))) {
+ // Show message
+ this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED", FacesMessage.SEVERITY_WARN); //NOI18N
+
+ // No difference in both together, no need to edit
+ return ""; //NOI18N
+ }
+
+ // Set all data
+ number.setMobileProvider(this.getMobileProvider());
+ number.setMobileNumber(this.getMobileNumber());
+
+ // Send to bean
+ final DialableMobileNumber updatedNumber = this.adminMobileBean.updateMobileData(number);
+
+ // Fire event
+ this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber));
+
+ // All fine, redirect
+ return "admin_show_mobile"; //NOI18N
+ }
+
+ /**
+ * Getter for phone entry created timestamp
+ * <p>
+ * @return Mobile entry created timestamp
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getMobileEntryCreated () {
+ return this.mobileEntryCreated;
+ }
+
+ /**
+ * Setter for phone entry created timestamp
+ * <p>
+ * @param mobileEntryCreated Mobile entry created timestamp
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setMobileEntryCreated (final Date mobileEntryCreated) {
+ this.mobileEntryCreated = mobileEntryCreated;
+ }
+
+ /**
+ * Getter for phone entry updated timestamp
+ * <p>
+ * @return Mobile entry updated timestamp
+ */
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getMobileEntryUpdated () {
+ return this.mobileEntryUpdated;
+ }
+
+ /**
+ * Setter for phone entry updated timestamp
+ * <p>
+ * @param mobileEntryUpdated Mobile entry updated timestamp
+ */
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setMobileEntryUpdated (final Date mobileEntryUpdated) {
+ this.mobileEntryUpdated = mobileEntryUpdated;
+ }
+
+ /**
+ * Getter for phone id
+ * <p>
+ * @return Mobile id
+ */
+ public Long getMobileId () {
+ return this.mobileId;
+ }
+
+ /**
+ * Setter for phone id
+ * <p>
+ * @param mobileId Mobile id
+ */
+ public void setMobileId (final Long mobileId) {
+ this.mobileId = mobileId;
+ }
+
+ /**
+ * Getter for dial number without prefix
+ * <p>
+ * @return Dial number without prefix
+ */
+ public Long getMobileNumber () {
+ return this.mobileNumber;
+ }
+
+ /**
+ * Setter for dial number without prefix
+ * <p>
+ * @param mobileNumber Dial number without prefix
+ */
+ public void setMobileNumber (final Long mobileNumber) {
+ this.mobileNumber = mobileNumber;
+ }
+
+ /**
+ * Getter for mobile provider
+ * <p>
+ * @return Mobile provider
+ */
+ public MobileProvider getMobileProvider () {
+ return this.mobileProvider;
+ }
+
+ /**
+ * Setter for mobile provider
+ * <p>
+ * @param mobileProvider Mobile provider
+ */
+ public void setMobileProvider (final MobileProvider mobileProvider) {
+ this.mobileProvider = mobileProvider;
+ }
+
+ /**
+ * Getter for chosen mobile number
+ * <p>
+ * @return mobile number
+ */
+ public DialableMobileNumber getSelectedMobileNumber () {
+ return this.selectedMobileNumber;
+ }
+
+ /**
+ * Setter for chosen mobile number
+ * <p>
+ * @param selectedMobileNumber mobile number
+ */
+ public void setSelectedMobileNumber (final DialableMobileNumber selectedMobileNumber) {
+ this.selectedMobileNumber = selectedMobileNumber;
+ }
+
+ /**
+ * Returns an instance of a DialableMobileNumber from all fields stored in
+ * this bean.
+ * <p>
+ * @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());
+ number.setMobileId(this.getMobileId());
+
+ // Return it
+ return number;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobile;
+
+import java.io.Serializable;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookAdminMobileWebRequestController extends Serializable {
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobile.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
+import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
+import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+import org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+
+/**
+ * Administrative listing controller (bean) for mobile numbers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("mobileListController")
+@ViewScoped
+public class AddressbookMobileListWebViewBean extends BaseAddressbookBean implements AddressbookMobileListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 491_058_674_675_690_106L;
+
+ /**
+ * A list of all mobile numbers
+ */
+ private final List<DialableMobileNumber> allMobileNumbers;
+
+ /**
+ * A list of filtered mobile numbers
+ */
+ private List<DialableMobileNumber> filteredMobileNumbers;
+
+ /**
+ * General EJB for mobile numbers
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/mobile!org.mxchange.jphone.model.phonenumbers.mobile.MobileSessionBeanRemote")
+ private MobileSessionBeanRemote mobileBean;
+
+ /**
+ * Cache for mobile numbers
+ */
+ @Inject
+ @NamedCache (cacheName = "mobileNumberCache")
+ private transient Cache<Long, DialableMobileNumber> mobileNumberCache;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookMobileListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allMobileNumbers = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @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
+ }
+
+ // Update contact's mobile, land-line and mobile number
+ this.updateContactMobileNumbers(event.getAddedContact());
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Event observer for newly added users by administrator
+ * <p>
+ * @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
+ }
+
+ // Update contact's mobile, land-line and mobile number
+ this.updateContactMobileNumbers(event.getAddedUser().getUserContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has deleted a land-line
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent 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.getDeletedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
+ } else if (event.getDeletedMobileNumber().getMobileId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedMobileNumber.mobileId is null"); //NOI18N
+ } else if (event.getDeletedMobileNumber().getMobileId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getMobileId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and mobile number
+ this.getAllMobileNumbers().remove(event.getDeletedMobileNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has a linked a
+ * land-line number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null"); //NOI18N
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null"); //NOI18N
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N
+ } else if (event.getContact().getContactMobileNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactMobileNumber is null"); //NOI18N
+ } else if (event.getContact().getContactMobileNumber().getMobileId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactMobileNumber.mobileId is null"); //NOI18N
+ } else if (event.getContact().getContactMobileNumber().getMobileId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactMobileNumber.mobileId={0} is invalid", event.getContact().getContactMobileNumber().getMobileId())); //NOI18N
+ } else if (event.getLinkedMobileNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedMobileNumer is null"); //NOI18N
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedMobileNumber().getMobileId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
+ }
+ }
+
+ /**
+ * Observes events being fired when an administrator has updated contact
+ * data.
+ * <p>
+ * @param event Event being fired
+ */
+ 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
+ }
+
+ // Update contact's mobile, land-line and mobile number
+ this.updateContactMobileNumbers(event.getUpdatedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has updated a land-line
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent 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.getUpdatedMobileNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
+ } else if (event.getUpdatedMobileNumber().getMobileId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedMobileNumber.mobileId is null"); //NOI18N
+ } else if (event.getUpdatedMobileNumber().getMobileId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("mobileId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getMobileId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an user has updated contact data.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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
+ }
+
+ // Update contact's mobile, land-line and mobile number
+ this.updateContactMobileNumbers(event.getUpdatedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public DialableMobileNumber findMobileNumberById (final Long mobileNumberId) throws MobileEntityNotFoundException {
+ // Validate paramter
+ if (null == mobileNumberId) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumberId is null"); //NOI18N
+ } else if (mobileNumberId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumberId={0} is invalid.", mobileNumberId)); //NOI18N
+ } else if (!this.mobileNumberCache.containsKey(mobileNumberId)) {
+ // Not found
+ throw new MobileEntityNotFoundException(mobileNumberId);
+ }
+
+ // Get it from cache
+ final DialableMobileNumber mobileNumber = this.mobileNumberCache.get(mobileNumberId);
+
+ // Return it
+ return mobileNumber;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableMobileNumber> getAllMobileNumbers () {
+ return this.allMobileNumbers;
+ }
+
+ /**
+ * Getter for filtered mobile numbers
+ * <p>
+ * @return Filtered mobile numbers
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableMobileNumber> getFilteredMobileNumbers () {
+ return this.filteredMobileNumbers;
+ }
+
+ /**
+ * Setter for filtered mobile numbers
+ * <p>
+ * @param filteredMobileNumbers Filtered mobile numbers
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredMobileNumbers (final List<DialableMobileNumber> filteredMobileNumbers) {
+ this.filteredMobileNumbers = filteredMobileNumbers;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.mobileNumberCache.iterator().hasNext()) {
+ // Add all
+ for (final DialableMobileNumber currentNumber : this.mobileBean.fetchAllMobileNumbers()) {
+ // Add it to cache
+ this.mobileNumberCache.put(currentNumber.getMobileId(), currentNumber);
+ }
+ }
+
+ // Is cache filled and list is empty
+ if ((this.mobileNumberCache.iterator().hasNext()) && (this.getAllMobileNumbers().isEmpty())) {
+ // Build up list
+ for (final Cache.Entry<Long, DialableMobileNumber> currentEntry : this.mobileNumberCache) {
+ // Add to list
+ this.getAllMobileNumbers().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllMobileNumbers().sort(new Comparator<DialableMobileNumber>() {
+ @Override
+ public int compare (final DialableMobileNumber mobileNumber1, final DialableMobileNumber mobileNumber2) {
+ return mobileNumber1.getMobileId() > mobileNumber2.getMobileId() ? 1 : mobileNumber1.getMobileId() < mobileNumber2.getMobileId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredMobileNumbers(this.getAllMobileNumbers());
+ }
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+ /**
+ * Uniquely add given land-line number to this bean's list. First remove the
+ * old instance (by id number), then re-add it again.
+ * <p>
+ * @param mobileNumber Land-line number to add
+ */
+ private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
+ // Make sure the parameter is valid
+ if (null == mobileNumber) {
+ // Throw NPE
+ throw new NullPointerException("mobileNumber is null"); //NOI18N
+ } else if (mobileNumber.getMobileId() == null) {
+ // Throw again ...
+ throw new NullPointerException("mobileNumber.mobileId is null"); //NOI18N
+ } else if (mobileNumber.getMobileId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileId={0} is not valid.", mobileNumber.getMobileId())); //NOI18N
+ }
+
+ // First remove it
+ if (!this.getAllMobileNumbers().remove(mobileNumber)) {
+ // Did not work, try by id number
+ for (final DialableMobileNumber currentNumber : this.getAllMobileNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(currentNumber.getMobileId(), mobileNumber.getMobileId())) {
+ // Found it
+ this.getAllMobileNumbers().remove(currentNumber);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.getAllMobileNumbers().add(mobileNumber);
+ }
+
+ /**
+ * Updates given contact's mobile number
+ * <p>
+ * @param contact Contact instance
+ */
+ private void updateContactMobileNumbers (final Contact contact) {
+ // Parameter must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Id number is not valid
+ }
+
+ // Is land-line set?
+ if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
+ // Unique-add it
+ this.uniqueAddMobileNumber(contact.getContactMobileNumber());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobile.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookMobileListWebViewController extends Serializable {
+
+ /**
+ * Returns a list of all mobile numbers. 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.
+ * <p>
+ * @return List of all mobile numbers
+ */
+ List<DialableMobileNumber> getAllMobileNumbers ();
+
+ /**
+ * Finds a mobile entry by given id number
+ * <p>
+ * @param mobileNumberId Mobile entry id number
+ * <p>
+ * @return A valid mobile instance
+ * <p>
+ * @throws MobileEntityNotFoundException If the entity was not found
+ */
+ DialableMobileNumber findMobileNumberById (Long mobileNumberId) throws MobileEntityNotFoundException;
+
+}
*/
package org.mxchange.addressbook.beans.mobileprovider;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.mobileprovider.list.AddressbookMobileProviderListWebViewController;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent;
import org.mxchange.jphone.events.mobileprovider.added.AdminMobileProviderAddedEvent;
-import org.mxchange.jphone.exceptions.MobileProviderAlreadyAddedException;
+import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderAlreadyAddedException;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.AdminMobileProviderSessionBeanRemote;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.CellphoneProvider;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
private AdminMobileProviderSessionBeanRemote adminRemoteBean;
/**
- * Regular bean
+ * Mobile provider list view
*/
@Inject
- private AddressbookMobileProviderWebRequestController mobileController;
+ private AddressbookMobileProviderListWebViewController mobileProviderListController;
/**
* Event being fired when the mobile provider was added
* dial-prefix and country combination is done, if found, an exception is
* thrown. A redirect should take place after successfull creation.
* <p>
- * @return Redirect outcome
- * <p>
* @todo Add field validation
*/
- public String addMobileProvider () {
+ public void addMobileProvider () {
// Create mobile provider instance
final MobileProvider mobileProvider = new CellphoneProvider(this.getProviderDialPrefix(), this.getProviderName(), this.getProviderCountry(), this.getProviderMailPattern());
// Is the provider already created?
if (this.isMobileProviderCreated(mobileProvider)) {
// Then throw exception
- this.showFacesMessage("form_add_mobile_provider:providerDialPrefix", new MobileProviderAlreadyAddedException(mobileProvider)); //NOI18N
- return ""; //NOI18N
+ this.showFacesMessage("form_add_mobile_provider:providerDialPrefix", new MobileProviderAlreadyAddedException(mobileProvider), FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
}
// Init variable
updatedProvider = this.adminRemoteBean.addMobileProvider(mobileProvider);
} catch (final MobileProviderAlreadyAddedException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
this.providerAddedEvent.fire(new AdminMobileProviderAddedEvent(updatedProvider));
-
- // Redirect to list
- return "admin_list_mobile_provider"; //NOI18N
}
/**
// Default is not found
boolean isFound = false;
- // Get list of all providers
- List<MobileProvider> providers = this.mobileController.allMobileProviders();
-
- // Get iterator from it
- Iterator<MobileProvider> iterator = providers.iterator();
-
// Loop through all
- while (iterator.hasNext()) {
- // Get next element
- MobileProvider next = iterator.next();
-
+ for (final MobileProvider currentMobileProvider : this.mobileProviderListController.getAllMobileProviders()) {
// Is the provider's dial prefix and country the same?
- if ((Objects.equals(mobileProvider.getProviderDialPrefix(), next.getProviderDialPrefix())) && (Objects.equals(mobileProvider.getProviderCountry(), next.getProviderCountry()))) {
+ if (Objects.equals(mobileProvider, currentMobileProvider)) {
// Is the same, abort loop
isFound = true;
break;
*/
package org.mxchange.addressbook.beans.mobileprovider;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent;
-import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
/**
*/
private static final long serialVersionUID = 15_869_423_671_950_276L;
- /**
- * A list of all mobile providers
- */
- private final List<MobileProvider> allMobileProviders;
-
- /**
- * A list of filtered mobile providers
- */
- private List<MobileProvider> filteredMobileProviders;
-
/**
* Remote EJB for mobile providers (regular)
*/
@EJB (lookup = "java:global/addressbook-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote")
private MobileProviderSingletonBeanRemote mobileProviderBean;
- /**
- * "Cached" list of mobile providers
- */
- @Inject
- @NamedCache (cacheName = "mobileProviderCache")
- private Cache<Long, MobileProvider> mobileProviderCache;
-
/**
* Default constructor
*/
public AddressbookMobileProviderWebRequestBean () {
// Call super constructor
super();
-
- // Init list
- this.allMobileProviders = new LinkedList<>();
- }
-
- /**
- * Observes events being fired after the administrator has added a new
- * mobile provider
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) {
- // Is all valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getAddedMobileProvider() == null) {
- // Throw again ...
- throw new NullPointerException("event.addedMobileProvider is null"); //NOI18N
- } else if (event.getAddedMobileProvider().getProviderId() == null) {
- // And again ...
- throw new NullPointerException("event.addedMobileProvider.providerId is null"); //NOI18N
- } else if (event.getAddedMobileProvider().getProviderId() < 1) {
- // Id is invalid
- throw new IllegalArgumentException(MessageFormat.format("event.addedMobileProvider.providerId={0} is not valid.", event.getAddedMobileProvider().getProviderId())); //NOI18N
- }
-
- // Add it to the list
- this.mobileProviderCache.put(event.getAddedMobileProvider().getProviderId(), event.getAddedMobileProvider());
- this.allMobileProviders.add(event.getAddedMobileProvider());
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<MobileProvider> allMobileProviders () {
- // Return it
- return this.allMobileProviders;
}
- /**
- * Getter for filtered mobile provider list
- * <p>
- * @return Filtered mobile providers
- */
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<MobileProvider> getFilteredMobileProviders () {
- return this.filteredMobileProviders;
- }
-
- /**
- * Getter for filtered mobile provider list
- * <p>
- * @param filteredMobileProviders Filtered mobile providers
- */
- @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
- public void setFilteredMobileProviders (final List<MobileProvider> filteredMobileProviders) {
- this.filteredMobileProviders = filteredMobileProviders;
- }
-
- /**
- * Post-construction method
- */
- @PostConstruct
- public void initCache () {
- // Is cache there?
- if (!this.mobileProviderCache.iterator().hasNext()) {
- // Get whole list
- final List<MobileProvider> list = this.mobileProviderBean.allMobileProviders();
-
- // Add all
- for (final Iterator<MobileProvider> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final MobileProvider next = iterator.next();
-
- // Add it to cache
- this.mobileProviderCache.put(next.getProviderId(), next);
- }
- }
-
- // Is the list empty, but filled cache?
- if (this.allMobileProviders.isEmpty() && this.mobileProviderCache.iterator().hasNext()) {
- // Get iterator
- final Iterator<Cache.Entry<Long, MobileProvider>> iterator = this.mobileProviderCache.iterator();
-
- // Build up list
- while (iterator.hasNext()) {
- // GEt next element
- final Cache.Entry<Long, MobileProvider> next = iterator.next();
-
- // Add to list
- this.allMobileProviders.add(next.getValue());
- }
-
- // Sort list
- this.allMobileProviders.sort(new Comparator<MobileProvider>() {
- @Override
- public int compare (final MobileProvider o1, final MobileProvider o2) {
- return o1.getProviderId() > o2.getProviderId() ? 1 : o1.getProviderId() < o2.getProviderId() ? -1 : 0;
- }
- }
- );
- }
- }
}
package org.mxchange.addressbook.beans.mobileprovider;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
/**
* An interface for general mobile provider controller
*/
public interface AddressbookMobileProviderWebRequestController extends Serializable {
- /**
- * Returns a list of all mobile providers
- * <p>
- * @return A list of all mobile providers
- */
- List<MobileProvider> allMobileProviders ();
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobileprovider.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jphone.events.mobileprovider.added.AdminAddedMobileProviderEvent;
+import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
+
+/**
+ * A views-scoped bean for mobile providers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("mobileProviderListController")
+@ViewScoped
+public class AddressbookMobileProviderListWebViewBean extends BaseAddressbookBean implements AddressbookMobileProviderListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 15_869_423_671_950_277L;
+
+ /**
+ * A list of all mobile providers
+ */
+ private final List<MobileProvider> allMobileProviders;
+
+ /**
+ * A list of filtered mobile providers
+ */
+ private List<MobileProvider> filteredMobileProviders;
+
+ /**
+ * Remote EJB for mobile providers (regular)
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote")
+ private MobileProviderSingletonBeanRemote mobileProviderBean;
+
+ /**
+ * "Cached" list of mobile providers
+ */
+ @Inject
+ @NamedCache (cacheName = "mobileProviderCache")
+ private transient Cache<Long, MobileProvider> mobileProviderCache;
+
+ /**
+ * Selected mobile provider instance
+ */
+ private MobileProvider selectedMobileProvider;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookMobileProviderListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allMobileProviders = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired after the administrator has added a new
+ * mobile provider
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminAddedMobileProviderEvent (@Observes final AdminAddedMobileProviderEvent event) {
+ // Is all valid?
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getAddedMobileProvider() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.addedMobileProvider is null"); //NOI18N
+ } else if (event.getAddedMobileProvider().getProviderId() == null) {
+ // And again ...
+ throw new NullPointerException("event.addedMobileProvider.providerId is null"); //NOI18N
+ } else if (event.getAddedMobileProvider().getProviderId() < 1) {
+ // Id is invalid
+ throw new IllegalArgumentException(MessageFormat.format("event.addedMobileProvider.providerId={0} is not valid.", event.getAddedMobileProvider().getProviderId())); //NOI18N
+ }
+
+ // Add it to the list
+ this.mobileProviderCache.put(event.getAddedMobileProvider().getProviderId(), event.getAddedMobileProvider());
+ this.getAllMobileProviders().add(event.getAddedMobileProvider());
+ }
+
+ @Override
+ public MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException {
+ // Validate parameter
+ if (null == mobileProviderId) {
+ // Throw NPE
+ throw new NullPointerException("mobileProviderId is null"); //NOI18N
+ } else if (mobileProviderId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("mobileProviderId=" + mobileProviderId + " is invalid."); //NOI18N
+ } else if (!this.mobileProviderCache.containsKey(mobileProviderId)) {
+ // Not found
+ throw new MobileProviderNotFoundException(mobileProviderId);
+ }
+
+ // Get it from cache
+ final MobileProvider mobileProvider = this.mobileProviderCache.get(mobileProviderId);
+
+ // Return it
+ return mobileProvider;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<MobileProvider> getAllMobileProviders () {
+ // Return it
+ return this.allMobileProviders;
+ }
+
+ /**
+ * Getter for filtered mobile provider list
+ * <p>
+ * @return Filtered mobile providers
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<MobileProvider> getFilteredMobileProviders () {
+ return this.filteredMobileProviders;
+ }
+
+ /**
+ * Getter for filtered mobile provider list
+ * <p>
+ * @param filteredMobileProviders Filtered mobile providers
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredMobileProviders (final List<MobileProvider> filteredMobileProviders) {
+ this.filteredMobileProviders = filteredMobileProviders;
+ }
+
+ /**
+ * Getter for selected mobile provider instance
+ * <p>
+ * @return Selected mobile provider instance
+ */
+ public MobileProvider getSelectedMobileProvider () {
+ return this.selectedMobileProvider;
+ }
+
+ /**
+ * Setter for selected mobile provider instance
+ * <p>
+ * @param selectedMobileProvider Selected mobile provider instance
+ */
+ public void setSelectedMobileProvider (final MobileProvider selectedMobileProvider) {
+ this.selectedMobileProvider = selectedMobileProvider;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.mobileProviderCache.iterator().hasNext()) {
+ // Add all
+ for (final MobileProvider mobileProvider : this.mobileProviderBean.fetchAllMobileProviders()) {
+ // Add it to cache
+ this.mobileProviderCache.put(mobileProvider.getProviderId(), mobileProvider);
+ }
+ }
+
+ // Is the list empty, but filled cache?
+ if (this.getAllMobileProviders().isEmpty() && this.mobileProviderCache.iterator().hasNext()) {
+ // Build up list
+ for (final Cache.Entry<Long, MobileProvider> currentEntry : this.mobileProviderCache) {
+ // Add to list
+ this.getAllMobileProviders().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllMobileProviders().sort(new Comparator<MobileProvider>() {
+ @Override
+ public int compare (final MobileProvider mobileProvider1, final MobileProvider mobileProvider2) {
+ return mobileProvider1.getProviderId() > mobileProvider2.getProviderId() ? 1 : mobileProvider1.getProviderId() < mobileProvider2.getProviderId() ? -1 : 0;
+ }
+ });
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.mobileprovider.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
+
+/**
+ * An interface for general mobile provider controller
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookMobileProviderListWebViewController extends Serializable {
+
+ /**
+ * Returns a mobile provider instance by given primary key. If not found, a
+ * proper exception is thrown.
+ * <p>
+ * @param mobileProviderId Primary key
+ * <p>
+ * @return Mobile provider instance
+ * <p>
+ * @throws MobileProviderNotFoundException If the primary key could not be
+ * found
+ */
+ MobileProvider findMobileProviderById (final Long mobileProviderId) throws MobileProviderNotFoundException;
+
+ /**
+ * Returns a list of all mobile providers
+ * <p>
+ * @return A list of all mobile providers
+ */
+ List<MobileProvider> getAllMobileProviders ();
+
+}
package org.mxchange.addressbook.beans.phone;
import java.text.MessageFormat;
-import java.util.Calendar;
+import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.ejb.EJB;
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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.phone.list.AddressbookPhoneListWebViewController;
import org.mxchange.jcountry.model.data.Country;
import org.mxchange.jphone.events.fax.created.ObservableCreatedFaxNumberEvent;
import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
import org.mxchange.jphone.events.landline.removed.AdminRemoveLandLineNumberFromListEvent;
import org.mxchange.jphone.events.landline.updated.AdminLandLineNumberUpdatedEvent;
import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.created.ObservableCreatedMobileNumberEvent;
-import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
-import org.mxchange.jphone.events.mobile.deleted.AdminMobileNumberDeletedEvent;
-import org.mxchange.jphone.events.mobile.remove.AdminMobileNumberRemovedFromListEvent;
import org.mxchange.jphone.events.mobile.remove.AdminRemoveMobileNumberFromListEvent;
-import org.mxchange.jphone.events.mobile.updated.AdminMobileNumberUpdatedEvent;
-import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
import org.mxchange.jphone.model.phonenumbers.fax.FaxNumber;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
import org.mxchange.jphone.model.phonenumbers.landline.LandLineNumber;
-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.jphone.model.phonenumbers.phone.AdminPhoneSessionBeanRemote;
@Any
private Event<AdminUpdatedLandLineNumberEvent> landLineNumberUpdatedEvent;
- /**
- * Chosen mobile number
- */
- private DialableMobileNumber mobileNumber;
-
- /**
- * Event being fired when an administrator has deleted mobile number
- */
- @Inject
- @Any
- private Event<AdminDeletedMobileNumberEvent> mobileNumberDeletedEvent;
-
- /**
- * Event being fired when an administrator has updated land-line number
- */
- @Inject
- @Any
- private Event<AdminUpdatedMobileNumberEvent> mobileNumberUpdatedEvent;
-
/**
* Mobile provider instance
*/
*/
private Integer phoneAreaCode;
- /**
- * Generic hone controller
- */
- @Inject
- private AddressbookPhoneWebRequestController phoneController;
-
/**
* Country (for dial prefix)
*/
/**
* When the phone entry has been created (persisted)
*/
- private Calendar phoneEntryCreated;
+ private Date phoneEntryCreated;
/**
* When the phone entry has been updated
*/
- private Calendar phoneEntryUpdated;
+ private Date phoneEntryUpdated;
/**
* Phone id (aka primary key)
*/
private Long phoneId;
+ /**
+ * Generic hone controller
+ */
+ @Inject
+ private AddressbookPhoneListWebViewController phoneListController;
+
/**
* Phone number
*/
public AddressbookAdminPhoneWebRequestBean () {
// 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 a bean helper has successfully created a
- * fax number instance.
+ * land-line number instance.
* <p>
* @param event Event being fired
*/
throw new NullPointerException("event is null"); //NOI18N
} else if (event.getFaxNumber() == null) {
// Throw NPE again
- throw new NullPointerException("event.faxNumber is null"); //NOI18N
+ throw new NullPointerException("event.landLineNumber is null"); //NOI18N
} else if (event.getFaxNumber().getPhoneId() == null) {
// Throw NPE yet again
- throw new NullPointerException("event.faxNumber.phoneId is null"); //NOI18N
+ throw new NullPointerException("event.landLineNumber.phoneId is null"); //NOI18N
} else if (event.getFaxNumber().getPhoneId() < 1) {
// Throw NPE yet again
- throw new NullPointerException(MessageFormat.format("event.faxNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
+ throw new NullPointerException(MessageFormat.format("event.landLineNumber.phoneId={0} is invalid", event.getFaxNumber().getPhoneId())); //NOI18N
}
// Get fax number from event
- DialableFaxNumber number = event.getFaxNumber();
+ final DialableFaxNumber number = event.getFaxNumber();
// Copy all data to this bean
this.setPhoneId(number.getPhoneId());
}
// Get fax number from event
- DialableLandLineNumber number = event.getLandLineNumber();
+ final DialableLandLineNumber number = event.getLandLineNumber();
// Copy all data to this bean
this.setPhoneId(number.getPhoneId());
this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
}
- /**
- * Observes events being fired when a bean helper has successfully created a
- * mobile number instance.
- * <p>
- * @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().getPhoneId() == null) {
- // Throw NPE yet again
- throw new NullPointerException("event.mobileNumber.phoneId is null"); //NOI18N
- } else if (event.getMobileNumber().getPhoneId() < 1) {
- // Throw NPE yet again
- throw new NullPointerException(MessageFormat.format("event.mobileNumber.phoneId={0} is invalid", event.getMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Get fax number from event
- DialableMobileNumber number = event.getMobileNumber();
-
- // Copy all data to this bean
- this.setPhoneId(number.getPhoneId());
- this.setMobileProvider(number.getMobileProvider());
- this.setPhoneNumber(number.getPhoneNumber());
- this.setPhoneEntryCreated(number.getPhoneEntryCreated());
- this.setPhoneEntryUpdated(number.getPhoneEntryUpdated());
- }
-
/**
* Returns a list of all unused ("non-linked") land-line numbers
* <p>
*/
public List<DialableFaxNumber> allNonLinkedFaxNumbers () {
// Get list of all mobile numbers
- List<DialableFaxNumber> list = this.phoneController.allFaxNumbers();
+ final List<DialableFaxNumber> numbers = this.phoneListController.getAllFaxNumbers();
// Visit all controllers to reduce the list
- this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(list));
+ this.removeLinkedFaxNumbersEvent.fire(new AdminFaxNumberRemovedFromListEvent(numbers));
// Return it
- return list;
+ return numbers;
}
/**
*/
public List<DialableLandLineNumber> allNonLinkedLandLineNumbers () {
// Get list of all mobile numbers
- List<DialableLandLineNumber> list = this.phoneController.allLandLineNumbers();
+ final List<DialableLandLineNumber> numbers = this.phoneListController.getAllLandLineNumbers();
// Visit all controllers to reduce the list
- this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(list));
+ this.removeLinkedLandLineNumbersEvent.fire(new AdminLandLineNumberRemovedFromListEvent(numbers));
// Return it
- return list;
- }
-
- /**
- * Returns a list of all unused ("non-linked") mobile numbers
- * <p>
- * @return List with all unused mobile numbers
- */
- public List<DialableMobileNumber> allNonLinkedMobileNumbers () {
- // Get list of all mobile numbers
- List<DialableMobileNumber> list = this.phoneController.allMobileNumbers();
-
- // Visit all controllers to reduce the list
- this.removeLinkedMobileNumbersEvent.fire(new AdminMobileNumberRemovedFromListEvent(list));
-
- // Return it
- return list;
+ return numbers;
}
/**
* Deletes given fax entry data
* <p>
- * @return Redirect outcome
*/
- public String deleteFaxData () {
+ public void deleteFaxData () {
// Get fax number from bean helper
- DialableFaxNumber number = this.createFaxNumber();
+ final DialableFaxNumber number = this.createFaxNumber();
// Is all data set
if (number == null) {
// Fire event
this.faxNumberDeletedEvent.fire(new AdminFaxNumberDeletedEvent(number));
-
- // All fine, redirect
- return "admin_list_fax"; //NOI18N
}
/**
* Deletes given land-line entry data
- * <p>
- * @return Redirect outcome
*/
- public String deleteLandLineData () {
+ public void deleteLandLineData () {
// Get land-line number from helper
- DialableLandLineNumber number = this.createLandLineNumber();
+ final DialableLandLineNumber number = this.createLandLineNumber();
// Is all data set
if (number == null) {
// Fire event
this.landLineNumberDeletedEvent.fire(new AdminLandLineNumberDeletedEvent(number));
-
- // All fine, redirect
- return "admin_list_landline"; //NOI18N
- }
-
- /**
- * Deletes given mobile entry data
- * <p>
- * @return Redirect outcome
- */
- public String deleteMobileData () {
- // Get mobile number from helper
- DialableMobileNumber number = this.createMobileNumber();
-
- // Is all data set
- if (number == null) {
- // Not set, throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (number.getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
- } else if (number.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
- } else if (number.getMobileProvider() == null) {
- // Throw NPE
- throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
- } else if (number.getMobileProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (number.getMobileProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
- } else if (number.getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
- } else if (number.getPhoneNumber() < 1) {
- // Throw NPE again
- throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
- }
-
- // Call EJB
- this.adminPhoneBean.deleteMobileData(number);
-
- // Fire event
- this.mobileNumberDeletedEvent.fire(new AdminMobileNumberDeletedEvent(number));
-
- // All fine, redirect
- return "admin_list_mobile"; //NOI18N
}
/**
*/
public String doChangeFaxNumber () {
// Get fax number from bean helper
- DialableFaxNumber number = this.createFaxNumber();
+ final DialableFaxNumber number = this.createFaxNumber();
// Is all data set
if (number == null) {
// Is the mobile provider and number the same?
if ((Objects.equals(this.getPhoneCountry(), number.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), number.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
// Show message
- this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+ this.showFacesMessage("form_edit_fax:faxNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED", FacesMessage.SEVERITY_WARN); //NOI18N
// No difference in both together, no need to edit
return ""; //NOI18N
number.setPhoneNumber(this.getPhoneNumber());
// Send to bean
- DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(number);
+ final DialableFaxNumber updatedNumber = this.adminPhoneBean.updateFaxData(number);
// Fire event
this.faxNumberUpdatedEvent.fire(new AdminFaxNumberUpdatedEvent(updatedNumber));
*/
public String doChangeLandLineNumber () {
// Get land-line number from helper
- DialableLandLineNumber number = this.createLandLineNumber();
+ final DialableLandLineNumber number = this.createLandLineNumber();
// Is all data set
if (number == null) {
// Is the mobile provider and number the same?
if ((Objects.equals(this.getPhoneCountry(), number.getPhoneCountry())) && (Objects.equals(this.getPhoneAreaCode(), number.getPhoneAreaCode())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
// Show message
- this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
+ this.showFacesMessage("form_edit_landline:landLineNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED", FacesMessage.SEVERITY_WARN); //NOI18N
// No difference in both together, no need to edit
return ""; //NOI18N
number.setPhoneNumber(this.getPhoneNumber());
// Send to bean
- DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(number);
+ final DialableLandLineNumber updatedNumber = this.adminPhoneBean.updateLandLineData(number);
// Fire event
this.landLineNumberUpdatedEvent.fire(new AdminLandLineNumberUpdatedEvent(updatedNumber));
return "admin_show_landline"; //NOI18N
}
- /**
- * Changes mobile entry data
- * <p>
- * @return Redirect outcome
- */
- public String doUpdateMobileNumber () {
- // Get mobile number from helper
- DialableMobileNumber number = this.createMobileNumber();
-
- // Is all data set
- if (number == null) {
- // Not set, throw NPE
- throw new NullPointerException("mobileNumber is null"); //NOI18N
- } else if (number.getPhoneId() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.phoneId is null"); //NOI18N
- } else if (number.getPhoneId() < 1) {
- // Invalid number
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid", number.getPhoneId())); //NOI18N
- } else if (number.getMobileProvider() == null) {
- // Throw NPE
- throw new NullPointerException("mobileNumber.mobileProvider is null"); //NOI18N
- } else if (number.getMobileProvider().getProviderId() == null) {
- // ... throw again
- throw new NullPointerException("mobileNumber.mobileProvider.providerId is null"); //NOI18N
- } else if (number.getMobileProvider().getProviderId() < 1) {
- // Id not valid
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.mobileProvider.providerId={0} is not valid.", number.getMobileProvider().getProviderId())); //NOI18N
- } else if (number.getPhoneNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("mobileNumber.phoneNumber is null"); //NOI18N
- } else if (number.getPhoneNumber() < 1) {
- // Throw NPE again
- throw new NullPointerException(MessageFormat.format("mobileNumber.phoneNumber={0} is not valid.", number.getPhoneNumber())); //NOI18N
- } else if (this.getMobileProvider() == null) {
- // Not provided
- this.showFacesMessage("form_edit_mobile:mobileProvider", "ERROR_ADMIN_NO_MOBILE_PROVIDER_SELECTED"); //NOI18N
- return ""; //NOI18N
- } else if (this.getMobileProvider().getProviderId() == null) {
- // Throw NPE again ...
- throw new NullPointerException("this.mobileProvider.providerId is null"); //NOI18N
- } else if (this.getMobileProvider().getProviderId() < 0) {
- // Invalid id number
- throw new IllegalArgumentException(MessageFormat.format("this.mobileProvider.providerId={0} is not valid.", this.getMobileProvider().getProviderId())); //NOI18N
- } else if (this.getPhoneNumber() == null) {
- // Not provided
- this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_EMPTY_MOBILE_NUMBER"); //NOI18N
- return ""; //NOI18N
- }
-
- // Is the mobile provider and number the same?
- if ((Objects.equals(this.getMobileProvider(), number.getMobileProvider())) && (Objects.equals(this.getPhoneNumber(), number.getPhoneNumber()))) {
- // Show message
- this.showFacesMessage("form_edit_mobile:mobileNumber", "ERROR_ADMIN_NO_CHANGE_ENTERED"); //NOI18N
-
- // No difference in both together, no need to edit
- return ""; //NOI18N
- }
-
- // Set all data
- number.setMobileProvider(this.getMobileProvider());
- number.setPhoneNumber(this.getPhoneNumber());
-
- // Send to bean
- DialableMobileNumber updatedNumber = this.adminPhoneBean.updateMobileData(number);
-
- // Fire event
- this.mobileNumberUpdatedEvent.fire(new AdminMobileNumberUpdatedEvent(updatedNumber));
-
- // All fine, redirect
- return "admin_show_mobile"; //NOI18N
- }
-
/**
* Getter for chosen fax number
* <p>
this.landLineNumber = landLineNumber;
}
- /**
- * Getter for chosen mobile number
- * <p>
- * @return mobile number
- */
- public DialableMobileNumber getMobileNumber () {
- return this.mobileNumber;
- }
-
- /**
- * Setter for chosen mobile number
- * <p>
- * @param mobileNumber mobile number
- */
- public void setMobileNumber (final DialableMobileNumber mobileNumber) {
- this.mobileNumber = mobileNumber;
- }
-
/**
* Getter for mobile provider
* <p>
* @return Phone entry created timestamp
*/
@SuppressWarnings ("ReturnOfDateField")
- public Calendar getPhoneEntryCreated () {
+ public Date getPhoneEntryCreated () {
return this.phoneEntryCreated;
}
* @param phoneEntryCreated Phone entry created timestamp
*/
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setPhoneEntryCreated (final Calendar phoneEntryCreated) {
+ public void setPhoneEntryCreated (final Date phoneEntryCreated) {
this.phoneEntryCreated = phoneEntryCreated;
}
* @return Phone entry updated timestamp
*/
@SuppressWarnings ("ReturnOfDateField")
- public Calendar getPhoneEntryUpdated () {
+ public Date getPhoneEntryUpdated () {
return this.phoneEntryUpdated;
}
* @param phoneEntryUpdated Phone entry updated timestamp
*/
@SuppressWarnings ("AssignmentToDateFieldFromParameter")
- public void setPhoneEntryUpdated (final Calendar phoneEntryUpdated) {
+ public void setPhoneEntryUpdated (final Date phoneEntryUpdated) {
this.phoneEntryUpdated = phoneEntryUpdated;
}
*/
private DialableFaxNumber createFaxNumber () {
// Initialize it
- DialableFaxNumber number = new FaxNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
+ final DialableFaxNumber number = new FaxNumber(
+ this.getPhoneCountry(),
+ this.getPhoneAreaCode(),
+ this.getPhoneNumber()
+ );
// Add all other data
number.setPhoneEntryCreated(this.getPhoneEntryCreated());
*/
private DialableLandLineNumber createLandLineNumber () {
// Initialize it
- DialableLandLineNumber number = new LandLineNumber(this.getPhoneCountry(), this.getPhoneAreaCode(), this.getPhoneNumber());
-
- // Add all other data
- number.setPhoneEntryCreated(this.getPhoneEntryCreated());
- number.setPhoneEntryUpdated(this.getPhoneEntryUpdated());
-
- // Is id number set?
- if (this.getPhoneId() instanceof Long) {
- // Set it
- number.setPhoneId(this.getPhoneId());
- }
-
- // Return it
- return number;
- }
-
- /**
- * Returns an instance of a DialableMobileNumber from all fields stored in
- * this bean.
- * <p>
- * @return An instance of a DialableMobileNumber class
- */
- private DialableMobileNumber createMobileNumber () {
- // Initialize it
- DialableMobileNumber number = new MobileNumber(this.getMobileProvider(), this.getPhoneNumber());
+ final DialableLandLineNumber number = new LandLineNumber(
+ this.getPhoneCountry(),
+ this.getPhoneAreaCode(),
+ this.getPhoneNumber()
+ );
// Add all other data
number.setPhoneEntryCreated(this.getPhoneEntryCreated());
*/
package org.mxchange.addressbook.beans.phone;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Observes;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
-import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
-import org.mxchange.jcontacts.events.fax.linked.ObservableAdminLinkedFaxNumberEvent;
-import org.mxchange.jcontacts.events.landline.linked.ObservableAdminLinkedLandLineNumberEvent;
-import org.mxchange.jcontacts.events.mobile.linked.ObservableAdminLinkedMobileNumberEvent;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
-import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
-import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
-import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
-import org.mxchange.jphone.events.mobile.deleted.AdminDeletedMobileNumberEvent;
-import org.mxchange.jphone.events.mobile.updated.AdminUpdatedMobileNumberEvent;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
/**
* Regular controller (bean) for phone numbers
*/
private static final long serialVersionUID = 491_058_674_675_690_105L;
- /**
- * All fax numbers
- */
- @Inject
- @NamedCache (cacheName = "faxNumberCache")
- private Cache<Long, DialableFaxNumber> faxNumberCache;
-
- /**
- * All land-line numbers
- */
- @Inject
- @NamedCache (cacheName = "landLineNumberCache")
- private Cache<Long, DialableLandLineNumber> landLineNumberCache;
-
- /**
- * All mobile numbers
- */
- @Inject
- @NamedCache (cacheName = "mobileNumberCache")
- private Cache<Long, DialableMobileNumber> mobileNumberCache;
-
- /**
- * General EJB for phone numbers
- */
- @EJB (lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote")
- private PhoneSessionBeanRemote phoneBean;
-
/**
* Default constructor
*/
super();
}
- /**
- * Observes events being fired when an administrator has added a new
- * contact.
- * <p>
- * @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
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getAddedContact());
-
- // Clear this bean
- this.clear();
- }
-
- /**
- * Event observer for newly added users by administrator
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event 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
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getAddedUser().getUserContact());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a fax
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedFaxNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
- } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allFaxNumbers().remove(event.getDeletedFaxNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a land-line
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allLandLineNumbers().remove(event.getDeletedLandLineNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has deleted a mobile
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedMobileNumberEvent (@Observes final AdminDeletedMobileNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedMobileNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedMobileNumber is null"); //NOI18N
- } else if (event.getDeletedMobileNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedMobileNumber.phoneId is null"); //NOI18N
- } else if (event.getDeletedMobileNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedMobileNumber(), event.getDeletedMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Update contact's mobile, land-line and fax number
- this.allMobileNumbers().remove(event.getDeletedMobileNumber());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has a linked a fax
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null");
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null");
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
- } else if (event.getContact().getContactFaxNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber is null");
- } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null");
- } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactFaxNumber.phoneId=" + event.getContact().getContactFaxNumber().getPhoneId() + " is invalid");
- } else if (event.getLinkedFaxNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedFaxNumer is null");
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedFaxNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has a linked a
- * land-line number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null");
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null");
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
- } else if (event.getContact().getContactLandLineNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber is null");
- } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null");
- } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactLandLineNumber.phoneId=" + event.getContact().getContactLandLineNumber().getPhoneId() + " is invalid");
- } else if (event.getLinkedLandLineNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedLandLineNumer is null");
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedLandLineNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has a linked a mobile
- * number
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedMobileNumberEvent (@Observes final ObservableAdminLinkedMobileNumberEvent event) {
- // Is the event fine?
- if (event == null) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getContact() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact is null");
- } else if (event.getContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId is null");
- } else if (event.getContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactId=" + event.getContact().getContactId() + " is invalid");
- } else if (event.getContact().getContactMobileNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber is null");
- } else if (event.getContact().getContactMobileNumber().getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber.phoneId is null");
- } else if (event.getContact().getContactMobileNumber().getPhoneId() < 1) {
- // Throw again ...
- throw new NullPointerException("event.contact.contactMobileNumber.phoneId=" + event.getContact().getContactMobileNumber().getPhoneId() + " is invalid");
- } else if (event.getLinkedMobileNumber() == null) {
- // Throw again ...
- throw new NullPointerException("event.linkedMobileNumer is null");
- }
-
- // Is the id number in linked number not set?
- if (event.getLinkedMobileNumber().getPhoneId() == null) {
- // Then it is a new number, so add it from contact as there the id number has been set
- this.uniqueAddMobileNumber(event.getContact().getContactMobileNumber());
- }
- }
-
- /**
- * Observes events being fired when an administrator has updated contact
- * data.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedContactDataEvent (@Observes final ObservableAdminUpdatedContactEvent event) {
- // event 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
- }
-
- // Update contact's mobile, land-line and fax number
- this.updateContactPhoneNumbers(event.getUpdatedContact());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a fax
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
-
- // Clear it
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a land-line
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
-
- // Clear it
- this.clear();
- }
-
- /**
- * Observes events being fired when an administrator has updated a mobile
- * number.
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUpdatedMobileNumberEvent (@Observes final AdminUpdatedMobileNumberEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedMobileNumber is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber().getPhoneId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedMobileNumber.phoneId is null"); //NOI18N
- } else if (event.getUpdatedMobileNumber().getPhoneId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedMobileNumber(), event.getUpdatedMobileNumber().getPhoneId())); //NOI18N
- }
-
- // Uniquely add it
- this.uniqueAddMobileNumber(event.getUpdatedMobileNumber());
-
- // Clear it
- this.clear();
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableFaxNumber> allFaxNumbers () {
- // Init list
- final List<DialableFaxNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableFaxNumber>> iterator = this.faxNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableFaxNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableLandLineNumber> allLandLineNumbers () {
- // Init list
- final List<DialableLandLineNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableLandLineNumber>> iterator = this.landLineNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableLandLineNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<DialableMobileNumber> allMobileNumbers () {
- // Init list
- final List<DialableMobileNumber> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, DialableMobileNumber>> iterator = this.mobileNumberCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, DialableMobileNumber> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- /**
- * Post-construction method
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.faxNumberCache.iterator().hasNext()) {
- // Get whole list
- final List<DialableFaxNumber> list = this.phoneBean.allFaxNumbers();
-
- // Add all
- for (final Iterator<DialableFaxNumber> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final DialableFaxNumber next = iterator.next();
-
- // Add it to cache
- this.faxNumberCache.put(next.getPhoneId(), next);
- }
- }
-
- // Is cache there?
- if (!this.landLineNumberCache.iterator().hasNext()) {
- // Get whole list
- final List<DialableLandLineNumber> list = this.phoneBean.allLandLineNumbers();
-
- // Add all
- for (final Iterator<DialableLandLineNumber> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final DialableLandLineNumber next = iterator.next();
-
- // Add it to cache
- this.landLineNumberCache.put(next.getPhoneId(), next);
- }
- }
-
- // Is cache there?
- if (!this.mobileNumberCache.iterator().hasNext()) {
- // Get whole list
- final List<DialableMobileNumber> list = this.phoneBean.allMobileNumbers();
-
- // Add all
- for (final Iterator<DialableMobileNumber> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final DialableMobileNumber next = iterator.next();
-
- // Add it to cache
- this.mobileNumberCache.put(next.getPhoneId(), next);
- }
- }
- }
-
- /**
- * Clears this bean
- */
- private void clear () {
- // Clear all data
- }
-
- /**
- * Uniquely add given fax number to this bean's list. First remove the old
- * instance (by id number), then re-add it again.
- * <p>
- * @param faxNumber number to add
- */
- private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
- // Make sure the parameter is valid
- if (null == faxNumber) {
- // Throw NPE
- throw new NullPointerException("faxNumber is null");
- } else if (faxNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("faxNumber.phoneId is null");
- } else if (faxNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId()));
- }
-
- // First remove it
- if (!this.allFaxNumbers().remove(faxNumber)) {
- // Did not work, try by id number
- for (final DialableFaxNumber fax : this.allFaxNumbers()) {
- // Is id number the same?
- if (Objects.equals(fax.getPhoneId(), faxNumber.getPhoneId())) {
- // Found it
- this.allFaxNumbers().remove(fax);
- break;
- }
- }
- }
-
- // ... then add it
- this.allFaxNumbers().add(faxNumber);
- }
-
- /**
- * Uniquely add given land-line number to this bean's list. First remove the
- * old instance (by id number), then re-add it again.
- * <p>
- * @param landLineNumber Land-line number to add
- */
- private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
- // Make sure the parameter is valid
- if (null == landLineNumber) {
- // Throw NPE
- throw new NullPointerException("landLineNumber is null");
- } else if (landLineNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("landLineNumber.phoneId is null");
- } else if (landLineNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId()));
- }
-
- // First remove it
- if (!this.allLandLineNumbers().remove(landLineNumber)) {
- // Did not work, try by id number
- for (final DialableLandLineNumber landLine : this.allLandLineNumbers()) {
- // Is id number the same?
- if (Objects.equals(landLine.getPhoneId(), landLineNumber.getPhoneId())) {
- // Found it
- this.allLandLineNumbers().remove(landLine);
- break;
- }
- }
- }
-
- // ... then add it
- this.allLandLineNumbers().add(landLineNumber);
- }
-
- /**
- * Uniquely add given mobile number to this bean's list. First remove the
- * old instance (by id number), then re-add it again.
- * <p>
- * @param mobileNumber Mobile number to add
- */
- private void uniqueAddMobileNumber (final DialableMobileNumber mobileNumber) {
- // Make sure the parameter is valid
- if (null == mobileNumber) {
- // Throw NPE
- throw new NullPointerException("mobileNumber is null");
- } else if (mobileNumber.getPhoneId() == null) {
- // Throw again ...
- throw new NullPointerException("mobileNumber.phoneId is null");
- } else if (mobileNumber.getPhoneId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("mobileNumber.phoneId={0} is not valid.", mobileNumber.getPhoneId()));
- }
-
- // First remove it by object
- if (!this.allMobileNumbers().remove(mobileNumber)) {
- // Did not work, try by id number
- for (final DialableMobileNumber cell : this.allMobileNumbers()) {
- // Is id number the same?
- if (Objects.equals(cell.getPhoneId(), mobileNumber.getPhoneId())) {
- // Found it
- this.allMobileNumbers().remove(cell);
- break;
- }
- }
- }
-
- // ... then add it
- this.allMobileNumbers().add(mobileNumber);
- }
-
- /**
- * Updates given contact's mobile, land-line and fax number
- * <p>
- * @param contact Contact instance
- */
- private void updateContactPhoneNumbers (final Contact contact) {
- // Parameter must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null");
- } else if (contact.getContactId() == null) {
- // Throw again
- throw new NullPointerException("contact.contactId is null");
- } else if (contact.getContactId() < 1) {
- // Id number is not valid
- }
-
- // Is mobile set?
- if (contact.getContactMobileNumber() instanceof DialableMobileNumber) {
- // Unique-add it
- this.uniqueAddMobileNumber(contact.getContactMobileNumber());
- }
-
- // Is land-line set?
- if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
- // Unique-add it
- this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
- }
-
- // Is fax set?
- if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
- // Unique-add it
- this.uniqueAddFaxNumber(contact.getContactFaxNumber());
- }
- }
-
}
package org.mxchange.addressbook.beans.phone;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
/**
* An interface for a request web controller (bean) for administrative phone
*/
public interface AddressbookPhoneWebRequestController extends Serializable {
- /**
- * Returns a list of all mobile numbers. For performance reasons, the
- * controller (bean) should be application-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.
- * <p>
- * @return List of all mobile numbers
- */
- List<DialableMobileNumber> allMobileNumbers ();
-
- /**
- * Returns a list of all fax numbers. For performance reasons, the
- * controller (bean) should be application-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.
- * <p>
- * @return List of all fax numbers
- */
- List<DialableFaxNumber> allFaxNumbers ();
-
- /**
- * Returns a list of all land-line numbers. For performance reasons, the
- * controller (bean) should be application-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.
- * <p>
- * @return List of all land-line numbers
- */
- List<DialableLandLineNumber> allLandLineNumbers ();
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jcontacts.events.contact.add.ObservableAdminAddedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableAdminUpdatedContactEvent;
+import org.mxchange.jcontacts.events.contact.update.ObservableUpdatedContactEvent;
+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.jphone.events.fax.deleted.AdminDeletedFaxNumberEvent;
+import org.mxchange.jphone.events.fax.updated.AdminUpdatedFaxNumberEvent;
+import org.mxchange.jphone.events.landline.deleted.AdminDeletedLandLineNumberEvent;
+import org.mxchange.jphone.events.landline.updated.AdminUpdatedLandLineNumberEvent;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
+
+/**
+ * Administrative listing controller (bean) for phone numbers
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("phoneListController")
+@ViewScoped
+public class AddressbookPhoneListWebViewBean extends BaseAddressbookBean implements AddressbookPhoneListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 491_058_674_675_690_107L;
+
+ /**
+ * A list of all fax numbers
+ */
+ private final List<DialableFaxNumber> allFaxNumbers;
+
+ /**
+ * A list of all land-line numbers
+ */
+ private final List<DialableLandLineNumber> allLandLineNumbers;
+
+ /**
+ * All fax numbers
+ */
+ @Inject
+ @NamedCache (cacheName = "faxNumberCache")
+ private transient Cache<Long, DialableFaxNumber> faxNumberCache;
+
+ /**
+ * A list of filtered fax numbers
+ */
+ private List<DialableFaxNumber> filteredFaxNumbers;
+
+ /**
+ * A list of filtered land-line numbers
+ */
+ private List<DialableLandLineNumber> filteredLandLineNumbers;
+
+ /**
+ * All land-line numbers
+ */
+ @Inject
+ @NamedCache (cacheName = "landLineNumberCache")
+ private transient Cache<Long, DialableLandLineNumber> landLineNumberCache;
+
+ /**
+ * General EJB for phone numbers
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote")
+ private PhoneSessionBeanRemote phoneBean;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookPhoneListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Initialize lists
+ this.allFaxNumbers = new LinkedList<>();
+ this.allLandLineNumbers = new LinkedList<>();
+ }
+
+ /**
+ * Observes events being fired when an administrator has added a new
+ * contact.
+ * <p>
+ * @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
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getAddedContact());
+
+ // Clear this bean
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has deleted a fax
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedFaxNumberEvent (@Observes final AdminDeletedFaxNumberEvent 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.getDeletedFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedFaxNumber is null"); //NOI18N
+ } else if (event.getDeletedFaxNumber().getPhoneId() == null) {
+ // phoneId is null
+ throw new NullPointerException("event.deletedFaxNumber.phoneId is null"); //NOI18N
+ } else if (event.getDeletedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedFaxNumber(), event.getDeletedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.getAllFaxNumbers().remove(event.getDeletedFaxNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has deleted a land-line
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedLandLineNumberEvent (@Observes final AdminDeletedLandLineNumberEvent 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.getDeletedLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedLandLineNumber is null"); //NOI18N
+ } else if (event.getDeletedLandLineNumber().getPhoneId() == null) {
+ // phoneId is null
+ throw new NullPointerException("event.deletedLandLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getDeletedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getDeletedLandLineNumber(), event.getDeletedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.getAllLandLineNumbers().remove(event.getDeletedLandLineNumber());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has a linked a fax
+ * number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedFaxNumberEvent (@Observes final ObservableAdminLinkedFaxNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null"); //NOI18N
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null"); //NOI18N
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N
+ } else if (event.getContact().getContactFaxNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactFaxNumber is null"); //NOI18N
+ } else if (event.getContact().getContactFaxNumber().getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactFaxNumber.phoneId is null"); //NOI18N
+ } else if (event.getContact().getContactFaxNumber().getPhoneId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactFaxNumber.phoneId={0} is invalid", event.getContact().getContactFaxNumber().getPhoneId())); //NOI18N
+ } else if (event.getLinkedFaxNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedFaxNumer is null"); //NOI18N
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedFaxNumber().getPhoneId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddFaxNumber(event.getContact().getContactFaxNumber());
+ }
+ }
+
+ /**
+ * Observes events being fired when an administrator has a linked a
+ * land-line number
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedLandLineNumberEvent (@Observes final ObservableAdminLinkedLandLineNumberEvent event) {
+ // Is the event fine?
+ if (event == null) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getContact() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact is null"); //NOI18N
+ } else if (event.getContact().getContactId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactId is null"); //NOI18N
+ } else if (event.getContact().getContactId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactId={0} is invalid", event.getContact().getContactId())); //NOI18N
+ } else if (event.getContact().getContactLandLineNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactLandLineNumber is null"); //NOI18N
+ } else if (event.getContact().getContactLandLineNumber().getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.contact.contactLandLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getContact().getContactLandLineNumber().getPhoneId() < 1) {
+ // Throw again ...
+ throw new NullPointerException(MessageFormat.format("event.contact.contactLandLineNumber.phoneId={0} is invalid", event.getContact().getContactLandLineNumber().getPhoneId())); //NOI18N
+ } else if (event.getLinkedLandLineNumber() == null) {
+ // Throw again ...
+ throw new NullPointerException("event.linkedLandLineNumer is null"); //NOI18N
+ }
+
+ // Is the id number in linked number not set?
+ if (event.getLinkedLandLineNumber().getPhoneId() == null) {
+ // Then it is a new number, so add it from contact as there the id number has been set
+ this.uniqueAddLandLineNumber(event.getContact().getContactLandLineNumber());
+ }
+ }
+
+ /**
+ * Observes events being fired when an administrator has updated contact
+ * data.
+ * <p>
+ * @param event Event being fired
+ */
+ 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) {
+ // phoneId 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
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getUpdatedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has updated a fax
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminUpdatedFaxNumberEvent (@Observes final AdminUpdatedFaxNumberEvent 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.getUpdatedFaxNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedFaxNumber is null"); //NOI18N
+ } else if (event.getUpdatedFaxNumber().getPhoneId() == null) {
+ // phoneId is null
+ throw new NullPointerException("event.updatedFaxNumber.phoneId is null"); //NOI18N
+ } else if (event.getUpdatedFaxNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedFaxNumber(), event.getUpdatedFaxNumber().getPhoneId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddFaxNumber(event.getUpdatedFaxNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an administrator has updated a land-line
+ * number.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminUpdatedLandLineNumberEvent (@Observes final AdminUpdatedLandLineNumberEvent 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.getUpdatedLandLineNumber() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedLandLineNumber is null"); //NOI18N
+ } else if (event.getUpdatedLandLineNumber().getPhoneId() == null) {
+ // phoneId is null
+ throw new NullPointerException("event.updatedLandLineNumber.phoneId is null"); //NOI18N
+ } else if (event.getUpdatedLandLineNumber().getPhoneId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("phoneId of contact={0} is not valid: {1}", event.getUpdatedLandLineNumber(), event.getUpdatedLandLineNumber().getPhoneId())); //NOI18N
+ }
+
+ // Uniquely add it
+ this.uniqueAddLandLineNumber(event.getUpdatedLandLineNumber());
+
+ // Clear it
+ this.clear();
+ }
+
+ /**
+ * Observes events being fired when an user has updated contact data.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUpdatedContactDataEvent (@Observes final ObservableUpdatedContactEvent 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) {
+ // phoneId 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
+ }
+
+ // Update contact's mobile, land-line and fax number
+ this.updateContactPhoneNumbers(event.getUpdatedContact());
+
+ // Clear all data
+ this.clear();
+ }
+
+ @Override
+ public DialableFaxNumber findFaxNumberById (final Long phoneId) throws PhoneEntityNotFoundException {
+ // Validate paramter
+ if (null == phoneId) {
+ // Throw NPE
+ throw new NullPointerException("phoneId is null"); //NOI18N
+ } else if (phoneId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("phoneId=" + phoneId + " is invalid."); //NOI18N
+ } else if (!this.faxNumberCache.containsKey(phoneId)) {
+ // Not found
+ throw new PhoneEntityNotFoundException(phoneId);
+ }
+
+ // Get it from cache
+ final DialableFaxNumber faxNumber = this.faxNumberCache.get(phoneId);
+
+ // Return it
+ return faxNumber;
+ }
+
+ @Override
+ public DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException {
+ // Validate paramter
+ if (null == landLineNumberId) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumberId is null"); //NOI18N
+ } else if (landLineNumberId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumberId={0} is invalid.", landLineNumberId)); //NOI18N
+ } else if (!this.landLineNumberCache.containsKey(landLineNumberId)) {
+ // Not found
+ throw new PhoneEntityNotFoundException(landLineNumberId);
+ }
+
+ // Get it from cache
+ final DialableLandLineNumber landLineNumber = this.landLineNumberCache.get(landLineNumberId);
+
+ // Return it
+ return landLineNumber;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableFaxNumber> getAllFaxNumbers () {
+ return this.allFaxNumbers;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableLandLineNumber> getAllLandLineNumbers () {
+ return this.allLandLineNumbers;
+ }
+
+ /**
+ * Getter for filtered fax number list
+ * <p>
+ * @return Filtered fax number list
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableFaxNumber> getFilteredFaxNumbers () {
+ return this.filteredFaxNumbers;
+ }
+
+ /**
+ * Setter for filtered fax number list
+ *
+ * @param filteredFaxNumbers Filtered fax number list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredFaxNumbers (final List<DialableFaxNumber> filteredFaxNumbers) {
+ this.filteredFaxNumbers = filteredFaxNumbers;
+ }
+
+ /**
+ * Getter for filtered land-line number list
+ * <p>
+ * @return Filtered land-line number list
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<DialableLandLineNumber> getFilteredLandLineNumbers () {
+ return this.filteredLandLineNumbers;
+ }
+
+ /**
+ * Setter for filtered land-line number list
+ *
+ * @param filteredLandLineNumbers Filtered land-line number list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredLandLineNumbers (final List<DialableLandLineNumber> filteredLandLineNumbers) {
+ this.filteredLandLineNumbers = filteredLandLineNumbers;
+ }
+
+ /**
+ * Post-construction method
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.faxNumberCache.iterator().hasNext()) {
+ // Add all
+ for (final DialableFaxNumber currentNumber : this.phoneBean.fetchAllFaxNumbers()) {
+ // Add it to cache
+ this.faxNumberCache.put(currentNumber.getPhoneId(), currentNumber);
+ }
+ }
+
+ // Is cache there?
+ if (!this.landLineNumberCache.iterator().hasNext()) {
+ // Add all
+ for (final DialableLandLineNumber currentNumber : this.phoneBean.fetchAllLandLineNumbers()) {
+ // Add it to cache
+ this.landLineNumberCache.put(currentNumber.getPhoneId(), currentNumber);
+ }
+ }
+
+ // Is cache filled and list is empty
+ if ((this.faxNumberCache.iterator().hasNext()) && (this.getAllFaxNumbers().isEmpty())) {
+ // Build up list
+ for (final Cache.Entry<Long, DialableFaxNumber> currentEntry : this.faxNumberCache) {
+ // Add to list
+ this.getAllFaxNumbers().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllFaxNumbers().sort(new Comparator<DialableFaxNumber>() {
+ @Override
+ public int compare (final DialableFaxNumber faxNumber1, final DialableFaxNumber faxNumber2) {
+ return faxNumber1.getPhoneId() > faxNumber2.getPhoneId() ? 1 : faxNumber1.getPhoneId() < faxNumber2.getPhoneId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredFaxNumbers(this.getAllFaxNumbers());
+ }
+
+ // Is cache filled and list is empty
+ if ((this.landLineNumberCache.iterator().hasNext()) && (this.getAllLandLineNumbers().isEmpty())) {
+ // Build up list
+ for (final Cache.Entry<Long, DialableLandLineNumber> currentEntry : this.landLineNumberCache) {
+ // Add to list
+ this.getAllLandLineNumbers().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllLandLineNumbers().sort(new Comparator<DialableLandLineNumber>() {
+ @Override
+ public int compare (final DialableLandLineNumber landLineNumber1, final DialableLandLineNumber landLineNumber2) {
+ return landLineNumber1.getPhoneId() > landLineNumber2.getPhoneId() ? 1 : landLineNumber1.getPhoneId() < landLineNumber2.getPhoneId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredLandLineNumbers(this.getAllLandLineNumbers());
+ }
+ }
+
+ /**
+ * Clears this bean
+ */
+ private void clear () {
+ // Clear all data
+ }
+
+ /**
+ * Uniquely add given fax number to this bean's list. First remove the old
+ * instance (by id number), then re-add it again.
+ * <p>
+ * @param faxNumber number to add
+ */
+ private void uniqueAddFaxNumber (final DialableFaxNumber faxNumber) {
+ // Make sure the parameter is valid
+ if (null == faxNumber) {
+ // Throw NPE
+ throw new NullPointerException("faxNumber is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("faxNumber.phoneId is null"); //NOI18N
+ } else if (faxNumber.getPhoneId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("faxNumber.phoneId={0} is not valid.", faxNumber.getPhoneId())); //NOI18N
+ }
+
+ // First remove it
+ if (!this.getAllFaxNumbers().remove(faxNumber)) {
+ // Did not work, try by id number
+ for (final DialableFaxNumber currentNumber : this.getAllFaxNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(currentNumber.getPhoneId(), faxNumber.getPhoneId())) {
+ // Found it
+ this.getAllFaxNumbers().remove(currentNumber);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.getAllFaxNumbers().add(faxNumber);
+ }
+
+ /**
+ * Uniquely add given land-line number to this bean's list. First remove the
+ * old instance (by id number), then re-add it again.
+ * <p>
+ * @param landLineNumber Land-line number to add
+ */
+ private void uniqueAddLandLineNumber (final DialableLandLineNumber landLineNumber) {
+ // Make sure the parameter is valid
+ if (null == landLineNumber) {
+ // Throw NPE
+ throw new NullPointerException("landLineNumber is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() == null) {
+ // Throw again ...
+ throw new NullPointerException("landLineNumber.phoneId is null"); //NOI18N
+ } else if (landLineNumber.getPhoneId() < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("landLineNumber.phoneId={0} is not valid.", landLineNumber.getPhoneId())); //NOI18N
+ }
+
+ // First remove it
+ if (!this.getAllLandLineNumbers().remove(landLineNumber)) {
+ // Did not work, try by id number
+ for (final DialableLandLineNumber currentNumber : this.getAllLandLineNumbers()) {
+ // Is id number the same?
+ if (Objects.equals(currentNumber.getPhoneId(), landLineNumber.getPhoneId())) {
+ // Found it
+ this.getAllLandLineNumbers().remove(currentNumber);
+ break;
+ }
+ }
+ }
+
+ // ... then add it
+ this.getAllLandLineNumbers().add(landLineNumber);
+ }
+
+ /**
+ * Updates given contact's mobile, land-line and fax number
+ * <p>
+ * @param contact Contact instance
+ */
+ private void updateContactPhoneNumbers (final Contact contact) {
+ // Parameter must be valid
+ if (null == contact) {
+ // Throw NPE
+ throw new NullPointerException("contact is null"); //NOI18N
+ } else if (contact.getContactId() == null) {
+ // Throw again
+ throw new NullPointerException("contact.contactId is null"); //NOI18N
+ } else if (contact.getContactId() < 1) {
+ // Id number is not valid
+ }
+
+ // Is land-line set?
+ if (contact.getContactLandLineNumber() instanceof DialableLandLineNumber) {
+ // Unique-add it
+ this.uniqueAddLandLineNumber(contact.getContactLandLineNumber());
+ }
+
+ // Is fax set?
+ if (contact.getContactFaxNumber() instanceof DialableFaxNumber) {
+ // Unique-add it
+ this.uniqueAddFaxNumber(contact.getContactFaxNumber());
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.phone.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
+import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
+import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
+
+/**
+ * An interface for a request web controller (bean) for administrative phone
+ * number purposes.
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookPhoneListWebViewController extends Serializable {
+
+ /**
+ * Returns a list of all fax numbers. 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.
+ * <p>
+ * @return List of all fax numbers
+ */
+ List<DialableFaxNumber> getAllFaxNumbers ();
+
+ /**
+ * Returns a list of all land-line numbers. 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.
+ * <p>
+ * @return List of all land-line numbers
+ */
+ List<DialableLandLineNumber> getAllLandLineNumbers ();
+
+ /**
+ * Finds a fax entry by given id number
+ * <p>
+ * @param faxNumberId Fax entry id number
+ * <p>
+ * @return A valid fax instance
+ * <p>
+ * @throws PhoneEntityNotFoundException If the entity was not found
+ */
+ DialableFaxNumber findFaxNumberById (final Long faxNumberId) throws PhoneEntityNotFoundException;
+
+ /**
+ * Finds a land-line entry by given id number
+ * <p>
+ * @param landLineNumberId Land-line entry id number
+ * <p>
+ * @return A valid land-line instance
+ * <p>
+ * @throws PhoneEntityNotFoundException If the entity was not found
+ */
+ DialableLandLineNumber findLandLineNumberById (final Long landLineNumberId) throws PhoneEntityNotFoundException;
+
+}
import java.text.MessageFormat;
import javax.enterprise.context.RequestScoped;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
private static final long serialVersionUID = 187_687_145_286_710L;
/**
- * User controller
+ * User list controller
*/
@Inject
- private AddressbookUserWebRequestController userController;
+ private AddressbookUserListWebViewController userListController;
/**
* Login controller
try {
// Try to get it
- user = this.userController.lookupUserById(userId);
+ user = this.userListController.lookupUserById(userId);
} catch (final UserNotFoundException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Is it null?
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.profilemode;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Named;
-import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-
-/**
- * A profile mode bean
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@Named ("profileModeController")
-@ApplicationScoped
-public class AddressbookProfileModeWebApplicationBean extends BaseAddressbookBean implements AddressbookProfileModeWebApplicationController {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 835_482_364_189L;
-
- /**
- * A list of all profile modes
- */
- private final List<ProfileMode> allProfileModes;
-
- /**
- * Default constructor
- */
- public AddressbookProfileModeWebApplicationBean () {
- // Call super constructor
- super();
-
- // Init list
- this.allProfileModes = Arrays.asList(ProfileMode.values());
- }
-
- /**
- * Getter for all profile modes as array
- * <p>
- * @return All profile modes as list
- */
- public List<ProfileMode> allProfileModes () {
- // Return it
- return Collections.unmodifiableList(this.allProfileModes);
- }
-}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.beans.profilemode;
-
-import java.io.Serializable;
-
-/**
- * An interface for data beans
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-public interface AddressbookProfileModeWebApplicationController extends Serializable {
-
-}
import javax.enterprise.event.Observes;
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.addressbook.beans.BaseAddressbookBean;
import org.mxchange.addressbook.beans.contact.AddressbookAdminContactWebRequestController;
import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
+import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
import org.mxchange.addressbook.beans.helper.AddressbookWebViewHelperController;
-import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcoreee.utils.FacesUtils;
import org.mxchange.jusercore.events.user.add.AdminAddedUserEvent;
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.AdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
+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;
private Event<ObservableAdminDeletedUserEvent> deleteUserEvent;
/**
- * Localization controller
+ * Features controller
*/
@Inject
- private AddressbookLocalizationSessionController localizationController;
+ private AddressbookFeaturesWebApplicationController featureController;
/**
* An event fired when the administrator has updated a new user
*/
@Inject
@Any
- private Event<ObservableAdminUpdatedUserDataEvent> updatedUserDataEvent;
+ private Event<ObservableAdminPostUserDataUpdatedEvent> updatedUserDataEvent;
/**
* General user EJB
@EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
private UserSessionBeanRemote userBean;
- /**
- * Regular user controller
- */
- @Inject
- private AddressbookUserWebRequestController userController;
-
/**
* Delete reason
*/
@Any
private Event<ObservableAdminLinkedUserEvent> userLinkedEvent;
+ /**
+ * Regular user controller
+ */
+ @Inject
+ private AddressbookUserListWebViewController userListController;
+
/**
* User lock reason
*/
*/
private String userPasswordRepeat;
+ /**
+ * Whether the user wants a public profile
+ */
+ private ProfileMode userProfileMode;
+
/**
* Event being fired when administrator unlocks an account
*/
* sending it to the EJB. The data set in the controller is being verified,
* e.g. if the user name or email address is not used yet.
* <p>
- * @return Redirect outcome
*/
- public String addUser () {
+ public void addUser () {
// As the form cannot validate the data (required="true"), check it here
if (this.getUserName() == null) {
// Throw NPE
}
// Create new user instance
- final User newUser = new LoginUser();
-
- // Set user name, CONFIRMED and INVISIBLE
- newUser.setUserName(this.getUserName());
- newUser.setUserMustChangePassword(this.getUserMustChangePassword());
- newUser.setUserAccountStatus(UserAccountStatus.CONFIRMED);
- newUser.setUserProfileMode(ProfileMode.INVISIBLE);
-
- // Get locale from view-root
- final Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
-
- // Copy user locale
- newUser.setUserLocale(locale);
-
- // Init instance
- Contact userContact;
-
- // Is a contact instance in helper set?
- if (this.getContact() instanceof Contact) {
- // Then use it for contact linking
- userContact = this.getContact();
- } else {
- // Create contact instance
- userContact = this.contactController.createContactInstance();
- }
-
- // Set contact in user
- newUser.setUserContact(userContact);
-
- // Init variable for password
- String password = null;
+ final User newUser = this.createUserInstance();
// Is the user name or email address used already?
// @TODO Add password length check
if ((this.featureController.isFeatureEnabled("user_login_require_user_name")) && (this.userListController.isUserNameRegistered(newUser))) {
// User name is already used
- throw new FaceletException(new UserNameAlreadyRegisteredException(newUser));
+ throw new FacesException(new UserNameAlreadyRegisteredException(newUser));
} else if ((this.getContact() == null) && (this.contactController.isEmailAddressRegistered(newUser.getUserContact()))) {
// Email address is already used
- this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED"); //NOI18N
+ this.showFacesMessage("admin_add_user:emailAddress", "ERROR_EMAIL_ADDRESS_ALREADY_USED", FacesMessage.SEVERITY_WARN); //NOI18N
// Always clear password
this.setUserPassword(null);
this.setUserPasswordRepeat(null);
// Skip it
- return ""; //NOI18N
- } else if ((this.getUserPassword() == null && (this.getUserPasswordRepeat() == null)) || ((this.getUserPassword().isEmpty()) && (this.getUserPasswordRepeat().isEmpty()))) {
- // Empty password entered, then generate one
- password = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH);
- } else if (!this.isSamePasswordEntered()) {
- // Both passwords don't match
- throw new FaceletException(new UserPasswordRepeatMismatchException(newUser));
- } else {
- // Both match, so get it from this bean
- password = this.getUserPassword();
+ return;
}
- // The password should not be null and at least 5 characters long
- assert (password != null) : "password is null"; //NOI18N
- assert (password.length() >= AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH) : "Password is not long enough."; //NOI18N
-
- // Encrypt password and set it
- newUser.setUserEncryptedPassword(UserLoginUtils.encryptPassword(password));
+ // Init variable
+ final User updatedUser;
try {
// Now, that all is set, call EJB
if (this.getContact() instanceof Contact) {
// Link contact with this user
- final User updatedUser = this.adminUserBean.linkUser(newUser);
-
- // Fire event
- this.userLinkedEvent.fire(new AdminLinkedUserEvent(updatedUser));
+ updatedUser = this.adminUserBean.linkUser(newUser);
} else {
- // Add new contact
- final User updatedUser = this.adminUserBean.addUser(newUser);
-
- // Fire event
- this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
+ // Add new user
+ updatedUser = this.adminUserBean.addUser(newUser);
}
} catch (final UserNameAlreadyRegisteredException | EmailAddressAlreadyRegisteredException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Now, that all is set, call EJB
// Fire event
this.addedUserEvent.fire(new AdminAddedUserEvent(updatedUser));
}
-
// Clear helper
this.setContact(null);
// Clear this bean
this.clear();
-
- // Return to user list (for now)
- return "admin_list_user"; //NOI18N
}
/**
* @param event User registration event
*/
public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
/**
* Deletes given user account
- * <p>
- * @return Redirect outcome
*/
- public String deleteUserData () {
+ public void deleteUserData () {
// Get user instance
final User user = this.beanHelper.getUser();
this.adminUserBean.deleteUser(user, this.getUserDeleteReason());
} catch (final UserNotFoundException ex) {
// Should not happen, so throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
- this.deleteUserEvent.fire(new AdminDeletedUserEvent(this.getUser(), this.getUserDeleteReason()));
-
- // Redirect
- return "admin_list_user"; //NOI18N
+ this.deleteUserEvent.fire(new AdminDeletedUserEvent(user, this.getUserDeleteReason()));
}
/**
* Edits currently loaded user's data in database.
- * <p>
- * @return Redirect outcome
*/
- public String editUserData () {
+ public void editUserData () {
// Get user instance
final User user = this.beanHelper.getUser();
this.clear();
// User name already exists
- this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS"); //NOI18N
- return ""; //NOI18N
+ this.showFacesMessage("form_edit_user:userName", "ADMIN_USER_NAME_ALREADY_EXISTS", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
} else if (this.isSamePasswordEntered()) {
// Same password entered, create container
if ((Objects.equals(user.getUserMustChangePassword(), this.getUserMustChangePassword())) && (UserLoginUtils.ifPasswordMatches(new UserLoginContainer(user, this.getUserPassword())))) {
this.setUserPasswordRepeat(null);
// Same password entered
- this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD"); //NOI18N
- return ""; //NOI18N
+ this.showFacesMessage("form_edit_user:userPassword", "ADMIN_USER_ENTERED_SAME_AS_OLD_PASSWORD", FacesMessage.SEVERITY_WARN); //NOI18N
+ return;
}
// Encrypt password
}
// Fire event
- this.updatedUserDataEvent.fire(new AdminUpdatedUserDataEvent(updatedUser));
-
- // Return to user list (for now)
- return "admin_list_user"; //NOI18N
+ this.updatedUserDataEvent.fire(new AdminPostUserDataUpdatedEvent(updatedUser));
}
/**
this.userPasswordRepeat = userPasswordRepeat;
}
+ /**
+ * Getter for user profile mode
+ * <p>
+ * @return User profile mode
+ */
+ public ProfileMode getUserProfileMode () {
+ return this.userProfileMode;
+ }
+
+ /**
+ * Setter for user profile mode
+ * <p>
+ * @param userProfileMode User profile mode
+ */
+ public void setUserProfileMode (final ProfileMode userProfileMode) {
+ this.userProfileMode = userProfileMode;
+ }
+
/**
* Locks selected user's account. This method makes sure that a lock reason
* is provided that th user later can read on login attempts.
updatedUser = this.adminUserBean.lockUserAccount(user, this.getUserLockReason(), baseUrl);
} catch (final UserStatusLockedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
updatedUser = this.adminUserBean.unlockUserAccount(user, baseUrl);
} catch (final UserStatusConfirmedException | UserStatusUnconfirmedException | UserNotFoundException ex) {
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
// Fire event
*/
package org.mxchange.addressbook.beans.user;
-import fish.payara.cdi.jsr107.impl.NamedCache;
-import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
-import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.enterprise.event.Event;
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.Any;
-import javax.faces.context.FacesContext;
-import javax.faces.view.facelets.FaceletException;
-import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
-import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
-import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
-import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent;
-import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
-import org.mxchange.jusercore.events.user.clear.password.ObservableClearUserPasswordEvent;
-import org.mxchange.jusercore.events.user.clear.username.ObservableClearUserNameEvent;
-import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
-import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
-import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
-import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
-import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
-import org.mxchange.jusercore.events.user.update.UpdatedUserPersonalDataEvent;
-import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.model.user.LoginUser;
-import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
-import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
-import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
-import org.mxchange.juserlogincore.events.login.ObservableUserLoggedInEvent;
-import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
-import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
-import org.mxchange.juserlogincore.login.UserLoginUtils;
/**
* A user bean (controller)
*/
private static final long serialVersionUID = 542_145_347_916L;
- /**
- * General contact controller
- */
- @Inject
- private AddressbookContactWebRequestController contactController;
-
- /**
- * Features controller
- */
- @Inject
- private AddressbookFeaturesWebApplicationController featureController;
-
- /**
- * Locale instance
- */
- private Locale locale;
-
- /**
- * Localization controller
- */
- @Inject
- private AddressbookLocalizationSessionController localizationController;
-
- /**
- * Event being fired when user updated personal data
- */
- @Inject
- @Any
- private Event<ObservableUpdatedUserPersonalDataEvent> updatedPersonalDataEvent;
-
- /**
- * Remote user bean
- */
- @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
- private UserSessionBeanRemote userBean;
-
- /**
- * A list of all user profiles
- */
- @Inject
- @NamedCache (cacheName = "userCache")
- private Cache<Long, User> userCache;
-
- /**
- * User id
- */
- private Long userId;
-
- /**
- * Login controller (bean)
- */
- @Inject
- private AddressbookUserLoginWebSessionController userLoginController;
-
- /**
- * User name
- */
- private String userName;
-
- /**
- * User name list
- */
- @Inject
- @NamedCache (cacheName = "userNameCache")
- private Cache<Long, String> userNameCache;
-
- /**
- * User password (clear-text from web form)
- */
- private String userPassword;
-
- /**
- * User password repeated (clear-text from web form)
- */
- private String userPasswordRepeat;
-
- /**
- * Whether the user wants a public profile
- */
- private ProfileMode userProfileMode;
-
/**
* Default constructor
*/
super();
}
- /**
- * Event observer for newly added users by administrator
- * <p>
- * @param event Event being fired
- */
- public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event 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
- }
-
- // Update user list
- this.updateList(event.getAddedUser());
-
- // Clear all data
- this.clear();
-
- // Set user id again
- this.setUserId(event.getAddedUser().getUserId());
- }
-
- /**
- * Event observer for deleted user accounts (by administrator)
- * <p>
- * @param event Event being fired
- */
- public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getDeletedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.deletedUser is null"); //NOI18N
- } else if (event.getDeletedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
- } else if (event.getDeletedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.removeFromList(event.getDeletedUser());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Event observer for linked users with existing contact data
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getLinkedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.linkedUser is null"); //NOI18N
- } else if (event.getLinkedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
- } else if (event.getLinkedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getLinkedUser());
-
- // Clear all data
- this.clear();
-
- // Set user id again
- this.setUserId(event.getLinkedUser().getUserId());
- }
-
- /**
- * Event observer for locked users
- * <p>
- * @param event Event being fired
- */
- public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getLockedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.lockedUser is null"); //NOI18N
- } else if (event.getLockedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
- } else if (event.getLockedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getLockedUser());
- }
-
- /**
- * Event observer for unlocked users
- * <p>
- * @param event Event being fired
- */
- public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUnlockedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.unlockedUser is null"); //NOI18N
- } else if (event.getUnlockedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
- } else if (event.getUnlockedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getUnlockedUser());
- }
-
- /**
- * Event observer for updated user data by administrator
- * <p>
- * @param event Event being updated
- */
- public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedUser is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getUpdatedUser());
-
- // Clear all data
- this.clear();
- }
-
- /**
- * Event observer for when a bean helper has successfully created a user
- * instance, means the user exists. If the user does not exist, this event
- * should not fire but instead a proper exception must be thrown.
- * <p>
- * @param event User created event
- */
- public void afterCreatedUserEvent (@Observes final ObservableCreatedUserEvent event) {
- // Is the instance valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getCreatedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.createdUser is null"); //NOI18N
- } else if (event.getCreatedUser().getUserId() == null) {
- // Throw NPE again
- throw new NullPointerException("event.createdUser.userId is null"); //NOI18N
- } else if (event.getCreatedUser().getUserId() < 1) {
- // Throw NPE again
- throw new NullPointerException(MessageFormat.format("event.createdUser.userId={0} is not valid", event.getCreatedUser().getUserId())); //NOI18N
- }
-
- // Get user instance
- final User user = event.getCreatedUser();
-
- // Set all fields here
- this.copyUser(user);
- }
-
- /**
- * Observer method for events being fired when the application's locale has
- * been changed.
- * <p>
- * @param event Event being fired
- */
- public void afterLocaleChangeEvent (@Observes final ObservableLocaleChangeEvent event) {
- // Is the parameter valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- } else if (event.getLocale() == null) {
- // Throw NPE again
- throw new NullPointerException("event.locale is null");
- }
-
- // Set it here
- this.setLocale(event.getLocale());
- }
-
- /**
- * Event observer when user confirmed account.
- * <p>
- * @param event Event being fired
- */
- public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getConfirmedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.confirmedUser is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
- } else if (event.getConfirmedUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getConfirmedUser());
- }
-
- /**
- * Event observer for logged-in user
- * <p>
- * @param event Event instance
- */
- public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getLoggedInUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getLoggedInUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getLoggedInUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLoggedInUser(), event.getLoggedInUser().getUserId())); //NOI18N
- }
-
- // "Cache" user instance
- final User loggedInUser = event.getLoggedInUser();
-
- // Copy all data to this bean
- this.copyUser(loggedInUser);
- }
-
- /**
- * Event observer for user password changes
- * <p>
- * @param event Event being fired
- */
- public void afterUserPasswordChangedEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
- // Is it valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUserPassword() == null) {
- // Throw NPE
- throw new NullPointerException("event.userPassword is null"); //NOI18N
- } else if (event.getUserPassword().isEmpty()) {
- // Throw NPE
- throw new IllegalArgumentException("event.userPassword is empty"); //NOI18N
- }
-
- // Set it here
- this.setUserPassword(event.getUserPassword());
- this.setUserPasswordRepeat(event.getUserPassword());
- }
-
- /**
- * Event observer for new user registrations
- * <p>
- * @param event User registration event
- */
- public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // event should not be null
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getRegisteredUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.registeredUser is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() == null) {
- // userId is null
- throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
- } else if (event.getRegisteredUser().getUserId() < 1) {
- // Not avalid id
- throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
- }
-
- // Get user instance
- final User registeredUser = event.getRegisteredUser();
-
- // Copy all data from registered->user
- this.copyUser(registeredUser);
-
- // Clear all data
- this.clear();
-
- // Update user list
- this.updateList(registeredUser);
-
- // Add user name
- this.addUserName(registeredUser);
-
- // Set user id again
- this.setUserId(registeredUser.getUserId());
- }
-
- /**
- * Method being call after user's password has been updated (and history
- * entry has been created).
- * <p>
- * @param event Event being observed
- */
- public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
- // Check parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getPasswordHistory() == null) {
- // Throw NPE again
- throw new NullPointerException("event.passwordHistory is null"); //NOI18N
- } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
- // ... and again
- throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
- } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
- // Invalid value
- throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
- }
-
- /**
- * Listens to fired event when user updated personal data
- * <p>
- * @param event Event being fired
- */
- public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
- // Check parameter
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null"); //NOI18N
- } else if (event.getUpdatedUser() == null) {
- // Throw NPE again
- throw new NullPointerException("event.updatedUser is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() == null) {
- // ... and again
- throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
- } else if (event.getUpdatedUser().getUserId() < 1) {
- // Invalid value
- throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
- }
-
- // Update user list
- this.updateList(event.getUpdatedUser());
- }
-
- @Override
- @SuppressWarnings ("ReturnOfCollectionOrArrayField")
- public List<User> allUsers () {
- // Init list
- final List<User> list = new LinkedList<>();
-
- // Get iterator
- final Iterator<Cache.Entry<Long, User>> iterator = this.userCache.iterator();
-
- // Loop over all
- while (iterator.hasNext()) {
- // Get next entry
- final Cache.Entry<Long, User> next = iterator.next();
-
- // Add value to list
- list.add(next.getValue());
- }
-
- // Return it
- return list;
- }
-
- /**
- * Event observer for when a user name should be cleared
- * <p>
- * @param event Event being fired
- */
- public void clearUserNameEvent (@Observes final ObservableClearUserNameEvent event) {
- // Is it valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- }
-
- // Clear it
- this.clearUserName();
- }
-
- /**
- * Event observer for when both user passwords should be cleared
- * <p>
- * @param event Event being fired
- */
- public void clearUserPasswordEvent (@Observes final ObservableClearUserPasswordEvent event) {
- // Is it valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- }
-
- // Clear it
- this.clearUserPasswords();
- }
-
- @Override
- public User createUserInstance (final boolean createContactData) {
- // Required personal data must be set
- assert (this.isRequiredPersonalDataSet()) : "not all personal data is set"; //NOI18N
-
- // Create new user instance
- final User user = new LoginUser();
-
- // Is user name required?
- if (!this.isUserNameRequired()) {
- // Generate pseudo-random user name
- String randomName = this.userBean.generateRandomUserName();
-
- // Set it and inivisible profile
- this.setUserName(randomName);
- this.setUserProfileMode(ProfileMode.INVISIBLE);
-
- // Generate random password
- String randomPassword = UserLoginUtils.createRandomPassword(AddressbookUserWebRequestController.MINIMUM_PASSWORD_LENGTH);
-
- // Set random password
- this.setUserPassword(randomPassword);
- this.setUserPasswordRepeat(randomPassword);
- }
-
- // Set user name profile mode and locale
- user.setUserName(this.getUserName());
- user.setUserProfileMode(this.getUserProfileMode());
- user.setUserLocale(this.getLocale());
-
- // Is multiple registration page
- if ((createContactData) || (!this.featureController.isFeatureEnabled("user_register_multiple_page"))) { //NOI18N
- // Create contact instance
- final Contact contact = this.contactController.createContactInstance();
-
- // Set contact in user
- user.setUserContact(contact);
- }
-
- // Return it
- return user;
- }
-
- @Override
- public User createUserLogin () {
- // Is all data set?
- if (this.getUserName() == null) {
- // Throw NPE
- throw new NullPointerException("userName is null"); //NOI18N
- } else if (this.getUserName().isEmpty()) {
- // Is empty
- throw new IllegalStateException("userName is empty."); //NOI18N
- }
-
- // Create new user instance
- final User user = new LoginUser();
-
- // Update all data ...
- user.setUserName(this.getUserName());
-
- // Return the new instance
- return user;
- }
-
- @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.isRequiredChangePersonalDataSet()) {
- // Not all required fields are set
- throw new FaceletException("Not all required fields are set."); //NOI18N
- } else if (!this.userLoginController.ifCurrentPasswordMatches()) {
- // Password not matching
- throw new FaceletException(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();
-
- // Copy contact data to contact instance
- this.contactController.updateContactDataFromController(user.getUserContact());
-
- // 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
-
- // Update all fields
- user.setUserProfileMode(this.getUserProfileMode());
-
- // Send it to the EJB
- final User updatedUser = this.userBean.updateUserPersonalData(user);
-
- // Fire event
- this.updatedPersonalDataEvent.fire(new UpdatedUserPersonalDataEvent(updatedUser));
-
- // All fine
- return "user_contact_data_saved"; //NOI18N
- }
-
- /**
- * Getter for user id
- * <p>
- * @return User id
- */
- public Long getUserId () {
- return this.userId;
- }
-
- /**
- * Setter for user id
- * <p>
- * @param userId User id
- */
- public void setUserId (final Long userId) {
- this.userId = userId;
- }
-
- /**
- * Getter for user name
- * <p>
- * @return User name
- */
- public String getUserName () {
- return this.userName;
- }
-
- /**
- * Setter for user name
- * <p>
- * @param userName User name
- */
- public void setUserName (final String userName) {
- this.userName = userName;
- }
-
- @Override
- public String getUserPassword () {
- return this.userPassword;
- }
-
- /**
- * Setter for clear-text user password
- * <p>
- * @param userPassword Clear-text user password
- */
- public void setUserPassword (final String userPassword) {
- this.userPassword = userPassword;
- }
-
- /**
- * Getter for clear-text user password repeated
- * <p>
- * @return Clear-text user password repeated
- */
- public String getUserPasswordRepeat () {
- return this.userPasswordRepeat;
- }
-
- /**
- * Setter for clear-text user password repeated
- * <p>
- * @param userPasswordRepeat Clear-text user password repeated
- */
- public void setUserPasswordRepeat (final String userPasswordRepeat) {
- this.userPasswordRepeat = userPasswordRepeat;
- }
-
- /**
- * Getter for user profile mode
- * <p>
- * @return User profile mode
- */
- public ProfileMode getUserProfileMode () {
- return this.userProfileMode;
- }
-
- /**
- * Setter for user profile mode
- * <p>
- * @param userProfileMode User profile mode
- */
- public void setUserProfileMode (final ProfileMode userProfileMode) {
- this.userProfileMode = userProfileMode;
- }
-
- @Override
- public boolean ifBothPasswordsEmptyAllowed () {
- // Check feature first
- return ((this.featureController.isFeatureEnabled("allow_user_registration_empty_password")) && //NOI18N
- ((this.getUserPassword() == null) || (this.getUserPassword().isEmpty())) &&
- ((this.getUserPasswordRepeat() == null) || (this.getUserPasswordRepeat().isEmpty())));
- }
-
- /**
- * Post-initialization of this class
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.userCache.iterator().hasNext()) {
- // Get whole list
- final List<User> list = this.userBean.allUsers();
-
- // Add all
- for (final Iterator<User> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final User next = iterator.next();
-
- // Add it to cache
- this.userCache.put(next.getUserId(), next);
- this.userNameCache.put(next.getUserId(), next.getUserName());
- }
- }
- }
-
- @Override
- public boolean isContactFound (final Contact contact) {
- // The contact must be valid
- if (null == contact) {
- // Throw NPE
- throw new NullPointerException("contact is null"); //NOI18N
- } else if (contact.getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("contact.contactId is null"); //NOI18N
- } else if (contact.getContactId() < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("contact.contactId={0} is not valid", contact.getContactId())); //NOI18N
- }
-
- // Default is not found
- boolean isFound = false;
-
- // Get iterator
- final Iterator<User> iterator = this.allUsers().iterator();
-
- // Loop through all entries
- while (iterator.hasNext()) {
- // Get user
- final User next = iterator.next();
-
- // Compare both objects
- if (Objects.equals(contact, next.getUserContact())) {
- // Found it
- isFound = true;
- break;
- }
- }
-
- // Return status
- return isFound;
- }
-
- @Override
- public boolean isPublicUserProfileEnabled () {
- // Get context parameter
- final String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_public_profile_enabled"); //NOI18N
-
- // Is it set?
- final boolean isEnabled = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
-
- // This requires user names being enabled, too.
- if ((isEnabled) && (!this.isUserNameRequired())) {
- // Not valid state, users must be able to modify their profile, especially when it is public
- throw new IllegalStateException("Public user profiles are enabled but user name requirement is disabled, this is not possible."); //NOI18N
- }
-
- // Return value
- return isEnabled;
- }
-
- @Override
- public boolean isRequiredChangePersonalDataSet () {
- return ((this.getUserProfileMode() != null) &&
- (this.getUserName() != null) && (!this.getUserName().isEmpty()) &&
- (this.contactController.isRequiredChangePersonalDataSet()));
- }
-
- @Override
- public boolean isRequiredPersonalDataSet () {
- if (this.featureController.isFeatureEnabled("user_register_multiple_page")) { //NOI18N
- // Multiple registration page
- return this.contactController.isRequiredPersonalDataSet();
- } else {
- // Single registration page
- return (((this.getUserName() != null) || (!this.isUserNameRequired())) &&
- (this.getUserProfileMode() != null) &&
- (this.contactController.isRequiredPersonalDataSet()) &&
- (this.getUserPassword() != null) &&
- (this.getUserPasswordRepeat() != null));
- }
- }
-
- @Override
- public boolean isSamePasswordEntered () {
- return ((!this.getUserPassword().isEmpty()) && (Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())));
- }
-
- @Override
- public boolean isUserIdEmpty () {
- return ((this.getUserId() == null) || (this.getUserId() == 0));
- }
-
- @Override
- public boolean isUserNameRegistered (final User user) {
- return ((this.userNameCache instanceof List) && (this.userNameCache.containsKey(user.getUserId())));
- }
-
- @Override
- public boolean isUserNameRequired () {
- // Get context parameter
- final String contextParameter = FacesContext.getCurrentInstance().getExternalContext().getInitParameter("is_user_login_require_user_name"); //NOI18N
-
- // Is it set?
- final boolean isRequired = ((contextParameter instanceof String) && (contextParameter.toLowerCase().equals("true"))); //NOI18N
-
- // Return value
- return isRequired;
- }
-
- @Override
- public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
- // Parameter must be valid
- if (null == emailAddress) {
- // Throw NPE
- throw new NullPointerException("emailAddress is null"); //NOI18N
- } else if (emailAddress.isEmpty()) {
- // Not valid
- throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
- }
-
- // Init variable
- User user = null;
-
- // Try to lookup it in visible user list
- for (final Iterator<Cache.Entry<Long, User>> iterator = this.userCache.iterator(); iterator.hasNext();) {
- // Get next user
- final Cache.Entry<Long, User> next = iterator.next();
-
- // Contact should be set
- if (next.getValue().getUserContact() == null) {
- // Contact is null
- throw new NullPointerException(MessageFormat.format("next.userContact is null for user id {0}", next.getKey())); //NOI18N
- } else if (next.getValue().getUserContact().getContactEmailAddress() == null) {
- // Email address should be set
- throw new NullPointerException(MessageFormat.format("next.userContact.contactEmailAddress is null for user id {0}", next.getKey())); //NOI18N
- }
-
- // Is the email address found?
- if (Objects.equals(next.getValue().getUserContact().getContactEmailAddress(), emailAddress)) {
- // Copy to other variable
- user = next.getValue();
- break;
- }
- }
-
- // Is it still null?
- if (null == user) {
- // Not visible for the current user
- throw new UserEmailAddressNotFoundException(emailAddress);
- }
-
- // Return it
- return user;
- }
-
- @Override
- public User lookupUserById (final Long userId) throws UserNotFoundException {
- // Parameter must be valid
- if (null == userId) {
- // Throw NPE
- throw new NullPointerException("userId is null"); //NOI18N
- } else if (userId < 1) {
- // Not valid
- throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
- }
-
- // Init variable
- User user = null;
-
- // Try to lookup it in visible user list
- for (final Iterator<Cache.Entry<Long, User>> iterator = this.userCache.iterator(); iterator.hasNext();) {
- // Get next user
- final Cache.Entry<Long, User> next = iterator.next();
-
- // Is the user id found?
- if (Objects.equals(next.getKey(), userId)) {
- // Copy to other variable
- user = next.getValue();
- break;
- }
- }
-
- // Is it still null?
- if (null == user) {
- // Not visible for the current user
- throw new UserNotFoundException(userId);
- }
-
- // Return it
- return user;
- }
-
- /**
- * Adds user's name to bean's internal list. It also updates the public user
- * list if the user has decided to have a public account,
- * <p>
- * @param user User instance
- */
- private void addUserName (final User user) {
- // Make sure the entry is not added yet
- if (this.userNameCache.containsKey(user.getUserId())) {
- // Abort here
- throw new IllegalArgumentException(MessageFormat.format("User name {0} already added.", user.getUserName())); //NOI18N
- }
-
- // Add user name
- this.userNameCache.put(user.getUserId(), user.getUserName());
- }
-
- /**
- * Clears this bean
- */
- private void clear () {
- // Clear all data
- // - personal data
- this.setUserId(null);
- this.setUserProfileMode(null);
-
- // - other data
- this.clearUserName();
- this.clearUserPasswords();
- this.setLocale(null);
- }
-
- /**
- * Clears user name
- */
- private void clearUserName () {
- // Clear it
- this.setUserName(null);
- }
-
- /**
- * Clears both user passwords
- */
- private void clearUserPasswords () {
- // Clear both
- this.setUserPassword(null);
- this.setUserPasswordRepeat(null);
- }
-
- /**
- * Copies given user into the controller
- * <p>
- * @param user User instance
- */
- private void copyUser (final User user) {
- // Make sure the instance is valid
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserContact() == null) {
- // Throw again ...
- throw new NullPointerException("user.userContact is null"); //NOI18N
- }
-
- // Copy all fields:
- // - base data
- this.setUserId(user.getUserId());
- this.setUserProfileMode(user.getUserProfileMode());
- }
-
- /**
- * Getter for locale instance
- * <p>
- * @return Locale instance
- */
- private Locale getLocale () {
- return this.locale;
- }
-
- /**
- * Setter for locale instance
- * <p>
- * @param locale Locale instance
- */
- private void setLocale (final Locale locale) {
- this.locale = locale;
- }
-
- /**
- * Removes user from all lists
- * <p>
- * @param user User to remove
- */
- private void removeFromList (final User user) {
- // The user should be valid
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // ... again NPE
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
- }
-
- // Remove it from lists
- this.userCache.remove(user.getUserId());
-
- // Remove name from list
- this.userNameCache.remove(user.getUserId());
- }
-
- /**
- * Updates list with given user instance
- * <p>
- * @param user User instance
- */
- private void updateList (final User user) {
- // The user should be valid
- if (null == user) {
- // Throw NPE
- throw new NullPointerException("user is null"); //NOI18N
- } else if (user.getUserId() == null) {
- // ... again NPE
- throw new NullPointerException("user.userId is null"); //NOI18N
- } else if (user.getUserId() < 1) {
- // Invalid id
- throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
- } else if (user.getUserContact() == null) {
- // Throw again ...
- throw new NullPointerException("user.userContact is null"); //NOI18N
- } else if (user.getUserContact().getContactId() == null) {
- // Throw again ...
- throw new NullPointerException("user.userContact.contactId is null"); //NOI18N
- } else if (user.getUserContact().getContactId() < 1) {
- // Throw again ...
- throw new NullPointerException(MessageFormat.format("user.userContact.contactId={0} is invalid.", user.getUserContact().getContactId())); //NOI18N
- }
-
- // Add/update user
- this.userCache.put(user.getUserId(), user);
- }
-
}
package org.mxchange.addressbook.beans.user;
import java.io.Serializable;
-import java.util.List;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.model.user.User;
/**
* An interface for user beans
@Deprecated
public static final Integer MINIMUM_PASSWORD_LENGTH = 5;
- /**
- * Getter for clear-text user password
- * <p>
- * @return Clear-text user password
- */
- String getUserPassword ();
-
- /**
- * Checks if both user passwords are left empty and if this is enabled
- * (allowed) in context parameter. If true, the calling bean should create a
- * random password (preferable with UserUtils.createRandomPassword() and set
- * it in both user password fields.
- * <p>
- * @return Whether empty passwords are allowed
- */
- boolean ifBothPasswordsEmptyAllowed ();
-
- /**
- * All users
- * <p>
- * @return A list of all public user profiles
- */
- List<User> allUsers ();
-
- /**
- * Checks whether the given contact is a user
- * <p>
- * @param contact Contact to check
- * <p>
- * @return Whether the contact is a user
- */
- boolean isContactFound (final Contact contact);
-
- /**
- * Checks whether given user instance's name is used
- * <p>
- * @param user User instance's name to check
- * <p>
- * @return Whether it is already used
- */
- boolean isUserNameRegistered (final User user);
-
- /**
- * Tries to lookup user by given id number. If the user is not found or the
- * account status is not CONFIRMED proper exceptions are thrown.
- * <p>
- * @param userId User id
- * <p>
- * @return User instance
- * <p>
- * @throws UserNotFoundException If the user is not found
- */
- User lookupUserById (final Long userId) throws UserNotFoundException;
-
- /**
- * Tries to lookup user by given email address. If the user is not found a
- * proper exceptions is thrown.
- * <p>
- * @param emailAddress Email address
- * <p>
- * @return User instance
- * <p>
- * @throws UserEmailAddressNotFoundException If the user's email address is
- * not found
- */
- User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException;
-
- /**
- * Creates an instance from all properties
- * <p>
- * @param createContactData Whether contact data should be created
- * <p>
- * @return A user instance
- */
- User createUserInstance (final boolean createContactData);
-
- /**
- * Creates a user instance for login phase
- * <p>
- * @return User instance
- */
- User createUserLogin ();
-
- /**
- * Checks whether all required personal data is set
- * <p>
- * @return Whether the required personal data is set
- */
- boolean isRequiredPersonalDataSet ();
-
- /**
- * Checks whether all required personal data is set for changing them
- * <p>
- * @return Whether the required personal data is set
- */
- boolean isRequiredChangePersonalDataSet ();
-
- /**
- * Checks whether same passwords has been entered
- * <p>
- * @return Whether same passwords has been entered
- */
- boolean isSamePasswordEntered ();
-
- /**
- * Checks if the user id is empty
- * <p>
- * @return Whether the user id is empty
- */
- boolean isUserIdEmpty ();
-
- /**
- * Changes logged-in user's personal data if the current password matches
- * and TAC + privacy statement has been accepted.
- * <p>
- * @return New target page
- */
- String doChangePersonalData ();
-
- /**
- * Checks whether this application requires a user name to be entered.
- * Otherwise a random name like "userXXXXX" is generated
- * <p>
- * @return Whether this application requires a user name
- */
- boolean isUserNameRequired ();
-
- /**
- * Checks wether public user profiles are enabled. This requires that user
- * names are also enabled.
- * <p>
- * @return Whether public user profiles are enabled
- */
- boolean isPublicUserProfileEnabled ();
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
+import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
+import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
+import org.mxchange.jcontacts.model.contact.Contact;
+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)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userActionController")
+@RequestScoped
+public class AddressbookUserActionWebRequestBean extends BaseAddressbookBean implements AddressbookUserActionWebRequestController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_920L;
+
+ /**
+ * General contact controller
+ */
+ @Inject
+ private AddressbookContactWebRequestController contactController;
+
+ /**
+ * Features controller
+ */
+ @Inject
+ private AddressbookFeaturesWebApplicationController featureController;
+
+ /**
+ * Event being fired when user updated personal data
+ */
+ @Inject
+ @Any
+ private Event<ObservablePostUserPersonalDataUpdatedEvent> postUpdatedPersonalDataEvent;
+
+ /**
+ * Event being fired when user updated personal data
+ */
+ @Inject
+ @Any
+ private Event<ObservablePreUserPersonalDataUpdatedEvent> preUpdatedPersonalDataEvent;
+
+ /**
+ * Remote user bean
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * Login controller (bean)
+ */
+ @Inject
+ private AddressbookUserLoginWebSessionController userLoginController;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUserActionWebRequestBean () {
+ // 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
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user.action;
+
+import java.io.Serializable;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookUserActionWebRequestController extends Serializable {
+
+ /**
+ * Minimum password length
+ * <p>
+ * @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.
+ * <p>
+ * @return New target page
+ */
+ String doChangePersonalData ();
+
+}
import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
import java.util.Collections;
-import java.util.GregorianCalendar;
+import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
-import org.mxchange.jusercore.events.user.update.ObservableAdminUpdatedUserDataEvent;
-import org.mxchange.jusercore.events.user.update.ObservableUpdatedUserPersonalDataEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservablePostUserPersonalDataUpdatedEvent;
import org.mxchange.jusercore.model.user.User;
import org.mxchange.jusercore.model.user.activity.LogableUserActivity;
import org.mxchange.jusercore.model.user.activity.UserActivityLog;
* @param event Event being fired
*/
public void afterAdminAddedUserEvent (@Observes final ObservableAdminAddedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* <p>
* @param event Event being updated
*/
- public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminUpdatedUserDataEvent event) {
- // event should not be null
+ public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminPostUserDataUpdatedEvent event) {
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterUserLoginEvent (@Observes final ObservableUserLoggedInEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event instance
*/
public void afterUserLogoutEvent (@Observes final ObservableUserLogoutEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* @param event Event being fired
*/
public void afterUserResendConfirmationLinkEvent (@Observes final ObservableUserResendLinkAccountEvent event) {
- // event should not be null
+ // Event and contained entity instance should not be null
if (null == event) {
// Throw NPE
throw new NullPointerException("event is null"); //NOI18N
* <p>
* @param event Event being fired
*/
- public void afterUserUpdatedPersonalDataEvent (@Observes final ObservableUpdatedUserPersonalDataEvent event) {
+ public void afterUserUpdatedPersonalDataEvent (@Observes final ObservablePostUserPersonalDataUpdatedEvent event) {
// Check parameter
if (null == event) {
// Throw NPE
* Post-constructor method
*/
@PostConstruct
- public void init () {
- // Get whole list
- final List<LogableUserActivity> list = this.userActivityBean.fetchAllUserActivityLog();
-
+ public void initializeList () {
// Put all in map, per-user
- for (final LogableUserActivity userActivity : list) {
+ for (final LogableUserActivity userActivity : this.userActivityBean.fetchAllUserActivityLog()) {
// Is the list there?
if (!this.userActivityCache.containsKey(userActivity.getActivityUser())) {
// Init list
}
// Create new activity object
- final LogableUserActivity userActivity = new UserActivityLog(activityType, user, new GregorianCalendar(), this.determinePrincipalName());
+ final LogableUserActivity userActivity = new UserActivityLog(activityType, user, new Date(), this.determinePrincipalName());
// Call bean to add it
this.userActivityBean.addUserActivityLog(userActivity);
}
// Create new activity object
- final LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new GregorianCalendar(), this.determinePrincipalName());
+ final LogableUserActivity userActivity = new UserActivityLog(message, activityType, user, new Date(), this.determinePrincipalName());
// Call bean to add it
this.userActivityBean.addUserActivityLog(userActivity);
package org.mxchange.addressbook.beans.user.confirmlink;
import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
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.jusercore.events.user.created.CreatedUserEvent;
import org.mxchange.jusercore.events.user.created.ObservableCreatedUserEvent;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.exceptions.UserStatusConfirmedException;
import org.mxchange.jusercore.exceptions.UserStatusLockedException;
import org.mxchange.jusercore.model.user.User;
private Event<ObservableUserConfirmedAccountEvent> userConfirmedEvent;
/**
- * User controller
+ * Event for when a user instance was created
*/
+ @Any
@Inject
- private AddressbookUserWebRequestController userController;
+ private Event<ObservableCreatedUserEvent> userCreatedEvent;
/**
- * Event for when a user instance was created
+ * User controller
*/
- @Any
@Inject
- private Event<ObservableCreatedUserEvent> userCreatedEvent;
+ private AddressbookUserListWebViewController userListController;
/**
* Default constructor
return;
}
- // Now try to find the user in user list, first get the whole list
- final List<User> users = this.userController.allUsers();
-
- // Get iterator from it
- final Iterator<User> iterator = users.iterator();
-
// Init instance
User user = null;
// Then loop through all
- while (iterator.hasNext()) {
- // Get next user
- final User next = iterator.next();
-
+ for (final User currentUser : this.userListController.getAllUsers()) {
// Same confirmation key?
- if (Objects.equals(this.getConfirmationKey(), next.getUserConfirmKey())) {
+ if (Objects.equals(this.getConfirmationKey(), currentUser.getUserConfirmKey())) {
// Found it, then set it and abort loop
- user = next;
+ user = currentUser;
break;
}
}
throw new IllegalArgumentException(MessageFormat.format("userId is not valid: {0}", user.getUserId())); //NOI18N
} else if (user.getUserAccountStatus() == UserAccountStatus.CONFIRMED) {
// Account is already confirmed
- throw new FaceletException(new UserStatusConfirmedException(user));
+ throw new FacesException(new UserStatusConfirmedException(user));
} else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
// Account is already confirmed
- throw new FaceletException(new UserStatusLockedException(user));
+ throw new FacesException(new UserStatusLockedException(user));
} else if (user.getUserConfirmKey() == null) {
// Throw NPE
throw new NullPointerException("user.userConfirmKey is null"); //NOI18N
// Confirm account
updatedUser = this.userBean.confirmAccount(user, baseUrl);
- } catch (final UserStatusConfirmedException | UserStatusLockedException ex) {
+ } catch (final UserStatusConfirmedException | UserStatusLockedException | UserNotFoundException ex) {
// Something unexpected happened
- throw new FaceletException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
+ throw new FacesException(MessageFormat.format("Cannot confirm user account {0}", user.getUserName()), ex); //NOI18N
}
// Fire event that the user has confirmed account
*/
package org.mxchange.addressbook.beans.user.email_address;
-import fish.payara.cdi.jsr107.impl.NamedCache;
import java.text.MessageFormat;
-import java.util.Iterator;
-import java.util.List;
import java.util.Objects;
-import javax.annotation.PostConstruct;
-import javax.cache.Cache;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
import org.mxchange.addressbook.beans.user.login.AddressbookUserLoginWebSessionController;
import org.mxchange.jcontacts.model.contact.Contact;
import org.mxchange.jcoreee.utils.FacesUtils;
+import org.mxchange.addressbook.beans.user.email_address.list.AddressbookEmailChangeListWebViewController;
import org.mxchange.jusercore.model.email_address.ChangeableEmailAddress;
import org.mxchange.jusercore.model.email_address.EmailAddressChange;
import org.mxchange.jusercore.model.email_address.status.EmailChangeStatus;
private UserEmailChangeSessionBeanRemote emailChangeBean;
/**
- * Features controller
+ * Controller for listing email address changes
*/
@Inject
- private AddressbookFeaturesWebApplicationController featureController;
+ private AddressbookEmailChangeListWebViewController emailChangeListController;
/**
- * Local list of already queued email addresses
+ * Features controller
*/
@Inject
- @NamedCache (cacheName = "queuedEmailCache")
- private Cache<String, Boolean> queuedEmailCache;
+ private AddressbookFeaturesWebApplicationController featureController;
/**
* Login controller (bean)
throw new IllegalStateException("User tried to change email address"); //NOI18N
} else if (!this.isRequiredChangeEmailAddressSet()) {
// Not all required fields are set
- throw new FaceletException("Not all required fields are set."); //NOI18N
+ throw new FacesException("Not all required fields are set."); //NOI18N
} else if (!Objects.equals(this.getEmailAddress(), this.getEmailAddressRepeat())) {
// Email address 1+2 mismatch
- this.showFacesMessage("form_user_change_email_address:emailAddressRepeat", "ERROR_USER_EMAIL_ADDRESSES_MISMATCH"); //NOI18N
+ this.showFacesMessage("form_user_change_email_address:emailAddressRepeat", "ERROR_USER_EMAIL_ADDRESSES_MISMATCH", FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- this.showFacesMessage("form_login_user_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser())); //NOI18N
+ this.showFacesMessage("form_login_user_change_email_address:currentPassword", new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()), FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
}
assert (user.getUserContact().getContactId() > 0) : MessageFormat.format("Instance userLoginController.userContact.contactId={0} is invalid", user.getUserContact().getContactId()); //NOI18N
// Check if the email address is already enqueued
- if (this.isEmailAddressQueued(this.getEmailAddress())) {
+ if (this.emailChangeListController.isEmailAddressQueued(this.getEmailAddress())) {
// Clear both email addresses
this.setEmailAddress(null);
this.setEmailAddressRepeat(null);
// Yes, then abort here
- this.showFacesMessage("form_user_change_email_address:emailAddress", "ERROR_USER_CHANGE_EMAIL_ADDRESS_ALREADY_QUEUED"); //NOI18N
+ this.showFacesMessage("form_user_change_email_address:emailAddress", "ERROR_USER_CHANGE_EMAIL_ADDRESS_ALREADY_QUEUED", FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
this.emailAddressRepeat = emailAddressRepeat;
}
- /**
- * Post-construction
- */
- @PostConstruct
- public void init () {
- // Is cache there?
- if (!this.queuedEmailCache.iterator().hasNext()) {
- // Get whole list
- final List<String> list = this.emailChangeBean.allQueuedAddresses();
-
- // Add all
- for (final Iterator<String> iterator = list.iterator(); iterator.hasNext();) {
- // Get next element
- final String next = iterator.next();
-
- // Add it to cache
- this.queuedEmailCache.put(next, Boolean.TRUE);
- }
- }
- }
-
@Override
public boolean isRequiredChangeEmailAddressSet () {
return ((this.getEmailAddress() != null) &&
this.setEmailAddressRepeat(null);
}
- /**
- * 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.
- * <p>
- * @param emailAddress Email address to verify
- * <p>
- * @return Whether the email address in field emailAddress is already queued
- */
- private boolean isEmailAddressQueued (final String emailAddress) {
- // It should be there
- assert (emailAddress != null) : "emailAddress should not be null"; //NOI18N
- assert (!emailAddress.trim().isEmpty()) : "emailAddress should not be empty"; //NOI18N
-
- // Check list
- if (this.queuedEmailCache.containsKey(emailAddress)) {
- // Okay, found it
- return true;
- }
-
- // Check EJB
- final boolean isQueued = this.emailChangeBean.isEmailAddressEnqueued(emailAddress);
-
- // Is it there?
- if (isQueued) {
- // Add to list
- this.queuedEmailCache.put(emailAddress, Boolean.TRUE);
- }
-
- // Return status
- return isQueued;
- }
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("emailChangeListController")
+@ViewScoped
+public class AddressbookEmailChangeListWebViewBean extends BaseAddressbookBean implements AddressbookEmailChangeListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 186_078_724_659_154L;
+
+ /**
+ * A list of all mobile numbers
+ */
+ private final List<ChangeableEmailAddress> allEmailAddressChanges;
+
+ /**
+ * Remote email change bean
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/userEmailChange!org.mxchange.jusercore.model.user.email_address.UserEmailChangeSessionBeanRemote")
+ private UserEmailChangeSessionBeanRemote emailChangeBean;
+
+ /**
+ * Features controller
+ */
+ @Inject
+ private AddressbookFeaturesWebApplicationController featureController;
+
+ /**
+ * A list of filtered mobile numbers
+ */
+ private List<ChangeableEmailAddress> filteredEmailAddressChanges;
+
+ /**
+ * Local list of already queued email addresses
+ */
+ @Inject
+ @NamedCache (cacheName = "queuedEmailCache")
+ private transient Cache<Long, ChangeableEmailAddress> queuedEmailCache;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookEmailChangeListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Initialize list
+ this.allEmailAddressChanges = new LinkedList<>();
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<ChangeableEmailAddress> getAllEmailAddressChanges () {
+ return this.allEmailAddressChanges;
+ }
+
+ /**
+ * Getter for filtered email address changed
+ * <p>
+ * @return Filtered email address changed
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<ChangeableEmailAddress> getFilteredEmailAddressChanges () {
+ return this.filteredEmailAddressChanges;
+ }
+
+ /**
+ * Setter for filtered email address changed
+ * <p>
+ * @param filteredEmailAddressChanges Filtered email address changed
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredEmailAddressChanges (final List<ChangeableEmailAddress> 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<Long, ChangeableEmailAddress> currentEntry : this.queuedEmailCache) {
+ // Add to list
+ this.getAllEmailAddressChanges().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllEmailAddressChanges().sort(new Comparator<ChangeableEmailAddress>() {
+ @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;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookEmailChangeListWebViewController 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.
+ * <p>
+ * @return List of all mobile numbers
+ */
+ List<ChangeableEmailAddress> 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.
+ * <p>
+ * @param emailAddress Email address to verify
+ * <p>
+ * @return Whether the email address in field emailAddress is already queued
+ */
+ boolean isEmailAddressQueued (final String emailAddress);
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user.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.addressbook.beans.BaseAddressbookBean;
+import org.mxchange.jusercore.events.user.add.ObservableAdminAddedUserEvent;
+import org.mxchange.jusercore.events.user.delete.ObservableAdminDeletedUserEvent;
+import org.mxchange.jusercore.events.user.linked.ObservableAdminLinkedUserEvent;
+import org.mxchange.jusercore.events.user.locked.ObservableAdminLockedUserEvent;
+import org.mxchange.jusercore.events.user.unlocked.ObservableAdminUnlockedUserEvent;
+import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
+import org.mxchange.juserlogincore.events.confirmation.ObservableUserConfirmedAccountEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
+import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservableAdminPostUserDataUpdatedEvent;
+import org.mxchange.jusercore.events.user.update.post.ObservablePostUserPersonalDataUpdatedEvent;
+
+/**
+ * A user list bean (controller)
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@Named ("userListController")
+@ViewScoped
+public class AddressbookUserListWebViewBean extends BaseAddressbookBean implements AddressbookUserListWebViewController {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 542_145_347_918L;
+
+ /**
+ * List of all users
+ */
+ private final List<User> allUsers;
+
+ /**
+ * List of filtered users
+ */
+ private List<User> filteredUsers;
+
+ /**
+ * Selected user instance
+ */
+ private User selectedUser;
+
+ /**
+ * Remote user bean
+ */
+ @EJB (lookup = "java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote")
+ private UserSessionBeanRemote userBean;
+
+ /**
+ * A list of all user profiles
+ */
+ @Inject
+ @NamedCache (cacheName = "userCache")
+ private transient Cache<Long, User> userCache;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUserListWebViewBean () {
+ // Call super constructor
+ super();
+
+ // Init list
+ this.allUsers = new LinkedList<>();
+ }
+
+ /**
+ * Event observer for newly added users by administrator
+ * <p>
+ * @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
+ }
+
+ // Update user list
+ this.updateList(event.getAddedUser());
+ }
+
+ /**
+ * Event observer for deleted user accounts (by administrator)
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminDeletedUserEvent (@Observes final ObservableAdminDeletedUserEvent 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.getDeletedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.deletedUser is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.deletedUser.userId is null"); //NOI18N
+ } else if (event.getDeletedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getDeletedUser(), event.getDeletedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.removeFromList(event.getDeletedUser());
+ }
+
+ /**
+ * Event observer for linked users with existing contact data
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent 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.getLinkedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.linkedUser is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getLinkedUser());
+ }
+
+ /**
+ * Event observer for locked users
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminLockedUserEvent (@Observes final ObservableAdminLockedUserEvent 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.getLockedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.lockedUser is null"); //NOI18N
+ } else if (event.getLockedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.lockedUser.userId is null"); //NOI18N
+ } else if (event.getLockedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLockedUser(), event.getLockedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getLockedUser());
+ }
+
+ /**
+ * Event observer for unlocked users
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterAdminUnlockedUserEvent (@Observes final ObservableAdminUnlockedUserEvent 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.getUnlockedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.unlockedUser is null"); //NOI18N
+ } else if (event.getUnlockedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.unlockedUser.userId is null"); //NOI18N
+ } else if (event.getUnlockedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUnlockedUser(), event.getUnlockedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getUnlockedUser());
+ }
+
+ /**
+ * Event observer for updated user data by administrator
+ * <p>
+ * @param event Event being updated
+ */
+ public void afterAdminUpdatedUserDataEvent (@Observes final ObservableAdminPostUserDataUpdatedEvent 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.getUpdatedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedUser is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getUpdatedUser(), event.getUpdatedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getUpdatedUser());
+ }
+
+ /**
+ * Event observer when user confirmed account.
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserConfirmedAccountEvent (@Observes final ObservableUserConfirmedAccountEvent 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.getConfirmedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.confirmedUser is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.confirmedUser.userId is null"); //NOI18N
+ } else if (event.getConfirmedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getConfirmedUser(), event.getConfirmedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getConfirmedUser());
+ }
+
+ /**
+ * Event observer for new user registrations
+ * <p>
+ * @param event User registration event
+ */
+ public void afterUserRegistrationEvent (@Observes final ObservableUserRegisteredEvent 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.getRegisteredUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.registeredUser is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.registeredUser.userId is null"); //NOI18N
+ } else if (event.getRegisteredUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getRegisteredUser(), event.getRegisteredUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getRegisteredUser());
+ }
+
+ /**
+ * Method being call after user's password has been updated (and history
+ * entry has been created).
+ * <p>
+ * @param event Event being observed
+ */
+ public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
+ // Check parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getPasswordHistory() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.passwordHistory is null"); //NOI18N
+ } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
+ // ... and again
+ throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
+ } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
+ // Invalid value
+ throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getPasswordHistory().getUserPasswordHistoryUser());
+ }
+
+ /**
+ * Listens to fired event when user updated personal data
+ * <p>
+ * @param event Event being fired
+ */
+ public void afterUserUpdatedPersonalDataEvent (@Observes final ObservablePostUserPersonalDataUpdatedEvent event) {
+ // Check parameter
+ if (null == event) {
+ // Throw NPE
+ throw new NullPointerException("event is null"); //NOI18N
+ } else if (event.getUpdatedUser() == null) {
+ // Throw NPE again
+ throw new NullPointerException("event.updatedUser is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() == null) {
+ // ... and again
+ throw new NullPointerException("event.updatedUser.userId is null"); //NOI18N
+ } else if (event.getUpdatedUser().getUserId() < 1) {
+ // Invalid value
+ throw new IllegalArgumentException(MessageFormat.format("event.updatedUser.userId={0} is in valid", event.getUpdatedUser().getUserId())); //NOI18N
+ }
+
+ // Update user list
+ this.updateList(event.getUpdatedUser());
+ }
+
+ @Override
+ public User findUserById (final Long userId) throws UserNotFoundException {
+ // Validate parameter
+ if (null == userId) {
+ // Throw NPE
+ throw new NullPointerException("userId is null"); //NOI18N
+ } else if (userId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("userId=" + userId + " is invalid."); //NOI18N
+ } else if (!this.userCache.containsKey(userId)) {
+ // Not found
+ throw new UserNotFoundException(userId);
+ }
+
+ // Get it from cache
+ final User user = this.userCache.get(userId);
+
+ // Return it
+ return user;
+ }
+
+ @Override
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<User> getAllUsers () {
+ return this.allUsers;
+ }
+
+ /**
+ * Getter for filtered users list
+ * <p>
+ * @return Filtered users list
+ */
+ @SuppressWarnings ("ReturnOfCollectionOrArrayField")
+ public List<User> getFilteredUsers () {
+ return this.filteredUsers;
+ }
+
+ /**
+ * Setter for filtered users list
+ * <p>
+ * @param filteredUsers Filtered users list
+ */
+ @SuppressWarnings ("AssignmentToCollectionOrArrayFieldFromParameter")
+ public void setFilteredUsers (final List<User> filteredUsers) {
+ this.filteredUsers = filteredUsers;
+ }
+
+ /**
+ * Getter for selected user instance
+ * <p>
+ * @return Selected user instance
+ */
+ public User getSelectedUser () {
+ return this.selectedUser;
+ }
+
+ /**
+ * Setter for selected user instance
+ * <p>
+ * @param selectedUser Selected user instance
+ */
+ public void setSelectedUser (final User selectedUser) {
+ this.selectedUser = selectedUser;
+ }
+
+ @Override
+ public boolean ifUserIdExists (final Long userId) {
+ // Validate parameter
+ if (null == userId) {
+ // Throw NPE
+ throw new NullPointerException("userId is null"); //NOI18N
+ } else if (userId < 1) {
+ // Throw IAE
+ throw new IllegalArgumentException("userId=" + userId + " is invalid."); //NOI18N
+ }
+
+ // Check if key is there
+ boolean isFound = this.userCache.containsKey(userId);
+
+ // Return flag
+ return isFound;
+ }
+
+ /**
+ * Post-initialization of this class
+ */
+ @PostConstruct
+ public void initializeList () {
+ // Is cache there?
+ if (!this.userCache.iterator().hasNext()) {
+ // Add all
+ for (final User user : this.userBean.fetchAllUsers()) {
+ // Add it to cache
+ this.userCache.put(user.getUserId(), user);
+ }
+ }
+
+ // Is cache filled and list is empty
+ if ((this.userCache.iterator().hasNext()) && (this.getAllUsers().isEmpty())) {
+ // Build up list
+ for (final Cache.Entry<Long, User> currentEntry : this.userCache) {
+ // Add to list
+ this.getAllUsers().add(currentEntry.getValue());
+ }
+
+ // Sort list
+ this.getAllUsers().sort(new Comparator<User>() {
+ @Override
+ public int compare (final User user1, final User user2) {
+ return user1.getUserId() > user2.getUserId() ? 1 : user1.getUserId() < user2.getUserId() ? -1 : 0;
+ }
+ });
+
+ // Set full list
+ this.setFilteredUsers(this.getAllUsers());
+ }
+ }
+
+ @Override
+ public boolean isUserNameRegistered (final User user) {
+ // Default is not found
+ boolean isFound = false;
+
+ // Determine it
+ for (final User currentUser : this.getAllUsers()) {
+ // Is same name found?
+ if (Objects.equals(user.getUserName(), currentUser.getUserName())) {
+ // Yes, then set flag and abort loop
+ isFound = true;
+ break;
+ }
+ }
+
+ // Return flag
+ return isFound;
+ }
+
+ @Override
+ public User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException {
+ // Parameter must be valid
+ if (null == emailAddress) {
+ // Throw NPE
+ throw new NullPointerException("emailAddress is null"); //NOI18N
+ } else if (emailAddress.isEmpty()) {
+ // Not valid
+ throw new IllegalArgumentException("emailAddress is empty"); //NOI18N
+ }
+
+ // Init variable
+ User user = null;
+
+ // Try to lookup it in visible user list
+ for (final Cache.Entry<Long, User> currentUser : this.userCache) {
+ // Contact should be set
+ if (currentUser.getValue().getUserContact() == null) {
+ // Contact is null
+ throw new NullPointerException(MessageFormat.format("currentUser.userContact is null for user id {0}", currentUser.getKey())); //NOI18N
+ } else if (currentUser.getValue().getUserContact().getContactEmailAddress() == null) {
+ // Email address should be set
+ throw new NullPointerException(MessageFormat.format("currentUser.userContact.contactEmailAddress is null for user id {0}", currentUser.getKey())); //NOI18N
+ }
+
+ // Is the email address found?
+ if (Objects.equals(currentUser.getValue().getUserContact().getContactEmailAddress(), emailAddress)) {
+ // Copy to other variable
+ user = currentUser.getValue();
+ break;
+ }
+ }
+
+ // Is it still null?
+ if (null == user) {
+ // Not visible for the current user
+ throw new UserEmailAddressNotFoundException(emailAddress);
+ }
+
+ // Return it
+ return user;
+ }
+
+ @Override
+ public User lookupUserById (final Long userId) throws UserNotFoundException {
+ // Parameter must be valid
+ if (null == userId) {
+ // Throw NPE
+ throw new NullPointerException("userId is null"); //NOI18N
+ } else if (userId < 1) {
+ // Not valid
+ throw new IllegalArgumentException(MessageFormat.format("userId={0} is not valid.", userId)); //NOI18N
+ }
+
+ // Init variable
+ User user = null;
+
+ // Try to lookup it in visible user list
+ for (final Cache.Entry<Long, User> currentUser : this.userCache) {
+ // Is the user id found?
+ if (Objects.equals(currentUser.getKey(), userId)) {
+ // Copy to other variable
+ user = currentUser.getValue();
+ break;
+ }
+ }
+
+ // Is it still null?
+ if (null == user) {
+ // Not visible for the current user
+ throw new UserNotFoundException(userId);
+ }
+
+ // Return it
+ return user;
+ }
+
+ /**
+ * Removes user from all lists
+ * <p>
+ * @param user User to remove
+ */
+ private void removeFromList (final User user) {
+ // Remove it from lists
+ this.getAllUsers().remove(user);
+ this.userCache.remove(user.getUserId());
+ }
+
+ /**
+ * Updates list with given user instance
+ * <p>
+ * @param user User instance
+ */
+ private void updateList (final User user) {
+ // Add/update user
+ this.userCache.put(user.getUserId(), user);
+ this.getAllUsers().add(user);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.beans.user.list;
+
+import java.io.Serializable;
+import java.util.List;
+import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
+import org.mxchange.jusercore.exceptions.UserNotFoundException;
+import org.mxchange.jusercore.model.user.User;
+
+/**
+ * An interface for user beans
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+public interface AddressbookUserListWebViewController extends Serializable {
+
+ /**
+ * Returns a user instance by given primary key. If not found, a proper
+ * exception is thrown.
+ * <p>
+ * @param userId User id
+ * <p>
+ * @return User instance
+ * <p>
+ * @throws UserNotFoundException If the user is not found
+ */
+ User findUserById (final Long userId) throws UserNotFoundException;
+
+ /**
+ * All users
+ * <p>
+ * @return A list of all public user profiles
+ */
+ List<User> getAllUsers ();
+
+ /**
+ * Checks if given user id exists
+ * <p>
+ * @param userId User id to check
+ * <p>
+ * @return Whether the user id exists
+ */
+ boolean ifUserIdExists (final Long userId);
+
+ /**
+ * Checks whether given user instance name is used
+ * <p>
+ * @param user User instance name to check
+ * <p>
+ * @return Whether it is already used
+ */
+ boolean isUserNameRegistered (final User user);
+
+ /**
+ * Tries to lookup user by given id number. If the user is not found or the
+ * account status is not CONFIRMED proper exceptions are thrown.
+ * <p>
+ * @param userId User id
+ * <p>
+ * @return User instance
+ * <p>
+ * @throws UserNotFoundException If the user is not found
+ */
+ User lookupUserById (final Long userId) throws UserNotFoundException;
+
+ /**
+ * Tries to lookup user by given email address. If the user is not found a
+ * proper exceptions is thrown.
+ * <p>
+ * @param emailAddress Email address
+ * <p>
+ * @return User instance
+ * <p>
+ * @throws UserEmailAddressNotFoundException If the user's email address is
+ * not found
+ */
+ User lookupUserByEmailAddress (final String emailAddress) throws UserEmailAddressNotFoundException;
+
+}
import javax.enterprise.event.Event;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.Any;
+import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
-import org.mxchange.jusercore.exceptions.UserNotFoundException;
-import org.mxchange.jusercore.exceptions.UserStatusLockedException;
-import org.mxchange.jusercore.exceptions.UserStatusUnconfirmedException;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
+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;
import org.mxchange.juserlogincore.events.login.UserLoggedInEvent;
import org.mxchange.juserlogincore.events.logout.ObservableUserLogoutEvent;
import org.mxchange.juserlogincore.events.logout.UserLogoutEvent;
+import org.mxchange.juserlogincore.events.registration.ObservableUserRegisteredEvent;
import org.mxchange.juserlogincore.events.user.password_change.ObservableUpdatedUserPasswordEvent;
-import org.mxchange.juserlogincore.exceptions.UserPasswordMismatchException;
import org.mxchange.juserlogincore.login.UserLoginUtils;
-import org.mxchange.juserlogincore.model.user.login.UserLoginSessionBeanRemote;
/**
* A web bean for user registration
private String userCurrentPassword;
/**
- * Flag whether the user has logged-in, set only from inside
+ * User id
*/
- private boolean userLoggedIn;
+ private Long userId;
/**
- * Remote register session-scoped bean
+ * Administrative user-list controller
*/
- @EJB (lookup = "java:global/addressbook-ejb/userLogin!org.mxchange.juserlogincore.model.user.login.UserLoginSessionBeanRemote")
- private UserLoginSessionBeanRemote userLoginBean;
+ @Inject
+ private AddressbookUserListWebViewController userListController;
+
+ /**
+ * Flag whether the user has logged-in, set only from inside
+ */
+ private boolean userLoggedIn;
/**
* Event fired when user has logged in
@Any
private Event<ObservableUserLogoutEvent> userLogoutEvent;
+ /**
+ * User name
+ */
+ private String userName;
+
+ /**
+ * User password (clear-text from web form)
+ */
+ private String userPassword;
+
/**
* User's password history
*/
@EJB (lookup = "java:global/addressbook-ejb/userPasswordHistory!org.mxchange.jusercore.model.user.password_history.UserPasswordHistorySessionBeanRemote")
private UserPasswordHistorySessionBeanRemote userPasswordHistoryBean;
+ /**
+ * Whether the user wants a public profile
+ */
+ private ProfileMode userProfileMode;
+
/**
* Default constructor
*/
}
/**
- * Method being call after user's password has been updated (and history
- * entry has been created).
+ * Event observer for newly added users by administrator
+ * <p>
+ * @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
+ }
+
+ // Set user id again
+ this.setUserId(event.getAddedUser().getUserId());
+ }
+
+ /**
+ * Event observer for linked users with existing contact data
* <p>
- * @param event Event being observed
+ * @param event Event being fired
*/
- public void afterUserUpdatedPasswordEvent (@Observes final ObservableUpdatedUserPasswordEvent event) {
- // Check parameter
+ public void afterAdminLinkedUserEvent (@Observes final ObservableAdminLinkedUserEvent 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.getPasswordHistory() == null) {
+ } else if (event.getLinkedUser() == null) {
// Throw NPE again
- throw new NullPointerException("event.passwordHistory is null"); //NOI18N
- } else if (event.getPasswordHistory().getUserPasswordHistoryId() == null) {
- // ... and again
- throw new NullPointerException("event.passwordHistory.userPasswordHistoryId is null"); //NOI18N
- } else if (event.getPasswordHistory().getUserPasswordHistoryId() < 1) {
- // Invalid value
- throw new IllegalArgumentException(MessageFormat.format("event.passwordHistory.userPasswordHistoryId={0} is in valid", event.getPasswordHistory().getUserPasswordHistoryId())); //NOI18N
+ throw new NullPointerException("event.linkedUser is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() == null) {
+ // userId is null
+ throw new NullPointerException("event.linkedUser.userId is null"); //NOI18N
+ } else if (event.getLinkedUser().getUserId() < 1) {
+ // Not avalid id
+ throw new IllegalArgumentException(MessageFormat.format("userId of user={0} is not valid: {1}", event.getLinkedUser(), event.getLinkedUser().getUserId())); //NOI18N
}
// Set user id again
* @return Redirect target
*/
public String doUserLogin () {
- // Get user instance
- final User user = this.userController.createUserLogin();
-
- // Create login container
- final LoginContainer loginContainer = new UserLoginContainer(user, this.userController.getUserPassword());
-
- try {
- // Call bean
- final User confirmedUser = this.userLoginBean.validateUserAccountStatus(loginContainer);
-
- // All fine here so set it here
- this.setLoggedInUser(confirmedUser);
-
- // Retrieve user's password list
- this.userPasswordHistory = this.userPasswordHistoryBean.getUserPasswordHistory(confirmedUser);
-
- // Set template to "login"
- this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME); //NOI18N
-
- // Fire event away. Keep this last before return statement.
- this.userLoginEvent.fire(new UserLoggedInEvent(confirmedUser));
-
- // Clear this bean
- this.clear();
+ // Found user instance
+ User updatedUser = null;
+
+ // Iterate over all users
+ for (final User currentUser : this.userListController.getAllUsers()) {
+ // Is the user name matching?
+ if (currentUser.getUserName().equals(this.getUserName())) {
+ // Yes, same user, then set it and stop iteration
+ updatedUser = currentUser;
+ break;
+ }
+ }
- // All fine
- return "login_user"; //NOI18N
- } catch (final UserNotFoundException ex) {
+ if (null == updatedUser) {
// Show JSF message
- this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND"); //NOI18N
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_NOT_FOUND", FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
- } catch (final UserStatusLockedException ex) {
- this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+ } else if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.LOCKED)) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_LOCKED", FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
- } catch (final UserStatusUnconfirmedException ex) {
- this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED"); //NOI18N
+ } else if (updatedUser.getUserAccountStatus().equals(UserAccountStatus.UNCONFIRMED)) {
+ this.showFacesMessage("form_user_login:userName", "ERROR_USER_STATUS_UNCONFIRMED", FacesMessage.SEVERITY_INFO); //NOI18N
return ""; //NOI18N
- } catch (final UserPasswordMismatchException ex) {
+ } else if (!UserLoginUtils.ifPasswordMatches(this.getUserPassword(), updatedUser)) {
// Show JSF message
- this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH"); //NOI18N
+ this.showFacesMessage("form_user_login:userPassword", "ERROR_USER_PASSWORD_MISMATCH", FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
}
+
+ // All fine here so set it here
+ this.setLoggedInUser(updatedUser);
+
+ // Retrieve user's password list
+ this.userPasswordHistory = this.userPasswordHistoryBean.fetchPasswordHistoryByUser(updatedUser);
+
+ // Set template to "login"
+ this.setBaseTemplatePathName(USER_BASE_TEMPLATE_NAME);
+
+ // Fire event away. Keep this last before return statement.
+ this.userLoginEvent.fire(new UserLoggedInEvent(updatedUser));
+
+ // Clear this bean
+ this.clear();
+
+ // All fine
+ return "login_user"; //NOI18N
}
/**
this.userCurrentPassword = userCurrentPassword;
}
+ /**
+ * Getter for user id
+ * <p>
+ * @return User id
+ */
+ public Long getUserId () {
+ return this.userId;
+ }
+
+ /**
+ * Setter for user id
+ * <p>
+ * @param userId User id
+ */
+ public void setUserId (final Long userId) {
+ this.userId = userId;
+ }
+
+ /**
+ * Getter for user name
+ * <p>
+ * @return User name
+ */
+ public String getUserName () {
+ return this.userName;
+ }
+
+ /**
+ * Setter for user name
+ * <p>
+ * @param userName User name
+ */
+ public void setUserName (final String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * Getter for clear-text user password
+ * <p>
+ * @return Clear-text user password
+ */
+ public String getUserPassword () {
+ return this.userPassword;
+ }
+
+ /**
+ * Setter for clear-text user password
+ * <p>
+ * @param userPassword Clear-text user password
+ */
+ public void setUserPassword (final String userPassword) {
+ this.userPassword = userPassword;
+ }
+
@Override
public List<PasswordHistory> getUserPasswordHistory () {
return Collections.unmodifiableList(this.userPasswordHistory);
}
+ /**
+ * Getter for user profile mode
+ * <p>
+ * @return User profile mode
+ */
+ public ProfileMode getUserProfileMode () {
+ return this.userProfileMode;
+ }
+
+ /**
+ * Setter for user profile mode
+ * <p>
+ * @param userProfileMode User profile mode
+ */
+ public void setUserProfileMode (final ProfileMode userProfileMode) {
+ this.userProfileMode = userProfileMode;
+ }
+
@Override
public boolean ifCurrentPasswordMatches () {
// The current password must be set and not empty
return isPasswordInHistory;
}
+ /**
+ * Checks if the user id is empty
+ * <p>
+ * @return Whether the user id is empty
+ */
+ public boolean isUserIdEmpty () {
+ return ((this.getUserId() == null) || (this.getUserId() == 0));
+ }
+
@Override
public boolean isUserLoggedIn () {
// Compare instance
*/
private void clear () {
// Clear all fields
+ this.setLoggedInUser(null);
+ this.setUserName(null);
+ this.setUserPassword(null);
this.setUserCurrentPassword(null);
this.setUserProfileMode(null);
}
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Event;
import javax.enterprise.inject.Any;
-import javax.faces.view.facelets.FaceletException;
+import javax.faces.FacesException;
+import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
throw new IllegalStateException("User is not logged-in"); //NOI18N
} else if (!this.isRequiredChangePasswordSet()) {
// Not all required fields are set
- throw new FaceletException("Not all required fields are set."); //NOI18N
+ throw new FacesException("Not all required fields are set."); //NOI18N
} else if (!this.userLoginController.ifCurrentPasswordMatches()) {
// Password not matching
- throw new FaceletException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
+ throw new FacesException(new UserPasswordMismatchException(this.userLoginController.getLoggedInUser()));
} else if (!this.featureController.isFeatureEnabled("change_user_password")) { //NOI18N
// Editing is not allowed
throw new IllegalStateException("User tried to change password."); //NOI18N
} else if (!UserLoginUtils.ifPasswordMatches(this.getUserCurrentPassword(), this.userLoginController.getLoggedInUser())) {
// Password mismatches
- this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userCurrentPassword", "Entered current password does not matched stored password.", FacesMessage.SEVERITY_WARN); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (!Objects.equals(this.getUserPassword(), this.getUserPasswordRepeat())) {
// Both entered passwords don't match
- this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPasswordRepeat", "Entered new passwords mismatch.", FacesMessage.SEVERITY_ERROR); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (Objects.equals(this.getUserCurrentPassword(), this.getUserPassword())) {
// New password matches current
- this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is same as current password.", FacesMessage.SEVERITY_WARN); //NOI18N
// Clear bean
this.clear();
return ""; //NOI18N
} else if (this.userLoginController.isPasswordInHistory(this.getUserPassword())) {
// Is already in list (to old passwords are ignored)
- this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago."); //NOI18N
+ this.showFacesMessage("form_user_change_password:userPassword", "Entered new password is has already been used some time ago.", FacesMessage.SEVERITY_WARN); //NOI18N
// Clear bean
this.clear();
// Set it in user
user.setUserEncryptedPassword(encryptedPassword);
+ // Init variable
+ final PasswordHistory passwordHistory;
+
try {
// Get base URL
final String baseUrl = FacesUtils.generateBaseUrl();
// All is set, then update password
- PasswordHistory passwordHistory = this.userBean.updateUserPassword(user, baseUrl);
-
- // Fire event
- this.userUpdatedPasswordEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, this.getUserPassword()));
+ passwordHistory = this.userBean.updateUserPassword(user, baseUrl);
} catch (final UserNotFoundException | UserStatusUnconfirmedException | UserStatusLockedException ex) {
// Clear bean
this.clear();
// Throw again
- throw new FaceletException(ex);
+ throw new FacesException(ex);
}
+ // Fire event
+ this.userUpdatedPasswordEvent.fire(new UpdatedUserPasswordEvent(passwordHistory, this.getUserPassword()));
+
// Clear bean
this.clear();
import javax.faces.application.FacesMessage;
import javax.inject.Inject;
import javax.inject.Named;
-import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcontacts.model.contact.UserContact;
-import org.mxchange.jcoreee.utils.FacesUtils;
import org.mxchange.addressbook.beans.BaseAddressbookBean;
import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
import org.mxchange.addressbook.beans.features.AddressbookFeaturesWebApplicationController;
import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
+import org.mxchange.jcontacts.model.contact.Contact;
+import org.mxchange.jcontacts.model.contact.UserContact;
+import org.mxchange.jcoreee.utils.FacesUtils;
import org.mxchange.jusercore.exceptions.DataRepeatMismatchException;
import org.mxchange.jusercore.exceptions.EmailAddressAlreadyRegisteredException;
import org.mxchange.jusercore.exceptions.UserNameAlreadyRegisteredException;
*/
public interface AddressbookUserRegisterWebRequestController extends Serializable {
+ /**
+ * Checks whether all required personal data is set for changing them
+ * <p>
+ * @return Whether the required personal data is set
+ */
+ boolean isRequiredChangePersonalDataSet ();
+
}
*/
package org.mxchange.addressbook.beans.user.resendlink;
-import java.util.Locale;
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.addressbook.beans.BaseAddressbookBean;
import org.mxchange.addressbook.beans.localization.AddressbookLocalizationSessionController;
-import org.mxchange.addressbook.beans.user.AddressbookUserWebRequestController;
-import org.mxchange.jcoreee.events.locale.ObservableLocaleChangeEvent;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
import org.mxchange.jcoreee.utils.FacesUtils;
import org.mxchange.jusercore.exceptions.UserEmailAddressNotFoundException;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
*/
private String emailAddress;
- /**
- * Locale instance
- */
- private Locale locale;
-
/**
* Localization controller
*/
* Regular user controller
*/
@Inject
- private AddressbookUserWebRequestController userController;
+ private AddressbookUserListWebViewController userListController;
/**
* Event being fired after confirmation link is being sent
super();
}
- /**
- * Observer method for events being fired when the application's locale has
- * been changed.
- * <p>
- * @param event Event being fired
- */
- public void afterLocaleChangeEvent (@Observes final ObservableLocaleChangeEvent event) {
- // Is the parameter valid?
- if (null == event) {
- // Throw NPE
- throw new NullPointerException("event is null");
- } else if (event.getLocale() == null) {
- // Throw NPE again
- throw new NullPointerException("event.locale is null");
- }
-
- // Set it here
- this.setLocale(event.getLocale());
- }
-
/**
* Resends (new) confirmation link to given email address, if found.
* Otherwise an exception is thrown. On success a redirect takes place.
try {
// Is the email address really not used?
- user = this.userController.lookupUserByEmailAddress(this.getEmailAddress());
+ user = this.userListController.lookupUserByEmailAddress(this.getEmailAddress());
} catch (final UserEmailAddressNotFoundException ex) {
// Always clear bean
this.clear();
// Not found, should not happen as the registered validator should find it
- this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND"); //NOI18N
+ this.showFacesMessage("form_resend_link:", "ERROR_USER_EMAIL_ADDRESS_NOT_FOUND", FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
this.clear();
// Then abort here
- this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED"); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_ALREADY_CONFIRMED", FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
} else if (user.getUserAccountStatus() == UserAccountStatus.LOCKED) {
// Always clear bean
this.clear();
// User account is locked
- this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED"); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_STATUS_LOCKED", FacesMessage.SEVERITY_WARN); //NOI18N
return ""; //NOI18N
} else if (user.getUserConfirmKey() == null) {
// Status is UNCONFIRMED but confirmation key is NULL
final String baseUrl = FacesUtils.generateBaseUrl();
// Call EJB and return redirect target
- managedUser = this.resendLinkBean.resendConfirmationLink(user, this.getLocale(), baseUrl);
+ managedUser = this.resendLinkBean.resendConfirmationLink(user, this.localizationController.getLocale(), baseUrl);
} catch (final UserNotFoundException ex) {
// User not found
- this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND"); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", "ERROR_USER_NOT_FOUND", FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
} catch (final UserStatusLockedException | UserStatusConfirmedException ex) {
// Output message, this should not happen as the confirmation key is being removed
- this.showFacesMessage("form_resend_link:resendEmailAddress", ex); //NOI18N
+ this.showFacesMessage("form_resend_link:resendEmailAddress", ex, FacesMessage.SEVERITY_ERROR); //NOI18N
return ""; //NOI18N
}
this.setEmailAddress(null);
}
- /**
- * Getter for locale instance
- * <p>
- * @return Locale instance
- */
- private Locale getLocale () {
- return this.locale;
- }
-
- /**
- * Setter for locale instance
- * <p>
- * @param locale Locale instance
- */
- private void setLocale (final Locale locale) {
- this.locale = locale;
- }
-
}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.business.basicdata;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewBean;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewController;
+import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicDataNotFoundException;
+import org.mxchange.jcontactsbusiness.model.basicdata.BasicData;
+
+/**
+ * Converter for basic company data id <-> valid basic company data instance
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("BusinessContactConverter")
+public class AddressbookBasicCompanyDataConverter implements Converter<BasicData> {
+
+ /**
+ * Business contact EJB
+ */
+ private static AddressbookBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER;
+
+ @Override
+ public BasicData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Return null
+ return null;
+ }
+
+ // Init instance
+ BasicData basicData = null;
+
+ // Is the instance there?
+ if (null == BASIC_DATA_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BASIC_DATA_LIST_CONTROLLER = CDI.current().select(AddressbookBasicDataListWebViewBean.class).get();
+ }
+
+ try {
+ // Try to parse the value as long
+ final Long basicDataId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ basicData = BASIC_DATA_LIST_CONTROLLER.findBasicDataById(basicDataId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final BasicDataNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return basicData;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final BasicData value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getBasicDataId());
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.converter.business.basicdata;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontactsbusiness.exceptions.basicdata.BasicCompanyDataNotFoundException;
-import org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.basicdata.BusinessBasicData;
-
-/**
- * Converter for basic company data id <-> valid basic company data instance
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesConverter ("BusinessContactConverter")
-public class AddressbookBusinessContactConverter implements Converter<BusinessBasicData> {
-
- /**
- * Business contact EJB
- */
- private static BasicCompanyDataSessionBeanRemote BASIC_DATA_BEAN;
-
- @Override
- public BusinessBasicData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (BASIC_DATA_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- BASIC_DATA_BEAN = (BasicCompanyDataSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); //NOI18N
- }
- }
-
- // Is the value null or empty?
- if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Return null
- return null;
- }
-
- // Init instance
- BusinessBasicData businessContact = null;
-
- try {
- // Try to parse the value as long
- final Long basicDataId = Long.valueOf(submittedValue);
-
- // Try to get user instance from it
- businessContact = BASIC_DATA_BEAN.findBasicDataById(basicDataId);
- } catch (final NumberFormatException ex) {
- // Throw again
- throw new ConverterException(ex);
- } catch (final BasicCompanyDataNotFoundException ex) {
- // Debug message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
- }
-
- // Return it
- return businessContact;
- }
-
- @Override
- public String getAsString (final FacesContext context, final UIComponent component, final BusinessBasicData value) {
- // Is the object null?
- if ((null == value) || (String.valueOf(value).isEmpty())) {
- // Is null
- return ""; //NOI18N
- }
-
- // Return id number
- return String.valueOf(value.getBasicDataId());
- }
-
-}
*/
package org.mxchange.addressbook.converter.business.branchoffice;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewBean;
+import org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewController;
import org.mxchange.jcontactsbusiness.exceptions.branchoffice.BranchOfficeNotFoundException;
import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOffice;
-import org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote;
/**
* Converter for branch office id <-> valid basic company data instance
/**
* Branch office EJB
*/
- private static BranchOfficeSessionBeanRemote BRANCH_OFFICE_BEAN;
+ private static AddressbookBranchOfficeListWebViewController BRANCH_OFFICE_LIST_CONTROLLER;
@Override
public BranchOffice getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (BRANCH_OFFICE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- BRANCH_OFFICE_BEAN = (BranchOfficeSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/branchOffice!org.mxchange.jcontactsbusiness.model.branchoffice.BranchOfficeSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
BranchOffice branchOffice = null;
+ // Is the instance there?
+ if (null == BRANCH_OFFICE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BRANCH_OFFICE_LIST_CONTROLLER = CDI.current().select(AddressbookBranchOfficeListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
- final Long branchOfficeId = Long.valueOf(submittedValue);
+ final Long branchId = Long.valueOf(submittedValue);
// Try to get user instance from it
- branchOffice = BRANCH_OFFICE_BEAN.findBranchOfficeById(branchOfficeId);
+ branchOffice = BRANCH_OFFICE_LIST_CONTROLLER.findBranchOfficeById(branchId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.converter.business.company_employee;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontactsbusiness.exceptions.employee.CompanyEmployeeNotFoundException;
-import org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.employee.Employee;
-
-/**
- * Converter for converting company employee to and from id number
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesConverter ("CompanyEmployeeConverter")
-public class AddressbookCompanyEmployeeConverter implements Converter<Employee> {
-
- /**
- * CompanyEmployee EJB
- */
- private static CompanyEmployeeSessionBeanRemote COMPANY_EMPLOYEE_BEAN;
-
- @Override
- public Employee getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (COMPANY_EMPLOYEE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- COMPANY_EMPLOYEE_BEAN = (CompanyEmployeeSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.employee.CompanyEmployeeSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); //NOI18N
- }
- }
-
- // Is the value null or empty?
- if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Return null
- return null;
- }
-
- // Init instance
- Employee companyEmployee = null;
-
- try {
- // Try to parse the value as long
- final Long employeeId = Long.valueOf(submittedValue);
-
- // Try to get user instance from it
- companyEmployee = COMPANY_EMPLOYEE_BEAN.findCompanyEmployeeById(employeeId);
- } catch (final NumberFormatException ex) {
- // Throw again
- throw new ConverterException(ex);
- } catch (final CompanyEmployeeNotFoundException ex) {
- // Debug message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
- }
-
- // Return it
- return companyEmployee;
- }
-
- @Override
- public String getAsString (final FacesContext context, final UIComponent component, final Employee value) {
- // Is the object null?
- if ((null == value) || (String.valueOf(value).isEmpty())) {
- // Is null
- return ""; //NOI18N
- }
-
- // Return id number
- return String.valueOf(value.getEmployeeId());
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.business.department;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.addressbook.beans.business.department.list.AddressbookDepartmentListWebViewBean;
+import org.mxchange.addressbook.beans.business.department.list.AddressbookDepartmentListWebViewController;
+import org.mxchange.jcontactsbusiness.exceptions.department.DepartmentNotFoundException;
+import org.mxchange.jcontactsbusiness.model.department.Department;
+
+/**
+ * Converter for company department id <-> instance
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("DepartmentConverter")
+public class AddressbookDepartmentConverter implements Converter<Department> {
+
+ /**
+ * Company department EJB
+ */
+ private static AddressbookDepartmentListWebViewController DEPARTMENT_LIST_CONTROLLER;
+
+ @Override
+ public Department getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Return null
+ return null;
+ }
+
+ // Init instance
+ Department companyDepartment = null;
+
+ // Is the instance there?
+ if (null == DEPARTMENT_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ DEPARTMENT_LIST_CONTROLLER = CDI.current().select(AddressbookDepartmentListWebViewBean.class).get();
+ }
+
+ try {
+ // Try to parse the value as long
+ final Long departmentId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ companyDepartment = DEPARTMENT_LIST_CONTROLLER.findDepartmentById(departmentId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final DepartmentNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return companyDepartment;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final Department value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getDepartmentId());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.business.employee;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.addressbook.beans.business.employee.list.AddressbookEmployeeListWebViewBean;
+import org.mxchange.addressbook.beans.business.employee.list.AddressbookEmployeeListWebViewController;
+import org.mxchange.jcontactsbusiness.exceptions.employee.EmployeeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.employee.Employable;
+
+/**
+ * Converter for converting company employee to and from id number
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("EmployeeConverter")
+public class AddressbookEmployeeConverter implements Converter<Employable> {
+
+ /**
+ * Employable EJB
+ */
+ private static AddressbookEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER;
+
+ @Override
+ public Employable getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Return null
+ return null;
+ }
+
+ // Init instance
+ Employable companyEmployee = null;
+
+ // Is the instance there?
+ if (null == EMPLOYEE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ EMPLOYEE_LIST_CONTROLLER = CDI.current().select(AddressbookEmployeeListWebViewBean.class).get();
+ }
+
+ try {
+ // Try to parse the value as long
+ final Long employeeId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ companyEmployee = EMPLOYEE_LIST_CONTROLLER.findEmployeeById(employeeId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final EmployeeNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return companyEmployee;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final Employable value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getEmployeeId());
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.converter.business.headquarters;
-
-import javax.faces.application.FacesMessage;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.convert.Converter;
-import javax.faces.convert.ConverterException;
-import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jcontactsbusiness.exceptions.headquarters.CompanyHeadquartersNotFoundException;
-import org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersSessionBeanRemote;
-import org.mxchange.jcontactsbusiness.model.headquarters.HeadquartersData;
-
-/**
- * Converter for converting company headquarters to and from id number
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesConverter ("CompanyHeadquartersConverter")
-public class AddressbookCompanyHeadquartersConverter implements Converter<HeadquartersData> {
-
- /**
- * CompanyEmployee EJB
- */
- private static CompanyHeadquartersSessionBeanRemote COMPANY_HEADQUARTERS_BEAN;
-
- @Override
- public HeadquartersData getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (COMPANY_HEADQUARTERS_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- COMPANY_HEADQUARTERS_BEAN = (CompanyHeadquartersSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/companyEmployee!org.mxchange.jcontactsbusiness.model.headquarters.CompanyHeadquartersSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex); //NOI18N
- }
- }
-
- // Is the value null or empty?
- if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
- // Return null
- return null;
- }
-
- // Init instance
- HeadquartersData companyHeadquarters = null;
-
- try {
- // Try to parse the value as long
- final Long headquartersId = Long.valueOf(submittedValue);
-
- // Try to get user instance from it
- companyHeadquarters = COMPANY_HEADQUARTERS_BEAN.findCompanyHeadquartersById(headquartersId);
- } catch (final NumberFormatException ex) {
- // Throw again
- throw new ConverterException(ex);
- } catch (final CompanyHeadquartersNotFoundException ex) {
- // Debug message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
- }
-
- // Return it
- return companyHeadquarters;
- }
-
- @Override
- public String getAsString (final FacesContext context, final UIComponent component, final HeadquartersData value) {
- // Is the object null?
- if ((null == value) || (String.valueOf(value).isEmpty())) {
- // Is null
- return ""; //NOI18N
- }
-
- // Return id number
- return String.valueOf(value.getHeadquartersId());
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.business.headquarters;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewBean;
+import org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewController;
+import org.mxchange.jcontactsbusiness.exceptions.headquarter.HeadquarterNotFoundException;
+import org.mxchange.jcontactsbusiness.model.headquarter.Headquarter;
+
+/**
+ * Converter for converting company headquarters to and from id number
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("CompanyHeadquartersConverter")
+public class AddressbookHeadquartersConverter implements Converter<Headquarter> {
+
+ /**
+ * Headquarter backing bean
+ */
+ private static AddressbookHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER;
+
+ @Override
+ public Headquarter getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Return null
+ return null;
+ }
+
+ // Init instance
+ Headquarter headquarter = null;
+
+ // Is the instance there?
+ if (null == HEADQUARTER_LIST_CONTROLLER) {
+ // Set it now
+ HEADQUARTER_LIST_CONTROLLER = CDI.current().select(AddressbookHeadquarterListWebViewBean.class).get();
+ }
+
+ try {
+ // Try to parse the value as long
+ final Long headquarterId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ headquarter = HEADQUARTER_LIST_CONTROLLER.findHeadquarterById(headquarterId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final HeadquarterNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return headquarter;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final Headquarter value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getHeadquarterId());
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.business.opening_time;
+
+import javax.enterprise.inject.spi.CDI;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.addressbook.beans.business.opening_time.list.AddressbookOpeningTimeListWebViewBean;
+import org.mxchange.addressbook.beans.business.opening_time.list.AddressbookOpeningTimeListWebViewController;
+import org.mxchange.jcontactsbusiness.exceptions.opening_time.OpeningTimeNotFoundException;
+import org.mxchange.jcontactsbusiness.model.opening_time.OpeningTime;
+
+/**
+ * Converter for opening time id <-> instance
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("OpeningTimeConverter")
+public class AddressbookOpeningTimeConverter implements Converter<OpeningTime> {
+
+ /**
+ * Opening time backing bean
+ */
+ private static AddressbookOpeningTimeListWebViewController OPENING_TIME_LIST_CONTROLLER;
+
+ @Override
+ public OpeningTime getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
+ // Is the value null or empty?
+ if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
+ // Return null
+ return null;
+ }
+
+ // Init instance
+ OpeningTime openingTime = null;
+
+ // Is the instance there?
+ if (null == OPENING_TIME_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ OPENING_TIME_LIST_CONTROLLER = CDI.current().select(AddressbookOpeningTimeListWebViewBean.class).get();
+ }
+
+ try {
+ // Try to parse the value as long
+ final Long openingTimeId = Long.valueOf(submittedValue);
+
+ // Try to get user instance from it
+ openingTime = OPENING_TIME_LIST_CONTROLLER.findOpeningTimeById(openingTimeId);
+ } catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final OpeningTimeNotFoundException ex) {
+ // Debug message
+ // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
+ }
+
+ // Return it
+ return openingTime;
+ }
+
+ @Override
+ public String getAsString (final FacesContext context, final UIComponent component, final OpeningTime value) {
+ // Is the object null?
+ if ((null == value) || (String.valueOf(value).isEmpty())) {
+ // Is null
+ return ""; //NOI18N
+ }
+
+ // Return id number
+ return String.valueOf(value.getOpeningTimeId());
+ }
+
+}
*/
package org.mxchange.addressbook.converter.contact;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewBean;
+import org.mxchange.addressbook.beans.contact.list.AddressbookContactListWebViewController;
import org.mxchange.jcontacts.exceptions.ContactNotFoundException;
import org.mxchange.jcontacts.model.contact.Contact;
-import org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote;
/**
* Converter for contact id <-> valid contact instance
public class AddressbookContactConverter implements Converter<Contact> {
/**
- * User EJB
+ * Contact EJB
*/
- private static ContactSessionBeanRemote CONTACT_BEAN;
+ private static AddressbookContactListWebViewController CONTACT_LIST_CONTROLLER;
@Override
public Contact getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (CONTACT_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- CONTACT_BEAN = (ContactSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
Contact contact = null;
+ // Is the instance there?
+ if (null == CONTACT_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ CONTACT_LIST_CONTROLLER = CDI.current().select(AddressbookContactListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long contactId = Long.valueOf(submittedValue);
// Try to get user instance from it
- contact = CONTACT_BEAN.findContactById(contactId);
+ contact = CONTACT_LIST_CONTROLLER.findContactById(contactId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
*/
package org.mxchange.addressbook.converter.country;
-import java.util.List;
-import java.util.Objects;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.country.list.AddressbookCountryListWebViewBean;
+import org.mxchange.addressbook.beans.country.list.AddressbookCountryListWebViewController;
+import org.mxchange.jcountry.exceptions.CountryNotFoundException;
import org.mxchange.jcountry.model.data.Country;
-import org.mxchange.jcountry.model.data.CountrySingletonBeanRemote;
/**
* Converter for country instance
public class AddressbookCountryConverter implements Converter<Country> {
/**
- * Country bean
+ * Country backing bean
*/
- private static CountrySingletonBeanRemote COUNTRY_BEAN;
+ private static AddressbookCountryListWebViewController COUNTRY_LIST_CONTROLLER;
@Override
public Country getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (COUNTRY_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- COUNTRY_BEAN = (CountrySingletonBeanRemote) initial.lookup("java:global/addressbook-ejb/country!org.mxchange.jcountry.model.data.CountrySingletonBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
- // Get full list
- final List<Country> countryList = COUNTRY_BEAN.allCountries();
-
// Init value
Country country = null;
+ // Is the instance there?
+ if (null == COUNTRY_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ COUNTRY_LIST_CONTROLLER = CDI.current().select(AddressbookCountryListWebViewBean.class).get();
+ }
+
// Try this better
try {
// Convert it to long
final Long countryId = Long.parseLong(submittedValue);
- // Category id should not be below 1
- assert (countryId > 0) : "countryId is smaller than one: " + countryId; //NOI18N
-
// Try to find it
- for (final Country cntry : countryList) {
- // Is the id the same? (null-safe)
- if (Objects.equals(cntry.getCountryId(), countryId)) {
- // Found it
- country = cntry;
- break;
- }
- }
+ country = COUNTRY_LIST_CONTROLLER.findCountryById(countryId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
+ } catch (final CountryNotFoundException ex) {
+ // Not handled
}
// Return it
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.dayofweek;
+
+import javax.faces.convert.EnumConverter;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.jcoreee.dates.DayOfTheWeek;
+
+/**
+ * A converter for day of the week enumeration
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter ("DayOfTheWeekConverter")
+public class AddressbookDayOfTheWeekConverter extends EnumConverter {
+
+ /**
+ * Default constructor which calls the super constructor with the proper
+ * enumeration as class type.
+ */
+ public AddressbookDayOfTheWeekConverter () {
+ // Call other constructor with class type
+ super(DayOfTheWeek.class);
+ }
+
+}
*/
package org.mxchange.addressbook.converter.fax;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
+import org.mxchange.addressbook.beans.phone.list.AddressbookPhoneListWebViewBean;
+import org.mxchange.addressbook.beans.phone.list.AddressbookPhoneListWebViewController;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
import org.mxchange.jphone.model.phonenumbers.fax.DialableFaxNumber;
-import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
/**
* Converter for fax id <-> valid fax number instance
/**
* Phone EJB
*/
- private static PhoneSessionBeanRemote PHONE_BEAN;
+ private static AddressbookPhoneListWebViewController PHONE_LIST_CONTROLLER;
@Override
public DialableFaxNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (PHONE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- PHONE_BEAN = (PhoneSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
- // Log message
- // @TODO Not possible here: this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: context={1},component={2},submittedValue={3} - CALLED!", this.getClass().getSimpleName(), context, component, submittedValue)); //NOI18N
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not possible here: this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
DialableFaxNumber faxNumber = null;
+ // Is the instance there?
+ if (null == PHONE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ PHONE_LIST_CONTROLLER = CDI.current().select(AddressbookPhoneListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long faxNumberId = Long.valueOf(submittedValue);
- // Log message
- // @TODO Not possible here: this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject: faxNumberId={1}", this.getClass().getSimpleName(), faxNumberId)); //NOI18N
// Try to get mobile instance from it
- faxNumber = PHONE_BEAN.findFaxNumberById(faxNumberId);
+ faxNumber = PHONE_LIST_CONTROLLER.findFaxNumberById(faxNumberId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
// @TODO Not possible here: this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
}
- // Log message
- // @TODO Not possible here: this.loggerBeanLocal.logTrace(MessageFormat.format("{0}.getAsObject: faxNumber={1} - EXIT!", this.getClass().getSimpleName(), faxNumber)); //NOI18N
// Return it
return faxNumber;
}
*/
package org.mxchange.addressbook.converter.landline;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
+import org.mxchange.addressbook.beans.phone.list.AddressbookPhoneListWebViewBean;
+import org.mxchange.addressbook.beans.phone.list.AddressbookPhoneListWebViewController;
+import org.mxchange.jphone.exceptions.phone.PhoneEntityNotFoundException;
import org.mxchange.jphone.model.phonenumbers.landline.DialableLandLineNumber;
-import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
/**
* Converter for land-line id <-> valid land-line number instance
/**
* Phone EJB
*/
- private static PhoneSessionBeanRemote PHONE_BEAN;
+ private static AddressbookPhoneListWebViewController PHONE_LIST_CONTROLLER;
@Override
public DialableLandLineNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (PHONE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- PHONE_BEAN = (PhoneSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not possible here: this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
DialableLandLineNumber landLineNumber = null;
+ // Is the instance there?
+ if (null == PHONE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ PHONE_LIST_CONTROLLER = CDI.current().select(AddressbookPhoneListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long landLineNumberId = Long.valueOf(submittedValue);
// Try to get mobile instance from it
- landLineNumber = PHONE_BEAN.findLandLineNumberById(landLineNumberId);
+ landLineNumber = PHONE_LIST_CONTROLLER.findLandLineNumberById(landLineNumberId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
*/
package org.mxchange.addressbook.converter.mobile;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.faces.validator.ValidatorException;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import org.mxchange.jphone.exceptions.PhoneEntityNotFoundException;
+import org.mxchange.addressbook.beans.mobile.list.AddressbookMobileListWebViewBean;
+import org.mxchange.addressbook.beans.mobile.list.AddressbookMobileListWebViewController;
+import org.mxchange.jphone.exceptions.mobile.MobileEntityNotFoundException;
import org.mxchange.jphone.model.phonenumbers.mobile.DialableMobileNumber;
-import org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote;
/**
* Converter for mobile id <-> valid mobile instance
/**
* Phone EJB
*/
- private static PhoneSessionBeanRemote PHONE_BEAN;
+ private static AddressbookMobileListWebViewController MOBILE_LIST_CONTROLLER;
@Override
public DialableMobileNumber getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (PHONE_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- PHONE_BEAN = (PhoneSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/phone!org.mxchange.jphone.model.phonenumbers.phone.PhoneSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
// Init instance
DialableMobileNumber mobileNumber = null;
+ // Is the instance there?
+ if (null == MOBILE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ MOBILE_LIST_CONTROLLER = CDI.current().select(AddressbookMobileListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long mobileNumberId = Long.valueOf(submittedValue);
// Try to get mobile instance from it
- mobileNumber = PHONE_BEAN.findMobileNumberById(mobileNumberId);
+ mobileNumber = MOBILE_LIST_CONTROLLER.findMobileNumberById(mobileNumberId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
- } catch (final PhoneEntityNotFoundException ex) {
+ } catch (final MobileEntityNotFoundException ex) {
// Debug message
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logDebug(MessageFormat.format("{0}.getAsObject(): Exception: {1} - Returning null ...", this.getClass().getSimpleName(), ex)); //NOI18N
}
}
// Return id number
- return String.valueOf(value.getPhoneId());
+ return String.valueOf(value.getMobileId());
}
}
*/
package org.mxchange.addressbook.converter.mobileprovider;
-import java.util.List;
-import java.util.Objects;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.mobileprovider.list.AddressbookMobileProviderListWebViewBean;
+import org.mxchange.addressbook.beans.mobileprovider.list.AddressbookMobileProviderListWebViewController;
+import org.mxchange.jphone.exceptions.mobileprovider.MobileProviderNotFoundException;
import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProvider;
-import org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote;
/**
* Converter for SMS provider instance
public class AddressbookMobileProviderConverter implements Converter<MobileProvider> {
/**
- * Mobile provider bean
+ * Mobile provider backing bean
*/
- private static MobileProviderSingletonBeanRemote MOBILE_PROVIDER_BEAN;
+ private static AddressbookMobileProviderListWebViewController MOBILE_PROVIDER_LIST_CONTROLLER;
@Override
public MobileProvider getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (MOBILE_PROVIDER_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- MOBILE_PROVIDER_BEAN = (MobileProviderSingletonBeanRemote) initial.lookup("java:global/addressbook-ejb/mobileProvider!org.mxchange.jphone.model.phonenumbers.mobileprovider.MobileProviderSingletonBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
- // Warning message
- // @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logWarning(MessageFormat.format("{0}.getAsObject(): submittedValue is null or empty - EXIT!", this.getClass().getSimpleName())); //NOI18N
-
// Return null
return null;
}
- // Get full list
- final List<MobileProvider> providerList = MOBILE_PROVIDER_BEAN.allMobileProviders();
-
// Init value
- MobileProvider provider = null;
+ MobileProvider mobileProvider = null;
+
+ // Is the instance there?
+ if (null == MOBILE_PROVIDER_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ MOBILE_PROVIDER_LIST_CONTROLLER = CDI.current().select(AddressbookMobileProviderListWebViewBean.class).get();
+ }
// Try this better
try {
// Convert it to long
final Long providerId = Long.parseLong(submittedValue);
- // Category id should not be below 1
- assert (providerId > 0) : "providerId is smaller than one: " + providerId; //NOI18N
-
- // Try to find it
- for (final MobileProvider prov : providerList) {
- // Is the id the same? (null-safe)
- if (Objects.equals(prov.getProviderId(), providerId)) {
- // Found it
- provider = prov;
- break;
- }
- }
+ // Lookup of mobile provider
+ mobileProvider = MOBILE_PROVIDER_LIST_CONTROLLER.findMobileProviderById(providerId);
} catch (final NumberFormatException ex) {
+ // Throw again
+ throw new ConverterException(ex);
+ } catch (final MobileProviderNotFoundException ex) {
// Log exception (maybe to much?)
// @TODO Not working with JNDI (no remote interface) this.loggerBeanLocal.logException(ex);
}
// Return it
- return provider;
+ return mobileProvider;
}
@Override
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.personal_title;
+
+import javax.faces.convert.EnumConverter;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.jcontacts.model.contact.title.PersonalTitle;
+
+/**
+ * A converter for personal titles
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter("PersonalTitleConverter")
+public class AddressbookPersonalTitleConverter extends EnumConverter {
+
+ /**
+ * Default constructor which calls the super constructor with the proper
+ * enumeration as class type.
+ */
+ public AddressbookPersonalTitleConverter () {
+ super(PersonalTitle.class);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.profile_mode;
+
+import javax.faces.convert.EnumConverter;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
+
+/**
+ * A converter for profile mode
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter("ProfileModeConverter")
+public class AddressbookProfileModeConverter extends EnumConverter {
+
+ /**
+ * Default constructor which calls the super constructor with the proper
+ * enumeration as class type.
+ */
+ public AddressbookProfileModeConverter () {
+ super(ProfileMode.class);
+ }
+
+}
*/
package org.mxchange.addressbook.converter.user;
-import javax.faces.application.FacesMessage;
+import javax.enterprise.inject.spi.CDI;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewBean;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
import org.mxchange.jusercore.exceptions.UserNotFoundException;
import org.mxchange.jusercore.model.user.User;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
/**
* Converter for user id <-> valid user instance
public class AddressbookUserConverter implements Converter<User> {
/**
- * User EJB
+ * User backing bean
*/
- private static UserSessionBeanRemote USER_BEAN;
+ private static AddressbookUserListWebViewController USER_LIST_CONTROLLER;
@Override
public User getAsObject (final FacesContext context, final UIComponent component, final String submittedValue) {
- // Is the instance there?
- if (USER_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ConverterException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// Is the value null or empty?
if ((null == submittedValue) || (submittedValue.trim().isEmpty())) {
// Warning message
// Init instance
User user = null;
+ // Is the instance there?
+ if (null == USER_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ USER_LIST_CONTROLLER = CDI.current().select(AddressbookUserListWebViewBean.class).get();
+ }
+
try {
// Try to parse the value as long
final Long userId = Long.valueOf(submittedValue);
// Try to get user instance from it
- user = USER_BEAN.findUserById(userId);
+ user = USER_LIST_CONTROLLER.findUserById(userId);
} catch (final NumberFormatException ex) {
// Throw again
throw new ConverterException(ex);
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.converter.user_account_status;
+
+import javax.faces.convert.EnumConverter;
+import javax.faces.convert.FacesConverter;
+import org.mxchange.jusercore.model.user.status.UserAccountStatus;
+
+/**
+ * A converter for user account status
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesConverter("UserAccountStatusConverter")
+public class AddressbookUserAccountStatusConverter extends EnumConverter {
+
+ /**
+ * Default constructor which calls the super constructor with the proper
+ * enumeration as class type.
+ */
+ public AddressbookUserAccountStatusConverter () {
+ super(UserAccountStatus.class);
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.business.basicdata;
+
+import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewBean;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for company names
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator ("CompanyNameValidator")
+public class AddressbookBasicDataCompanyNameValidator extends BaseStringValidator {
+
+ /**
+ * Business basic data backing bean
+ */
+ private static AddressbookBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 57_283_657_476_561L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Is the instance there?
+ if (null == BASIC_DATA_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BASIC_DATA_LIST_CONTROLLER = CDI.current().select(AddressbookBasicDataListWebViewBean.class).get();
+ }
+
+ // All accepted, required fields
+ final String[] requiredFields = {"companyName"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, true);
+
+ // Convert name to string (now securely checked in BaseStringValidator)
+ final String companyName = (String) value;
+
+ // Default is to check on existing names
+ Boolean checkExisting = Boolean.TRUE;
+
+ // Is attribute "checkExisting" set?
+ if (component.getAttributes().containsKey("checkExisting")) { //NOI18N
+ // Get attribute
+ final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N
+
+ // Make sure, it is Boolean as no String is accepted anymore
+ if (!(attribute instanceof String)) {
+ // Not valid attribute, please use "true" or "false" (default)
+ throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+ }
+
+ // Securely cast it
+ checkExisting = Boolean.parseBoolean((String) attribute);
+ }
+
+ // Check if name is already used
+ final Boolean nameExists = (companyName != null && BASIC_DATA_LIST_CONTROLLER.isCompanyNameUsed(companyName));
+
+ // Is the user id valid?
+ if ((!nameExists) && (checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName);
+
+ // Name does not exist
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ } else if ((nameExists) && (!checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName);
+
+ // Name already exists
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.business.basicdata;
+
+import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewBean;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for basic data company short names
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "BasicDataCompanyShortNameValidator")
+public class AddressbookBasicDataCompanyShortNameValidator extends BaseStringValidator {
+
+ /**
+ * Business basic data backing bean
+ */
+ private static AddressbookBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 57_283_657_476_562L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // All accepted, required fields
+ final String[] requiredFields = {"companyShortName"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, false);
+
+ // Convert name to string (now securely checked in BaseStringValidator)
+ final String companyShortName = (String) value;
+
+ // Default is to check on existing names
+ Boolean checkExisting = Boolean.TRUE;
+
+ // Is attribute "checkExisting" set?
+ if (component.getAttributes().containsKey("checkExisting")) { //NOI18N
+ // Get attribute
+ final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N
+
+ // Make sure, it is Boolean as no String is accepted anymore
+ if (!(attribute instanceof String)) {
+ // Not valid attribute, please use "true" or "false" (default)
+ throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+ }
+
+ // Securely cast it
+ checkExisting = Boolean.parseBoolean((String) attribute);
+ }
+
+ // Is the instance there?
+ if (null == BASIC_DATA_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BASIC_DATA_LIST_CONTROLLER = CDI.current().select(AddressbookBasicDataListWebViewBean.class).get();
+ }
+
+ // Check if name is already used
+ final Boolean nameExists = BASIC_DATA_LIST_CONTROLLER.isCompanyShortNameUsed(companyShortName);
+
+ // Is the user id valid?
+ if ((!nameExists) && (checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("No basic data found with comany name {0}.", companyShortName);
+
+ // Name does not exist
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ } else if ((nameExists) && (!checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("Found basic data with comany name {0}.", companyShortName);
+
+ // Name already exists
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ }
+ }
+
+}
+++ /dev/null
-/*
- * Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.addressbook.validator.business.basicdata;
-
-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.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote;
-import org.mxchange.jcoreee.validator.string.BaseStringValidator;
-
-/**
- * A validator for company names
- * <p>
- * @author Roland Häder<roland@mxchange.org>
- */
-@FacesValidator ("CompanyNameValidator")
-public class AddressbookCompanyNameValidator extends BaseStringValidator {
-
- /**
- * Business contact EJB
- */
- private static BasicCompanyDataSessionBeanRemote BASIC_DATA_BEAN;
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 57_283_657_476_561L;
-
- @Override
- public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // Is the instance there?
- if (BASIC_DATA_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- BASIC_DATA_BEAN = (BasicCompanyDataSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/basicCompanyData!org.mxchange.jcontactsbusiness.model.basicdata.BasicCompanyDataSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
- // All accepted, required fields
- final String[] requiredFields = {"companyName"}; //NOI18N
-
- // Pre-validation (example: not null, not a string, empty string ...)
- super.preValidate(context, component, value, requiredFields, Boolean.FALSE);
-
- // Convert name to string (now securely checked in BaseStringValidator)
- final String companyName = (String) value;
-
- // Default is to check on existing names
- Boolean checkExisting = Boolean.TRUE;
-
- // Is attribute "checkExisting" set?
- if (component.getAttributes().containsKey("checkExisting")) { //NOI18N
- // Get attribute
- final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N
-
- // Make sure, it is Boolean as no String is accepted anymore
- if (!(attribute instanceof String)) {
- // Not valid attribute, please use "true" or "false" (default)
- throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
- }
-
- // Securely cast it
- checkExisting = Boolean.parseBoolean((String) attribute);
- }
-
- // Check if name is already used
- final Boolean nameExists = BASIC_DATA_BEAN.isCompanyNameUsed(companyName);
-
- // Is the user id valid?
- if ((!nameExists) && (checkExisting)) {
- // Format message
- final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName);
-
- // Name does not exist
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
- } else if ((nameExists) && (!checkExisting)) {
- // Format message
- final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName);
-
- // Name already exists
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
- }
- }
-
-}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.business.basicdata.roadnumber;
+
+import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewBean;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for basic data company road number
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "BasicDataCompanyRoadNumberValidator")
+public class AddressbookBasicDataCompanyRoadNumberValidator extends BaseStringValidator {
+
+ /**
+ * Business basic data backing bean
+ */
+ private static AddressbookBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 57_283_657_476_561L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Is the instance there?
+ if (null == BASIC_DATA_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BASIC_DATA_LIST_CONTROLLER = CDI.current().select(AddressbookBasicDataListWebViewBean.class).get();
+ }
+
+ // All accepted, required fields
+ final String[] requiredFields = {"companyRoadNumber"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, true);
+
+ // Convert name to string (now securely checked in BaseStringValidator)
+ final String companyRoadNumber = (String) value;
+
+ // Default is to check on existing names
+ Boolean checkExisting = Boolean.TRUE;
+
+ // Is attribute "checkExisting" set?
+ if (component.getAttributes().containsKey("checkExisting")) { //NOI18N
+ // Get attribute
+ final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N
+
+ // Make sure, it is Boolean as no String is accepted anymore
+ if (!(attribute instanceof String)) {
+ // Not valid attribute, please use "true" or "false" (default)
+ throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+ }
+
+ // Securely cast it
+ checkExisting = Boolean.parseBoolean((String) attribute);
+ }
+
+ // Check if name is already used
+ final Boolean nameExists = (companyRoadNumber != null && BASIC_DATA_LIST_CONTROLLER.isCompanyRoadNumberUsed(companyRoadNumber));
+
+ // Is the user id valid?
+ if ((!nameExists) && (checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("Comany with road number {0} does not exist.", companyRoadNumber);
+
+ // Name does not exist
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ } else if ((nameExists) && (!checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("Company with road number {0} already exist.", companyRoadNumber);
+
+ // Name already exists
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2017 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.business.headquarter;
+
+import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewBean;
+import org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for headquarter company names
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "HeadquarterCompanyNameValidator")
+public class AddressbookHeadquarterCompanyNameValidator extends BaseStringValidator {
+
+ /**
+ * Headquarter backing bean
+ */
+ private static AddressbookHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER;
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 57_283_657_476_561L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // All accepted, required fields
+ final String[] requiredFields = {"companyName"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, Boolean.FALSE);
+
+ // Convert name to string (now securely checked in BaseStringValidator)
+ final String companyName = (String) value;
+
+ // Default is to check on existing names
+ Boolean checkExisting = Boolean.TRUE;
+
+ // Is attribute "checkExisting" set?
+ if (component.getAttributes().containsKey("checkExisting")) { //NOI18N
+ // Get attribute
+ final Object attribute = component.getAttributes().get("checkExisting"); //NOI18N
+
+ // Make sure, it is Boolean as no String is accepted anymore
+ if (!(attribute instanceof String)) {
+ // Not valid attribute, please use "true" or "false" (default)
+ throw new IllegalArgumentException("checkExisting must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
+ }
+
+ // Securely cast it
+ checkExisting = Boolean.parseBoolean((String) attribute);
+ }
+
+ // Is the instance there?
+ if (null == HEADQUARTER_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ HEADQUARTER_LIST_CONTROLLER = CDI.current().select(AddressbookHeadquarterListWebViewBean.class).get();
+ }
+
+ // Check if name is already used
+ final Boolean nameExists = HEADQUARTER_LIST_CONTROLLER.isCompanyNameUsed(companyName);
+
+ // Is the user id valid?
+ if ((!nameExists) && (checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("No basic data found with comany name {0}.", companyName);
+
+ // Name does not exist
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ } else if ((nameExists) && (!checkExisting)) {
+ // Format message
+ final String message = MessageFormat.format("Found basic data with comany name {0}.", companyName);
+
+ // Name already exists
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message)); //NOI18N
+ }
+ }
+
+}
import java.text.MessageFormat;
import java.util.regex.Pattern;
+import javax.enterprise.inject.spi.CDI;
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.jcontacts.model.contact.ContactSessionBeanRemote;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestBean;
+import org.mxchange.addressbook.beans.contact.AddressbookContactWebRequestController;
import org.mxchange.jcoreee.validator.string.BaseStringValidator;
/**
public class AddressbookEmailAddressValidator extends BaseStringValidator {
/**
- * Contact session-scoped bean
+ * Contact backing bean
*/
- private static ContactSessionBeanRemote CONTACT_BEAN;
+ private static AddressbookContactWebRequestController CONTACT_CONTROLLER;
/**
* Email pattern
*/
private static final long serialVersionUID = 187_536_745_607_192L;
+ /**
+ * Whether empty data is allowed
+ */
+ private Boolean allowEmptyRequiredData;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookEmailAddressValidator () {
+ // Set allowEmpty to FALSE by default
+ this.allowEmptyRequiredData = Boolean.FALSE;
+ }
+
+ /**
+ * Setter for allowEmptyRequiredData flag
+ * <p>
+ * @param allowEmptyRequiredData Whether empty values are allowed
+ */
+ public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) {
+ this.allowEmptyRequiredData = allowEmptyRequiredData;
+ }
+
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // Is the instance there?
- if (CONTACT_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- CONTACT_BEAN = (ContactSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/contact!org.mxchange.jcontacts.model.contact.ContactSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
+ // Validate parameter
+ if (null == context) {
+ // Throw NPE
+ throw new NullPointerException("Parameter context is null"); //NOI18N
+ } else if (null == component) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter component is null"); //NOI18N
+ } else if (null == this.allowEmptyRequiredData) {
+ // Should not be NULL
+ throw new IllegalStateException("this.allowEmptyRequiredData was set to null, this should not happen."); //NOI18N
}
// The required field
final String[] requiredFields = {"emailAddress", "emailAddressRepeat", "resendEmailAddress"}; //NOI18N
- // Default is to reject empty email address fields
- Boolean allowEmptyValue = Boolean.FALSE;
-
- // Is attribute "allowEmptyValue" set?
- if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N
- // Get attribute
- final Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N
-
- // Make sure, it is Boolean as no String is accepted anymore
- if (!(attribute instanceof String)) {
- // Not valid attribute, please use "true" or "false" (default)
- throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
- }
-
- // Securely cast it
- allowEmptyValue = Boolean.parseBoolean((String) attribute);
- }
-
// Pre-validation (example: not null, not a string, empty string ...)
- super.preValidate(context, component, value, requiredFields, allowEmptyValue);
+ super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData);
// Is the email address empty and allowed?
- if (null == value && allowEmptyValue) {
+ if (null == value && this.allowEmptyRequiredData) {
// Then accept this here
return;
} else if (null == value) {
// Get client id (aka form id)
final String clientId = component.getClientId();
+ // Is the instance there?
+ if (null == CONTACT_CONTROLLER) {
+ // Get bean from CDI directly
+ CONTACT_CONTROLLER = CDI.current().select(AddressbookContactWebRequestBean.class).get();
+ }
+
// Is it registered?
- final Boolean isRegistered = CONTACT_BEAN.isEmailAddressRegistered(emailAddress);
+ final Boolean isRegistered = CONTACT_CONTROLLER.isEmailAddressRegistered(emailAddress);
// Is the email address already registered?
if ((!clientId.endsWith("resendEmailAddress")) && (isRegistered)) { //NOI18N
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.emailaddress.basicdata;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewBean;
+import org.mxchange.addressbook.beans.business.basicdata.list.AddressbookBasicDataListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for basic company data email address validation
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "BasicDataEmailAddressValidator")
+public class AddressbookBasicDataEmailAddressValidator extends BaseStringValidator {
+
+ /**
+ * Basic company data backing bean
+ */
+ private static AddressbookBasicDataListWebViewController BASIC_DATA_LIST_CONTROLLER;
+
+ /**
+ * Email pattern
+ */
+ private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
+
+ /**
+ * Pattern matcher
+ */
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookBasicDataEmailAddressValidator.EMAIL_REGEX);
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 187_536_745_607_195L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Validate parameter
+ if (null == context) {
+ // Throw NPE
+ throw new NullPointerException("Parameter context is null"); //NOI18N
+ } else if (null == component) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter component is null"); //NOI18N
+ }
+
+ // The required field
+ final String[] requiredFields = {"companyEmailAddress"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
+
+ // Is the email address empty and allowed?
+ if (null == value) {
+ // Then accept this here
+ return;
+ }
+
+ // Get string from object ... ;-)
+ // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat
+ final String emailAddress = String.valueOf(value).trim();
+
+ // Checks if the email address matches a regex ("low-level" check)
+ // @TODO Should also be done by <f:validatorRegex />)
+ final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
+
+ // Is the email address valid?
+ if (!matches) {
+ // Generate message
+ String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N
+
+ // Not matching
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
+ }
+
+ // Get client id (aka form id)
+ final String clientId = component.getClientId();
+
+ // Is the instance there?
+ if (null == BASIC_DATA_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BASIC_DATA_LIST_CONTROLLER = CDI.current().select(AddressbookBasicDataListWebViewBean.class).get();
+ }
+
+ // Is it registered?
+ final Boolean isRegistered = BASIC_DATA_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress);
+
+ // Is the email address already registered?
+ if ((clientId.endsWith("companyEmailAddress")) && isRegistered) { //NOI18N
+ // Generate message
+ final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
+
+ // No, then abort here
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.emailaddress.branchoffice;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewBean;
+import org.mxchange.addressbook.beans.business.branchoffice.list.AddressbookBranchOfficeListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for branch office email address validation
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "BranchOfficeEmailAddressValidator")
+public class AddressbookBranchOfficeEmailAddressValidator extends BaseStringValidator {
+
+ /**
+ * Branch office backing bean
+ */
+ private static AddressbookBranchOfficeListWebViewController BRANCH_OFFICE_LIST_CONTROLLER;
+
+ /**
+ * Email pattern
+ */
+ private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
+
+ /**
+ * Pattern matcher
+ */
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookBranchOfficeEmailAddressValidator.EMAIL_REGEX);
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 187_536_745_607_196L;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookBranchOfficeEmailAddressValidator () {
+ }
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // The required field
+ final String[] requiredFields = {"branchEmailAddress"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
+
+ // Is the email address empty and allowed?
+ if (null == value) {
+ // Then accept this here
+ return;
+ }
+
+ // Get string from object ... ;-)
+ // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat
+ final String emailAddress = String.valueOf(value).trim();
+
+ // Checks if the email address matches a regex ("low-level" check)
+ // @TODO Should also be done by <f:validatorRegex />)
+ final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
+
+ // Is the email address valid?
+ if (!matches) {
+ // Generate message
+ String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N
+
+ // Not matching
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
+ }
+
+ // Get client id (aka form id)
+ final String clientId = component.getClientId();
+
+ // Is the instance there?
+ if (null == BRANCH_OFFICE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ BRANCH_OFFICE_LIST_CONTROLLER = CDI.current().select(AddressbookBranchOfficeListWebViewBean.class).get();
+ }
+
+ // Is it registered?
+ final Boolean isRegistered = BRANCH_OFFICE_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress);
+
+ // Is the email address already registered?
+ if ((clientId.endsWith("branchEmailAddress")) && isRegistered) { //NOI18N
+ // Generate message
+ final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
+
+ // No, then abort here
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.emailaddress.employee;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.employee.list.AddressbookEmployeeListWebViewBean;
+import org.mxchange.addressbook.beans.business.employee.list.AddressbookEmployeeListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for employee email address validation
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "EmployeeEmailAddressValidator")
+public class AddressbookEmployeeEmailAddressValidator extends BaseStringValidator {
+
+ /**
+ * Email pattern
+ */
+ private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
+
+ /**
+ * Employee backing bean
+ */
+ private static AddressbookEmployeeListWebViewController EMPLOYEE_LIST_CONTROLLER;
+
+ /**
+ * Pattern matcher
+ */
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookEmployeeEmailAddressValidator.EMAIL_REGEX);
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 187_536_745_607_196L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Validate parameter
+ if (null == context) {
+ // Throw NPE
+ throw new NullPointerException("Parameter context is null"); //NOI18N
+ } else if (null == component) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter component is null"); //NOI18N
+ }
+
+ // The required field
+ final String[] requiredFields = {"employeeEmailAddress"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
+
+ // Is the email address empty and allowed?
+ if (null == value) {
+ // Then accept this here
+ return;
+ }
+
+ // Get string from object ... ;-)
+ // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat
+ final String emailAddress = String.valueOf(value).trim();
+
+ // Checks if the email address matches a regex ("low-level" check)
+ // @TODO Should also be done by <f:validatorRegex />)
+ final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
+
+ // Is the email address valid?
+ if (!matches) {
+ // Generate message
+ String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N
+
+ // Not matching
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
+ }
+
+ // Get client id (aka form id)
+ final String clientId = component.getClientId();
+
+ // Is the instance there?
+ if (null == EMPLOYEE_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ EMPLOYEE_LIST_CONTROLLER = CDI.current().select(AddressbookEmployeeListWebViewBean.class).get();
+ }
+
+ // Is it registered?
+ final Boolean isRegistered = EMPLOYEE_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress);
+
+ // Is the email address already registered?
+ if ((clientId.endsWith("employeeEmailAddress")) && isRegistered) { //NOI18N
+ // Generate message
+ final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
+
+ // No, then abort here
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (C) 2016 - 2022 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.addressbook.validator.emailaddress.headquarter;
+
+import java.text.MessageFormat;
+import java.util.regex.Pattern;
+import javax.enterprise.inject.spi.CDI;
+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 org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewBean;
+import org.mxchange.addressbook.beans.business.headquarter.list.AddressbookHeadquarterListWebViewController;
+import org.mxchange.jcoreee.validator.string.BaseStringValidator;
+
+/**
+ * A validator for headquarter's email address validation
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+@FacesValidator (value = "HeadquarterEmailAddressValidator")
+public class AddressbookHeadquarterEmailAddressValidator extends BaseStringValidator {
+
+ /**
+ * Email pattern
+ */
+ private static final String EMAIL_REGEX = "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"; //NOI18N
+
+ /**
+ * Headquarter backing bean
+ */
+ private static AddressbookHeadquarterListWebViewController HEADQUARTER_LIST_CONTROLLER;
+
+ /**
+ * Pattern matcher
+ */
+ private static final Pattern PATTERN_MATCHER = Pattern.compile(AddressbookHeadquarterEmailAddressValidator.EMAIL_REGEX);
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 187_536_745_607_194L;
+
+ @Override
+ public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
+ // Validate parameter
+ if (null == context) {
+ // Throw NPE
+ throw new NullPointerException("Parameter context is null"); //NOI18N
+ } else if (null == component) {
+ // Throw NPE again
+ throw new NullPointerException("Parameter component is null"); //NOI18N
+ }
+
+ // The required field
+ final String[] requiredFields = {"headquarterEmailAddress"}; //NOI18N
+
+ // Pre-validation (example: not null, not a string, empty string ...)
+ super.preValidate(context, component, value, requiredFields, Boolean.TRUE);
+
+ // Is the email address empty and allowed?
+ if (null == value) {
+ // Then accept this here
+ return;
+ }
+
+ // Get string from object ... ;-)
+ // @TODO Add IDN support (GNU lib?) Search for emailAddressRepeat
+ final String emailAddress = String.valueOf(value).trim();
+
+ // Checks if the email address matches a regex ("low-level" check)
+ // @TODO Should also be done by <f:validatorRegex />)
+ final boolean matches = PATTERN_MATCHER.matcher(emailAddress).matches(); //NOI18N
+
+ // Is the email address valid?
+ if (!matches) {
+ // Generate message
+ String message = MessageFormat.format("Email address {0} does not match regular expression.", emailAddress); //NOI18N
+
+ // Not matching
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
+ }
+
+ // Get client id (aka form id)
+ final String clientId = component.getClientId();
+
+ // Is the instance there?
+ if (null == HEADQUARTER_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ HEADQUARTER_LIST_CONTROLLER = CDI.current().select(AddressbookHeadquarterListWebViewBean.class).get();
+ }
+
+ // Is it registered?
+ final Boolean isRegistered = HEADQUARTER_LIST_CONTROLLER.isEmailAddressRegistered(emailAddress);
+
+ // Is the email address already registered?
+ if ((clientId.endsWith("headquarterEmailAddress")) && isRegistered) { //NOI18N
+ // Generate message
+ final String message = MessageFormat.format("Email address {0} is already registered.", emailAddress); //NOI18N
+
+ // No, then abort here
+ throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_INFO, message, message));
+ }
+ }
+
+}
super.preValidate(context, component, value, requiredFields, false);
/*
- * @TODO injection is not working in converters. No, JavaEE is not so super-flexible.
- // value is known to be an entered password, so instance login container
- LoginContainer container = new UserLoginContainer(this.userLoginController.getLoggedInUser(), (String) value);
-
- // Test it here
- if (!UserUtils.ifPasswordMatches(container, this.userLoginController.getLoggedInUser())) {
- // Password mismatches
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_WARN, "Password mismatching.", "The password the user has entered does not match the stored password.")); //NOI18N
- }
+ * @TODO injection is not working in converters. No, JavaEE is not so
+ * super-flexible. // value is known to be an entered password, so
+ * instance login container LoginContainer container = new
+ * UserLoginContainer(this.userLoginController.getLoggedInUser(),
+ * (String) value);
+ *
+ * // Test it here if (!UserUtils.ifPasswordMatches(container,
+ * this.userLoginController.getLoggedInUser())) { // Password mismatches
+ * throw new ValidatorException(new
+ * FacesMessage(FacesMessage.SEVERITY_WARN, "Password mismatching.",
+ * "The password the user has entered does not match the stored
+ * password.")); //NOI18N }
*/
}
*/
private static final long serialVersionUID = 187_536_745_607_193L;
+ /**
+ * Whether empty data is allowed
+ */
+ private Boolean allowEmptyRequiredData;
+
+ /**
+ * Default constructor
+ */
+ public AddressbookUrlValidator () {
+ this.allowEmptyRequiredData = Boolean.FALSE;
+ }
+
+ /**
+ * Setter for allowEmptyRequiredData flag
+ * <p>
+ * @param allowEmptyRequiredData Whether empty values are allowed
+ */
+ public void setAllowEmptyRequiredData (final Boolean allowEmptyRequiredData) {
+ this.allowEmptyRequiredData = allowEmptyRequiredData;
+ }
+
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
// The required field
final String[] requiredFields = {"companyWebsiteUrl"}; //NOI18N
- // Default is to reject empty email address fields
- Boolean allowEmptyValue = Boolean.FALSE;
-
- // Is attribute "allowEmptyValue" set?
- if (component.getAttributes().containsKey("allowEmptyValue")) { //NOI18N
- // Get attribute
- Object attribute = component.getAttributes().get("allowEmptyValue"); //NOI18N
-
- // Make sure, it is Boolean as no String is accepted anymore
- if (!(attribute instanceof String)) {
- // Not valid attribute, please use "true" or "false" (default)
- throw new IllegalArgumentException("allowEmptyValue must be of type String. Please use \"true\" or \"false\" for f:attribute value."); //NOI18N
- }
-
- // Securely cast it
- allowEmptyValue = Boolean.parseBoolean((String) attribute);
- }
-
// Pre-validation (example: not null, not a string, empty string ...)
- super.preValidate(context, component, value, requiredFields, allowEmptyValue);
+ super.preValidate(context, component, value, requiredFields, this.allowEmptyRequiredData);
// Is the email address empty and allowed?
- if (null == value && allowEmptyValue) {
+ if (null == value && this.allowEmptyRequiredData) {
// Then accept this here
return;
} else if (null == value) {
package org.mxchange.addressbook.validator.user;
import java.text.MessageFormat;
+import javax.enterprise.inject.spi.CDI;
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.beans.user.list.AddressbookUserListWebViewBean;
+import org.mxchange.addressbook.beans.user.list.AddressbookUserListWebViewController;
import org.mxchange.jcoreee.validator.number.BaseNumberValidator;
-import org.mxchange.jusercore.model.user.UserSessionBeanRemote;
/**
* A validator for user ids
public class AddressbookUserIdValidator extends BaseNumberValidator {
/**
- * Remote bean
+ * User backing bean
*/
- private static UserSessionBeanRemote USER_BEAN;
+ private static AddressbookUserListWebViewController USER_LIST_CONTROLLER;
/**
* Serial number
@Override
public void validate (final FacesContext context, final UIComponent component, final Object value) throws ValidatorException {
- // Is the instance there?
- if (USER_BEAN == null) {
- try {
- // Not yet, attempt lookup
- final Context initial = new InitialContext();
-
- // Lookup EJB
- USER_BEAN = (UserSessionBeanRemote) initial.lookup("java:global/addressbook-ejb/user!org.mxchange.jusercore.model.user.UserSessionBeanRemote");
- } catch (final NamingException ex) {
- // Throw it again
- throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, "Cannot lookup EJB", ex.getMessage()), ex);
- }
- }
-
// All accepted, required fields
final String[] requiredFields = {"userId"}; //NOI18N
// Pre-validation (example: not null, not a string, empty string ...)
super.preValidate(context, component, value, requiredFields, false);
+ // Is the instance there?
+ if (null == USER_LIST_CONTROLLER) {
+ // Get bean from CDI directly
+ USER_LIST_CONTROLLER = CDI.current().select(AddressbookUserListWebViewBean.class).get();
+ }
+
// Cast value
final Long userId = (Long) value;
// Define variable
- final Boolean ifUserExists = USER_BEAN.ifUserIdExists(userId);
+ final Boolean ifUserExists = USER_LIST_CONTROLLER.ifUserIdExists(userId);
// Is the user id valid?
if (!ifUserExists) {
filter="true"
filterMatchMode="contains"
>
- <f:converter converterId="CompanyEmployeeConverter" />
+ <f:converter converterId="EmployeeConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{companyEmployeeController.allCompanyEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
+ <f:selectItems value="#{companyEmployeeController.allEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
</p:selectOneMenu>
</div>
</h:panelGroup>
filter="true"
filterMatchMode="contains"
>
- <f:converter converterId="CompanyEmployeeConverter" />
+ <f:converter converterId="EmployeeConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{companyEmployeeController.allCompanyEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
+ <f:selectItems value="#{companyEmployeeController.allEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
</p:selectOneMenu>
</div>
</h:panelGroup>
filter="true"
filterMatchMode="contains"
>
- <f:converter converterId="CompanyEmployeeConverter" />
+ <f:converter converterId="EmployeeConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{companyEmployeeController.allCompanyEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
+ <f:selectItems value="#{companyEmployeeController.allEmployees()}" var="companyHeadQuarters" itemValue="#{companyEmployee}" itemLabel="#{companyEmployee.foo}" />
</p:selectOneMenu>
</div>
</h:panelGroup>
<p:column headerText="#{msg.ADMIN_CONTACT_PERSON}" sortBy="#{branchOffice.branchContactEmployee.employeePersonalData.contactFamilyName}" filterBy="#{branchOffice.branchContactEmployee}" filterMatchMode="in">
<f:facet name="filter">
<p:selectCheckboxMenu filter="true" filterMatchMode="contains" label="#{msg.LABEL_COMPANY_EMPLOYEES}" onchange="PF('branchOfficeTable').filter()" updateLabel="true" title="#{msg.FILTER_BY_MULTIPLE_COMPANY_EMPLOYEES_TITLE}">
- <f:converter converterId="CompanyEmployeeConverter" />
+ <f:converter converterId="EmployeeConverter" />
<f:selectItem itemValue="#{null}" itemLabel="#{msg.NONE_SELECTED}" />
- <f:selectItems value="#{companyEmployeeController.allCompanyEmployees()}" var="employee" itemValue="#{employee}" itemLabel="#{employee.employeePersonalData.contactFirstName} #{employee.employeePersonalData.contactFamilyName}" />
+ <f:selectItems value="#{companyEmployeeController.allEmployees()}" var="employee" itemValue="#{employee}" itemLabel="#{employee.employeePersonalData.contactFirstName} #{employee.employeePersonalData.contactFamilyName}" />
</p:selectCheckboxMenu>
</f:facet>