GestoreRepositoryBitOrAndFunction.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.protocol.engine.driver.repository;

  21. import org.openspcoop2.protocol.sdk.ProtocolException;


  22. /**
  23.  * Classe utilizzata per accedere ai flag di accesso al repository da parte di:
  24.  *  HISTORY: Busta usata per funzionalita di confermaRicezione(OUTBOX)/FiltroDuplicati(INBOX)
  25.  *  PROFILI: Busta usata per funzionalita di profili di collaborazione
  26.  *  PDD:     Busta usata eventualmente da un PdD
  27.  *
  28.  *
  29.  * @author Manca Andrea (manca@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class GestoreRepositoryBitOrAndFunction  implements IGestoreRepository{
  34.     // Bit 2^0 = PDD
  35.     // Bit 2^1 = PROFILO
  36.     // Bit 2^2 = HISTORY
  37.    
  38.     private static final int OR_MASK_PDD = 1; // mask-bit 001 da utilizzare con OR
  39.     private static final int OR_MASK_PROFILO = 2; // mask-bit 010 da utilizzare con OR
  40.     private static final int OR_MASK_HISTORY = 4; // mask-bit 100 da utilizzare con OR
  41.     private static final int AND_MASK_PDD = 6; // mask-bit 110 da utilizzare con AND
  42.     private static final int AND_MASK_PROFILO = 5; // mask-bit 1.4 da utilizzare con AND
  43.     private static final int AND_MASK_HISTORY = 3; // mask-bit 011 da utilizzare con AND
  44.    
  45.     // Tabella dei valori
  46.     private static final int HISTORY_PROFILO_PDD = 7;  // 111
  47.     private static final int HISTORY_PROFILO = 6;  // 110
  48.     private static final int HISTORY_PDD = 5;  // 101
  49.     private static final int PROFILO_PDD = 3;  // 011
  50.     private static final int HISTORY = 4; // 100
  51.     private static final int PROFILO = 2; // 010
  52.     private static final int PDD = 1; // 001
  53.     private static final int NONE = 0; // 000
  54.    
  55.     /**
  56.      * Imposta la modalita' di accesso per l'history
  57.      *
  58.      * @param value
  59.      */
  60.     @Override
  61.     public String createSQLSet_History(boolean value) throws ProtocolException{
  62.         if(value)
  63.             return "REPOSITORY_ACCESS = (bitor(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.OR_MASK_HISTORY+"))";
  64.         else
  65.             return "REPOSITORY_ACCESS = (bitand(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.AND_MASK_HISTORY+"))";
  66.     }
  67.    
  68.     /**
  69.      * Imposta la modalita' di accesso per i profili di collaborazione
  70.      *
  71.       * @param value
  72.      */
  73.     @Override
  74.     public String createSQLSet_ProfiloCollaborazione(boolean value) throws ProtocolException{
  75.         if(value)
  76.             return "REPOSITORY_ACCESS = (bitor(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.OR_MASK_PROFILO+"))";
  77.         else
  78.             return "REPOSITORY_ACCESS = (bitand(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.AND_MASK_PROFILO+"))";
  79.     }
  80.    
  81.     /**
  82.      * Imposta la modalita' di accesso per una pdd
  83.      *
  84.       * @param value
  85.      */
  86.     @Override
  87.     public String createSQLSet_PdD(boolean value) throws ProtocolException{
  88.         if(value)
  89.             return "REPOSITORY_ACCESS = (bitor(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.OR_MASK_PDD+"))";
  90.         else
  91.             return "REPOSITORY_ACCESS = (bitand(REPOSITORY_ACCESS,"+GestoreRepositoryBitOrAndFunction.AND_MASK_PDD+"))";
  92.     }
  93.    
  94.     /**
  95.      * @param value Indicazione sull'utilizzo
  96.      */
  97.     @Override
  98.     public String createSQLCondition_History(boolean value) throws ProtocolException{
  99.         if(value)
  100.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO_PDD+
  101.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PDD+
  102.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO+
  103.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY+")";
  104.        
  105.         else
  106.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO_PDD+
  107.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PDD+
  108.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO+
  109.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.NONE+")";
  110.     }
  111.    
  112.     /**
  113.      * @param value Indicazione sull'utilizzo
  114.      */
  115.     @Override
  116.     public String createSQLCondition_ProfiloCollaborazione(boolean value) throws ProtocolException{
  117.         if(value)
  118.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO_PDD+
  119.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO_PDD+
  120.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO+
  121.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO+")";
  122.        
  123.         else
  124.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PDD+
  125.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PDD+
  126.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY+
  127.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.NONE+")";
  128.     }
  129.    
  130.     /**
  131.      * @param value Indicazione sull'utilizzo
  132.      */
  133.     @Override
  134.     public String createSQLCondition_PdD(boolean value) throws ProtocolException{
  135.         if(value)
  136.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO_PDD+
  137.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO_PDD+
  138.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PDD+
  139.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PDD+")";
  140.        
  141.         else
  142.             return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY_PROFILO+
  143.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO+
  144.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY+
  145.                " OR REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.NONE+")";
  146.     }


  147.     @Override
  148.     public String createSQLCondition_enableOnlyHistory() throws ProtocolException{
  149.         return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.HISTORY+")";
  150.     }
  151.      

  152.     @Override
  153.     public String createSQLCondition_enableOnlyPdd() throws ProtocolException{
  154.         return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PDD+")";
  155.     }
  156.    

  157.     @Override
  158.     public String createSQLCondition_enableOnlyProfilo() throws ProtocolException{
  159.         return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO+")";
  160.     }
  161.    

  162.     @Override
  163.     public String createSQLCondition_enableOnlyPddAndProfilo() throws ProtocolException{
  164.         return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.PROFILO_PDD+")";
  165.     }
  166.    

  167.     @Override
  168.     public String createSQLCondition_disabledAll() throws ProtocolException{
  169.         return "(REPOSITORY_ACCESS="+GestoreRepositoryBitOrAndFunction.NONE+")";
  170.     }
  171.    
  172.     /**
  173.      * Ritorna il valore da associare al field che gestisce l'History
  174.      *
  175.      * @return SQLField Value
  176.      * @throws ProtocolException
  177.      */
  178.     @Override
  179.     public String getSQLValueHistory(boolean history) throws ProtocolException{
  180.         if(history)
  181.             return GestoreRepositoryBitOrAndFunction.HISTORY+"";
  182.         else
  183.             return GestoreRepositoryBitOrAndFunction.NONE+"";
  184.     }
  185.    
  186.     /**
  187.      * Ritorna i field che gestiscono la modalita di accesso al Repository
  188.      *
  189.      * @return SQL Field
  190.      * @throws ProtocolException
  191.      */
  192.     @Override
  193.     public String createSQLFields() throws ProtocolException{
  194.         return "REPOSITORY_ACCESS";
  195.     }
  196.    
  197.     /**
  198.      * Ritorna il field che gestisce la modalita di accesso all'History flag
  199.      *
  200.      * @return SQL Field History
  201.      * @throws ProtocolException
  202.      */
  203.     @Override
  204.     public String createSQLFieldHistory() throws ProtocolException{
  205.         return "REPOSITORY_ACCESS";
  206.     }

  207. }