Package

Source Code of ApplicationUserManagerBean

/**
- $Header: /usr/local/cvslocalrepository/SeamWebAppGenerator/projectSkeleton/src/packageName/manager/Attic/ApplicationUserManagerBean.java,v 1.1.2.9 2008/06/02 09:11:37 fab Exp $
- $Author: fab $
- $Revision: 1.1.2.9 $
- $Date: 2008/06/02 09:11:37 $

- $Log: ApplicationUserManagerBean.java,v $
- Revision 1.1.2.9  2008/06/02 09:11:37  fab
- *** empty log message ***
-
- Revision 1.1.2.8  2008/05/29 19:34:20  fab
- Disabled sostituito con enabled
-
- Revision 1.1.2.7  2008/05/25 07:31:45  fab
- Fix vari nella gestione delle operazioni CRUD in popup
-
- Revision 1.1.2.6  2008/04/22 05:37:57  fab
- Aggiornamento indirizzo di posta
-
- Revision 1.1.2.5  2008/04/19 10:07:24  fab
- *** empty log message ***
-
- Revision 1.1.2.4  2008/04/14 12:03:48  fab
- Inserito un campo nell'utente per indicare quando è disabilitato
-
-
**/

/***************************************************************************
*  Copyright (c) 2004 - 2008  Fabrizio Boco fabboco@users.sourceforge.net *
*                                                                         *
*   This file is generated with SeamWebAppGen.                            *
*                                                                         *
*   This is free software; you can redistribute it and/or                 *
*   modify it under the terms of the GNU Library General Public           *
*   License as published by the Free Software Foundation; either          *
*   version 2 of the License, or (at your option) any later version.      *
*                                                                         *
*   This library  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 Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this library; see the file COPYING.LIB. If not,    *
*   write to the Free Software Foundation, Inc., 59 Temple Place,         *
*   Suite 330, Boston, MA  02111-1307, USA                                *
*                                                                         *
***************************************************************************/

package @basePackage.manager;

import @basePackage.entity.*;
import @basePackage.manager.managerInterface.*;
import @basePackage.manager.managerInterface.remote.*;

import java.rmi.RemoteException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.HashMap;
import java.util.Vector;
import java.util.ArrayList;


import javax.ejb.EJB;
import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.DoubleConverter;
import javax.faces.convert.IntegerConverter;
import javax.faces.event.AbortProcessingException;
import javax.faces.event.ActionEvent;
import javax.naming.Context;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.transaction.SystemException;

import org.apache.commons.collections.set.ListOrderedSet;


import org.boco.seamUtility.upload.FileManagement;
import org.boco.seamUtility.QueryBuilder;
import org.boco.seamUtility.FileUtility;
import org.boco.seamUtility.JasperReportManager;
import org.boco.seamUtility.SeamUtility;
import org.boco.seamUtility.messages.MessagesLoader;
import org.boco.seamUtility.pathManagement.PathItem;
import org.boco.seamUtility.comparator.GenericFieldComparator;
import org.boco.seamUtility.chartManagement.*;

import org.hibernate.Hibernate;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Destroy;
import org.jboss.seam.annotations.Factory;
import org.jboss.seam.annotations.FlushModeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.annotations.web.RequestParameter;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Synchronized;
import org.jboss.seam.annotations.datamodel.DataModel;
import org.jboss.seam.annotations.datamodel.DataModelSelection;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Conversation;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.core.Manager;
import org.jboss.seam.annotations.security.Restrict;
import org.jboss.seam.log.Log;
import org.jboss.seam.transaction.Transaction;

import org.jboss.seam.annotations.Begin;
import org.jboss.seam.annotations.End;

/***********************************************/
/** Generated with SeamWebAppGen version: 0.1 **/
/***********************************************/

@Stateful
@Name("ApplicationUserManager")
@Scope(ScopeType.CONVERSATION)
@Synchronized
public class ApplicationUserManagerBean implements Serializable, ApplicationUserManager, ApplicationUserManagerRemote
{
  private static final long  serialVersionUID  = 1L;
 
  // @PersistenceContext(type = PersistenceContextType.EXTENDED)
  @In
  private EntityManager              entityManager;

  @In(create=true)
  @Out(required=false, scope = ScopeType.CONVERSATION)
  @DataModelSelection(value="applicationUserList")
  private ApplicationUser                applicationUser;

  @DataModel(value="applicationUserList")
  private List<ApplicationUser>            applicationUserList; 
 
  @Logger
  private Log                      log;

  @Out
  private String                    applicationUserOperation  = "DISPLAY";
  private String                    returningPage;
 
  @In(required=false)
  private FacesContext                facesContext;
 
  @In(create=true)
  private transient FacesMessages          facesMessages;

  /** Gestione ordinamento colonne **/
  private int                     order        = 0;

  /** Gestione PopUp **/
  private Object                    callingBean = null;
  private String                    relationshipName = null;
  @Out(scope = ScopeType.CONVERSATION,     required = false)
  private HashMap<ApplicationUser, Boolean>      selections        = new HashMap<ApplicationUser, Boolean>();
  private Vector<ApplicationUser>            selectedItems      = new Vector<ApplicationUser>();
  private Vector<ApplicationUser>            justCreatedItems   = new Vector<ApplicationUser>();
  private String                    popUpReturningPage = "";
  private String                    oldReferrer    = null;
 
 
   
  /** Gestione MASTER-DETAIL **/
  @RequestParameter("masterReference")
  private String                    masterReferenceParameter = null;
  private boolean                  masterReference          = false;
  private String                    filter               = "";
 
  /** Gestione Local Search **/ 
  private boolean                  localSearch         = false;


 
  /** Gestione Search **/ 
  @DataModel(value="applicationUserSearchList")
  private List<ApplicationUser>                applicationUserSearchList;

  @In(required=false,create=true,value="applicationUserSearch")
  @Out(required=false, scope = ScopeType.CONVERSATION)
  private ApplicationUser                    applicationUserSearch;
 
  /** Gestione Dettagli **/

 
  @In
  private Conversation conversation;

  /** Gestione Bean derivati **/


 
  /** Variabili per codice custom **/
// YOUR CODE GOES HERE
// END OF YOUR CODE
 

  public ApplicationUserManagerBean()
  {
  }

  @Create()
  public void create()
  {
    log.debug("********************************************************");
    log.debug(" Creato bean per Conversation id "+conversation.getId()  );
    log.debug("********************************************************");
   
    // entityManager.setFlushMode(javax.persistence.FlushModeType.COMMIT);
    log.debug("Flush Mode "+entityManager.getFlushMode());
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
  }

  public String getApplicationUserConversationId()
  {
    return conversation.getId();
 
 
  public void setReturningPage(String returningPage)
  {
    this.returningPage = returningPage;
  }

  public void setApplicationUserOperation(String applicationUserOperation)
  {
    this.applicationUserOperation = applicationUserOperation;
 
 
  @End(beforeRedirect=true)
  //@Rollback
  public String cancel() throws IllegalStateException
  {
    log.info("------------------------------------------------");
    log.info("cancel");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("entityManager FlushMode " + entityManager.getFlushMode());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    try
    {
      Transaction.instance().setRollbackOnly();
    }
    catch (SystemException e)
    {
      log.debug(e);
    }   
    return returningPage;
  }
 
 
  /** Init **/
  @Restrict("#{s:hasRole('Administrator')}"
  @Begin(nested = true, flushMode = FlushModeType.MANUAL)
  public String initCreate()
  {
    log.info("------------------------------------------------");
    log.info("initCreate");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    returningPage = SeamUtility.getReferrer(facesContext);
     
// YOUR CODE GOES HERE
    applicationUser.setEnabled(true);
// END OF YOUR CODE
   
    applicationUser = new ApplicationUser();
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
    applicationUserOperation = "CREATE";
    return "/ApplicationUser.xhtml";
  }

  @Restrict("#{s:hasRole('Administrator')}"
  @Begin(join = true, flushMode = FlushModeType.MANUAL)
  public String initCreateInPopUp()
  {
    returningPage = SeamUtility.getReferrer(facesContext);
    relationshipName = SeamUtility.getParameter(facesContext, "relationship");

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    applicationUser = new ApplicationUser();

    // YOUR CODE GOES HERE
    applicationUser.setEnabled(true);
    // END OF YOUR CODE

    applicationUserOperation = "CREATE";

    if (relationshipName != null)
    {
      callingBean = Contexts.getConversationContext().get(SeamUtility.makeFirstLetterLowerCase(SeamUtility.getParameter(facesContext, "callingBean")));
    }

    return "/ApplicationUserInPopUp.xhtml";
  }
 
 
  @Restrict("#{s:hasRole('Administrator')}")
  @Begin(nested=true, flushMode=FlushModeType.MANUAL)
  public String initEdit()
  {
    log.info("------------------------------------------------");
    log.info("initEdit");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    returningPage = SeamUtility.getReferrer(facesContext);
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
    applicationUserOperation = "EDIT";
   
    entityManager.clear();
    applicationUser = entityManager.find(ApplicationUser.class, applicationUser.getId());

        Hibernate.initialize(applicationUser.getRoles());

   
// YOUR CODE GOES HERE
    @basePackage.security.DesEncrypter desEncrypyter = new @basePackage.security.DesEncrypter();
    applicationUser.setPassword(desEncrypyter.decrypt(applicationUser.getPassword()));
// END OF YOUR CODE

    return "/ApplicationUser.xhtml";
  }
 
  @Restrict("#{s:hasRole('Administrator')}")
  @Begin(join = true, flushMode = FlushModeType.MANUAL)
  public String initEditInPopUp()
  {
    returningPage = SeamUtility.getReferrer(facesContext);
    relationshipName = SeamUtility.getParameter(facesContext, "relationship");

    Field callingBeanField = SeamUtility.getCallingBeanField(this.getClass(), returningPage);
    callingBean = Contexts.getConversationContext().get(callingBeanField.getName());

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    applicationUserOperation = "EDIT";

    applicationUser = (ApplicationUser) SeamUtility.getSelectedBean(callingBean, relationshipName, applicationUser);

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    return "/ApplicationUserInPopUp.xhtml";
  }

  @Restrict("#{s:hasRole('Administrator')}")
  @Begin(nested = true, flushMode = FlushModeType.MANUAL)
  public String initDelete()
  {
    log.info("------------------------------------------------");
    log.info("initDelete")
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    returningPage = SeamUtility.getReferrer(facesContext);
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
    applicationUserOperation = "DELETE";

    entityManager.clear();
    applicationUser = entityManager.find(ApplicationUser.class, applicationUser.getId());
   
   
   
// YOUR CODE GOES HERE
// END OF YOUR CODE

    return "/ApplicationUser.xhtml";
  }

  @Begin(nested=true)
  public String initDisplay()
  {
    log.info("------------------------------------------------");
    log.info("initDisplay");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    returningPage = SeamUtility.getReferrer(facesContext);
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
    applicationUserOperation = "DISPLAY";

    entityManager.clear();
    applicationUser = entityManager.find(ApplicationUser.class, applicationUser.getId());



// YOUR CODE GOES HERE
// END OF YOUR CODE

    return "/ApplicationUser.xhtml";
  }

  @Begin(join=true)
  public String initSearch()
  {
    log.info("initSearch");
         
    applicationUserSearch = new ApplicationUser();
    applicationUserSearchList = null;
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
    applicationUserOperation = "SEARCH";
   
    return "/search/ApplicationUserSearch.xhtml";
  }

  /** Process **/
  @Restrict("#{s:hasRole('Administrator')}"
  public String processCreate()
  {
    log.info("------------------------------------------------");
    log.info("processCreate");
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
   
   
// YOUR CODE GOES HERE
    @basePackage.security.DesEncrypter desEncrypyter = new @basePackage.security.DesEncrypter();
    applicationUser.setPassword(desEncrypyter.encrypt(applicationUser.getPassword()));
// END OF YOUR CODE
   
   
    applicationUser = entityManager.merge(applicationUser);
   
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
   
   
   
// YOUR CODE GOES HERE
// END OF YOUR CODE
       
    applicationUserList = null;
    applicationUserSearchList = null;
   
    selectedItems.add(applicationUser);
    justCreatedItems.add(applicationUser);

    applicationUser = null;

    conversation.endBeforeRedirect();
   
    return returningPage;
  }

  @Restrict("#{s:hasRole('Administrator')}")
  @End
  public String processCreateInPopUp()
  {
    log.info("------------------------------------------------");
    log.info("processCreateInPopUp");
    log.debug("Conversation id " + conversation.getId());
    log.debug("Conversation view id " + conversation.getViewId());
    log.debug("Conversation nested " + conversation.isNested());
    log.debug("Conversation parent id " + conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username}");
    log.info("------------------------------------------------");

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    applicationUser = entityManager.merge(applicationUser);

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    // YOUR CODE GOES HERE
    // END OF YOUR CODE

    if (relationshipName != null)
    {
      SeamUtility.addRelatedValue2(callingBean, relationshipName, applicationUser.getClass(), applicationUser);

      relationshipName = null;

      return "/close.xhtml?goTo=." + returningPage;
    }
   
    return "/closeOnly.xhtml";
  }
   
  @Restrict("#{s:hasRole('Administrator')}")
  public String processEdit()
  {
    log.info("------------------------------------------------");
    log.info("processEdit");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    entityManager.clear();
   
// YOUR CODE GOES HERE

    @basePackage.security.DesEncrypter desEncrypyter = new @basePackage.security.DesEncrypter();
    applicationUser.setPassword(desEncrypyter.encrypt(applicationUser.getPassword()));

// END OF YOUR CODE
   
   
   
    applicationUser=entityManager.merge(applicationUser);

// YOUR CODE GOES HERE
// END OF YOUR CODE

    applicationUserList = null;
    applicationUserSearchList = null;
   
    entityManager.flush();
   
    conversation.endBeforeRedirect();
   
    return returningPage;
  }

  @Restrict("#{s:hasRole('Administrator')}")
  public String processEditInPopUp()
  {
    processEdit();
   
    return "/closeOnly.xhtml";
  }
 
 
  @Restrict("#{s:hasRole('Administrator')}")
  @End(beforeRedirect=true)
  public String processDelete()
  {
    log.info("------------------------------------------------");
    log.info("processDelete");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
   
   
    entityManager.remove(applicationUser);
       
    applicationUserList = null;   
    applicationUserSearchList = null;
   
    selectedItems.remove(applicationUser);
   
    while( contains(selections.keySet(),applicationUser) )
      selections = remove(selections,applicationUser);
   
    justCreatedItems.remove(applicationUser);
   
    applicationUser = null;
   
    return returningPage;
  }

  @End(beforeRedirect=true)
  public String processDisplay()
  {
    log.info("------------------------------------------------");
    log.info("processDisplay");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    return returningPage;
  }
 
  public String processSearch()
  {
    log.info("------------------------------------------------");
    log.info("processSearch");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    return "/search/ApplicationUserSearchList.seam";
  }

 
  public ApplicationUser find(Long id)
  {
    log.info("------------------------------------------------");
    log.info("find");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    return entityManager.find(ApplicationUser.class,id);
  }
 
  @Factory("applicationUserList")
  @Begin(join = true)
  public void findAll()
  {
    log.info("findAll");
    boolean localSearchConditionAdded = false;
    String customFilter = "";
    QueryBuilder qb = new QueryBuilder(entityManager);

//    String referrer = SeamUtility.getReferrer(facesContext);

    String viewId = facesContext.getViewRoot().getViewId();
    qb.addSelect("o");
    qb.addFrom("ApplicationUser o");
     
// YOUR CODE GOES HERE
// END OF YOUR CODE

    qb.addTextWhere(customFilter,customFilter);

    switch (order)
    {
      case 1:
        qb.addOrderBy("o.surname desc");
        break;
      case 2:
        qb.addOrderBy("o.surname asc");
        break;

      case 3:
        qb.addOrderBy("o.name desc");
        break;
      case 4:
        qb.addOrderBy("o.name asc");
        break;

// YOUR CODE GOES HERE
// END OF YOUR CODE
      default:
        qb.addOrderBy("o.surname asc");
    }


    PathItem myInfo = SeamUtility.getReferenceToMaster();
    log.debug("  query: "+qb.getQuery());
    long startTime = System.currentTimeMillis();

    entityManager.clear();

    ListOrderedSet tmp = new ListOrderedSet();
    tmp.addAll(qb.getEjbQuery().getResultList());
    Vector<ApplicationUser> tmp1 = new Vector<ApplicationUser>(tmp.asList());
    applicationUserList = tmp1;


    if (callingBean != null)
    {
      // Sta caricando una popUp e deve gestire gli item selezionati
     
      List<ApplicationUser> relatedApplicationUsers = SeamUtility.getBeanRelationshipValues(callingBean, viewId);

      if (justCreatedItems.size() > 0 && SeamUtility.isRelationshipToOne(callingBean, viewId))
      {       
        // La relazione e' :1 ed e' stato creato un nuovo item da collegare. Sicuramente l'eventuale
        // item correlato non deve essere selezionato       
        relatedApplicationUsers = null;

        selections.clear();

        if(contains(selections.keySet(),justCreatedItems.lastElement()))
          selections = remove(selections,justCreatedItems.lastElement());
       
        selections.put(justCreatedItems.lastElement(), true);
               
        selectedItems.clear();
        selectedItems.add(justCreatedItems.lastElement());
      }
           
      for (ApplicationUser localApplicationUser : applicationUserList)
      {
        if (relatedApplicationUsers != null && relatedApplicationUsers.contains(localApplicationUser))
        {
          // Aggiunge gli elementi correlati a quelli selezionati
         
          if (contains(selections.keySet(),localApplicationUser))
            selections = remove(selections,localApplicationUser);
         
          selections.put(localApplicationUser, true);
        }

        if (selectedItems.contains(localApplicationUser))
        {
          // Aggiunge gli elementi eventualmente gia' selezionati in altre pagine

          if (contains(selections.keySet(),localApplicationUser))
            selections = remove(selections,localApplicationUser);

          selections.put(localApplicationUser, true);
        }

      }
    }

    // Sposta gli elementi selezionati all'inizio della lista
    List<ApplicationUser> adding = new Vector<ApplicationUser>();
    List<ApplicationUser> removing = new Vector<ApplicationUser>();

    for (ApplicationUser applicationUserLocal : applicationUserList)
    {
      if (selections!=null && selections.containsKey(applicationUserLocal) && selections.get(applicationUserLocal))
      {
        adding.add(applicationUserLocal);
        removing.add(applicationUserLocal);
      }
    }
    applicationUserList.removeAll(removing);
    adding.addAll(applicationUserList);
    applicationUserList.clear();
    applicationUserList.addAll(adding);

    // Gestione ordinamento dei campi transient
    switch (order)
    {
    }



    long endTime = System.currentTimeMillis();

    log.debug("Query Time: "+(endTime-startTime)+" ms "+(endTime-startTime)/1000+" s" );

  }

 
  @Factory("applicationUserSearchList")
  @Begin(join = true)
  public void search() throws Exception
  {
    if(applicationUserSearch == null)
      return;

    String customFilter = "";
    QueryBuilder qb = new QueryBuilder(entityManager);

    qb.addSelect("o");
    qb.addFrom("ApplicationUser o");

    qb.addTextWhere(customFilter,customFilter);

    switch (order)
    {
      case 1:
        qb.addOrderBy("o.surname desc");
        break;
      case 2:
        qb.addOrderBy("o.surname asc");
        break;

      case 3:
        qb.addOrderBy("o.name desc");
        break;
      case 4:
        qb.addOrderBy("o.name asc");
        break;

      default:
        qb.addOrderBy("o.surname asc");
    }

// YOUR CODE GOES HERE
// END OF YOUR CODE

    entityManager.clear();

    applicationUserSearchList = qb.getEjbQuery().getResultList();

  }

 
  public void resetList()
  {
    log.info("resetList");
   
    applicationUserList = null;
  }
 
 
  public List<ApplicationUser> getSelectionItems()
  {
    String query = "select o from ApplicationUser as o ";
   
// YOUR CODE GOES HERE
// END OF YOUR CODE   
   
    List<ApplicationUser> tmp = entityManager.createQuery(query).getResultList();
       
    return tmp;
  }
 
 
  @Begin(join=true, flushMode=FlushModeType.MANUAL)
  public void onListLoad()
  {   
    log.info("------------------------------------------------");
    log.info("metodo onListLoad");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    String referrer = SeamUtility.getReferrer(facesContext);
    masterReferenceParameter = SeamUtility.getParameter(facesContext,"masterReference");
   
    if (!referrer.contains("/list/ApplicationUser") && !referrer.contains("/ApplicationUser") && !referrer.contains("PopUp"))
    {
      // Deve entrare qui al caricamento della pagina
     
      if (masterReferenceParameter == null)
      {
        SeamUtility.resetPath();
        applicationUserList = null;
        applicationUserSearchList = null;
        masterReference = false;
      }
      else
      {
        masterReference = true;
        SeamUtility.removeLastPathItem("ApplicationUser");
      }
    }
       
    if ( referrer.contains("/ApplicationUser")  )
    {
      // Deve aggiornare la lista dopo una azione su un item
      applicationUserList = null;
      applicationUserSearchList = null;
    }
   
    if (referrer.contains("/list/") || referrer.contains("Administration.seam"))
    {
      // Reload al caricamento delle pagine indicate
      applicationUserList = null;
      applicationUserSearchList = null;
    }
   
    if (SeamUtility.getParameter(facesContext, "forceReload") != null && SeamUtility.getParameter(facesContext, "forceReload").equals("true"))
    {
      // Forzato il reload della pagina se il parametro forceReload = true
      applicationUserList = null;
      applicationUserSearchList = null;
    }   
// YOUR CODE GOES HERE
// END OF YOUR CODE
  }
 

  public void onPopUpLoad()
  {   
    log.info("------------------------------------------------");
    log.info("metodo onPopUpLoad");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId());
    log.debug("Is long running " + conversation.isLongRunning());
    log.debug("User #{user.username} ");
    log.info("------------------------------------------------");
   
    String referrer = SeamUtility.getReferrer(facesContext);
    masterReferenceParameter = SeamUtility.getParameter(facesContext,"masterReference");

    if (SeamUtility.getParameter(facesContext, "callingConversationId") != null && popUpReturningPage.equals(""))
    {
      // Memorizza la pagina di ritorno nel caso in cui la popup sia chiamata
      // per la prima volta
     
      // Non utilizza il referrer per supportare IE
      popUpReturningPage = "/"+SeamUtility.getParameter(facesContext, "callingBean")+".seam?conversationId="+SeamUtility.getParameter(facesContext, "callingConversationId")+"&conversationIsLongRunning=true";
      referrer = popUpReturningPage;
    }
       
    applicationUserList = null;
           
    selections.clear();
   
    log.debug("Referrer "+referrer);
    if (!referrer.contains("/popup/"))
    {
      // Prima chiamata alla popup
      // deve essere creata una conversazione nested
     
      log.debug("Start di una nuova conversazione");
      conversation.begin();
     
      // Salva id conversazione corrente per ripristinarla in seguito
     
      String currentConversationId = conversation.getId();
     
      // Dal referrer estrae la conversazione che contiene il bean chiamante

      int start = popUpReturningPage.indexOf("conversationId") + 15;
      int end   = popUpReturningPage.indexOf("&",start);
      if (end==-1)
        end = oldReferrer.length();

      String callingConversationId = popUpReturningPage.substring(start, end);
     
      // Switch alla conversazione che contiene il bean chiamante
     
      Contexts.getConversationContext().flush();             // Suggerito da pete.muir per errore con relazioni N:M sullo stesso bean
     
      Manager.instance().switchConversation(callingConversationId);

      // Recupera il bean chiamante dalla conversazione
     
      Field  callingBeanField = SeamUtility.getCallingBeanField(this.getClass(), popUpReturningPage);

      try
      {
        callingBean = Contexts.getConversationContext().get(callingBeanField.getName());
      }
      catch(Exception e)
      {
        ;
      }

      // Switch back alla conversazione corrente
      Manager.instance().switchConversation(currentConversationId);
     
      // Inserisce il bean padre nella conversazione corrente
      // Serve per recuperare i valori da ripristinare nel form alla chisura
      // della popup
      try
      {
        Contexts.getConversationContext().set(callingBeanField.getName(), callingBean);
      }
      catch(Exception e)
      {
        ;
      }           
    }
    else
    {
      // Chiamata successiva alla popup

      log.debug("Join alla conversazione esistente");
      // conversation.begin(true, false); // Sembra che se presente uccida
      // tutte le conversazioni !!
    }   
// YOUR CODE GOES HERE
// END OF YOUR CODE
  }

 
  @Remove
  @Destroy
  public void destroy()
  {
    log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
    log.debug("Rilasciato bean per Conversation id "+conversation.getId());
    log.debug("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
  }

 
   
  public ApplicationUser getApplicationUser()
  {
    return applicationUser;
  }

  public void setApplicationUser(ApplicationUser applicationUser)
  {
    this.applicationUser = applicationUser;
  }

// public String getOperation()
// {
// return operation;
// }
//
// public void setOperation(String operation)
// {
// this.operation = operation;
// }
 
  public boolean isShowNavigationMenuItems()
  {
    String referrer = SeamUtility.getReferrer(facesContext);

    if (referrer.contains("/popup/"))
      return false;
   
    return true;
 
 
 
  /** Gestione ordinamento colonne **/
  public Integer getOrder()
  {
    return order;
  }

    public void orderBy1A()
  {
    order = 1;
  }
  public void orderBy1D()
  {
    order = 2;
  }
  public void orderBy2A()
  {
    order = 3;
  }
  public void orderBy2D()
  {
    order = 4;
  }

 
  /** Gestione PopUp **/
 
  public HashMap<ApplicationUser, Boolean> getSelections()
  {
    return selections;
  }

  public void setSelections(HashMap<ApplicationUser, Boolean> selections)
  {
    this.selections = selections;
  }
 
  public String select()
  {
    log.info("------------------------------------------------");
    log.info("select");   
    log.debug("Conversation id "+conversation.getId());
    log.debug("Conversation view id "+conversation.getViewId());
    log.debug("Conversation nested "+conversation.isNested());
    log.debug("Conversation parent id "+conversation.getParentId())
    log.debug("Is long running " + conversation.isLongRunning())
    log.debug("User #{user.username} ");
    log.debug("\tSelected Items "+selectedItems);
    log.debug("\tJust Created Items "+justCreatedItems);
    log.debug("\tSelection "+selections);
    log.info("------------------------------------------------");
   
    Field beanField = null;
       
    String referrer = SeamUtility.getReferrer(facesContext);

    if (popUpReturningPage.startsWith("/search"))
      beanField = SeamUtility.getCallingBeanField2(this.getClass(),referrer,true);
    else
      beanField = SeamUtility.getCallingBeanField2(this.getClass(),referrer,false);
   
    Object bean = null;

    // Individua la conversazione del bean chiamante la popup
   
    int start = popUpReturningPage.indexOf("conversationId") + 15;
    int end = popUpReturningPage.indexOf("&");

    if(end==-1)
      end = popUpReturningPage.length();
   
    String toConversation = popUpReturningPage.substring(start, end);

    // Recupera il bean che deve essere aggiornato dalla conversazione corrente
   
    bean = Contexts.getConversationContext().get(beanField.getName());
   
    Set<ApplicationUser> keys = selections.keySet();

    // Rimuove i valori presenti

    SeamUtility.removeAllRelatedValues(bean,referrer);
   
    // Inserisce solo i selezionati

    for (ApplicationUser localApplicationUser : keys)
    {
      if (selections.get(localApplicationUser).equals(true))
      {
        List relatedApplicationUsers = SeamUtility.getBeanRelationshipValues(bean,referrer);
       
        if (relatedApplicationUsers==null || !relatedApplicationUsers.contains(localApplicationUser))
          SeamUtility.addRelatedValue(bean, referrer, applicationUser.getClass(), localApplicationUser);       
      }
    }

    // Chiudere la conversazione corrente
    conversation.end();

    // Switch alla conversazione che contiene il bean che deve essere aggiornato
    Manager.instance().switchConversation(toConversation);

// YOUR CODE GOES HERE
// END OF YOUR CODE

    // Inserito il bean chiamante modificato dalla popup nella sua conversazione
    // Il bean ora contiene anche i valori dei campi trasferiti nella popup via javascript
    Contexts.getConversationContext().set(beanField.getName(),bean);
   
    // Resetta i valori selezionati
    selections.clear();
    justCreatedItems.clear();
   
    String ret = "/close.xhtml?goTo=."+popUpReturningPage;
   
    log.debug("\tReturning page "+ret);
   
    popUpReturningPage = "";
   
    return ret;
  }
 
  private boolean contains(Set<ApplicationUser> keys, ApplicationUser key)
  {

    for (Iterator iter = keys.iterator(); iter.hasNext();)
    {
      ApplicationUser element = (ApplicationUser) iter.next();

      if (key.equals(element))
        return true;
    }

    return false;
  }

  private HashMap<ApplicationUser, Boolean> remove(HashMap<ApplicationUser, Boolean> map, ApplicationUser key)
  {
    HashMap<ApplicationUser, Boolean> ret = new HashMap<ApplicationUser, Boolean>();

    Set<ApplicationUser> mapKeys = map.keySet();
    for (ApplicationUser localApplicationUser : mapKeys)
    {
      if (!localApplicationUser.equals(key))
        ret.put(localApplicationUser, true);
    }

    return ret;
  }

  private List<ApplicationUser> remove(List<ApplicationUser> list, ApplicationUser key)
  {
    List<ApplicationUser> ret = new Vector<ApplicationUser>();

    for (ApplicationUser localApplicationUser : list)
    {
      if (!localApplicationUser.equals(key))
        ret.add(localApplicationUser);
    }

    return ret;
  }
 
  private boolean get(HashMap<ApplicationUser, Boolean> selections, ApplicationUser selected)
  {
    Set<ApplicationUser> keys = selections.keySet();
   
    for (ApplicationUser applicationUser : keys)
    {
      if (applicationUser.equals(selected))
        return selections.get(applicationUser);
    }
   
    return false;
  }

  /** Gestione MASTER-DETAIL **/
   
 
 
 
  public Boolean isDetailOf(String masterBeanName)
  {
    PathItem myInfo = SeamUtility.getReferenceToMaster();
   
    if (myInfo.getBeanName().equals(masterBeanName))
      return true;
   
    return false;
 
 
  /** Gestione Local Search **/
  public boolean isLocalSearch()
  {
    return localSearch;
  }

  public void setLocalSearch(boolean search)
  {
    this.localSearch = search;
  }

  public void startLocalSearch()
  {
    localSearch = true;
  }

  public void stopLocalSearch()
  {
    localSearch = false;

    applicationUserList = null;
  }


 
 
  /** Gestione Popup Menu Data Table **/
  public void popupMenuSelectItem(ActionEvent event)
  {           
    Map<String,String> parameters = facesContext.getExternalContext().getRequestParameterMap();   
    applicationUser = find(new Long(parameters.get("selectedId")));
  }

 
  /** Gestione Dettagli **/
  // This function must be megrated from Trinidad to ICEFaces
  public void processDisclosure(int arg0) throws AbortProcessingException
  {
// YOUR CODE GOES HERE
// END OF YOUR CODE
  }
 
// YOUR CODE GOES HERE
// END OF YOUR CODE
}
TOP

Related Classes of ApplicationUserManagerBean

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.