AccordiServizioParteComunePortTypeOperationsMessageDel.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.core.Utilities;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.Costanti;
  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.ServletUtils;

  44. /**
  45.  * AccordiServizioParteComunePortTypeOperationsMessageDel
  46.  *
  47.  * @author Andrea Poli (apoli@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  */
  51. public class AccordiServizioParteComunePortTypeOperationsMessageDel extends Action {

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

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

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         // Inizializzo GeneralData
  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  61.         try {
  62.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
  63.             AccordiServizioParteComuneHelper apcHelper = new AccordiServizioParteComuneHelper(request, pd, session);

  64.             String id = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID);
  65.             long idAccordoLong = Long.parseLong(id);
  66.             String nomept = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPES_NOME);
  67.             String nomeop = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_NOME);
  68.             String objToRemove = apcHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  69.             String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  70.             String tipoMessagge = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_TYPE);

  71.             boolean isMessageInput = tipoMessagge.equals(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_PORT_TYPE_OPERATION_MESSAGE_INPUT);
  72.                        
  73.             if("".equals(tipoAccordo))
  74.                 tipoAccordo = null;

  75.             // Preparo il menu
  76.             apcHelper.makeMenu();

  77.             ArrayList<String> optsToRemove = Utilities.parseIdsToRemove(objToRemove);
  78.             AccordoServizioParteComune as = apcCore.getAccordoServizioFull(idAccordoLong);

  79.             // Prendo il port-type e l'operation
  80.             PortType pt = null;
  81.             Operation operation = null;
  82.             for (int i = 0; i < as.sizePortTypeList(); i++) {
  83.                 pt = as.getPortType(i);
  84.                 if (nomept.equals(pt.getNome())){
  85.                     for (Operation opTmp : pt.getAzioneList()) {
  86.                         if(opTmp.getNome().equals(nomeop)){
  87.                             operation = opTmp;
  88.                             break;
  89.                         }
  90.                     }
  91.                 }
  92.             }

  93.             String nomeopToRemove = "";

  94.             for (int i = 0; i < optsToRemove.size(); i++) {

  95.                 nomeopToRemove = optsToRemove.get(i);
  96.                
  97.                 Message m = null;
  98.                 if(isMessageInput)
  99.                     m = operation.getMessageInput();
  100.                 else
  101.                     m = operation.getMessageOutput();
  102.                
  103.                 for (int j = 0; j < m.sizePartList(); j++) {
  104.                     MessagePart mp = m.getPart(j);
  105.                     if (nomeopToRemove.equals(mp.getName())) {
  106.                         m.removePart(j);
  107.                         break;
  108.                     }
  109.                 }
  110.             }

  111.             // effettuo le operazioni
  112.             apcCore.performUpdateOperation(userLogin, apcHelper.smista(), pt);

  113.             // Preparo la lista
  114.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  115.                    
  116.             List<MessagePart> lista = apcCore.accordiPorttypeOperationMessagePartList(operation.getId().intValue(), isMessageInput, ricerca);

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

  118.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  119.            
  120.             return ServletUtils.getStrutsForward(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.DEL());
  121.            
  122.         } catch (Exception e) {
  123.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  124.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_PORT_TYPE_OPERATIONS_MESSAGE, ForwardParams.DEL());
  125.         }
  126.     }

  127. }