SoggettiProprietaDel.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.Proprieta;
  32. import org.openspcoop2.core.registry.Soggetto;
  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.dao.SoggettoCtrlStat;
  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.  * SoggettiProprietaDel
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public final class SoggettiProprietaDel extends Action {

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  61.  

  62.         try {
  63.             SoggettiHelper soggettiHelper = new SoggettiHelper(request, pd, session);
  64.             soggettiHelper.makeMenu();
  65.            
  66.             String id = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  67.             int idSogg = Integer.parseInt(id);
  68.             String nomeprov = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME);
  69.             String tipoprov = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO);
  70.             String objToRemove = soggettiHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  71.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  72.            
  73.             SoggettiCore soggettiCore = new SoggettiCore();
  74.            
  75.             Soggetto soggettoRegistry = null;
  76.             org.openspcoop2.core.config.Soggetto soggettoConfig = null;
  77.            
  78.             if(soggettiCore.isRegistroServiziLocale()){
  79.                 soggettoRegistry = soggettiCore.getSoggettoRegistro(idSogg);// core.getSoggettoRegistro(new
  80.             }

  81.             soggettoConfig = soggettiCore.getSoggetto(idSogg);// core.getSoggetto(new
  82.            
  83.             String nome = "";

  84.             for (int i = 0; i < idsToRemove.size(); i++) {

  85.                 nome = idsToRemove.get(i);

  86.                 for (int j = 0; j < soggettoRegistry.sizeProprietaList(); j++) {
  87.                     Proprieta ssp = soggettoRegistry.getProprieta(j);
  88.                     if (nome.equals(ssp.getNome())) {
  89.                         soggettoRegistry.removeProprieta(j);
  90.                         break;
  91.                     }
  92.                 }
  93.             }
  94.            
  95.             SoggettoCtrlStat sog = new SoggettoCtrlStat(soggettoRegistry, soggettoConfig);
  96.             sog.setOldNomeForUpdate(nomeprov);
  97.             sog.setOldTipoForUpdate(tipoprov);

  98.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  99.            
  100.             // update
  101.             List<Object> listOggettiDaAggiornare = SoggettiUtilities.getOggettiDaAggiornare(soggettiCore, nomeprov, nomeprov, tipoprov, tipoprov, sog);
  102.             soggettiCore.performUpdateOperation(userLogin, soggettiHelper.smista(), listOggettiDaAggiornare.toArray());
  103.            
  104.             soggettoRegistry = soggettiCore.getSoggettoRegistro(idSogg);
  105.            

  106.             // Preparo la lista
  107.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  108.             int idLista = Liste.SOGGETTI_PROP;

  109.             ricerca = soggettiHelper.checkSearchParameters(idLista, ricerca);

  110.             List<Proprieta> lista = soggettiCore.soggettiProprietaList(Integer.parseInt(id), ricerca);

  111.             soggettiHelper.prepareSoggettiProprietaList(soggettoRegistry, id, ricerca, lista);

  112.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  113.             // Forward control to the specified success URI
  114.             return ServletUtils.getStrutsForward (mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  115.                     ForwardParams.DEL());
  116.         } catch (Exception e) {
  117.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  118.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  119.                     ForwardParams.DEL());
  120.         }  
  121.     }
  122. }