2 * Copyright (C) 2016 Roland Häder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation, either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
14 * You should have received a copy of the GNU Affero General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jjobs.beans.profile;
19 import java.text.MessageFormat;
20 import javax.annotation.PostConstruct;
21 import javax.enterprise.context.RequestScoped;
22 import javax.faces.view.facelets.FaceletException;
23 import javax.inject.Inject;
24 import javax.inject.Named;
25 import org.mxchange.jjobs.beans.BaseJobsController;
26 import org.mxchange.jjobs.beans.login.JobsUserLoginWebSessionController;
27 import org.mxchange.jjobs.beans.user.JobsUserWebSessionController;
28 import org.mxchange.jusercore.exceptions.UserNotFoundException;
29 import org.mxchange.jusercore.model.user.User;
30 import org.mxchange.jusercore.model.user.profilemodes.ProfileMode;
33 * A web request bean for user profiles
35 * @author Roland Häder<roland@mxchange.org>
37 @Named (value = "profileController")
39 public class JobsUserProfileWebRequestBean extends BaseJobsController implements JobsUserProfileWebRequestController {
44 private static final long serialVersionUID = 187_687_145_286_710L;
50 private JobsUserWebSessionController userController;
56 private JobsUserLoginWebSessionController userLoginController;
61 public JobsUserProfileWebRequestBean () {
65 * Post-construction method
72 public boolean isProfileLinkVisibleById (final Long userId) {
78 user = this.userController.lookupUserById(userId);
79 } catch (final UserNotFoundException ex) {
81 throw new FaceletException(ex);
86 // Not found, not visible.
91 return this.isProfileLinkVisibleByUser(user);
95 public boolean isProfileLinkVisibleByUser (final User user) {
99 * Not set, means wrong invocation of this method as the user
100 * instance needs to be set first.
102 throw new NullPointerException("user is null"); //NOI18N
103 } else if (user.getUserId() == null) {
105 * If the id number is not set it means that the user instance has
106 * not been persisted and the JPA has not been flushed. Or a
107 * "virgin" instance (e.g. from registration) has been used.
109 throw new NullPointerException("user.userId is null"); //NOI18N
110 } else if (user.getUserId() < 1) {
112 * The id number is set invalid for an unknown reason.
114 throw new IllegalArgumentException(MessageFormat.format("user.userId={0} is invalid", user.getUserId())); //NOI18N
115 } else if (user.getUserProfileMode() == null) {
117 * Possibly an out-dated user profile is being used. This should not
120 throw new NullPointerException("user.userProfileMode is null"); //NOI18N
123 // Get profile mode from user instance (safe now)
124 ProfileMode profileMode = user.getUserProfileMode();
126 // Check all conditions (except for admin)
127 return ((profileMode.equals(ProfileMode.PUBLIC)) ||
128 (this.userLoginController.isUserLoggedIn()) && (profileMode.equals(ProfileMode.MEMBERS)));