AccordiCooperazioneDel.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.HashMap;
  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.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  32. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  33. import org.openspcoop2.core.id.IDAccordoCooperazione;
  34. import org.openspcoop2.core.registry.AccordoCooperazione;
  35. import org.openspcoop2.core.registry.driver.IDAccordoCooperazioneFactory;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.core.Utilities;
  39. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  40. import org.openspcoop2.web.lib.mvc.Costanti;
  41. import org.openspcoop2.web.lib.mvc.ForwardParams;
  42. import org.openspcoop2.web.lib.mvc.GeneralData;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.ServletUtils;

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

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

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

  59.         // Inizializzo PageData
  60.         PageData pd = new PageData();

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

  62.         // Inizializzo GeneralData
  63.         GeneralData gd = generalHelper.initGeneralData(request);

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

  65.         IDAccordoCooperazioneFactory idAccordoCooperazioneFactory = IDAccordoCooperazioneFactory.getInstance();
  66.        
  67.         try {
  68.             AccordiCooperazioneHelper acHelper = new AccordiCooperazioneHelper(request, pd, session);

  69.             String objToRemove = acHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  70.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  71.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();

  72.             // Preparo il menu
  73.             acHelper.makeMenu();

  74.             String msg = "";
  75.             boolean isInUso = false;
  76.            
  77.             for (int i = 0; i < idsToRemove.size(); i++) {

  78.                 String id = idsToRemove.get(i);
  79.                 int idAccordo = Integer.parseInt(id);
  80.                 String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
  81.                 if("".equals(tipoSICA))
  82.                     tipoSICA = null;

  83.                 HashMap<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<>();
  84.                
  85.                 AccordoCooperazione ac = acCore.getAccordoCooperazione(idAccordo);
  86.                 IDAccordoCooperazione idAccordoCooperazione = idAccordoCooperazioneFactory.getIDAccordoFromAccordo(ac);

  87.                 boolean normalizeObjectIds = !acHelper.isModalitaCompleta();
  88.                 if (acCore.isAccordoCooperazioneInUso(ac, whereIsInUso, normalizeObjectIds)) {// accordo in uso
  89.                     isInUso = true;
  90.                     msg += DBOggettiInUsoUtils.toString(idAccordoCooperazione, whereIsInUso, true, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE, normalizeObjectIds);
  91.                     msg += org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE;
  92.                 } else {// accordo non in uso
  93.                     acCore.performDeleteOperation(userLogin, acHelper.smista(), ac);
  94.                 }
  95.                
  96.             }

  97.             if (isInUso) {
  98.                 pd.setMessage(msg);
  99.             }
  100.            
  101.             // Preparo la lista
  102.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  103.            
  104.             List<AccordoCooperazione> lista = null;
  105.             if(acCore.isVisioneOggettiGlobale(userLogin)){
  106.                 lista = acCore.accordiCooperazioneList(null, ricerca);
  107.             }else{
  108.                 lista = acCore.accordiCooperazioneList(userLogin, ricerca);
  109.             }

  110.             acHelper.prepareAccordiCooperazioneList(lista, ricerca);

  111.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  112.            
  113.             return ServletUtils.getStrutsForward(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_ACCORDI_COOPERAZIONE , ForwardParams.DEL());
  114.         } catch (Exception e) {
  115.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  116.                     AccordiCooperazioneCostanti.OBJECT_NAME_ACCORDI_COOPERAZIONE,
  117.                     ForwardParams.DEL());
  118.         }  
  119.     }
  120. }