AttachmentsReader.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.pdd.core.dynamic;

  21. import java.io.Serializable;

  22. import org.openspcoop2.core.id.IDAccordo;
  23. import org.openspcoop2.core.id.IDServizio;
  24. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  25. import org.openspcoop2.core.registry.constants.TipiDocumentoLivelloServizio;
  26. import org.openspcoop2.core.registry.constants.TipiDocumentoSemiformale;
  27. import org.openspcoop2.core.registry.constants.TipiDocumentoSicurezza;
  28. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  29. import org.openspcoop2.core.registry.driver.DriverRegistroServiziNotFound;
  30. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  31. import org.openspcoop2.protocol.registry.RegistroServiziManager;
  32. import org.openspcoop2.protocol.sdk.state.RequestInfo;

  33. /**
  34.  * SystemPropertiesReader
  35.  *
  36.  * @author Andrea Poli (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class AttachmentsReader implements Serializable {

  41.     private static final long serialVersionUID = 1L;
  42.    
  43.     private IDServizio idServizio;
  44.     private IDAccordo idAccordo;
  45.     private transient RegistroServiziManager registroServiziManagerField;
  46.     private RequestInfo requestInfo;
  47.    
  48.     public AttachmentsReader(IDServizio idServizio, RequestInfo requestInfo) {
  49.         this.idServizio = idServizio;
  50.         this.registroServiziManagerField = RegistroServiziManager.getInstance();
  51.         this.requestInfo = requestInfo;
  52.     }
  53.    
  54.     private RegistroServiziManager getRegistroServiziManager() {
  55.         if(this.registroServiziManagerField==null) {
  56.             this.registroServiziManagerField = RegistroServiziManager.getInstance();
  57.         }
  58.         return this.registroServiziManagerField;
  59.     }
  60.    
  61.     private IDAccordo getIDAccordo() throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  62.         if(this.idAccordo==null) {
  63.             AccordoServizioParteSpecifica asps = this.getRegistroServiziManager().getAccordoServizioParteSpecifica(this.idServizio, null, false, this.requestInfo);
  64.             this.idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  65.         }
  66.         return this.idAccordo;
  67.     }
  68.        
  69.     public byte[] read(String nome) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  70.         return read(nome, false);
  71.     }
  72.     public byte[] read(String nome, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  73.         try {
  74.             return this.getRegistroServiziManager().getAllegato(this.idServizio, nome, this.requestInfo).getByteContenuto();
  75.         }catch(DriverRegistroServiziNotFound notFound) {
  76.             byte[] bNull = null;
  77.             if(throwNotFoundException) {
  78.                 throw notFound;
  79.             }
  80.             else {
  81.                 return bNull;
  82.             }
  83.         }
  84.     }
  85.    
  86.     public byte[] readSemiformalDocumentation(String nome, String tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  87.         return readSemiformalDocumentation(nome, TipiDocumentoSemiformale.toEnumConstant(tipo), false);
  88.     }
  89.     public byte[] readSemiformalDocumentation(String nome, String tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  90.         return readSemiformalDocumentation(nome, TipiDocumentoSemiformale.toEnumConstant(tipo), throwNotFoundException);
  91.     }
  92.     public byte[] readSemiformalDocumentation(String nome, TipiDocumentoSemiformale tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  93.         return readSemiformalDocumentation(nome, tipo, false);
  94.     }
  95.     public byte[] readSemiformalDocumentation(String nome, TipiDocumentoSemiformale tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  96.         try {
  97.             return this.getRegistroServiziManager().getSpecificaSemiformale(this.idServizio, tipo, nome, this.requestInfo).getByteContenuto();
  98.         }catch(DriverRegistroServiziNotFound notFound) {
  99.             byte[] bNull = null;
  100.             if(throwNotFoundException) {
  101.                 throw notFound;
  102.             }
  103.             else {
  104.                 return bNull;
  105.             }
  106.         }
  107.     }

  108.     public byte[] readSecurityDocumentation(String nome, String tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  109.         return readSecurityDocumentation(nome, TipiDocumentoSicurezza.toEnumConstant(tipo), false);
  110.     }
  111.     public byte[] readSecurityDocumentation(String nome, String tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  112.         return readSecurityDocumentation(nome, TipiDocumentoSicurezza.toEnumConstant(tipo), throwNotFoundException);
  113.     }
  114.     public byte[] readSecurityDocumentation(String nome, TipiDocumentoSicurezza tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  115.         return readSecurityDocumentation(nome, tipo, false);
  116.     }
  117.     public byte[] readSecurityDocumentation(String nome, TipiDocumentoSicurezza tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  118.         try {
  119.             return this.getRegistroServiziManager().getSpecificaSicurezza(this.idServizio, tipo, nome, this.requestInfo).getByteContenuto();
  120.         }catch(DriverRegistroServiziNotFound notFound) {
  121.             byte[] bNull = null;
  122.             if(throwNotFoundException) {
  123.                 throw notFound;
  124.             }
  125.             else {
  126.                 return bNull;
  127.             }
  128.         }
  129.     }
  130.    
  131.     public byte[] readServiceLevelDocumentation(String nome, String tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  132.         return readServiceLevelDocumentation(nome, TipiDocumentoLivelloServizio.toEnumConstant(tipo), false);
  133.     }
  134.     public byte[] readServiceLevelDocumentation(String nome, String tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  135.         return readServiceLevelDocumentation(nome, TipiDocumentoLivelloServizio.toEnumConstant(tipo), throwNotFoundException);
  136.     }
  137.     public byte[] readServiceLevelDocumentation(String nome, TipiDocumentoLivelloServizio tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  138.         return readServiceLevelDocumentation(nome, tipo, false);
  139.     }
  140.     public byte[] readServiceLevelDocumentation(String nome, TipiDocumentoLivelloServizio tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  141.         try {
  142.             return this.getRegistroServiziManager().getSpecificaLivelloServizio(this.idServizio, tipo, nome, this.requestInfo).getByteContenuto();
  143.         }catch(DriverRegistroServiziNotFound notFound) {
  144.             byte[] bNull = null;
  145.             if(throwNotFoundException) {
  146.                 throw notFound;
  147.             }
  148.             else {
  149.                 return bNull;
  150.             }
  151.         }
  152.     }

  153.    
  154.     public byte[] readFromApi(String nome) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  155.         return readFromApi(nome, false);
  156.     }
  157.     public byte[] readFromApi(String nome, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  158.         try {
  159.             return this.getRegistroServiziManager().getAllegato(getIDAccordo(), nome, this.requestInfo).getByteContenuto();
  160.         }catch(DriverRegistroServiziNotFound notFound) {
  161.             byte[] bNull = null;
  162.             if(throwNotFoundException) {
  163.                 throw notFound;
  164.             }
  165.             else {
  166.                 return bNull;
  167.             }
  168.         }
  169.     }
  170.    
  171.     public byte[] readSemiformalDocumentationFromApi(String nome, String tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  172.         return readSemiformalDocumentationFromApi(nome, TipiDocumentoSemiformale.toEnumConstant(tipo), false);
  173.     }
  174.     public byte[] readSemiformalDocumentationFromApi(String nome, String tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  175.         return readSemiformalDocumentationFromApi(nome, TipiDocumentoSemiformale.toEnumConstant(tipo), throwNotFoundException);
  176.     }
  177.     public byte[] readSemiformalDocumentationFromApi(String nome, TipiDocumentoSemiformale tipo) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  178.         return readSemiformalDocumentationFromApi(nome, tipo, false);
  179.     }
  180.     public byte[] readSemiformalDocumentationFromApi(String nome, TipiDocumentoSemiformale tipo, boolean throwNotFoundException) throws DriverRegistroServiziException, DriverRegistroServiziNotFound {
  181.         try {
  182.             return this.getRegistroServiziManager().getSpecificaSemiformale(getIDAccordo(), tipo, nome, this.requestInfo).getByteContenuto();
  183.         }catch(DriverRegistroServiziNotFound notFound) {
  184.             byte[] bNull = null;
  185.             if(throwNotFoundException) {
  186.                 throw notFound;
  187.             }
  188.             else {
  189.                 return bNull;
  190.             }
  191.         }
  192.     }
  193. }