AccordiCooperazioneAllegatiDel.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.registry.AccordoCooperazione;
  31. import org.openspcoop2.core.registry.Documento;
  32. import org.openspcoop2.core.registry.constants.RuoliDocumento;
  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.archivi.ArchiviCore;
  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.  * accordiCoopAllegatiDel
  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 AccordiCooperazioneAllegatiDel extends Action {

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

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

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

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);
  62.        
  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.             String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
  69.             if("".equals(tipoSICA))
  70.                 tipoSICA = null;
  71.            
  72.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();
  73.             ArchiviCore archiviCore =  new ArchiviCore(acCore);

  74.             // Preparo il menu
  75.             acHelper.makeMenu();

  76.             AccordoCooperazione ac = null;
  77.            
  78.             for (int i = 0; i < idsToRemove.size(); i++) {
  79.                 long idAllegato = Long.parseLong(idsToRemove.get(i));
  80.                
  81.                 Documento doc = archiviCore.getDocumento(idAllegato, false);
  82.                
  83.                 if(ac==null)
  84.                     ac = acCore.getAccordoCooperazione(doc.getIdProprietarioDocumento());
  85.                
  86.                 switch (RuoliDocumento.valueOf(doc.getRuolo())) {
  87.                     case allegato:
  88.                         //rimuovo il vecchio doc dalla lista
  89.                         for (int j = 0; j < ac.sizeAllegatoList(); j++) {
  90.                             Documento documento = ac.getAllegato(j);                        
  91.                             if(documento.getFile().equals(doc.getFile()))
  92.                                 ac.removeAllegato(j);
  93.                         }
  94.                        
  95.                         break;

  96.                     case specificaSemiformale:
  97.                        
  98.                         for (int j = 0; j < ac.sizeSpecificaSemiformaleList(); j++) {
  99.                             Documento documento = ac.getSpecificaSemiformale(j);                        
  100.                             if(documento.getFile().equals(doc.getFile()))
  101.                                 ac.removeSpecificaSemiformale(j);
  102.                         }
  103.                         break;
  104.                    
  105.                     case specificaCoordinamento:
  106.                         break;
  107.                     case specificaLivelloServizio:
  108.                         break;
  109.                     case specificaSicurezza:
  110.                         break;
  111.                 }
  112.                
  113.             }

  114.             // effettuo le operazioni
  115.             acCore.performUpdateOperation(userLogin, acHelper.smista(), ac);

  116.             // Preparo la lista
  117.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  118.            
  119.             List<Documento> lista = acCore.accordiCoopAllegatiList(ac.getId().intValue(), ricerca);

  120.             acHelper.prepareAccordiCoopAllegatiList(ac, ricerca, lista);

  121.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  122.            
  123.             return ServletUtils.getStrutsForward(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI , ForwardParams.DEL());
  124.         } catch (Exception e) {
  125.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  126.                     AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
  127.                     ForwardParams.DEL());
  128.         }  
  129.     }
  130. }