GestoreRepositoryOracle.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 Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class GestoreRepositoryOracle implements IGestoreRepository{

  34.     // Nota: con Oracle viene utilizzato il 2,3 e 4 bit, quindi i valori 2, 4 e 8
  35.     // Bit 2^1 = PDD
  36.     // Bit 2^2 = PROFILO
  37.     // Bit 2^3 = HISTORY
  38.    
  39.     private static final String OR_MASK_PDD = "'C103'"; // number:2, mask-bit 001 da utilizzare con OR
  40.     private static final String OR_MASK_PROFILO = "'C105'"; // number:4, mask-bit 010 da utilizzare con OR
  41.     private static final String OR_MASK_HISTORY = "'C109'"; // number:8, mask-bit 100 da utilizzare con OR
  42.     private static final String AND_MASK_PDD = "'C10D'"; // number:12, mask-bit 110 da utilizzare con AND
  43.     private static final String AND_MASK_PROFILO = "'C10B'"; // number:10, mask-bit 1.4 da utilizzare con AND
  44.     private static final String AND_MASK_HISTORY = "'C107'"; // number:6, mask-bit 011 da utilizzare con AND
  45.    
  46.     // Tabella dei valori
  47.     private static final String HISTORY_PROFILO_PDD = "'C10F'";  // number:14, bit: 111
  48.     private static final String HISTORY_PROFILO = "'C10D'";  // number:12, bit: 110
  49.     private static final String HISTORY_PDD = "'C10B'";  // number:10, bit: 101
  50.     private static final String PROFILO_PDD = "'C107'";  // number:6, bit: 011
  51.     private static final String HISTORY = "'C109'"; // number:8, bit: 100
  52.     private static final String PROFILO = "'C105'"; // number:4, bit: 010
  53.     private static final String PDD = "'C103'"; // number:2, bit: 001
  54.     private static final String NONE = "'C101'"; // number:0, bit: 000
  55.    
  56.     /** Query di utility:
  57.      *
  58.      * CREATE TABLE TEST
  59.      * (
  60.      *     TIPO VARCHAR(255) NOT NULL,
  61.      *     T1 RAW(8) DEFAULT 'C101' NOT NULL
  62.      * );
  63.      *
  64.      * INSERT INTO TEST (TIPO) VALUES ('TIPO');
  65.      *
  66.      * select TIPO,T1,utl_raw.CAST_TO_NUMBER(T1) from TEST;
  67.      *
  68.      * select TIPO,T1,utl_raw.CAST_TO_NUMBER(T1) from TEST WHERE T1 ='C101';
  69.      *
  70.      * UPDATE TEST SET t1 = (utl_raw.bit_or(t1,utl_raw.CAST_FROM_NUMBER(2)))
  71.      *
  72.      * UPDATE TEST SET t1 = 'C101';
  73.      *
  74.      * */
  75.    
  76.     /**
  77.      * Imposta la modalita' di accesso per l'history
  78.      *
  79.      * @param value
  80.      */
  81.     @Override
  82.     public String createSQLSet_History(boolean value) throws ProtocolException{
  83.         if(value)
  84.             return "REPOSITORY_ACCESS = (utl_raw.bit_or(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.OR_MASK_HISTORY+"))";
  85.         else
  86.             return "REPOSITORY_ACCESS = (utl_raw.bit_and(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.AND_MASK_HISTORY+"))";
  87.     }
  88.    
  89.     /**
  90.      * Imposta la modalita' di accesso per i profili di collaborazione
  91.      *
  92.       * @param value
  93.      */
  94.     @Override
  95.     public String createSQLSet_ProfiloCollaborazione(boolean value) throws ProtocolException{
  96.         if(value)
  97.             return "REPOSITORY_ACCESS = (utl_raw.bit_or(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.OR_MASK_PROFILO+"))";
  98.         else
  99.             return "REPOSITORY_ACCESS = (utl_raw.bit_and(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.AND_MASK_PROFILO+"))";
  100.     }
  101.    
  102.     /**
  103.      * Imposta la modalita' di accesso per una pdd
  104.      *
  105.       * @param value
  106.      */
  107.     @Override
  108.     public String createSQLSet_PdD(boolean value) throws ProtocolException{
  109.         if(value)
  110.             return "REPOSITORY_ACCESS = (utl_raw.bit_or(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.OR_MASK_PDD+"))";
  111.         else
  112.             return "REPOSITORY_ACCESS = (utl_raw.bit_and(REPOSITORY_ACCESS,"+GestoreRepositoryOracle.AND_MASK_PDD+"))";
  113.     }
  114.    
  115.     /**
  116.      * @param value Indicazione sull'utilizzo
  117.      */
  118.     @Override
  119.     public String createSQLCondition_History(boolean value) throws ProtocolException{
  120.        
  121.         if(value)
  122.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO_PDD+
  123.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PDD+
  124.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO+
  125.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY+" )";
  126.         else
  127.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO_PDD+
  128.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PDD+
  129.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO+
  130.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.NONE+" )";
  131.     }
  132.    
  133.     /**
  134.      * @param value Indicazione sull'utilizzo
  135.      */
  136.     @Override
  137.     public String createSQLCondition_ProfiloCollaborazione(boolean value) throws ProtocolException{
  138.         if(value)
  139.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO_PDD+
  140.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO_PDD+
  141.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO+
  142.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO+" )";
  143.        
  144.         else
  145.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PDD+
  146.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PDD+
  147.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY+
  148.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.NONE+" )";
  149.     }
  150.    
  151.     /**
  152.      * @param value Indicazione sull'utilizzo
  153.      */
  154.     @Override
  155.     public String createSQLCondition_PdD(boolean value) throws ProtocolException{
  156.         if(value)
  157.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO_PDD+
  158.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO_PDD+
  159.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PDD+
  160.                    " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PDD+" )";
  161.        
  162.         else
  163.             return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY_PROFILO+
  164.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO+
  165.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY+
  166.                " OR REPOSITORY_ACCESS="+GestoreRepositoryOracle.NONE+" )";
  167.     }


  168.     @Override
  169.     public String createSQLCondition_enableOnlyHistory() throws ProtocolException{
  170.         return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.HISTORY+")";
  171.     }
  172.        

  173.     @Override
  174.     public String createSQLCondition_enableOnlyPdd() throws ProtocolException{
  175.         return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.PDD+")";
  176.     }
  177.    

  178.     @Override
  179.     public String createSQLCondition_enableOnlyProfilo() throws ProtocolException{
  180.         return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO+")";
  181.     }
  182.    

  183.     @Override
  184.     public String createSQLCondition_enableOnlyPddAndProfilo() throws ProtocolException{
  185.         return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.PROFILO_PDD+")";
  186.     }
  187.    

  188.     @Override
  189.     public String createSQLCondition_disabledAll() throws ProtocolException{
  190.         return "(REPOSITORY_ACCESS="+GestoreRepositoryOracle.NONE+")";
  191.     }

  192.    
  193.     /**
  194.      * Ritorna il valore da associare al field che gestisce l'History
  195.      *
  196.      * @return SQLField Value
  197.      * @throws ProtocolException
  198.      */
  199.     @Override
  200.     public String getSQLValueHistory(boolean history) throws ProtocolException{
  201.         if(history)
  202.             return GestoreRepositoryOracle.HISTORY+"";
  203.         else
  204.             return GestoreRepositoryOracle.NONE+"";
  205.     }
  206.    
  207.     /**
  208.      * Ritorna i field che gestiscono la modalita di accesso al Repository
  209.      *
  210.      * @return SQLField
  211.      * @throws ProtocolException
  212.      */
  213.     @Override
  214.     public String createSQLFields() throws ProtocolException{
  215.         return "REPOSITORY_ACCESS";
  216.     }
  217.    
  218.     /**
  219.      * Ritorna il field che gestisce la modalita di accesso all'History flag
  220.      *
  221.      * @return SQL Field History
  222.      * @throws ProtocolException
  223.      */
  224.     @Override
  225.     public String createSQLFieldHistory() throws ProtocolException{
  226.         return "REPOSITORY_ACCESS";
  227.     }
  228. }