AccordiServizioParteComunePortTypeOperationsMessageAdd.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.apc;

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

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

  26. import org.apache.struts.action.Action;
  27. import org.apache.struts.action.ActionForm;
  28. import org.apache.struts.action.ActionForward;
  29. import org.apache.struts.action.ActionMapping;
  30. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  31. import org.openspcoop2.core.registry.Message;
  32. import org.openspcoop2.core.registry.MessagePart;
  33. import org.openspcoop2.core.registry.Operation;
  34. import org.openspcoop2.core.registry.PortType;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiCostanti;
  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.  * AccordiServizioParteComunePortTypeOperationsMessageAdd
  48.  *
  49.  * @author Andrea Poli (apoli@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  */
  53. public class AccordiServizioParteComunePortTypeOperationsMessageAdd extends Action {

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

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

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

  59.         // Inizializzo GeneralData
  60.         GeneralHelper generalHelper = new GeneralHelper(session);

  61.         GeneralData gd = generalHelper.initGeneralData(request);

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

  63.         try {
  64.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
  65.             AccordiServizioParteComuneHelper apcHelper = new AccordiServizioParteComuneHelper(request, pd, session);
  66.            
  67.             String id = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID);
  68.             int idInt = Integer.parseInt(id);
  69.             String nomept = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPES_NOME);
  70.             String nomeop = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_NOME);
  71.             String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  72.             if("".equals(tipoAccordo))
  73.                 tipoAccordo = null;
  74.            
  75.             String tipoMessage = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_TYPE);

  76.             boolean isMessageInput = tipoMessage.equals(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_INPUT);
  77.            
  78.             String messagePartName = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_NAME);
  79.             String messagePartLocalName = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_LOCAL_NAME);
  80.             String messagePartNs = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_NS);
  81.             String messagePartType = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_TYPE);

  82.             // Preparo il menu
  83.             apcHelper.makeMenu();

  84.             // Prendo il nome dal db
  85.             AccordoServizioParteComune as = apcCore.getAccordoServizioFull(idInt);
  86.             String labelASTitle = apcHelper.getLabelIdAccordo(as);
  87.            
  88.             // Prendo il port-type e l'operation
  89.             PortType pt = null;
  90.             Operation operation = null;
  91.             boolean found = false;
  92.             for (int i = 0; i < as.sizePortTypeList(); i++) {
  93.                 pt = as.getPortType(i);
  94.                 if (nomept.equals(pt.getNome())){
  95.                     for (Operation opTmp : pt.getAzioneList()) {
  96.                         if(opTmp.getNome().equals(nomeop)){
  97.                             operation = opTmp;
  98.                             found = true;
  99.                             break;
  100.                         }
  101.                     }
  102.                 }
  103.                 if(found){
  104.                     break;
  105.                 }
  106.             }
  107.            
  108.             if(messagePartType == null)
  109.                 messagePartType = AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_TYPE_ELEMENT;
  110.            
  111.             Parameter pIdAccordo  = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID, id);
  112.             Parameter pNomeAccordo  = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_NOME, as.getNome());
  113.             Parameter pNomePt  = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPES_NOME, nomept);
  114.             Parameter pNomeOp  = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_NOME, nomeop);
  115.             Parameter pTipoMsg  = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_TYPE, tipoMessage);
  116.             Parameter pTipoAccordo = AccordiServizioParteComuneUtilities.getParametroAccordoServizio(tipoAccordo);
  117.            
  118.             Boolean isModalitaVistaApiCustom = ServletUtils.getBooleanAttributeFromSession(ApiCostanti.SESSION_ATTRIBUTE_VISTA_APC_API, session, request, false).getValue();
  119.             List<Parameter> listaParams = apcHelper.getTitoloApc(TipoOperazione.ADD, as, tipoAccordo, labelASTitle, null, false);
  120.        
  121.             // porttypes
  122.             String labelPortTypes = (isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) ? AccordiServizioParteComuneCostanti.LABEL_PORT_TYPES: AccordiServizioParteComuneCostanti.LABEL_PORT_TYPES + " di " + labelASTitle;
  123.             listaParams.add(new Parameter(labelPortTypes, AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_PORT_TYPES_LIST, pIdAccordo, pNomeAccordo, pTipoAccordo));

  124.             // azioni
  125.             String labelOperations = AccordiServizioParteComuneCostanti.LABEL_AZIONI  + " di " + nomept;
  126.             listaParams.add(new Parameter(labelOperations, AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_PORT_TYPE_OPERATIONS_LIST, pIdAccordo, pNomeAccordo, pTipoAccordo,pNomePt));
  127.            
  128.             // azione
  129.             String labelOperation = nomeop;
  130.             listaParams.add(new Parameter(labelOperation,AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_PORT_TYPE_OPERATIONS_CHANGE,pIdAccordo,pNomeOp,pNomePt,pTipoAccordo));

  131.             String labelMessage = AccordiServizioParteComuneCostanti.LABEL_OPERATION_MESSAGE_INPUT;
  132.             if(!isMessageInput){
  133.                 labelMessage = AccordiServizioParteComuneCostanti.LABEL_OPERATION_MESSAGE_OUTPUT;
  134.             }
  135.            
  136.             labelMessage = (isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) ? labelMessage : labelMessage + " di " + nomeop;

  137.             listaParams.add(new Parameter(labelMessage,AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE_LIST,   pIdAccordo,pNomeAccordo,pNomeOp, pNomePt , pTipoMsg,pTipoAccordo));
  138.             listaParams.add(ServletUtils.getParameterAggiungi());
  139.            
  140.             if(apcHelper.isEditModeInProgress()){
  141.                
  142.                 // setto la barra del titolo
  143.                 ServletUtils.setPageDataTitle( pd,listaParams);
  144.                
  145.                 // preparo i campi
  146.                 List<DataElement> dati = new ArrayList<>();

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

  148.                 dati = apcHelper.addAccordiPorttypeOperationMessageToDati(TipoOperazione.ADD, dati,
  149.                         id, tipoAccordo, nomept, nomeop, messagePartName, messagePartType, messagePartLocalName, messagePartNs, tipoMessage);
  150.                        

  151.                 pd.setDati(dati);

  152.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  153.                
  154.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.ADD());
  155.             }

  156.             // Controlli sui campi immessi
  157.             boolean isOk = apcHelper.accordiPorttypeOperationMessageCheckData(TipoOperazione.ADD);
  158.             if (!isOk) {
  159.                
  160.                 // setto la barra del titolo
  161.                 ServletUtils.setPageDataTitle( pd,listaParams);

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

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

  165.                 dati = apcHelper.addAccordiPorttypeOperationMessageToDati(TipoOperazione.ADD, dati,
  166.                         id, tipoAccordo, nomept, nomeop, messagePartName, messagePartType, messagePartLocalName, messagePartNs, tipoMessage);

  167.                 pd.setDati(dati);

  168.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  169.                
  170.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.ADD());
  171.             }
  172.            
  173.            
  174.            
  175.             MessagePart part = new MessagePart();
  176.            
  177.             Message m = null;
  178.             if(isMessageInput){
  179.                 m = operation.getMessageInput();
  180.                 if(m==null){
  181.                     m = new Message();
  182.                     operation.setMessageInput(m);
  183.                 }
  184.             }
  185.             else{
  186.                 m = operation.getMessageOutput();
  187.                 if(m==null){
  188.                     m = new Message();
  189.                     operation.setMessageOutput(m);
  190.                 }
  191.             }
  192.            
  193.             part.setName(messagePartName);
  194.            
  195.             if(messagePartType.equals(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_PART_TYPE_TYPE)){
  196.                 part.setTypeName(messagePartLocalName);
  197.                 part.setTypeNamespace(messagePartNs);
  198.             }else {
  199.                 part.setElementName(messagePartLocalName);
  200.                 part.setElementNamespace(messagePartNs);
  201.             }
  202.            
  203.             m.addPart(part);
  204.            
  205.             // effettuo le operazioni
  206.             apcCore.performUpdateOperation(userLogin, apcHelper.smista(), pt);

  207.             // Preparo la lista
  208.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  209.            
  210.             List<MessagePart> lista = apcCore.accordiPorttypeOperationMessagePartList(operation.getId().intValue(), isMessageInput, ricerca);

  211.             apcHelper.prepareAccordiPorttypeOperationMessagePartList(ricerca, lista, as, tipoAccordo, nomept, nomeop, isMessageInput);

  212.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  213.            
  214.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.ADD());
  215.            
  216.         } catch (Exception e) {
  217.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  218.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.ADD());
  219.         }
  220.     }

  221. }