AccordiServizioParteComuneDel.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.commons.Liste;
  31. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  32. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.core.Utilities;
  36. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  37. import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiCostanti;
  38. import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiHelper;
  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.  * accordiDel
  46.  *
  47.  * @author Andrea Poli (apoli@link.it)
  48.  * @author Stefano Corallo (corallo@link.it)
  49.  * @author Sandra Giangrandi (sandra@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  *
  53.  */
  54. public final class AccordiServizioParteComuneDel 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.             ApiHelper apcHelper = new ApiHelper(request, pd, session);
  65.             Boolean isModalitaVistaApiCustom = ServletUtils.getBooleanAttributeFromSession(ApiCostanti.SESSION_ATTRIBUTE_VISTA_APC_API, session, request, false).getValue();
  66.            
  67.             String objToRemove = apcHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  68.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  69.            
  70.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
  71.            
  72.             String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  73.             if("".equals(tipoAccordo))
  74.                 tipoAccordo = null;
  75.            
  76.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  77.             String userLogin = (String) ServletUtils.getUserLoginFromSession(session);
  78.            
  79.             StringBuilder inUsoMessage = new StringBuilder();
  80.            
  81.             boolean deleteAlmostOneApi = false;
  82.            
  83.             for (int i = 0; i < idsToRemove.size(); i++) {

  84.                 AccordoServizioParteComune as = apcCore.getAccordoServizioFull(Long.parseLong(idsToRemove.get(i)));
  85.                
  86.                 boolean deleted = AccordiServizioParteComuneUtilities.deleteAccordoServizioParteComune(as, userLogin, apcCore, apcHelper, inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  87.                 if(deleted) {
  88.                     deleteAlmostOneApi = true;
  89.                 }
  90.                

  91.             }// chiudo for
  92.            
  93.             if(deleteAlmostOneApi) {
  94.                 ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.ACCORDI);
  95.             }

  96.             if (inUsoMessage.length()>0) {
  97.                 pd.setMessage(inUsoMessage.toString());
  98.             }

  99.             // con.commit();
  100.             // con.setAutoCommit(true);

  101.             // Preparo il menu
  102.             apcHelper.makeMenu();

  103.             // preparo la lista
  104.             List<AccordoServizioParteComuneSintetico> lista = AccordiServizioParteComuneUtilities.accordiList(apcCore, userLogin, ricerca, tipoAccordo);
  105.            
  106.             if(isModalitaVistaApiCustom) {
  107.                 apcHelper.prepareApiList(lista, ricerca, tipoAccordo);
  108.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  109.                 return ServletUtils.getStrutsForward(mapping, ApiCostanti.OBJECT_NAME_APC_API, ForwardParams.DEL());
  110.             }
  111.            
  112.             apcHelper.prepareAccordiList(lista, ricerca, tipoAccordo);

  113.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  114.            
  115.             return ServletUtils.getStrutsForward(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.DEL());

  116.         } catch (Exception e) {
  117.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  118.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC, ForwardParams.DEL());
  119.         }

  120.     }
  121. }