PorteApplicativeValidazioneContenuti.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.ctrlstat.servlet.pa;

  21. import java.util.ArrayList;
  22. import java.util.List;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.config.PortaApplicativa;
  32. import org.openspcoop2.core.config.ValidazioneContenutiApplicativi;
  33. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  34. import org.openspcoop2.core.config.constants.StatoFunzionalitaConWarning;
  35. import org.openspcoop2.core.config.constants.ValidazioneContenutiApplicativiTipo;
  36. import org.openspcoop2.core.id.IDServizio;
  37. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  39. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  40. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  41. import org.openspcoop2.message.constants.ServiceBinding;
  42. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  43. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  44. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  45. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  46. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  47. import org.openspcoop2.web.lib.mvc.Costanti;
  48. import org.openspcoop2.web.lib.mvc.DataElement;
  49. import org.openspcoop2.web.lib.mvc.ForwardParams;
  50. import org.openspcoop2.web.lib.mvc.GeneralData;
  51. import org.openspcoop2.web.lib.mvc.PageData;
  52. import org.openspcoop2.web.lib.mvc.Parameter;
  53. import org.openspcoop2.web.lib.mvc.ServletUtils;
  54. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  55. /**    
  56.  * PorteApplicativeValidazioneContenuti
  57.  *
  58.  * @author Poli Andrea (poli@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  */
  62. public class PorteApplicativeValidazioneContenuti extends Action {

  63.     @Override
  64.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  65.         HttpSession session = request.getSession(true);

  66.         // Inizializzo PageData
  67.         PageData pd = new PageData();

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         // Inizializzo GeneralData
  70.         GeneralData gd = generalHelper.initGeneralData(request);

  71.         boolean isPortaDelegata = false;

  72.         try {
  73.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  75.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  76.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  77.             String id = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  78.             int idInt = Integer.parseInt(id);
  79.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  80.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";

  83.             String applicaModificaS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_APPLICA_MODIFICA);
  84.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);

  85.             String statoValidazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_XSD);
  86.             String tipoValidazione = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE);
  87.             String applicaMTOM = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_APPLICA_MTOM);

  88.             String idTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  89.             if(!porteApplicativeHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  90.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  91.             }

  92.             // Preparo il menu
  93.             porteApplicativeHelper.makeMenu();

  94.             // Prendo il nome della porta
  95.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  96.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  97.             AccordiServizioParteComuneCore aspcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);

  98.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  99.             String idporta = pa.getNome();

  100.             IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(pa.getServizio().getTipo(), pa.getServizio().getNome(),
  101.                     pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario(), pa.getServizio().getVersione());
  102.             long idServizioLong = aspsCore.getIdAccordoServizioParteSpecifica(idServizio);
  103.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idServizioLong, false);
  104.             AccordoServizioParteComuneSintetico aspc = aspcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  105.            
  106.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  107.             String labelPerPorta = null;
  108.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  109.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  110.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI_CONFIG_DI,
  111.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI,
  112.                         pa);
  113.             }
  114.             else {
  115.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI_CONFIG_DI+idporta;
  116.             }
  117.            
  118.             lstParam.add(new Parameter(labelPerPorta,  null));

  119.             // setto la barra del titolo
  120.             ServletUtils.setPageDataTitle(pd, lstParam);
  121.            
  122.             // imposta menu' contestuale
  123.             porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);

  124.             if( porteApplicativeHelper.isEditModeInProgress() && !applicaModifica){

  125.                 if (statoValidazione == null) {
  126.                     ValidazioneContenutiApplicativi vx = pa.getValidazioneContenutiApplicativi();
  127.                     if (vx == null) {
  128.                         statoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_DISABILITATO;
  129.                     } else {
  130.                         if(vx.getStato()!=null)
  131.                             statoValidazione = vx.getStato().toString();
  132.                         if ((statoValidazione == null) || "".equals(statoValidazione)) {
  133.                             statoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_DISABILITATO;
  134.                         }
  135.                     }
  136.                 }
  137.                 if (tipoValidazione == null) {
  138.                     ValidazioneContenutiApplicativi vx = pa.getValidazioneContenutiApplicativi();
  139.                     if (vx == null) {
  140.                         tipoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE_INTERFACE;
  141.                     } else {
  142.                         if(vx.getTipo()!=null && !StatoFunzionalitaConWarning.DISABILITATO.equals(vx.getStato()))
  143.                             tipoValidazione = vx.getTipo().toString();
  144.                         if (tipoValidazione == null || "".equals(tipoValidazione)) {
  145.                             tipoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE_INTERFACE ;
  146.                         }
  147.                     }
  148.                 }
  149.                 if (applicaMTOM == null) {
  150.                     ValidazioneContenutiApplicativi vx = pa.getValidazioneContenutiApplicativi();
  151.                     applicaMTOM = "";
  152.                     if (vx != null &&
  153.                         vx.getAcceptMtomMessage()!=null &&
  154.                             vx.getAcceptMtomMessage().equals(StatoFunzionalita.ABILITATO)) {
  155.                         applicaMTOM = Costanti.CHECK_BOX_ENABLED;
  156.                     }
  157.                 }

  158.                 // preparo i campi
  159.                 List<DataElement> dati = new ArrayList<>();
  160.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  161.                 porteApplicativeHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  162.                         ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  163.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null,idAsps, dati);

  164.                 pd.setDati(dati);

  165.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  166.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  167.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI, ForwardParams.OTHER(""));
  168.             }

  169.             // Controlli sui campi immessi
  170.             boolean isOk = porteApplicativeHelper.validazioneContenutiCheck(TipoOperazione.OTHER, isPortaDelegata);

  171.             if (!isOk) {
  172.                 // preparo i campi
  173.                 List<DataElement> dati = new ArrayList<>();

  174.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  175.                 porteApplicativeHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  176.                         ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  177.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null,idAsps, dati);

  178.                 pd.setDati(dati);

  179.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  180.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  181.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI,
  182.                         ForwardParams.OTHER(""));
  183.             }

  184.             ValidazioneContenutiApplicativi vx = new ValidazioneContenutiApplicativi();
  185.             vx.setStato(StatoFunzionalitaConWarning.toEnumConstant(statoValidazione));
  186.             vx.setTipo(ValidazioneContenutiApplicativiTipo.toEnumConstant(tipoValidazione));
  187.             if(applicaMTOM != null){
  188.                 if(ServletUtils.isCheckBoxEnabled(applicaMTOM))
  189.                     vx.setAcceptMtomMessage(StatoFunzionalita.ABILITATO);
  190.                 else
  191.                     vx.setAcceptMtomMessage(StatoFunzionalita.DISABILITATO);
  192.             } else
  193.                 vx.setAcceptMtomMessage(null);

  194.             pa.setValidazioneContenutiApplicativi(vx);

  195.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  196.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

  197.             // preparo i campi
  198.             List<DataElement> dati = new ArrayList<>();

  199.             pa = porteApplicativeCore.getPortaApplicativa(idInt);

  200.             if (statoValidazione == null) {
  201.                 vx = pa.getValidazioneContenutiApplicativi();
  202.                 if (vx == null) {
  203.                     statoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_DISABILITATO;
  204.                 } else {
  205.                     if(vx.getStato()!=null)
  206.                         statoValidazione = vx.getStato().toString();
  207.                     if ((statoValidazione == null) || "".equals(statoValidazione)) {
  208.                         statoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_VALIDAZIONE_DISABILITATO;
  209.                     }
  210.                 }
  211.             }
  212.             if (tipoValidazione == null) {
  213.                 vx = pa.getValidazioneContenutiApplicativi();
  214.                 if (vx == null) {
  215.                     tipoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE_INTERFACE;
  216.                 } else {
  217.                     if(vx.getTipo()!=null)
  218.                         tipoValidazione = vx.getTipo().toString();
  219.                     if (tipoValidazione == null || "".equals(tipoValidazione)) {
  220.                         tipoValidazione = PorteApplicativeCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_APPLICATIVE_TIPO_VALIDAZIONE_INTERFACE ;
  221.                     }
  222.                 }
  223.             }
  224.             if (applicaMTOM == null) {
  225.                 vx = pa.getValidazioneContenutiApplicativi();
  226.                 applicaMTOM = "";
  227.                 if (vx != null &&
  228.                     vx.getAcceptMtomMessage()!=null &&
  229.                         vx.getAcceptMtomMessage().equals(StatoFunzionalita.ABILITATO)) {
  230.                             applicaMTOM = Costanti.CHECK_BOX_ENABLED;
  231.                 }
  232.             }

  233.             porteApplicativeHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  234.                     ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  235.             dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null,idAsps, dati);

  236.             pd.setDati(dati);

  237.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  238.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  239.            
  240.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  241.             // Forward control to the specified success URI
  242.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI,
  243.                     ForwardParams.OTHER(""));

  244.         } catch (Exception e) {
  245.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  246.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_VALIDAZIONE_CONTENUTI ,
  247.                     ForwardParams.OTHER(""));
  248.         }
  249.     }          
  250. }