gt:         if (search.isLoginSet()) {
context: /*
   * TNTConcept Easy Enterprise Management by Autentia Real Bussiness Solution S.L.
   *	Copyright (C) 2007 Autentia Real Bussiness Solution S.L.
   *
   * 	This program is free software; you can redistribute it and/or
   * 	modify it under the terms of the GNU General Public License
   * 	as published by the Free Software Foundation; either version 2
   * 	of the License, or (at your option) any later version.
   *
   * 	This program is distributed in the hope that it will be useful,
   * 	but WITHOUT ANY WARRANTY; without even the implied warranty of
   * 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * 	GNU General Public License for more details.
   *
   * 	You should have received a copy of the GNU General Public License
   * 	along with this program; if not, write to the Free Software
   * 	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   *
   * 	Autentia Real Bussiness Solution S.L.
   * 	Tlf: +34 91 675 33 06, +34 655 99 11 72
   * 	Fax: +34 91 656 65 04
   * 	info@autentia.com
   */
  package com.autentia.intra.bean.admin;
  
  import com.autentia.intra.bean.BaseBean;
  import com.autentia.intra.bean.NavigationResults;
  import com.autentia.intra.bean.document.DocumentBean;
  import com.autentia.intra.businessobject.*;
  import com.autentia.intra.dao.SortCriteria;
  import com.autentia.intra.dao.hibernate.UserDAO;
  import com.autentia.intra.dao.search.UserSearch;
  import com.autentia.intra.manager.admin.*;
  import com.autentia.intra.manager.contacts.OrganizationManager;
  import com.autentia.intra.manager.document.DocumentCategoryManager;
  import com.autentia.intra.manager.security.AuthenticationManager;
  import com.autentia.intra.manager.security.Permission;
  import com.autentia.intra.upload.Uploader;
  import com.autentia.intra.upload.UploaderFactory;
  import com.autentia.intra.util.ConfigurationUtil;
  import com.autentia.intra.util.FacesUtils;
  import com.autentia.intra.util.FileUtil;
  import com.autentia.intra.util.SpringUtils;
  import org.acegisecurity.acls.domain.BasePermission;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.myfaces.custom.fileupload.UploadedFile;
  
  import javax.faces.component.UIComponent;
  import javax.faces.component.html.HtmlDataTable;
  import javax.faces.model.SelectItem;
  import java.io.IOException;
  import java.math.BigDecimal;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  /**
   * UI bean for User objects.
   *
   * @author stajanov code generator
   */
  public class UserBean extends BaseBean {
      /**
       * Serial version field
       */
      private static final long serialVersionUID = -1L;
  
      /**
       * Default authentication manager
       */
      private static final AuthenticationManager authManager = AuthenticationManager.getDefault();
  
      /**
       * Default DocumentCategory manager
       */
      private static final DocumentCategoryManager dcManager = DocumentCategoryManager.getDefault();
  
      /**
       * New generated password when user clicks on resetPassword
       */
      private String changedPassword;
  
      /**
       * Saves and goes to user's document category
       */
      public String goDocuments() {
          User currentUser = getUser();
          // Save user's data
          save();
          // Prepares the category bean filter
          DocumentBean documentBean = (DocumentBean) FacesUtils.getBean("documentBean");
          List<DocumentCategory> categories = new ArrayList<DocumentCategory>();
          categories.add(currentUser.getDocumentCategory());
          documentBean.setSearchCategoriesValid(true);
          documentBean.setSearchCategories(categories);
          return "goDocuments";
      }
  
      /**
       * Creates user's category when the user or not has a category
       */
      @Override
      public String doBeforeSave() {
          String result = super.doBeforeSave();
          // if the user not has a category
          user = (User) UserDAO.getDefault().merge(user); //arregla lazy see #38
          if (getUser().getDocumentCategory() == null || getUser().getDocumentCategory().getId() == null) {
  
              DocumentCategory padre = dcManager.getDocumentCategoryParent();
              // User category
              DocumentCategory userDocCategory = new DocumentCategory();
              userDocCategory.setName(getUser().getName());
              userDocCategory.setDescription(getUser().getName());
              userDocCategory.setPadre(padre);
              getUser().setDocumentCategory(userDocCategory);
          } else {
              // Updates the category name
              getUser().getDocumentCategory().setName(getUser().getName());
              getUser().getDocumentCategory().setDescription(getUser().getName());
          }
          return result;
      }
  
      /**
       * Reset current user password
       *
       * @return "userPasswordReset"
       */
      public String resetPassword() {
          // Change user password
          changedPassword = authManager.resetPassword(getUser());
          manager.updateEntity(getUser());
  
          return "userPasswordReset";
      }
  
      public String getChangedPassword() {
          return changedPassword;
      }
  
      public boolean isResetPasswordAvailable() {
          return SpringUtils.isRolePermissionGranted(Permission.Action_ResetPassword);
      }
  
      /**
       * Wheter or not role field is available to user
       *
       * @return true if user is administrator
       */
      public boolean isRoleAvailable() {
          return SpringUtils.isRolePermissionGranted(Permission.Action_ChangeRole);
      }
  
  /* user - generated by stajanov (do not edit/delete) */
  
  
      /**
       * Logger
       */
      private static final Log log = LogFactory.getLog(UserBean.class);
  
      /**
       * Active search object
       */
      private UserSearch search = new UserSearch();
  
      /**
       * Manager
       */
      private static UserManager manager = UserManager.getDefault();
  
      /**
       * Upload service
       */
      private static final Uploader uploader = UploaderFactory.getInstance("user");
  
  
      /**
       * Temporary photo field
       */
      private String oldPhoto;
  
      /**
       * Uploaded photo object
       */
      private UploadedFile uploadPhoto;
  
  
      /**
       * Active User object
       */
      private User user;
  
      /**
       * Default sort column
       */
      private String sortColumn = "name";
  
      /**
       * Default sort order
       */
      private boolean sortAscending = true;
  
      /**
       * Quick search letter for ABC pager control
       */
      private Character letter;
  
      /**
       * List users. Order depends on Faces parameter sort.
       *
       * @return the list of all users sorted by requested criterion
       */
      public List<User> getAll() {
          return manager.getAllEntities(search, new SortCriteria(sortColumn, sortAscending));
      }
  
      // Getters to list possible values of related entities
  
  
      /**
       * Get the list of all roles
       *
       * @return the list of all roles
       */
      public List<SelectItem> getRoles() {
          List<Role> refs = RoleManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (Role ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
  
      /**
       * Get the list of all categorys
       *
       * @return the list of all categorys
       */
      public List<SelectItem> getCategorys() {
          List<UserCategory> refs = UserCategoryManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (UserCategory ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
      /**
       * Get the list of all organizations
       *
       * @return the list of all organizations
       */
      public List<SelectItem> getOrganizations() {
          Organization lab = OrganizationManager.getDefault().getEntityById(ConfigurationUtil.getDefault().getIdLabCompany());
          Organization cpy = OrganizationManager.getDefault().getEntityById(ConfigurationUtil.getDefault().getIdOurCompany());
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          ret.add(new SelectItem(lab, lab.getName()));
          ret.add(new SelectItem(cpy, cpy.getName()));
          return ret;
      }
  
      /**
       * Get the list of all provinces
       *
       * @return the list of all provinces
       */
      public List<SelectItem> getProvinces() {
          List<Province> refs = ProvinceManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (Province ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
  
      /**
       * Get the list of all documentCategorys
       *
       * @return the list of all documentCategorys
       */
      public List<SelectItem> getDocumentCategorys() {
          List<DocumentCategory> refs = DocumentCategoryManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (DocumentCategory ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
  
      /**
       * Get the list of all departments
       *
       * @return the list of all departments
       */
      public List<SelectItem> getDepartments() {
          List<Department> refs = DepartmentManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (Department ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
  
      /**
       * Get the list of all contractTypes
       *
       * @return the list of all contractTypes
       */
      public List<SelectItem> getContractTypes() {
          List<ContractType> refs = ContractTypeManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (ContractType ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
  
      /**
       * Get the list of all agreements
       *
       * @return the list of all agreements
       */
      public List<SelectItem> getAgreements() {
          List<WorkingAgreement> refs = WorkingAgreementManager.getDefault().getAllEntities(null, new SortCriteria("name"));
  
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          for (WorkingAgreement ref : refs) {
              ret.add(new SelectItem(ref, ref.getName()));
          }
          return ret;
      }
  
      // Getters to list possible values of enum fields
  
      public String getGenreFormatted() {
          if (this.getGenre() != null) {
              return FacesUtils.formatMessage("UserGenre." + this.getGenre().name());
          } else {
              return "";
          }
      }
  
      /**
       * Get the list of all Genre values
       *
       * @return the list of all Genre values
       */
      public List<SelectItem> getGenres() {
          ArrayList<SelectItem> ret = new ArrayList<SelectItem>();
          UserGenre[] vals = UserGenre.values();
          for (UserGenre val : vals) {
              ret.add(new SelectItem(val, FacesUtils.formatMessage("UserGenre." + val.name())));
          }
          return ret;
      }
  
      // Methods to create/remove instances of one-to-many entities (slave entities)
  
      /**
       * Whether or not create button is available for user
       *
       * @return true if user can create objects of type User
       */
      public boolean isCreateAvailable() {
          return SpringUtils.isRolePermissionGranted(Permission.Entity_Create(User.class));
      }
  
      /**
       * Whether or not edit button is available for user
       *
       * @return true if user can edit current object
       */
      public boolean isEditAvailable() {
          return SpringUtils.isAclPermissionGranted(getUser(), BasePermission.WRITE);
      }
  
      /**
       * Whether or not delete button is available for user
       *
       * @return true if user can delete current object
       */
      public boolean isDeleteAvailable() {
          return (getUser().getId() != null) &&
                  SpringUtils.isAclPermissionGranted(getUser(), BasePermission.DELETE);
      }
  
      /**
       * Go to create page
       *
       * @return forward to CREATE page
       */
      public String create() {
          setUser(new User());
          // Set default password to "password"
          getUser().setPassword("5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8");
  // Set default hours to 8*60 
          getUser().setDayDuration(480);
          return NavigationResults.CREATE;
      }
  
      /**
       * Go to detail page
       *
       * @return forward to DETAIL page
       */
      public String detail() {
          Integer id = Integer.parseInt(FacesUtils.getRequestParameter("id"));
          setUser(manager.getEntityById(id));
  
          return SpringUtils.isAclPermissionGranted(getUser(), BasePermission.WRITE)
                  ? NavigationResults.EDIT
                  : NavigationResults.DETAIL;
      }
  
      /**
       * Save bean and stay on it
       *
       * @return forward to list page
       */
      public String save() {
  
          doBeforeSave();
  
          if (getUser().getId() == null) {
              manager.insertEntity(getUser());
          } else {
              manager.updateEntity(getUser());
          }
  
          // Handle uploads for photo field
          if (uploadPhoto != null) {
              try {
                  uploader.replace(Integer.toString(getUser().getId()), oldPhoto, uploadPhoto);
              } catch (IOException e) {
                  log.error("save - exception uploading field photo", e);
                  FacesUtils.addErrorMessage("photo", "error.fileTransfer", e.getMessage());
              }
          }
  
          // Calls an after save action
          String result = doAfterSave(NavigationResults.LIST);
  
          // Unselect object
          //setUser(null);
  
          return null;
      }
  
      /**
       * Delete bean and go back to beans list
       *
       * @return forward to LIST page
       */
      public String delete() {
          manager.deleteEntity(getUser());
          setUser(null);
          return NavigationResults.LIST;
      }
  
      /**
       * Go back to beans list
       *
       * @return forward to LIST page
       */
      public String list() {
          return NavigationResults.LIST;
      }
  
      /**
       * Reset search criteria
       *
       * @return forward to LIST page
       */
      public String reset() {
          search.reset();
          return list();
      }
  
      /**
       * Go to search page
       *
       * @return forward to SEARCH page
       */
      public String search() {
          return NavigationResults.SEARCH;
      }
  
      /**
       * Check if we have an active object.
       *
       * @return true is an object is selected
       */
      public boolean isUserSelected() {
          return getUser() != null;
      }
  
      // Getters and setters to manipulate sorting
      public boolean isSortAscending() {
          return sortAscending;
      }
  
      public void setSortAscending(boolean sortAscending) {
          this.sortAscending = sortAscending;
      }
  
      public String getSortColumn() {
          return sortColumn;
      }
  
      public void setSortColumn(String sortColumn) {
          this.sortColumn = sortColumn;
      }
  
      // Getters and setters to handle search
      public UserSearch getSearch() {
          return search;
      }
  
  
      public java.lang.Boolean getSearchActive() {
          return search.getActive();
      }
  
      public void setSearchActive(java.lang.Boolean val) {
          if (search.isActiveSet()) {
              search.setActive(val);
          }
      }
  
      public boolean isSearchActiveValid() {
          return search.isActiveSet();
      }
  
      public void setSearchActiveValid(boolean val) {
          if (val) {
              search.setActive(search.getActive());
          } else {
              search.unsetActive();
          }
      }
  
  
      public String getSearchLogin() {
          return search.getLogin();
      }
  
      public void setSearchLogin(String val) {
  