PorteDelegateValidazioneContenuti.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.pd;

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

  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.PortaDelegata;
  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.  * PorteDelegateValidazioneContenuti
  57.  *
  58.  * @author Poli Andrea (poli@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  */
  62. public class PorteDelegateValidazioneContenuti 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 = true;

  72.         try {
  73.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  75.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  76.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  77.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  78.             int idInt = Integer.parseInt(id);
  79.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  80.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";
  83.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  84.             if(idFruizione == null)
  85.                 idFruizione = "";

  86.             String statoValidazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_XSD);
  87.             String tipoValidazione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE);
  88.             String applicaMTOM = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MTOM);

  89.             String applicaModificaS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MODIFICA);
  90.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);

  91.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  92.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  93.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  94.             }

  95.             // Preparo il menu
  96.             porteDelegateHelper.makeMenu();

  97.             // Prendo il nome della porta
  98.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  99.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  100.             AccordiServizioParteComuneCore aspcCore = new AccordiServizioParteComuneCore(porteDelegateCore);

  101.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  102.             String idporta = portaDelegata.getNome();

  103.             IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromValues(portaDelegata.getServizio().getTipo(), portaDelegata.getServizio().getNome(),
  104.                     portaDelegata.getSoggettoErogatore().getTipo(), portaDelegata.getSoggettoErogatore().getNome(), portaDelegata.getServizio().getVersione());
  105.             long idServizioLong = aspsCore.getIdAccordoServizioParteSpecifica(idServizio);
  106.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idServizioLong, false);
  107.             AccordoServizioParteComuneSintetico aspc = aspcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  108.            
  109.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);

  110.             String labelPerPorta = null;
  111.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  112.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  113.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI_CONFIG_DI,
  114.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI,
  115.                         portaDelegata);
  116.             }
  117.             else {
  118.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI_CONFIG_DI+idporta;
  119.             }
  120.             lstParam.add(new Parameter(labelPerPorta,  null));

  121.             // setto la barra del titolo
  122.             ServletUtils.setPageDataTitle(pd, lstParam);
  123.            
  124.             // imposto menu' contestuale
  125.             porteDelegateHelper.impostaComandiMenuContestualePD(idSoggFruitore, idAsps, idFruizione);

  126.             if( porteDelegateHelper.isEditModeInProgress() && !applicaModifica){

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

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

  163.                 porteDelegateHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  164.                         ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  165.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  166.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  167.                 pd.setDati(dati);

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

  169.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  170.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI, ForwardParams.OTHER(""));
  171.             }

  172.             // Controlli sui campi immessi
  173.             boolean isOk = porteDelegateHelper.validazioneContenutiCheck(TipoOperazione.OTHER, isPortaDelegata);

  174.             if (!isOk) {
  175.                 // preparo i campi
  176.                 List<DataElement> dati = new ArrayList<>();

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

  178.                 porteDelegateHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  179.                         ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  180.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  181.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  182.                 pd.setDati(dati);

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

  184.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  185.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI,
  186.                         ForwardParams.OTHER(""));
  187.             }

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

  198.             portaDelegata.setValidazioneContenutiApplicativi(vx);

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

  200.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);

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

  203.             portaDelegata = porteDelegateCore.getPortaDelegata(idInt);

  204.             if (statoValidazione == null) {
  205.                 vx = portaDelegata.getValidazioneContenutiApplicativi();
  206.                 if (vx == null) {
  207.                     statoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_DISABILITATO;
  208.                 } else {
  209.                     if(vx.getStato()!=null)
  210.                         statoValidazione = vx.getStato().toString();
  211.                     if ((statoValidazione == null) || "".equals(statoValidazione)) {
  212.                         statoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_VALIDAZIONE_DISABILITATO;
  213.                     }
  214.                 }
  215.             }
  216.             if (tipoValidazione == null) {
  217.                 vx = portaDelegata.getValidazioneContenutiApplicativi();
  218.                 if (vx == null) {
  219.                     tipoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE_INTERFACE;
  220.                 } else {
  221.                     if(vx.getTipo()!=null)
  222.                         tipoValidazione = vx.getTipo().toString();
  223.                     if (tipoValidazione == null || "".equals(tipoValidazione)) {
  224.                         tipoValidazione = PorteDelegateCostanti.DEFAULT_VALUE_PARAMETRO_PORTE_DELEGATE_TIPO_VALIDAZIONE_INTERFACE ;
  225.                     }
  226.                 }
  227.             }
  228.             if (applicaMTOM == null) {
  229.                 vx = portaDelegata.getValidazioneContenutiApplicativi();
  230.                 applicaMTOM = "";
  231.                 if (vx != null &&
  232.                     vx.getAcceptMtomMessage()!=null &&
  233.                         vx.getAcceptMtomMessage().equals(StatoFunzionalita.ABILITATO)) {
  234.                     applicaMTOM = Costanti.CHECK_BOX_ENABLED;
  235.                 }
  236.             }

  237.             porteDelegateHelper.validazioneContenuti(TipoOperazione.OTHER,dati, isPortaDelegata, statoValidazione, tipoValidazione, applicaMTOM,
  238.                     ServiceBinding.valueOf(aspc.getServiceBinding().name()), aspc.getFormatoSpecifica());

  239.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  240.                     idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  241.             pd.setDati(dati);

  242.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  243.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  244.            
  245.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  246.             // Forward control to the specified success URI
  247.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI,
  248.                     ForwardParams.OTHER(""));

  249.         } catch (Exception e) {
  250.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  251.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_VALIDAZIONE_CONTENUTI,
  252.                     ForwardParams.OTHER(""));
  253.         }
  254.     }
  255. }