AlarmContext.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.monitor.engine.alarm;

  21. import java.util.Date;
  22. import java.util.HashMap;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.apache.commons.lang.StringUtils;
  26. import org.openspcoop2.core.allarmi.Allarme;
  27. import org.openspcoop2.core.allarmi.utils.ProjectInfo;
  28. import org.openspcoop2.core.commons.dao.DAOFactory;
  29. import org.openspcoop2.core.commons.dao.DAOFactoryProperties;
  30. import org.openspcoop2.core.constants.TipoPdD;
  31. import org.openspcoop2.generic_project.beans.IProjectInfo;
  32. import org.openspcoop2.monitor.sdk.constants.CRUDType;
  33. import org.openspcoop2.monitor.sdk.constants.SearchType;
  34. import org.openspcoop2.monitor.sdk.parameters.Parameter;
  35. import org.openspcoop2.protocol.sdk.builder.EsitoTransazione;
  36. import org.openspcoop2.utils.TipiDatabase;
  37. import org.slf4j.Logger;

  38. /**
  39.  * AlarmContext
  40.  *
  41.  * @author Poli Andrea (apoli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class AlarmContext implements org.openspcoop2.monitor.sdk.condition.AlarmContext{
  46.    
  47.     private Allarme allarme;
  48.     private Logger log;
  49.     private DAOFactory daoFactory;
  50.     private List<Parameter<?>> parameters;

  51.     public AlarmContext(Allarme allarme,Logger log, DAOFactory daoFactory){
  52.         this(allarme, log, daoFactory, null);
  53.     }
  54.    
  55.     public AlarmContext(Allarme allarme,Logger log, DAOFactory daoFactory,List<Parameter<?>> parameters){
  56.         this.allarme = allarme;
  57.         this.log = log;
  58.         this.daoFactory = daoFactory;
  59.         this.parameters = parameters;
  60.     }

  61.     public void setParameters(List<Parameter<?>> parameters) {
  62.         this.parameters = parameters;
  63.     }
  64.    
  65.     @Override
  66.     public SearchType getTipoRicerca() {
  67.         return SearchType.ALL;
  68.     }

  69.     @Override
  70.     public Date getIntervalloInferiore() {
  71.         return null;
  72.     }

  73.     @Override
  74.     public Date getIntervalloSuperiore() {
  75.         return null;
  76.     }

  77.     @Override
  78.     public String getTipoSoggettoMittente(){
  79.         if(this.allarme!=null &&
  80.                 this.allarme.getFiltro()!=null &&
  81.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getTipoFruitore()) &&
  82.                 !"*".equals(this.allarme.getFiltro().getTipoFruitore())
  83.             ){
  84.             return this.allarme.getFiltro().getTipoFruitore();          
  85.         }
  86.         return null;
  87.     }
  88.     @Override
  89.     public String getSoggettoMittente(){
  90.         if(this.allarme!=null &&
  91.                 this.allarme.getFiltro()!=null &&
  92.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getNomeFruitore()) &&
  93.                 !"*".equals(this.allarme.getFiltro().getNomeFruitore())
  94.             ){
  95.             return this.allarme.getFiltro().getNomeFruitore();          
  96.         }
  97.         return null;
  98.     }
  99.    
  100.     @Override
  101.     public String getTipoSoggettoDestinatario(){
  102.         if(this.allarme!=null &&
  103.                 this.allarme.getFiltro()!=null &&
  104.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getTipoErogatore()) &&
  105.                 !"*".equals(this.allarme.getFiltro().getTipoErogatore())
  106.             ){
  107.             return this.allarme.getFiltro().getTipoErogatore();        
  108.         }
  109.         return null;
  110.     }
  111.     @Override
  112.     public String getSoggettoDestinatario(){
  113.         if(this.allarme!=null &&
  114.                 this.allarme.getFiltro()!=null &&
  115.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getNomeErogatore()) &&
  116.                 !"*".equals(this.allarme.getFiltro().getNomeErogatore())
  117.             ){
  118.             return this.allarme.getFiltro().getNomeErogatore();        
  119.         }
  120.         return null;
  121.     }
  122.    
  123.     @Override
  124.     public String getTipoServizio(){
  125.         if(this.allarme!=null &&
  126.                 this.allarme.getFiltro()!=null &&
  127.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getTipoServizio()) &&
  128.                 !"*".equals(this.allarme.getFiltro().getTipoServizio())
  129.             ){
  130.             return this.allarme.getFiltro().getTipoServizio();          
  131.         }
  132.         return null;
  133.     }
  134.     @Override
  135.     public String getServizio(){
  136.         if(this.allarme!=null &&
  137.                 this.allarme.getFiltro()!=null &&
  138.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getNomeServizio()) &&
  139.                 !"*".equals(this.allarme.getFiltro().getNomeServizio())
  140.             ){
  141.             return this.allarme.getFiltro().getNomeServizio();          
  142.         }
  143.         return null;
  144.     }
  145.     @Override
  146.     public Integer getVersioneServizio() {
  147.         if(this.allarme!=null &&
  148.                 this.allarme.getFiltro()!=null &&
  149.                 this.allarme.getFiltro().getVersioneServizio()!=null &&
  150.                 this.allarme.getFiltro().getVersioneServizio()>0
  151.             ){
  152.             return this.allarme.getFiltro().getVersioneServizio();          
  153.         }
  154.         return null;
  155.     }

  156.     @Override
  157.     public String getAzione() {
  158.         if(this.allarme!=null &&
  159.                 this.allarme.getFiltro()!=null &&
  160.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getAzione()) &&
  161.                 !"*".equals(this.allarme.getFiltro().getAzione())
  162.             ){
  163.             return this.allarme.getFiltro().getAzione();            
  164.         }
  165.         return null;
  166.     }

  167.     @Override
  168.     public String getInterfaccia() {
  169.         if(this.allarme!=null &&
  170.                 this.allarme.getFiltro()!=null &&
  171.                 StringUtils.isNotEmpty(this.allarme.getFiltro().getNomePorta()) &&
  172.                 !"*".equals(this.allarme.getFiltro().getNomePorta())
  173.             ){
  174.             return this.allarme.getFiltro().getNomePorta();        
  175.         }
  176.         return null;
  177.     }
  178.    
  179.     @Override
  180.     public TipoPdD getRuolo() {
  181.         if(this.allarme!=null &&
  182.                 this.allarme.getFiltro()!=null &&
  183.                 this.allarme.getFiltro().getRuoloPorta()!=null)
  184.             {
  185.             switch (this.allarme.getFiltro().getRuoloPorta()) {
  186.             case DELEGATA:
  187.                 return TipoPdD.DELEGATA;
  188.             case APPLICATIVA:
  189.                 return TipoPdD.APPLICATIVA;
  190.             default:
  191.                 return null;
  192.             }
  193.         }
  194.         return null;
  195.     }
  196.    
  197.     @Override
  198.     public EsitoTransazione getEsitoTransazione() {
  199.         return null; // non dovrebbe venire usato
  200.     }

  201.     @Override
  202.     public Parameter<?> getParameter(String paramID) {
  203.         return this.getParameters().get(paramID);
  204.     }

  205.     @Override
  206.     public Map<String, Parameter<?>> getParameters() {
  207.         // 2020/10/09 modifica per salvataggio in console
  208.         Map<String, Parameter<?>> map  =  new HashMap<String, Parameter<?>>();
  209.         if(this.parameters != null){
  210.             for (Parameter<?> param : this.parameters) {
  211.                 map.put(param.getId(), param);
  212.             }
  213.         }
  214.         return map;
  215.     }


  216.     @Override
  217.     public TipiDatabase getDatabaseType() {
  218.         return _getTipoDatabase(ProjectInfo.getInstance());
  219.     }

  220.     public TipiDatabase _getTipoDatabase(IProjectInfo nomeDAO) {
  221.         try{
  222.             DAOFactoryProperties prop =  DAOFactoryProperties.getInstance(this.getLogger());
  223.             return prop.getTipoDatabaseEnum(nomeDAO);
  224.         }catch(Exception e){
  225.             this.log.error(e.getMessage(),e);
  226.             return null;
  227.         }
  228.     }

  229.     @Override
  230.     public Logger getLogger() {
  231.         return this.log;
  232.     }

  233.     @Override
  234.     public DAOFactory getDAOFactory() {
  235.         return this.daoFactory;
  236.     }
  237.    
  238.     @Override
  239.     public CRUDType getTipoOperazione() {
  240.         if(this.allarme!=null && this.allarme.getId()!=null &&
  241.                 this.allarme.getId()>0) {
  242.             return CRUDType.UPDATE;
  243.         }
  244.         else {
  245.             return CRUDType.CREATE;
  246.         }
  247.     }

  248.     @Override
  249.     public Allarme getConfigAllarme() {
  250.         return this.allarme;
  251.     }
  252. }