AccordiCooperazionePartecipantiAdd.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.core.registry.Soggetto;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.Parameter;
  44. import org.openspcoop2.web.lib.mvc.ServletUtils;
  45. import org.openspcoop2.web.lib.mvc.TipoOperazione;

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


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

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

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

  62.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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


  66.         try {
  67.             AccordiCooperazioneHelper acHelper = new AccordiCooperazioneHelper(request, pd, session);

  68.             String idAccordoCoop = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID);
  69.             String partecipante = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_PARTECIPANTE);

  70.             /**String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
  71.             if("".equals(tipoSICA))
  72.                 tipoSICA = null;*/

  73.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();
  74.             SoggettiCore soggettiCore = new SoggettiCore(acCore);

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

  77.             AccordoCooperazione ac = acCore.getAccordoCooperazione(Long.parseLong(idAccordoCoop));
  78.             String titleAS = acHelper.getLabelIdAccordoCooperazione(ac);
  79.            
  80.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(ac.getSoggettoReferente().getTipo());
  81.             List<String> tipiSoggettiCompatibiliAccordo = soggettiCore.getTipiSoggettiGestitiProtocollo(protocollo);

  82.             //prendo partecipanti gia' inseriti in accordo
  83.             ArrayList<String> tmpInseriti = new ArrayList<>();
  84.             if(ac.getElencoPartecipanti()!=null){
  85.                 AccordoCooperazionePartecipanti partecipantiInseriti = ac.getElencoPartecipanti();
  86.                 for (int i = 0; i < partecipantiInseriti.sizeSoggettoPartecipanteList(); i++) {
  87.                     IdSoggetto accordoCooperazioneElencoPartecipanti = partecipantiInseriti.getSoggettoPartecipante(i);
  88.                     String tipo = accordoCooperazioneElencoPartecipanti.getTipo();
  89.                     String nome = accordoCooperazioneElencoPartecipanti.getNome();
  90.                     tmpInseriti.add(tipo+"/"+nome);
  91.                 }
  92.             }

  93.             //lista partecipanti non inseriti
  94.             ArrayList<String> partecipantiNonInseriti = new ArrayList<>();
  95.             ArrayList<String> partecipantiNonInseritiLabels = new ArrayList<>();
  96.             partecipantiNonInseriti.add("-");
  97.             partecipantiNonInseritiLabels.add("-");

  98.             List<Soggetto> soggetti = null;
  99.             if(acCore.isVisioneOggettiGlobale(userLogin)){
  100.                 soggetti = soggettiCore.soggettiRegistroList(null, new ConsoleSearch(true));
  101.             }else{
  102.                 soggetti = soggettiCore.soggettiRegistroList(userLogin, new ConsoleSearch(true));
  103.             }
  104.             for (Soggetto sogg : soggetti) {
  105.                 String s = sogg.getTipo()+"/"+sogg.getNome();
  106.                 if(!tmpInseriti.contains(s) &&
  107.                     tipiSoggettiCompatibiliAccordo.contains(sogg.getTipo())) {
  108.                     partecipantiNonInseriti.add(s);
  109.                     partecipantiNonInseritiLabels.add(acHelper.getLabelNomeSoggetto(soggettiCore.getProtocolloAssociatoTipoSoggetto(sogg.getTipo()),
  110.                             sogg.getTipo(), sogg.getNome()));
  111.                 }
  112.             }



  113.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  114.             // dati
  115.             if (acHelper.isEditModeInProgress()) {
  116.                 // setto la barra del titolo
  117.                 List<Parameter> lstParam = new ArrayList<>();
  118.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
  119.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_PARTECIPANTI_DI + titleAS,
  120.                         AccordiCooperazioneCostanti.SERVLET_NAME_AC_PARTECIPANTI_LIST,
  121.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, ac.getId() + ""),
  122.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())
  123.                         ));            
  124.                 lstParam.add(ServletUtils.getParameterAggiungi());
  125.                
  126.                 ServletUtils.setPageDataTitle(pd, lstParam);
  127.                
  128.                 // preparo i campi
  129.                 List<DataElement> dati = new ArrayList<>();

  130.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  131.                 dati = acHelper.addPartecipanteToDati(TipoOperazione.ADD, idAccordoCoop,
  132.                         partecipantiNonInseriti.toArray(new String[partecipantiNonInseriti.size()]),
  133.                         partecipantiNonInseritiLabels.toArray(new String[partecipantiNonInseritiLabels.size()]),
  134.                         dati);

  135.                 pd.setDati(dati);

  136.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  137.                
  138.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI,
  139.                         ForwardParams.ADD());
  140.             }

  141.             // Controlli sui campi immessi
  142.             boolean isOk = true;

  143.             if (!isOk) {
  144.                 // setto la barra del titolo
  145.                 List<Parameter> lstParam = new ArrayList<>();
  146.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
  147.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_PARTECIPANTI_DI + titleAS,
  148.                         AccordiCooperazioneCostanti.SERVLET_NAME_AC_PARTECIPANTI_LIST,
  149.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, ac.getId() + ""),
  150.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())
  151.                         ));            
  152.                 lstParam.add(ServletUtils.getParameterAggiungi());

  153.                 pd.setSearchDescription("");


  154.                 // preparo i campi
  155.                 List<DataElement> dati = new ArrayList<>();
  156.  
  157.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  158.                
  159.                 dati = acHelper.addPartecipanteToDati(TipoOperazione.ADD, idAccordoCoop,
  160.                         partecipantiNonInseriti.toArray(new String[partecipantiNonInseriti.size()]),
  161.                         partecipantiNonInseritiLabels.toArray(new String[partecipantiNonInseritiLabels.size()]),
  162.                         dati);
  163.                
  164.                 pd.setDati(dati);

  165.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  166.                
  167.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI, ForwardParams.ADD());
  168.                
  169.             }

  170.             if(!"-".equals(partecipante)){
  171.                 String tipo = partecipante.split("/")[0];
  172.                 String nome = partecipante.split("/")[1];

  173.                 IdSoggetto asog = new IdSoggetto();
  174.                 asog.setTipo(tipo);
  175.                 asog.setNome(nome);
  176.                 if(ac.getElencoPartecipanti()==null){
  177.                     ac.setElencoPartecipanti(new AccordoCooperazionePartecipanti());
  178.                 }
  179.                 ac.getElencoPartecipanti().addSoggettoPartecipante(asog);

  180.                 acCore.performUpdateOperation(userLogin, acHelper.smista(), ac);
  181.             }



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

  184.             List<IDSoggetto> lista = acCore.accordiCoopPartecipantiList(ac.getId(),ricerca);

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

  186.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  187.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI, ForwardParams.ADD());

  188.         } catch (Exception e) {
  189.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  190.                     AccordiCooperazioneCostanti.OBJECT_NAME_AC_PARTECIPANTI,
  191.                     ForwardParams.ADD());
  192.         }  
  193.     }


  194. }