View Javadoc

1   package comum.database;
2   
3   import gov.pr.celepar.sentinela.comunicacao.SentinelaAdmInterface;
4   import gov.pr.celepar.sentinela.comunicacao.SentinelaAdministracao;
5   import gov.pr.celepar.sentinela.comunicacao.SentinelaComunicacao;
6   import gov.pr.celepar.sentinela.comunicacao.SentinelaInterface;
7   import gov.pr.celepar.sentinela.comunicacao.SentinelaParam;
8   
9   import javax.servlet.http.HttpServletRequest;
10  
11  /**
12   * @author N/C
13   * @since N/C
14   * @version N/C
15   */
16  public class SentinelaUtil {
17  	private static final ThreadLocal<SentinelaInterface> thread = new ThreadLocal<SentinelaInterface>();
18  	private SentinelaInterface sentinelaInterface = null;
19  	//private SentinelaAdmInterface sentinelaAdmInterface= null;
20  	
21  	/**
22  	 * Construtor.<br>
23  	 * 
24  	 * @author N/C
25  	 * @since N/C
26  	 * @version N/C
27  	 * @param HttpServletRequest request
28  	 */
29  	public SentinelaUtil(HttpServletRequest request) {
30  		sentinelaInterface = SentinelaComunicacao.getInstance(request);
31  		thread.set(sentinelaInterface);
32  	}
33  
34  /**
35   * Retorna SentinelaInterface.<br>
36   * 
37   * @author N/C
38   * @param N/C
39   * @version N/C
40   * @return SentinelaInterface
41   */
42  	public static SentinelaInterface getSentinelaInterface() {
43  		return (SentinelaInterface)thread.get();
44  	}
45  	
46  
47  	/**
48  	 * Retorna SentinelaAdmInterface.<br>
49  	 * 
50  	 * @author N/C
51  	 * @param N/C
52  	 * @version N/C
53  	 * @return SentinelaAdmInterface
54  	 */
55  		public static SentinelaAdmInterface getSentinelaAdmInterface(HttpServletRequest  request) {
56  			return  SentinelaAdministracao.getInstance (request); 
57  		}
58  
59  	/**
60  	 * 
61  	 * @param grupos  Todos os grupos do sistema 
62  	 * @param vinculados  Grupos pertencentes ao usuário 
63  	 * @return retorna lista dos não vinculados atraves dos parametros passados 
64  	 */
65  	public static SentinelaParam[] getGruposNaoVinculados(SentinelaParam[] grupos, SentinelaParam[] vinculados ){
66  		
67  		/*Grupos não pertencentes ao usuário */   
68  		SentinelaParam[] naoVinculados = new SentinelaParam[grupos.length - vinculados.length ] ;
69  		
70  		int contNaoVinculado = 0;
71  		for (int i =0; i<grupos.length;i++){
72  			boolean ehVinculado = false;
73  			
74  			for (int j = 0; j<vinculados.length;j++ ){
75  				if ( grupos[i].getCodigo()== vinculados[j].getCodigo() ){
76  					ehVinculado = true;
77  					break;
78  				}
79  			}
80  			//se não eh vinculado
81  			if (! ehVinculado){
82  				naoVinculados[contNaoVinculado++]=grupos[i] ;		
83  			}
84  					
85  		}
86  		
87  		return naoVinculados;
88  		
89  	}
90      
91  }