PorteApplicativeTrasformazioniRispostaChange.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.Arrays;
  23. import java.util.List;

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

  27. import org.apache.commons.lang.StringUtils;
  28. import org.apache.struts.action.Action;
  29. import org.apache.struts.action.ActionForm;
  30. import org.apache.struts.action.ActionForward;
  31. import org.apache.struts.action.ActionMapping;
  32. import org.openspcoop2.core.commons.Liste;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.config.TrasformazioneRegola;
  35. import org.openspcoop2.core.config.TrasformazioneRegolaApplicabilitaRisposta;
  36. import org.openspcoop2.core.config.TrasformazioneRegolaRisposta;
  37. import org.openspcoop2.core.config.TrasformazioneSoapRisposta;
  38. import org.openspcoop2.core.config.Trasformazioni;
  39. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  40. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  41. import org.openspcoop2.message.constants.ServiceBinding;
  42. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  43. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  44. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  45. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  46. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  47. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  48. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  49. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  50. import org.openspcoop2.web.lib.mvc.DataElement;
  51. import org.openspcoop2.web.lib.mvc.ForwardParams;
  52. import org.openspcoop2.web.lib.mvc.GeneralData;
  53. import org.openspcoop2.web.lib.mvc.PageData;
  54. import org.openspcoop2.web.lib.mvc.Parameter;
  55. import org.openspcoop2.web.lib.mvc.ServletUtils;
  56. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  57. /**
  58.  * PorteApplicativeTrasformazioniRispostaChange
  59.  *
  60.  * @author Giuliano Pintori (pintori@link.it)
  61.  * @author $Author$
  62.  * @version $Rev$, $Date$
  63.  *
  64.  */
  65. public class PorteApplicativeTrasformazioniRispostaChange extends Action {

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

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

  69.         // Inizializzo PageData
  70.         PageData pd = new PageData();

  71.         GeneralHelper generalHelper = new GeneralHelper(session);
  72.        
  73.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  74.         // Inizializzo GeneralData
  75.         GeneralData gd = generalHelper.initGeneralData(request);
  76.        
  77.         try {
  78.            
  79.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  80.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  81.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  82.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  83.            
  84.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  85.             long idInt = Long.parseLong(idPorta);
  86.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  87.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  88.             if(idAsps == null)
  89.                 idAsps = "";
  90.            
  91.            
  92.             String first = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_FIRST);
  93.             String nomeRisposta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_NOME);
  94.            
  95.             String returnCode = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_STATUS);
  96.            
  97.             String statusMin = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_STATUS_MIN);
  98.             if(statusMin == null)
  99.                 statusMin = "";
  100.             String statusMax = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_STATUS_MAX);
  101.             if(statusMax == null)
  102.                 statusMax = "";
  103.             String pattern = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_PATTERN);
  104.             String contentType = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_CT);
  105.            
  106.             String idTrasformazioneS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE);
  107.             long idTrasformazione = Long.parseLong(idTrasformazioneS);
  108.            
  109.             String idTrasformazioneRispostaS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE_RISPOSTA);
  110.             long idTrasformazioneRisposta = Long.parseLong(idTrasformazioneRispostaS);
  111.            
  112.             String trasformazioneContenutoRispostaAbilitatoS  = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_ENABLED);
  113.             boolean trasformazioneContenutoRispostaAbilitato = trasformazioneContenutoRispostaAbilitatoS != null ? ServletUtils.isCheckBoxEnabled(trasformazioneContenutoRispostaAbilitatoS) : false;
  114.             String trasformazioneContenutoRispostaTipoS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_TIPO);
  115.             org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione trasformazioneContenutoRispostaTipo =
  116.                     trasformazioneContenutoRispostaTipoS != null ? org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.toEnumConstant(trasformazioneContenutoRispostaTipoS) :
  117.                         org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  118.             BinaryParameter trasformazioneContenutoRispostaTemplate = porteApplicativeHelper.getBinaryParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_TEMPLATE);
  119.             String trasformazioneContenutoRispostaTipoCheck = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_TIPO_CHECK);
  120.             String trasformazioneContenutoRispostaContentType = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONTENT_TYPE);
  121.             String trasformazioneContenutoRispostaReturnCode = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_RETURN_CODE);
  122.            
  123.             String trasformazioneRispostaSoapAbilitatoS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_TRANSFORMATION);
  124.             boolean trasformazioneRispostaSoapAbilitato = trasformazioneRispostaSoapAbilitatoS != null ? ServletUtils.isCheckBoxEnabled(trasformazioneRispostaSoapAbilitatoS) : false;
  125.             String trasformazioneRispostaSoapEnvelope = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE);
  126.             String trasformazioneRispostaSoapEnvelopeTipoS = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE_TIPO);
  127.             org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione trasformazioneRispostaSoapEnvelopeTipo =
  128.                     trasformazioneRispostaSoapEnvelopeTipoS != null ? org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.toEnumConstant(trasformazioneRispostaSoapEnvelopeTipoS) :
  129.                         org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  130.             BinaryParameter trasformazioneRispostaSoapEnvelopeTemplate = porteApplicativeHelper.getBinaryParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE_TEMPLATE);
  131.             String trasformazioneRispostaSoapEnvelopeTipoCheck = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE_TIPO_CHECK);

  132.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  133.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  134.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  135.             SoggettiCore soggettiCore = new SoggettiCore(porteApplicativeCore);
  136.            
  137.             // Preparo il menu
  138.             porteApplicativeHelper.makeMenu();

  139.             // Prendo nome della porta applicativa
  140.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  141.             String nomePorta = pa.getNome();
  142.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(pa.getTipoSoggettoProprietario());
  143.            
  144.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  145.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  146.             ServiceBinding serviceBindingMessage = apcCore.toMessageServiceBinding(apc.getServiceBinding());
  147.            
  148.             Trasformazioni trasformazioni = pa.getTrasformazioni();
  149.             TrasformazioneRegola oldRegola = null;
  150.             TrasformazioneRegolaRisposta oldRisposta = null;
  151.             for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  152.                 if(reg.getId().longValue() == idTrasformazione) {
  153.                     oldRegola = reg;
  154.                     break;
  155.                 }
  156.             }
  157.             if(oldRegola==null) {
  158.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  159.             }
  160.            
  161.             for (int j = 0; j < oldRegola.sizeRispostaList(); j++) {
  162.                 TrasformazioneRegolaRisposta risposta = oldRegola.getRisposta(j);
  163.                 if (risposta.getId().longValue() == idTrasformazioneRisposta) {
  164.                     oldRisposta = risposta;
  165.                     break;
  166.                 }
  167.             }
  168.             if(oldRisposta==null) {
  169.                 throw new Exception("TrasformazioneRegolaRisposta con id '"+idTrasformazioneRisposta+"' non trovata");
  170.             }
  171.            
  172.            
  173.             boolean trasformazioneContenutoRichiestaAbilitato = false;
  174.             boolean trasformazioneRichiestaRestAbilitato = false;
  175.             boolean trasformazioneRichiestaSoapAbilitato = false;
  176.             if(oldRegola.getRichiesta() != null) {
  177.                 trasformazioneContenutoRichiestaAbilitato = oldRegola.getRichiesta().getConversione();
  178.                 trasformazioneRichiestaRestAbilitato = oldRegola.getRichiesta().getTrasformazioneRest() != null;
  179.                 trasformazioneRichiestaSoapAbilitato = oldRegola.getRichiesta().getTrasformazioneSoap() != null;
  180.             }
  181.            
  182.             String nomeRispostaTitle = oldRisposta.getNome();
  183.             String nomeTrasformazione = oldRegola.getNome();
  184.             Parameter pIdTrasformazione = new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE, idTrasformazione+"");
  185.            
  186.             String postBackElementName = porteApplicativeHelper.getPostBackElementName();
  187.            
  188.             if (postBackElementName != null) {
  189.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_APPLICABILITA_STATUS)) {
  190.                     statusMin = "";
  191.                     statusMax = "";
  192.                 }
  193.                
  194.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_ENABLED)) {
  195.                     trasformazioneContenutoRispostaTipo = org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  196.                     trasformazioneContenutoRispostaContentType = "";
  197.                     trasformazioneRispostaSoapAbilitato = false;
  198.                     trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_DISABILITATO;
  199.                     trasformazioneRispostaSoapEnvelopeTipo = org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  200.                    
  201.                     porteApplicativeHelper.deleteBinaryParameters(trasformazioneContenutoRispostaTemplate, trasformazioneRispostaSoapEnvelopeTemplate);
  202.                 }
  203.                
  204.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_CONVERSIONE_TIPO)) {
  205.                     trasformazioneContenutoRispostaTipoCheck = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_REQ_CONVERSIONE_TIPO_CHECK_UPDATE_TIPO;
  206.                     porteApplicativeHelper.deleteBinaryParameters(trasformazioneContenutoRispostaTemplate);
  207.                 }
  208.                
  209.                 if(postBackElementName.equals(trasformazioneContenutoRispostaTemplate.getName()) &&
  210.                     StringUtils.isEmpty(trasformazioneContenutoRispostaTipoCheck)) {
  211.                     trasformazioneContenutoRispostaTipoCheck = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_REQ_CONVERSIONE_TIPO_CHECK_UPDATE_FILE;
  212.                 }
  213.                
  214.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_TRANSFORMATION)) {
  215.                     porteApplicativeHelper.deleteBinaryParameters(trasformazioneRispostaSoapEnvelopeTemplate);
  216.                     if(trasformazioneRispostaSoapAbilitato) {
  217.                         trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_DISABILITATO;
  218.                         trasformazioneRispostaSoapEnvelopeTipo = org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  219.                     }
  220.                 }
  221.                
  222.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE)) {
  223.                     porteApplicativeHelper.deleteBinaryParameters(trasformazioneRispostaSoapEnvelopeTemplate);
  224.                     if(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_AS_ATTACHMENT.equals(trasformazioneRispostaSoapEnvelope)) {
  225.                         trasformazioneRispostaSoapEnvelopeTipo = org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  226.                     }
  227.                 }
  228.                
  229.                 if(postBackElementName.equals(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_SOAP_ENVELOPE_TIPO)) {
  230.                     trasformazioneRispostaSoapEnvelopeTipoCheck = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_REQ_CONVERSIONE_TIPO_CHECK_UPDATE_TIPO;
  231.                     porteApplicativeHelper.deleteBinaryParameters(trasformazioneRispostaSoapEnvelopeTemplate);
  232.                 }
  233.                
  234.                 if(postBackElementName.equals(trasformazioneRispostaSoapEnvelopeTemplate.getName()) &&
  235.                     StringUtils.isEmpty(trasformazioneRispostaSoapEnvelopeTipoCheck)) {
  236.                     trasformazioneRispostaSoapEnvelopeTipoCheck = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_REQ_CONVERSIONE_TIPO_CHECK_UPDATE_FILE;
  237.                 }
  238.             }
  239.            
  240.             // parametri visualizzazione link
  241.             String servletTrasformazioniRispostaHeadersList = PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_HEADER_LIST;
  242.             int numeroTrasformazioniRispostaHeaders = oldRisposta.sizeHeaderList();
  243.            
  244.             List<Parameter> parametriInvocazioneServletTrasformazioniRispostaHeaders = new ArrayList<>();
  245.             parametriInvocazioneServletTrasformazioniRispostaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  246.             parametriInvocazioneServletTrasformazioniRispostaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  247.             parametriInvocazioneServletTrasformazioniRispostaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  248.             parametriInvocazioneServletTrasformazioniRispostaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE, idTrasformazioneS));
  249.             parametriInvocazioneServletTrasformazioniRispostaHeaders.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_TRASFORMAZIONE_RISPOSTA, idTrasformazioneRispostaS));
  250.            

  251.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  252.             String labelPerPorta = null;
  253.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  254.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  255.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI,
  256.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI,
  257.                         pa);
  258.             }
  259.             else {
  260.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_DI+nomePorta;
  261.             }

  262.             lstParam.add(new Parameter(labelPerPorta,
  263.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_LIST,
  264.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  265.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  266.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  267.                     ));
  268.            
  269.             lstParam.add(new Parameter(nomeTrasformazione, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_CHANGE,
  270.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  271.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  272.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps), pIdTrasformazione));
  273.            
  274.             String labelPag = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE;
  275.            
  276.             List<Parameter> parametriInvocazioneServletTrasformazioniRisposta = new ArrayList<>();
  277.             parametriInvocazioneServletTrasformazioniRisposta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  278.             parametriInvocazioneServletTrasformazioniRisposta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  279.             parametriInvocazioneServletTrasformazioniRisposta.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  280.             parametriInvocazioneServletTrasformazioniRisposta.add(pIdTrasformazione);
  281.            
  282.             lstParam.add(new Parameter(labelPag,PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA_LIST,parametriInvocazioneServletTrasformazioniRisposta));
  283.            
  284.             lstParam.add(new Parameter(nomeRispostaTitle, null));

  285.             ServletUtils.setPageDataTitle(pd, lstParam);
  286.            
  287.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  288.             // dati
  289.             if (porteApplicativeHelper.isEditModeInProgress()) {
  290.                 // preparo i campi
  291.                 List<DataElement> dati = new ArrayList<>();
  292.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  293.                
  294.                 // primo accesso
  295.                 if(first == null) {
  296.                    
  297.                     nomeRisposta = oldRisposta.getNome();
  298.                    
  299.                     TrasformazioneRegolaApplicabilitaRisposta applicabilita = oldRisposta.getApplicabilita();
  300.                    
  301.                     Integer statusMinInteger = applicabilita != null ? applicabilita.getReturnCodeMin() : null;
  302.                     Integer statusMaxInteger = applicabilita != null ? applicabilita.getReturnCodeMax() : null;
  303.                    
  304.                     if(statusMinInteger != null) {
  305.                         statusMin = statusMinInteger +"";
  306.                     }
  307.                    
  308.                     if(statusMaxInteger != null) {
  309.                         statusMax = statusMaxInteger +"";
  310.                     }
  311.                    
  312.                     // se e' stato salvato il valore 0 lo tratto come null
  313.                     if(statusMinInteger != null && statusMinInteger.intValue() <= 0) {
  314.                         statusMinInteger = null;
  315.                     }
  316.                    
  317.                     if(statusMaxInteger != null && statusMaxInteger.intValue() <= 0) {
  318.                         statusMaxInteger = null;
  319.                     }
  320.                    
  321.                     // Intervallo
  322.                     if(statusMinInteger != null && statusMaxInteger != null) {
  323.                         if(statusMaxInteger.longValue() == statusMinInteger.longValue()) // esatto
  324.                             returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_ESATTO;
  325.                         else
  326.                             returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_INTERVALLO;
  327.                     } else if(statusMinInteger != null && statusMaxInteger == null) { // definito solo l'estremo inferiore
  328.                         returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_INTERVALLO;
  329.                     } else if(statusMinInteger == null && statusMaxInteger != null) { // definito solo l'estremo superiore
  330.                         returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_INTERVALLO;
  331.                     } else { //entrambi null
  332.                         returnCode = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_QUALSIASI;
  333.                     }
  334.                    
  335.                     if(applicabilita != null) {
  336.                         pattern = applicabilita.getPattern();
  337.                         contentType = applicabilita.getContentTypeList() != null ? StringUtils.join(applicabilita.getContentTypeList(), ",") : "";  
  338.                     }  
  339.                    
  340.                     // dati contenuto
  341.                     trasformazioneContenutoRispostaAbilitato = oldRisposta.getConversione();
  342.                     trasformazioneContenutoRispostaTipo = StringUtils.isNotEmpty(oldRisposta.getConversioneTipo()) ?
  343.                             org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.toEnumConstant(oldRisposta.getConversioneTipo()) : org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  344.                     trasformazioneContenutoRispostaTemplate.setValue(oldRisposta.getConversioneTemplate());
  345.                     trasformazioneContenutoRispostaContentType = StringUtils.isNotEmpty(oldRisposta.getContentType()) ? oldRisposta.getContentType() : "";
  346.                     trasformazioneContenutoRispostaReturnCode = oldRisposta.getReturnCode() != null ? oldRisposta.getReturnCode() + "" : "";
  347.                    
  348.                     if(oldRisposta.getTrasformazioneSoap() == null) {
  349.                         trasformazioneRispostaSoapAbilitato = false;
  350.                         trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_DISABILITATO;
  351.                         trasformazioneRispostaSoapEnvelopeTipo = org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  352.                     } else {
  353.                         trasformazioneRispostaSoapAbilitato = true;
  354.                        
  355.                         if(oldRisposta.getTrasformazioneSoap().isEnvelope()) {
  356.                             if(oldRisposta.getTrasformazioneSoap().isEnvelopeAsAttachment()) {
  357.                                 trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_AS_ATTACHMENT;
  358.                             } else {
  359.                                 trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_AS_BODY;
  360.                             }
  361.                         } else {
  362.                             trasformazioneRispostaSoapEnvelope = CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_DISABILITATO;
  363.                         }
  364.                        
  365.                         trasformazioneRispostaSoapEnvelopeTipo = StringUtils.isNotEmpty(oldRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo()) ?
  366.                                 org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.toEnumConstant(oldRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTipo())
  367.                                 : org.openspcoop2.pdd.core.trasformazioni.TipoTrasformazione.EMPTY;
  368.                         trasformazioneRispostaSoapEnvelopeTemplate.setValue(oldRisposta.getTrasformazioneSoap().getEnvelopeBodyConversioneTemplate());
  369.                     }
  370.                 }

  371.                 dati = porteApplicativeHelper.addTrasformazioneRispostaToDati(TipoOperazione.CHANGE, protocollo, dati, idInt, oldRisposta, false, idTrasformazioneS, idTrasformazioneRispostaS,
  372.                         apc.getServiceBinding(),
  373.                         nomeRisposta,
  374.                         returnCode, statusMin, statusMax, pattern, contentType, servletTrasformazioniRispostaHeadersList, parametriInvocazioneServletTrasformazioniRispostaHeaders, numeroTrasformazioniRispostaHeaders,
  375.                         trasformazioneContenutoRichiestaAbilitato, trasformazioneRichiestaRestAbilitato, trasformazioneRichiestaSoapAbilitato,
  376.                         trasformazioneContenutoRispostaAbilitato, trasformazioneContenutoRispostaTipo, trasformazioneContenutoRispostaTemplate, trasformazioneContenutoRispostaTipoCheck, trasformazioneContenutoRispostaContentType, trasformazioneContenutoRispostaReturnCode,
  377.                         serviceBindingMessage, trasformazioneRispostaSoapAbilitato, trasformazioneRispostaSoapEnvelope, trasformazioneRispostaSoapEnvelopeTipo, trasformazioneRispostaSoapEnvelopeTemplate, trasformazioneRispostaSoapEnvelopeTipoCheck);
  378.                
  379.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);
  380.                
  381.                 pd.setDati(dati);

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

  383.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA, ForwardParams.CHANGE());
  384.             }
  385.            
  386.                
  387.             boolean isOk = porteApplicativeHelper.trasformazioniRispostaCheckData(TipoOperazione.CHANGE, oldRegola, oldRisposta,
  388.                     serviceBindingMessage);
  389.            
  390.             if(isOk) {
  391.                 // quando un parametro viene inviato come vuoto, sul db viene messo null, gestisco il caso
  392.                 Integer statusMinDBCheck = StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null;
  393.                 Integer statusMaxDBCheck = StringUtils.isNotEmpty(statusMax) ? Integer.parseInt(statusMax) : null;
  394.                 if(returnCode.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_ESATTO))
  395.                     statusMaxDBCheck = statusMinDBCheck;
  396.                 String patternDBCheck = StringUtils.isNotEmpty(pattern) ? pattern : null;
  397.                 String contentTypeDBCheck = StringUtils.isNotEmpty(contentType) ? contentType : null;
  398.                 TrasformazioneRegolaRisposta regolaRispostaDBCheckApplicabilita = porteApplicativeCore.getTrasformazioneRisposta(Long.parseLong(idPorta), idTrasformazione, statusMinDBCheck, statusMaxDBCheck, patternDBCheck, contentTypeDBCheck);
  399.                 TrasformazioneRegolaRisposta regolaRispostaDBCheckNome = porteApplicativeCore.getTrasformazioneRisposta(Long.parseLong(idPorta), idTrasformazione, nomeRisposta);
  400.                
  401.                 // controllo che le modifiche ai parametri non coincidano con altre regole gia' presenti
  402.                 if(regolaRispostaDBCheckApplicabilita != null && regolaRispostaDBCheckApplicabilita.getId().longValue() != oldRisposta.getId().longValue()) {
  403.                     pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_REGOLA_TRASFORMAZIONE_APPLICABILITA_DUPLICATA);
  404.                     isOk = false;
  405.                 }
  406.                 if(isOk && regolaRispostaDBCheckNome != null && regolaRispostaDBCheckNome.getId().longValue() != oldRisposta.getId().longValue()) {
  407.                     pd.setMessage(CostantiControlStation.MESSAGGIO_ERRORE_REGOLA_TRASFORMAZIONE_APPLICABILITA_NOME);
  408.                     isOk = false;
  409.                 }
  410.             }
  411.            
  412.             if (!isOk) {

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

  415.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  416.                
  417.                 dati = porteApplicativeHelper.addTrasformazioneRispostaToDati(TipoOperazione.CHANGE, protocollo, dati, idInt, oldRisposta, false, idTrasformazioneS, idTrasformazioneRispostaS,
  418.                         apc.getServiceBinding(),
  419.                         nomeRisposta,
  420.                         returnCode, statusMin, statusMax, pattern, contentType, servletTrasformazioniRispostaHeadersList, parametriInvocazioneServletTrasformazioniRispostaHeaders, numeroTrasformazioniRispostaHeaders,
  421.                         trasformazioneContenutoRichiestaAbilitato, trasformazioneRichiestaRestAbilitato, trasformazioneRichiestaSoapAbilitato,
  422.                         trasformazioneContenutoRispostaAbilitato, trasformazioneContenutoRispostaTipo, trasformazioneContenutoRispostaTemplate, trasformazioneContenutoRispostaTipoCheck, trasformazioneContenutoRispostaContentType, trasformazioneContenutoRispostaReturnCode,
  423.                         serviceBindingMessage, trasformazioneRispostaSoapAbilitato, trasformazioneRispostaSoapEnvelope, trasformazioneRispostaSoapEnvelopeTipo, trasformazioneRispostaSoapEnvelopeTemplate, trasformazioneRispostaSoapEnvelopeTipoCheck);
  424.                
  425.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta,idAsps,  dati);
  426.                
  427.                 pd.setDati(dati);

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

  429.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA, ForwardParams.CHANGE());
  430.             }
  431.            
  432.             // aggiorno la regola  
  433.             TrasformazioneRegola regola = null;
  434.             for (TrasformazioneRegola reg : trasformazioni.getRegolaList()) {
  435.                 if(reg.getId().longValue() == idTrasformazione) {
  436.                     regola = reg;
  437.                     break;
  438.                 }
  439.             }
  440.             if(regola==null) {
  441.                 throw new Exception("TrasformazioneRegola con id '"+idTrasformazione+"' non trovata");
  442.             }
  443.            
  444.             TrasformazioneRegolaRisposta rispostaDaAggiornare = null;
  445.             for (int j = 0; j < regola.sizeRispostaList(); j++) {
  446.                 TrasformazioneRegolaRisposta risposta = regola.getRisposta(j);
  447.                 if (risposta.getId().longValue() == idTrasformazioneRisposta) {
  448.                     rispostaDaAggiornare = risposta;
  449.                     break;
  450.                 }
  451.             }
  452.             if(rispostaDaAggiornare==null) {
  453.                 throw new Exception("TrasformazioneRegolaRisposta con id '"+idTrasformazioneRisposta+"' non trovata");
  454.             }
  455.            
  456.             rispostaDaAggiornare.setNome(nomeRisposta);
  457.            
  458.             if(rispostaDaAggiornare.getApplicabilita() == null)
  459.                 rispostaDaAggiornare.setApplicabilita(new TrasformazioneRegolaApplicabilitaRisposta());

  460.             if(returnCode.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_QUALSIASI)) {
  461.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMin(null);
  462.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMax(null);
  463.             } else if(returnCode.equals(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_RETURN_CODE_ESATTO)) {
  464.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMin(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  465.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMax(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  466.             } else { // intervallo
  467.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMin(StringUtils.isNotEmpty(statusMin) ? Integer.parseInt(statusMin) : null);
  468.                 rispostaDaAggiornare.getApplicabilita().setReturnCodeMax(StringUtils.isNotEmpty(statusMax) ? Integer.parseInt(statusMax) : null);
  469.             }
  470.            
  471.             rispostaDaAggiornare.getApplicabilita().setPattern(pattern);
  472.             rispostaDaAggiornare.getApplicabilita().getContentTypeList().clear();
  473.             if(contentType != null) {
  474.                 rispostaDaAggiornare.getApplicabilita().getContentTypeList().addAll(Arrays.asList(contentType.split(",")));
  475.             }
  476.            
  477.             rispostaDaAggiornare.setReturnCode(StringUtils.isNotEmpty(trasformazioneContenutoRispostaReturnCode) ? trasformazioneContenutoRispostaReturnCode : null);
  478.                        
  479.             rispostaDaAggiornare.setConversione(trasformazioneContenutoRispostaAbilitato);
  480.            
  481.             if(trasformazioneContenutoRispostaAbilitato) {
  482.                 if(trasformazioneContenutoRispostaTipo.isTemplateRequired()) {
  483.                     //  se e' stato aggiornato il template lo sovrascrivo
  484.                     if(trasformazioneContenutoRispostaTemplate.getValue() != null && trasformazioneContenutoRispostaTemplate.getValue().length  > 0)
  485.                         rispostaDaAggiornare.setConversioneTemplate(trasformazioneContenutoRispostaTemplate.getValue());
  486.                 }else {
  487.                     rispostaDaAggiornare.setConversioneTemplate(null);
  488.                 }
  489.                
  490.                 if(trasformazioneContenutoRispostaContentType!=null && !"".equals(trasformazioneContenutoRispostaContentType)) {
  491.                     rispostaDaAggiornare.setContentType(trasformazioneContenutoRispostaContentType);
  492.                 }
  493.                 else {
  494.                     rispostaDaAggiornare.setContentType(null);
  495.                 }
  496.                 rispostaDaAggiornare.setConversioneTipo(trasformazioneContenutoRispostaTipo.getValue());
  497.                
  498.                 if(trasformazioneRispostaSoapAbilitato) {
  499.                     if(rispostaDaAggiornare.getTrasformazioneSoap() == null)
  500.                         rispostaDaAggiornare.setTrasformazioneSoap(new TrasformazioneSoapRisposta());
  501.                    
  502.                     if(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_AS_ATTACHMENT.equals(trasformazioneRispostaSoapEnvelope)) { // attachment
  503.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelope(true);
  504.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeAsAttachment(true);
  505.                        
  506.                         if(trasformazioneRispostaSoapEnvelopeTipo.isTemplateRequired()) {
  507.                             //  se e' stato aggiornato il template lo sovrascrivo
  508.                             if(trasformazioneRispostaSoapEnvelopeTemplate.getValue() != null && trasformazioneRispostaSoapEnvelopeTemplate.getValue().length  > 0)
  509.                                 rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTemplate(trasformazioneRispostaSoapEnvelopeTemplate.getValue());
  510.                         } else {
  511.                             rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTemplate(null);
  512.                         }
  513.                        
  514.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTipo(trasformazioneRispostaSoapEnvelopeTipo.getValue());
  515.                     } else if(CostantiControlStation.VALUE_PARAMETRO_CONFIGURAZIONE_TRASFORMAZIONI_SOAP_ENVELOPE_AS_BODY.equals(trasformazioneRispostaSoapEnvelope)) { // body
  516.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelope(true);
  517.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeAsAttachment(false);
  518.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTemplate(null);
  519.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTipo(null);
  520.                     } else  { // disabilitato
  521.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelope(false);
  522.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeAsAttachment(false);
  523.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTemplate(null);
  524.                         rispostaDaAggiornare.getTrasformazioneSoap().setEnvelopeBodyConversioneTipo(null);
  525.                     }
  526.                        
  527.                 } else {
  528.                     rispostaDaAggiornare.setTrasformazioneSoap(null);
  529.                 }
  530.             } else {
  531.                 rispostaDaAggiornare.setConversioneTemplate(null);
  532.                 rispostaDaAggiornare.setContentType(null);
  533.                 rispostaDaAggiornare.setConversioneTipo(null);
  534.                 rispostaDaAggiornare.setTrasformazioneSoap(null);
  535.             }
  536.            
  537.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  538.            
  539.             // ricaricare id trasformazione
  540.             pa = porteApplicativeCore.getPortaApplicativa(Long.parseLong(idPorta));

  541.             TrasformazioneRegola trasformazioneAggiornata = porteApplicativeCore.getTrasformazione(pa.getId(), regola.getNome());
  542.            
  543.            
  544.             // Preparo la lista
  545.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  546.            
  547.             int idLista = Liste.PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTE;
  548.            
  549.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  550.             List<TrasformazioneRegolaRisposta> lista = porteApplicativeCore.porteAppTrasformazioniRispostaList(Long.parseLong(idPorta), trasformazioneAggiornata.getId(), ricerca);
  551.            
  552.             porteApplicativeHelper.preparePorteAppTrasformazioniRispostaList(nomePorta, trasformazioneAggiornata.getId(), ricerca, lista);
  553.                        
  554.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  555.            
  556.             // Forward control to the specified success URI
  557.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA,   ForwardParams.CHANGE());
  558.         } catch (Exception e) {
  559.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  560.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_TRASFORMAZIONI_RISPOSTA,
  561.                     ForwardParams.CHANGE());
  562.         }
  563.     }
  564. }