PorteDelegateMTOM.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.MtomProcessor;
  32. import org.openspcoop2.core.config.MtomProcessorFlow;
  33. import org.openspcoop2.core.config.PortaDelegata;
  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.  * PorteDelegateMTOM
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteDelegateMTOM 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  66.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  67.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  68.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  69.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  70.             int idInt = Integer.parseInt(id);
  71.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  72.             String mtomRichiesta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MTOM_RICHIESTA);
  73.             String mtomRisposta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_MTOM_RISPOSTA);
  74.             String applicaModificaS = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_APPLICA_MODIFICA);
  75.             boolean applicaModifica = ServletUtils.isCheckBoxEnabled(applicaModificaS);
  76.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  81.             if(idFruizione == null)
  82.                 idFruizione = "";
  83.            
  84.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  85.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  86.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  87.             }
  88.            
  89.             // Preparo il menu
  90.             porteDelegateHelper.makeMenu();

  91.             // Prendo il nome della porta
  92.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  93.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  94.             String idporta = pde.getNome();

  95.             boolean visualizzazioneCompletaMTOM = porteDelegateCore.isShowMTOMVisualizzazioneCompleta();

  96.             String [] modeMtomListRichiesta = null;
  97.             String [] modeMtomListRisposta = null;

  98.             if(visualizzazioneCompletaMTOM){
  99.                 modeMtomListRichiesta = new String [4];
  100.                 modeMtomListRichiesta[0] = MTOMProcessorType.DISABLE.getValue();
  101.                 modeMtomListRichiesta[1] =  MTOMProcessorType.PACKAGING.getValue();
  102.                 modeMtomListRichiesta[2] =  MTOMProcessorType.UNPACKAGING.getValue();
  103.                 modeMtomListRichiesta[3] =  MTOMProcessorType.VERIFY.getValue();

  104.                 modeMtomListRisposta = new String [4];
  105.                 modeMtomListRisposta[0] = MTOMProcessorType.DISABLE.getValue();
  106.                 modeMtomListRisposta[1] =   MTOMProcessorType.PACKAGING.getValue();
  107.                 modeMtomListRisposta[2] =   MTOMProcessorType.UNPACKAGING.getValue();
  108.                 modeMtomListRisposta[3] =   MTOMProcessorType.VERIFY.getValue();
  109.             }else {
  110.                 modeMtomListRichiesta = new String [3];
  111.                 modeMtomListRichiesta[0] = MTOMProcessorType.DISABLE.getValue();
  112.                 modeMtomListRichiesta[1] =  MTOMProcessorType.PACKAGING.getValue();
  113.                 modeMtomListRichiesta[2] =  MTOMProcessorType.VERIFY.getValue();

  114.                 modeMtomListRisposta = new String [3];
  115.                 modeMtomListRisposta[0] = MTOMProcessorType.DISABLE.getValue();
  116.                 modeMtomListRisposta[1] =   MTOMProcessorType.UNPACKAGING.getValue();
  117.                 modeMtomListRisposta[2] =   MTOMProcessorType.VERIFY.getValue();
  118.             }


  119.             // prelevo lo stato di MTOM
  120.             int numMTOMreq = 0;
  121.             int numMTOMres = 0;
  122.             boolean isMTOMAbilitatoReq = false;
  123.             boolean isMTOMAbilitatoRes= false;

  124.             MTOMProcessorType mtomReqTmp = null;
  125.             MTOMProcessorType mtomResTmp = null;

  126.             if(pde.getMtomProcessor()!= null){
  127.                 if(pde.getMtomProcessor().getRequestFlow() != null){
  128.                     numMTOMreq = pde.getMtomProcessor().getRequestFlow().sizeParameterList();
  129.                     mtomReqTmp = pde.getMtomProcessor().getRequestFlow().getMode();
  130.                 }

  131.                 if(pde.getMtomProcessor().getResponseFlow() != null){
  132.                     numMTOMres = pde.getMtomProcessor().getResponseFlow().sizeParameterList();
  133.                     mtomResTmp = pde.getMtomProcessor().getResponseFlow().getMode();
  134.                 }
  135.             }

  136.             if(mtomRichiesta == null){
  137.                 if(mtomReqTmp == null)
  138.                     mtomRichiesta = MTOMProcessorType.DISABLE.getValue();
  139.                 else
  140.                     mtomRichiesta = mtomReqTmp.getValue();
  141.             }

  142.             if(mtomRisposta == null){
  143.                 if(mtomResTmp == null)
  144.                     mtomRisposta = MTOMProcessorType.DISABLE.getValue();
  145.                 else
  146.                     mtomRisposta = mtomResTmp.getValue();
  147.             }

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

  151.             if(!mtomRisposta.equals(MTOMProcessorType.DISABLE.getValue()) && !mtomRisposta.equals(MTOMProcessorType.UNPACKAGING.getValue()))
  152.                 isMTOMAbilitatoRes = true;
  153.            
  154.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  155.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  156.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  157.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);

  158.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  159.            
  160.             String labelPerPorta = null;
  161.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  162.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  163.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI,
  164.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG,
  165.                         pde);
  166.             }
  167.             else {
  168.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI+idporta;
  169.             }
  170.             lstParam.add(new Parameter(labelPerPorta,  null));
  171.            
  172.             // setto la barra del titolo
  173.             ServletUtils.setPageDataTitle(pd, lstParam);
  174.            
  175.             // imposto menu' contestuale
  176.             porteDelegateHelper.impostaComandiMenuContestualePD(idsogg, idAsps, idFruizione);

  177.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  178.            
  179.             Parameter url1 = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM_REQUEST_LIST , urlParms);
  180.             Parameter url2 = new Parameter("", PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM_RESPONSE_LIST , urlParms);

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


  182.                 // preparo i campi
  183.                 List<DataElement> dati = new ArrayList<>();
  184.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  185.                 // Parametri per la form di abilitazione
  186.                 dati = porteDelegateHelper.addMTOMToDati(dati, modeMtomListRichiesta,modeMtomListRisposta, mtomRichiesta, mtomRisposta,
  187.                         isMTOMAbilitatoReq ? url1.getValue() : null,
  188.                                 isMTOMAbilitatoRes ? url2.getValue() : null,
  189.                                         contaListe, numMTOMreq, numMTOMres);

  190.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  191.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  192.                 pd.setDati(dati);

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

  194.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  195.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM, ForwardParams.OTHER(""));
  196.             }

  197.             // Controlli sui campi immessi
  198.             boolean isOk = porteDelegateHelper.MTOMCheckData(TipoOperazione.OTHER);
  199.             if (!isOk) {
  200.                 // preparo i campi
  201.                 List<DataElement> dati = new ArrayList<>();

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

  203.                 // Parametri per la form di abilitazione
  204.                 dati = porteDelegateHelper.addMTOMToDati(dati, modeMtomListRichiesta,modeMtomListRisposta ,mtomRichiesta, mtomRisposta,
  205.                         isMTOMAbilitatoReq ? url1.getValue() : null,
  206.                                 isMTOMAbilitatoRes ? url2.getValue() : null,
  207.                                         contaListe, numMTOMreq, numMTOMres);

  208.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  209.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  210.                 pd.setDati(dati);

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

  212.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  213.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM,
  214.                         ForwardParams.OTHER(""));
  215.             }


  216.             // Modifico i dati della porta delegata nel db
  217.             MTOMProcessorType nuovoValoreRichiesta = MTOMProcessorType.toEnumConstant(mtomRichiesta);
  218.             MTOMProcessorType nuovoValoreRisposta = MTOMProcessorType.toEnumConstant(mtomRisposta);

  219.             // se il processor e' null lo creo
  220.             if(pde.getMtomProcessor() == null){
  221.                 MtomProcessor mtomProcessor = new MtomProcessor();
  222.                 pde.setMtomProcessor(mtomProcessor);
  223.             }

  224.             if(pde.getMtomProcessor().getRequestFlow() == null){
  225.                 MtomProcessorFlow requestFlow = new MtomProcessorFlow();
  226.                 pde.getMtomProcessor().setRequestFlow(requestFlow);
  227.             }

  228.             if(pde.getMtomProcessor().getResponseFlow() == null){
  229.                 MtomProcessorFlow responseFlow = new MtomProcessorFlow();
  230.                 pde.getMtomProcessor().setResponseFlow(responseFlow);
  231.             }

  232.             pde.getMtomProcessor().getRequestFlow().setMode(nuovoValoreRichiesta);
  233.             pde.getMtomProcessor().getResponseFlow().setMode(nuovoValoreRisposta);

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

  235.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

  238.             // Aggiorno valori MTOM request e response
  239.             pde = porteDelegateCore.getPortaDelegata(idInt);

  240.             numMTOMreq = 0;
  241.             numMTOMres = 0;
  242.             isMTOMAbilitatoReq = false;
  243.             isMTOMAbilitatoRes= false;

  244.             if(pde.getMtomProcessor()!= null){
  245.                 if(pde.getMtomProcessor().getRequestFlow() != null){
  246.                     numMTOMreq = pde.getMtomProcessor().getRequestFlow().sizeParameterList();
  247.                     mtomReqTmp = pde.getMtomProcessor().getRequestFlow().getMode();
  248.                 }

  249.                 if(pde.getMtomProcessor().getResponseFlow() != null){
  250.                     numMTOMres = pde.getMtomProcessor().getResponseFlow().sizeParameterList();
  251.                     mtomResTmp = pde.getMtomProcessor().getResponseFlow().getMode();
  252.                 }
  253.             }

  254.             if(mtomReqTmp == null)
  255.                 mtomRichiesta = MTOMProcessorType.DISABLE.getValue();
  256.             else
  257.                 mtomRichiesta = mtomReqTmp.getValue();

  258.             if(mtomResTmp == null)
  259.                 mtomRisposta = MTOMProcessorType.DISABLE.getValue();
  260.             else
  261.                 mtomRisposta = mtomResTmp.getValue();

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

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

  267.             //  Parametri per la form di abilitazione
  268.             dati = porteDelegateHelper.addMTOMToDati(dati, modeMtomListRichiesta,modeMtomListRisposta, mtomRichiesta, mtomRisposta,
  269.                     isMTOMAbilitatoReq ? url1.getValue() : null,
  270.                             isMTOMAbilitatoRes ? url2.getValue() : null,
  271.                                     contaListe, numMTOMreq, numMTOMres);

  272.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, id, idsogg, null, idAsps,
  273.                     idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  274.             pd.setDati(dati);
  275.            
  276.             pd.setMessage(CostantiControlStation.LABEL_AGGIORNAMENTO_EFFETTUATO_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);
  277.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  278.            
  279.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  280.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  281.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM,
  282.                     ForwardParams.OTHER(""));
  283.         } catch (Exception e) {
  284.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  285.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM ,
  286.                     ForwardParams.OTHER(""));
  287.         }
  288.     }

  289. }