AccordiCooperazionePartecipantiDel.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.ac;

  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.id.IDSoggetto;
  31. import org.openspcoop2.core.registry.AccordoCooperazione;
  32. import org.openspcoop2.core.registry.AccordoCooperazionePartecipanti;
  33. import org.openspcoop2.core.registry.IdSoggetto;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.core.Utilities;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * accordiCoopPartecipantiDel
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class AccordiCooperazionePartecipantiDel extends Action {

  54.        
  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.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  64.         try {
  65.             AccordiCooperazioneHelper acHelper = new AccordiCooperazioneHelper(request, pd, session);

  66.             String objToRemove = acHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  67.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  68.            
  69.             String idAccordoCoop = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID);
  70.            
  71.             String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
  72.             if("".equals(tipoSICA))
  73.                 tipoSICA = null;

  74.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();
  75.            
  76.             // Preparo il menu
  77.             acHelper.makeMenu();
  78.            
  79.             AccordoCooperazione ac = acCore.getAccordoCooperazione(Long.parseLong(idAccordoCoop));
  80.            
  81.             for (String partecipante : idsToRemove) {
  82.                 String tipo = partecipante.split("/")[0];
  83.                 String nome = partecipante.split("/")[1];
  84.                
  85.                 if(ac.getElencoPartecipanti()!=null){
  86.                     AccordoCooperazionePartecipanti list = ac.getElencoPartecipanti();
  87.                     int deleted = 0;
  88.                     for (int i = 0; i < list.sizeSoggettoPartecipanteList(); i++) {
  89.                         IdSoggetto acep = list.getSoggettoPartecipante(i);
  90.                          if(tipo.equals(acep.getTipo())  && nome.equals(acep.getNome())){  
  91.                              ac.getElencoPartecipanti().removeSoggettoPartecipante(i-deleted);
  92.                              deleted++;
  93.                          }
  94.                     }
  95.                 }
  96.             }
  97.            
  98.             acCore.performUpdateOperation(userLogin, acHelper.smista(), ac);
  99.            
  100.             // Preparo la lista
  101.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  102.            
  103.             List<IDSoggetto> lista = acCore.accordiCoopPartecipantiList(ac.getId(),ricerca);

  104.             acHelper.prepareAccordiCoopPartecipantiList(ac,lista,ricerca);

  105.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  106.            
  107.             return ServletUtils.getStrutsForward(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI , ForwardParams.DEL());
  108.         } catch (Exception e) {
  109.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  110.                     AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI,
  111.                     ForwardParams.DEL());
  112.         }
  113.     }
  114. }