SoggettiDel.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.soggetti;

  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.Soggetto;
  32. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  34. import org.openspcoop2.web.ctrlstat.core.Utilities;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.Costanti;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.PageData;
  40. import org.openspcoop2.web.lib.mvc.ServletUtils;

  41. /**
  42.  * soggettiDel
  43.  *
  44.  * @author Andrea Poli (apoli@link.it)
  45.  * @author Stefano Corallo (corallo@link.it)
  46.  * @author Sandra Giangrandi (sandra@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class SoggettiDel 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.         GeneralHelper generalHelper = new GeneralHelper(session);

  58.         // Inizializzo GeneralData
  59.         GeneralData gd = generalHelper.initGeneralData(request);

  60.         try {
  61.             SoggettiHelper soggettiHelper = new SoggettiHelper(request, pd, session);
  62.            
  63.             // ctrlstatHelper ch = new ctrlstatHelper(request, pd, con, session);
  64.             String objToRemove = soggettiHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  65.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  66.             // // Elimino i soggetti dal db
  67.             // StringTokenizer objTok = new StringTokenizer(objToRemove, ",");
  68.             // int[] idToRemove = new int[objTok.countTokens()];
  69.             //
  70.             // int k = 0;
  71.             // while (objTok.hasMoreElements()) {
  72.             // idToRemove[k++] = Integer.parseInt(objTok.nextToken());
  73.             // }
  74.    
  75.             // String soggInUsoServizioApplicativo = "", soggInUsoServ = "",
  76.             // soggInUsoPorteDel = "";
  77.             // String nomeprov = "", tipoprov = "";
  78.            
  79.             soggettiHelper.makeMenu();
  80.    
  81.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  82.    
  83.             SoggettiCore soggettiCore = new SoggettiCore();
  84.            
  85.             StringBuilder inUsoMessage = new StringBuilder();

  86.             boolean deleteOperativo = false;
  87.             boolean deleteAlmostOne = false;
  88.            
  89.             for (int i = 0; i < idsToRemove.size(); i++) {

  90.                 Soggetto soggettoRegistro = null;
  91.                 org.openspcoop2.core.config.Soggetto soggettoConfig = null;
  92.                 if(soggettiCore.isRegistroServiziLocale()){
  93.                     soggettoRegistro = soggettiCore.getSoggettoRegistro(Long.parseLong(idsToRemove.get(i)));
  94.                 }
  95.                 else{
  96.                     soggettoConfig = soggettiCore.getSoggetto(Long.parseLong(idsToRemove.get(i)));
  97.                 }
  98.                
  99.                 SoggettiDelStatus delStatus = SoggettiUtilities.deleteSoggetto(soggettoRegistro, soggettoConfig, userLogin, soggettiCore, soggettiHelper, inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  100.                 if(delStatus.isDeletedOperativo()) {
  101.                     deleteOperativo = true;
  102.                 }
  103.                 if(delStatus.isDeleted()) {
  104.                     deleteAlmostOne = true;
  105.                 }
  106.                
  107.             }// chiudo for

  108.             if(deleteAlmostOne) {
  109.                 ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.SOGGETTI);
  110.             }
  111.            
  112.             if (inUsoMessage.length()>0) {
  113.                 pd.setMessage(inUsoMessage.toString());
  114.             }

  115.             // preparo lista
  116.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  117.            
  118.             if(soggettiCore.isRegistroServiziLocale()){
  119.                 List<Soggetto> lista = null;
  120.                 if(soggettiCore.isVisioneOggettiGlobale(userLogin)){
  121.                     lista = soggettiCore.soggettiRegistroList(null, ricerca);
  122.                 }else{
  123.                     lista = soggettiCore.soggettiRegistroList(userLogin, ricerca);
  124.                 }
  125.                 soggettiHelper.prepareSoggettiList(lista, ricerca);
  126.             }
  127.             else{
  128.                 List<org.openspcoop2.core.config.Soggetto> lista = null;
  129.                 if(soggettiCore.isVisioneOggettiGlobale(userLogin)){
  130.                     lista = soggettiCore.soggettiList(null, ricerca);
  131.                 }else{
  132.                     lista = soggettiCore.soggettiList(userLogin, ricerca);
  133.                 }
  134.                 soggettiHelper.prepareSoggettiConfigList(lista, ricerca);
  135.             }

  136.             if(deleteOperativo) {
  137.                 generalHelper = new GeneralHelper(session);
  138.                 gd = generalHelper.initGeneralData(request); // re-inizializzo per ricalcolare il menu in alto a destra
  139.             }
  140.            
  141.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  142.            
  143.             return ServletUtils.getStrutsForward(mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI, ForwardParams.DEL());
  144.            
  145.         } catch (Exception e) {
  146.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  147.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI, ForwardParams.DEL());
  148.         }
  149.     }
  150. }