PermessiUtente.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.web.lib.users.dao;

  21. import java.io.Serializable;

  22. /**
  23.  * Permessi di un utente
  24.  *
  25.  *
  26.  * @author Andrea Poli (apoli@link.it)
  27.  * @author Stefano Corallo (corallo@link.it)
  28.  * @author Sandra Giangrandi (sandra@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  *
  32.  */
  33. public class PermessiUtente implements Serializable {

  34.     /**
  35.      *
  36.      */
  37.     private static final long serialVersionUID = 1L;
  38.    
  39.     /** Permessi di visualizzazione dei servizi */
  40.     private boolean servizi;
  41.     /** Permessi di visualizzazione della diagnostica */
  42.     private boolean diagnostica;
  43.     /** Permessi di visualizzazione della reportistica */
  44.     private boolean reportistica;
  45.     /** Permessi di visualizzazione del sistema */
  46.     private boolean sistema;
  47.     /** Permessi di visualizzazione del monitoraggio applicativo */
  48.     private boolean codeMessaggi;
  49.     /** Permessi di visualizzazione del auditing */
  50.     private boolean auditing;
  51.     /** Permessi di visualizzazione del utenti */
  52.     private boolean utenti;
  53.     /** Permessi di visualizzazione degli accordi di cooperazione */
  54.     private boolean accordiCooperazione;
  55.    
  56.    
  57.     @Override
  58.     public String toString(){
  59.         StringBuilder bf = new StringBuilder();
  60.         if(this.servizi)
  61.             bf.append(Permessi.SERVIZI.toString());
  62.         if(this.diagnostica)
  63.             bf.append(Permessi.DIAGNOSTICA.toString());
  64.         if(this.reportistica)
  65.             bf.append(Permessi.REPORTISTICA.toString());
  66.         if(this.sistema)
  67.             bf.append(Permessi.SISTEMA.toString());
  68.         if(this.codeMessaggi)
  69.             bf.append(Permessi.CODE_MESSAGGI.toString());
  70.         if(this.auditing)
  71.             bf.append(Permessi.AUDITING.toString());
  72.         if(this.utenti)
  73.             bf.append(Permessi.UTENTI.toString());
  74.         if(this.accordiCooperazione)
  75.             bf.append(Permessi.ACCORDI_COOPERAZIONE.toString());
  76.         return bf.toString();
  77.     }
  78.    
  79.     public String toString(String separatore){
  80.         PermessiUtente p = new PermessiUtente();
  81.         p.setAuditing(true);
  82.         p.setCodeMessaggi(true);
  83.         p.setDiagnostica(true);
  84.         p.setReportistica(true);
  85.         p.setServizi(true);
  86.         p.setSistema(true);
  87.         p.setUtenti(true);
  88.         p.setAccordiCooperazione(true);
  89.         return this.toString(separatore, p);
  90.     }
  91.     public String toString(String separatore,PermessiUtente maschera){
  92.         StringBuilder bf = new StringBuilder();
  93.         if(maschera.servizi){
  94.             if(this.servizi){
  95.                 if(bf.length()>0)
  96.                     bf.append(separatore);
  97.                 bf.append(Permessi.SERVIZI.toString());
  98.             }
  99.         }
  100.         if(maschera.diagnostica){
  101.             if(this.diagnostica){
  102.                 if(bf.length()>0)
  103.                     bf.append(separatore);
  104.                 bf.append(Permessi.DIAGNOSTICA.toString());
  105.             }
  106.         }
  107.         if(maschera.reportistica){
  108.             if(this.reportistica){
  109.                 if(bf.length()>0)
  110.                     bf.append(separatore);
  111.                 bf.append(Permessi.REPORTISTICA.toString());
  112.             }
  113.         }
  114.         if(maschera.sistema){
  115.             if(this.sistema){
  116.                 if(bf.length()>0)
  117.                     bf.append(separatore);
  118.                 bf.append(Permessi.SISTEMA.toString());
  119.             }
  120.         }
  121.         if(maschera.codeMessaggi){
  122.             if(this.codeMessaggi){
  123.                 if(bf.length()>0)
  124.                     bf.append(separatore);
  125.                 bf.append(Permessi.CODE_MESSAGGI.toString());
  126.             }
  127.         }
  128.         if(maschera.auditing){
  129.             if(this.auditing){
  130.                 if(bf.length()>0)
  131.                     bf.append(separatore);
  132.                 bf.append(Permessi.AUDITING.toString());
  133.             }
  134.         }
  135.         if(maschera.utenti){
  136.             if(this.utenti){
  137.                 if(bf.length()>0)
  138.                     bf.append(separatore);
  139.                 bf.append(Permessi.UTENTI.toString());
  140.             }
  141.         }
  142.         if(maschera.accordiCooperazione){
  143.             if(this.accordiCooperazione){
  144.                 if(bf.length()>0)
  145.                     bf.append(separatore);
  146.                 bf.append(Permessi.ACCORDI_COOPERAZIONE.toString());
  147.             }
  148.         }
  149.         return bf.toString();
  150.     }
  151.    
  152.     public static PermessiUtente toPermessiUtente(String value){
  153.         PermessiUtente permUtenti = new PermessiUtente();
  154.         if(value.contains(Permessi.SERVIZI.toString())){
  155.             permUtenti.setServizi(true);
  156.         }
  157.         if(value.contains(Permessi.DIAGNOSTICA.toString())){
  158.             permUtenti.setDiagnostica(true);
  159.         }
  160.         if(value.contains(Permessi.REPORTISTICA.toString())){
  161.             permUtenti.setReportistica(true);
  162.         }
  163.         if(value.contains(Permessi.SISTEMA.toString())){
  164.             permUtenti.setSistema(true);
  165.         }
  166.         if(value.contains(Permessi.CODE_MESSAGGI.toString())){
  167.             permUtenti.setCodeMessaggi(true);
  168.         }
  169.         if(value.contains(Permessi.AUDITING.toString())){
  170.             permUtenti.setAuditing(true);
  171.         }
  172.         if(value.contains(Permessi.UTENTI.toString())){
  173.             permUtenti.setUtenti(true);
  174.         }
  175.         if(value.contains(Permessi.ACCORDI_COOPERAZIONE.toString())){
  176.             permUtenti.setAccordiCooperazione(true);
  177.         }
  178.         return permUtenti;
  179.     }
  180.    
  181.    
  182.    
  183.     public boolean isAccordiCooperazione() {
  184.         return this.accordiCooperazione;
  185.     }

  186.     public void setAccordiCooperazione(boolean accordiCooperazione) {
  187.         this.accordiCooperazione = accordiCooperazione;
  188.     }

  189.     public boolean isServizi() {
  190.         return this.servizi;
  191.     }


  192.     public void setServizi(boolean servizi) {
  193.         this.servizi = servizi;
  194.     }


  195.     public boolean isDiagnostica() {
  196.         return this.diagnostica;
  197.     }


  198.     public void setDiagnostica(boolean diagnostica) {
  199.         this.diagnostica = diagnostica;
  200.     }
  201.    
  202.    
  203.     public boolean isReportistica() {
  204.         return this.reportistica;
  205.     }


  206.     public void setReportistica(boolean reportistica) {
  207.         this.reportistica = reportistica;
  208.     }


  209.     public boolean isSistema() {
  210.         return this.sistema;
  211.     }


  212.     public void setSistema(boolean sistema) {
  213.         this.sistema = sistema;
  214.     }


  215.     public boolean isCodeMessaggi() {
  216.         return this.codeMessaggi;
  217.     }


  218.     public void setCodeMessaggi(boolean codeMessaggi) {
  219.         this.codeMessaggi = codeMessaggi;
  220.     }


  221.     public boolean isAuditing() {
  222.         return this.auditing;
  223.     }


  224.     public void setAuditing(boolean auditing) {
  225.         this.auditing = auditing;
  226.     }


  227.     public boolean isUtenti() {
  228.         return this.utenti;
  229.     }


  230.     public void setUtenti(boolean utenti) {
  231.         this.utenti = utenti;
  232.     }
  233.    
  234.    
  235.     public boolean or(PermessiUtente permessi){
  236.         boolean ok = false;
  237.         if(this.isAuditing()){
  238.             if(permessi.isAuditing()){
  239.                 ok = true;
  240.             }
  241.         }
  242.         if(this.isCodeMessaggi()){
  243.             if(permessi.isCodeMessaggi()){
  244.                 ok = true;
  245.             }
  246.         }
  247.         if(this.isDiagnostica()){
  248.             if(permessi.isDiagnostica()){
  249.                 ok = true;
  250.             }
  251.         }
  252.         if(this.isReportistica()){
  253.             if(permessi.isReportistica()){
  254.                 ok = true;
  255.             }
  256.         }
  257.         if(this.isServizi()){
  258.             if(permessi.isServizi()){
  259.                 ok = true;
  260.             }
  261.         }
  262.         if(this.isSistema()){
  263.             if(permessi.isSistema()){
  264.                 ok = true;
  265.             }
  266.         }
  267.         if(this.isUtenti()){
  268.             if(permessi.isUtenti()){
  269.                 ok = true;
  270.             }
  271.         }
  272.         if(this.isAccordiCooperazione()){
  273.             if(permessi.isAccordiCooperazione()){
  274.                 ok = true;
  275.             }
  276.         }
  277.         return ok;
  278.     }
  279.    
  280.     public boolean and(PermessiUtente permessi){
  281.         if(this.isAuditing()){
  282.             if(permessi.isAuditing()){
  283.                 return false;
  284.             }
  285.         }
  286.         if(this.isCodeMessaggi()){
  287.             if(permessi.isCodeMessaggi()){
  288.                 return false;
  289.             }
  290.         }
  291.         if(this.isDiagnostica()){
  292.             if(permessi.isDiagnostica()){
  293.                 return false;
  294.             }
  295.         }
  296.         if(this.isReportistica()){
  297.             if(permessi.isReportistica()){
  298.                 return false;
  299.             }
  300.         }
  301.         if(this.isServizi()){
  302.             if(permessi.isServizi()){
  303.                 return false;
  304.             }
  305.         }
  306.         if(this.isSistema()){
  307.             if(permessi.isSistema()){
  308.                 return false;
  309.             }
  310.         }
  311.         if(this.isUtenti()){
  312.             if(permessi.isUtenti()){
  313.                 return false;
  314.             }
  315.         }
  316.         if(this.isAccordiCooperazione()){
  317.             if(permessi.isAccordiCooperazione()){
  318.                 return false;
  319.             }
  320.         }
  321.         return true;
  322.     }
  323. }