PorteApplicativeMTOM.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.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.MtomProcessor;
  32. import org.openspcoop2.core.config.MtomProcessorFlow;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.config.constants.MTOMProcessorType;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.Parameter;
  44. import org.openspcoop2.web.lib.mvc.ServletUtils;
  45. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  46. /***
  47.  *
  48.  * PorteApplicativeMTOM
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteApplicativeMTOM extends Action {

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

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

  58.         // Inizializzo PageData
  59.         PageData pd = new PageData();

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

  61.         // Inizializzo GeneralData
  62.         GeneralData gd = generalHelper.initGeneralData(request);

  63.         try {
  64.             Boolean contaListe = ServletUtils.getContaListeFromSession(session);

  65.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  66.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  67.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  68.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  69.             String id = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  70.             int idInt = Integer.parseInt(id);
  71.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  72.             String mtomRichiesta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MTOM_RICHIESTA);
  73.             String mtomRisposta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_MTOM_RISPOSTA);
  74.             String applicaModificaS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_APPLICA_MODIFICA);
  75.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);
  76.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             String idTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  81.             if(!porteApplicativeHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  82.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  83.             }
  84.            
  85.             // Preparo il menu
  86.             porteApplicativeHelper.makeMenu();

  87.             // Prendo il nome della porta
  88.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  89.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  90.             String idporta = pa.getNome();

  91.             boolean visualizzazioneCompletaMTOM = porteApplicativeCore.isShowMTOMVisualizzazioneCompleta();

  92.             String [] modeMtomListRichiesta = null;
  93.             String [] modeMtomListRisposta = null;

  94.             if(visualizzazioneCompletaMTOM){
  95.                 modeMtomListRichiesta = new String [4];
  96.                 modeMtomListRichiesta[0] = MTOMProcessorType.DISABLE.getValue();
  97.                 modeMtomListRichiesta[1] =  MTOMProcessorType.PACKAGING.getValue();
  98.                 modeMtomListRichiesta[2] =  MTOMProcessorType.UNPACKAGING.getValue();
  99.                 modeMtomListRichiesta[3] =  MTOMProcessorType.VERIFY.getValue();

  100.                 modeMtomListRisposta = new String [4];
  101.                 modeMtomListRisposta[0] = MTOMProcessorType.DISABLE.getValue();
  102.                 modeMtomListRisposta[1] =   MTOMProcessorType.PACKAGING.getValue();
  103.                 modeMtomListRisposta[2] =   MTOMProcessorType.UNPACKAGING.getValue();
  104.                 modeMtomListRisposta[3] =   MTOMProcessorType.VERIFY.getValue();
  105.             }else {
  106.                 modeMtomListRichiesta = new String [3];
  107.                 modeMtomListRichiesta[0] = MTOMProcessorType.DISABLE.getValue();
  108.                 modeMtomListRichiesta[1] =  MTOMProcessorType.UNPACKAGING.getValue();
  109.                 modeMtomListRichiesta[2] =  MTOMProcessorType.VERIFY.getValue();

  110.                 modeMtomListRisposta = new String [3];
  111.                 modeMtomListRisposta[0] = MTOMProcessorType.DISABLE.getValue();
  112.                 modeMtomListRisposta[1] =   MTOMProcessorType.PACKAGING.getValue();
  113.                 modeMtomListRisposta[2] =   MTOMProcessorType.VERIFY.getValue();
  114.             }

  115.             // prelevo lo stato di MTOM
  116.             int numMTOMreq = 0;
  117.             int numMTOMres = 0;
  118.             boolean isMTOMAbilitatoReq = false;
  119.             boolean isMTOMAbilitatoRes= false;

  120.             MTOMProcessorType mtomReqTmp = null;
  121.             MTOMProcessorType mtomResTmp = null;

  122.             if(pa.getMtomProcessor()!= null){
  123.                 if(pa.getMtomProcessor().getRequestFlow() != null){
  124.                     numMTOMreq = pa.getMtomProcessor().getRequestFlow().sizeParameterList();
  125.                     mtomReqTmp = pa.getMtomProcessor().getRequestFlow().getMode();
  126.                 }

  127.                 if(pa.getMtomProcessor().getResponseFlow() != null){
  128.                     numMTOMres = pa.getMtomProcessor().getResponseFlow().sizeParameterList();
  129.                     mtomResTmp = pa.getMtomProcessor().getResponseFlow().getMode();
  130.                 }
  131.             }

  132.             if(mtomRichiesta == null){
  133.                 if(mtomReqTmp == null)
  134.                     mtomRichiesta = MTOMProcessorType.DISABLE.getValue();
  135.                 else
  136.                     mtomRichiesta = mtomReqTmp.getValue();
  137.             }

  138.             if(mtomRisposta == null){
  139.                 if(mtomResTmp == null)
  140.                     mtomRisposta = MTOMProcessorType.DISABLE.getValue();
  141.                 else
  142.                     mtomRisposta = mtomResTmp.getValue();
  143.             }

  144.             // calcolo lo stato di richiesta e risposta
  145.             if(!mtomRichiesta.equals(MTOMProcessorType.DISABLE.getValue()) && !mtomRichiesta.equals(MTOMProcessorType.UNPACKAGING.getValue()))
  146.                 isMTOMAbilitatoReq = true;

  147.             if(!mtomRisposta.equals(MTOMProcessorType.DISABLE.getValue()) && !mtomRisposta.equals(MTOMProcessorType.UNPACKAGING.getValue()))
  148.                 isMTOMAbilitatoRes = true;
  149.            
  150.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  151.            
  152.             String labelPerPorta = null;
  153.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  154.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  155.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI,
  156.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM,
  157.                         pa);
  158.             }
  159.             else {
  160.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI+idporta;
  161.             }
  162.            
  163.             lstParam.add(new Parameter(labelPerPorta,  null));
  164.            
  165.             // setto la barra del titolo
  166.             ServletUtils.setPageDataTitle(pd, lstParam);
  167.            
  168.             // imposta menu' contestuale
  169.             porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);

  170.             Parameter[] urlParms = {
  171.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID,id)   ,
  172.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO,idsogg),
  173.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS,idAsps) };
  174.             Parameter url1 = new Parameter("", PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM_REQUEST_LIST , urlParms);
  175.             Parameter url2 = new Parameter("", PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE_LIST , urlParms);

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


  177.                 // preparo i campi
  178.                 List<DataElement> dati = new ArrayList<>();
  179.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  180.                 // Parametri per la form di abilitazione
  181.                 dati = porteApplicativeHelper.addMTOMToDati(dati, modeMtomListRichiesta,modeMtomListRisposta, mtomRichiesta, mtomRisposta,
  182.                         isMTOMAbilitatoReq ? url1.getValue() : null,
  183.                                 isMTOMAbilitatoRes ? url2.getValue() : null,
  184.                                         contaListe, numMTOMreq, numMTOMres);
  185.                
  186.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null,idAsps, dati);

  187.                 pd.setDati(dati);

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

  189.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  190.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM, ForwardParams.OTHER(""));
  191.             }

  192.             // Controlli sui campi immessi
  193.             boolean isOk = porteApplicativeHelper.MTOMCheckData(TipoOperazione.OTHER);
  194.             if (!isOk) {
  195.                 // preparo i campi
  196.                 List<DataElement> dati = new ArrayList<>();

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

  198.                 // Parametri per la form di abilitazione
  199.                 dati = porteApplicativeHelper.addMTOMToDati(dati, modeMtomListRichiesta, modeMtomListRisposta,mtomRichiesta, mtomRisposta,
  200.                         isMTOMAbilitatoReq ? url1.getValue() : null,
  201.                                 isMTOMAbilitatoRes ? url2.getValue() : null,
  202.                                         contaListe, numMTOMreq, numMTOMres);
  203.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null,idAsps, dati);

  204.                 pd.setDati(dati);

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

  206.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  207.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM,
  208.                         ForwardParams.OTHER(""));
  209.             }


  210.             // Modifico i dati della porta delegata nel db
  211.             MTOMProcessorType nuovoValoreRichiesta = MTOMProcessorType.toEnumConstant(mtomRichiesta);
  212.             MTOMProcessorType nuovoValoreRisposta = MTOMProcessorType.toEnumConstant(mtomRisposta);

  213.             // se il processor e' null lo creo
  214.             if(pa.getMtomProcessor() == null){
  215.                 MtomProcessor mtomProcessor = new MtomProcessor();
  216.                 pa.setMtomProcessor(mtomProcessor);
  217.             }

  218.             if(pa.getMtomProcessor().getRequestFlow() == null){
  219.                 MtomProcessorFlow requestFlow = new MtomProcessorFlow();
  220.                 pa.getMtomProcessor().setRequestFlow(requestFlow);
  221.             }

  222.             if(pa.getMtomProcessor().getResponseFlow() == null){
  223.                 MtomProcessorFlow responseFlow = new MtomProcessorFlow();
  224.                 pa.getMtomProcessor().setResponseFlow(responseFlow);
  225.             }

  226.             pa.getMtomProcessor().getRequestFlow().setMode(nuovoValoreRichiesta);
  227.             pa.getMtomProcessor().getResponseFlow().setMode(nuovoValoreRisposta);

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

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

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

  232.             // Aggiorno valori MTOM request e response
  233.             pa = porteApplicativeCore.getPortaApplicativa(idInt);

  234.             numMTOMreq = 0;
  235.             numMTOMres = 0;
  236.             isMTOMAbilitatoReq = false;
  237.             isMTOMAbilitatoRes= false;

  238.             if(pa.getMtomProcessor()!= null){
  239.                 if(pa.getMtomProcessor().getRequestFlow() != null){
  240.                     numMTOMreq = pa.getMtomProcessor().getRequestFlow().sizeParameterList();
  241.                     mtomReqTmp = pa.getMtomProcessor().getRequestFlow().getMode();
  242.                 }

  243.                 if(pa.getMtomProcessor().getResponseFlow() != null){
  244.                     numMTOMres = pa.getMtomProcessor().getResponseFlow().sizeParameterList();
  245.                     mtomResTmp = pa.getMtomProcessor().getResponseFlow().getMode();
  246.                 }
  247.             }

  248.             if(mtomReqTmp == null)
  249.                 mtomRichiesta = MTOMProcessorType.DISABLE.getValue();
  250.             else
  251.                 mtomRichiesta = mtomReqTmp.getValue();

  252.             if(mtomResTmp == null)
  253.                 mtomRisposta = MTOMProcessorType.DISABLE.getValue();
  254.             else
  255.                 mtomRisposta = mtomResTmp.getValue();

  256.             // calcolo lo stato di richiesta e risposta
  257.             if(!mtomRichiesta.equals(MTOMProcessorType.DISABLE.getValue()) && !mtomRichiesta.equals(MTOMProcessorType.UNPACKAGING.getValue()))
  258.                 isMTOMAbilitatoReq = true;

  259.             if(!mtomRisposta.equals(MTOMProcessorType.DISABLE.getValue()) && !mtomRisposta.equals(MTOMProcessorType.UNPACKAGING.getValue()))
  260.                 isMTOMAbilitatoRes = true;

  261.             //  Parametri per la form di abilitazione
  262.             dati = porteApplicativeHelper.addMTOMToDati(dati, modeMtomListRichiesta,modeMtomListRisposta, mtomRichiesta, mtomRisposta,
  263.                     isMTOMAbilitatoReq ? url1.getValue() : null,
  264.                             isMTOMAbilitatoRes ? url2.getValue() : null,
  265.                                     contaListe, numMTOMreq, numMTOMres);
  266.             dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null, idAsps, dati);

  267.             pd.setDati(dati);
  268.            
  269.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  270.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  271.            
  272.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  273.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  274.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM,
  275.                     ForwardParams.OTHER(""));
  276.         } catch (Exception e) {
  277.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  278.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM ,
  279.                     ForwardParams.OTHER(""));
  280.         }
  281.     }

  282. }