AccordiCooperazioneAllegatiAdd.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.apache.struts.upload.FormFile;
  31. import org.openspcoop2.core.registry.AccordoCooperazione;
  32. import org.openspcoop2.core.registry.Documento;
  33. import org.openspcoop2.core.registry.constants.ProprietariDocumento;
  34. import org.openspcoop2.core.registry.constants.RuoliDocumento;
  35. import org.openspcoop2.core.registry.constants.TipiDocumentoSemiformale;
  36. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  37. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  38. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  39. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  40. import org.openspcoop2.web.ctrlstat.servlet.FileUploadForm;
  41. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  42. import org.openspcoop2.web.ctrlstat.servlet.archivi.ArchiviHelper;
  43. import org.openspcoop2.web.lib.mvc.DataElement;
  44. import org.openspcoop2.web.lib.mvc.ForwardParams;
  45. import org.openspcoop2.web.lib.mvc.GeneralData;
  46. import org.openspcoop2.web.lib.mvc.PageData;
  47. import org.openspcoop2.web.lib.mvc.Parameter;
  48. import org.openspcoop2.web.lib.mvc.ServletUtils;
  49. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  50. /**
  51.  * accordiCoopAllegatiAdd
  52.  *
  53.  * @author Andrea Poli (apoli@link.it)
  54.  * @author Stefano Corallo (corallo@link.it)
  55.  * @author Sandra Giangrandi (sandra@link.it)
  56.  * @author $Author$
  57.  * @version $Rev$, $Date$
  58.  *
  59.  */
  60. public final class AccordiCooperazioneAllegatiAdd extends Action {

  61.     @SuppressWarnings("incomplete-switch")
  62.     @Override
  63.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  64.         HttpSession session = request.getSession(true);
  65.        
  66.         // Inizializzo PageData
  67.         PageData pd = new PageData();

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         // Inizializzo GeneralData
  70.         GeneralData gd = generalHelper.initGeneralData(request);

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

  72.         try {
  73.            
  74.             FileUploadForm fileUpload = (FileUploadForm) form;
  75.            
  76.             AccordiCooperazioneHelper acHelper = new AccordiCooperazioneHelper(request, pd, session);
  77.             ArchiviHelper archiviHelper = new ArchiviHelper(request, pd, session);

  78.             String idAccordo = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID);
  79.             long idAccordoLong = Long.parseLong(idAccordo);
  80.             String ruolo = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_RUOLO);
  81.             String tipoFile = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_FILE);
  82.             FormFile ff = fileUpload.getTheFile();
  83.             /**String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
  84.             if("".equals(tipoSICA))
  85.                 tipoSICA = null;*/
  86.            
  87.             AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();

  88.             // Preparo il menu
  89.             acHelper.makeMenu();

  90.             // Prendo il nome
  91.             AccordoCooperazione ac = acCore.getAccordoCooperazione(idAccordoLong);
  92.             String titleAS = acHelper.getLabelIdAccordoCooperazione(ac);
  93.             IProtocolFactory<?> pf = ProtocolFactoryManager.getInstance().getProtocolFactoryByOrganizationType(ac.getSoggettoReferente().getTipo());
  94.            
  95.             String[] ruoli = {RuoliDocumento.allegato.toString(),RuoliDocumento.specificaSemiformale.toString()};
  96.            
  97.             String[] tipiAmmessi = null;
  98.             String[] tipiAmmessiLabel = null;
  99.            
  100.             if(ruolo!=null && !"".equals(ruolo)){
  101.                 switch (RuoliDocumento.valueOf(ruolo)) {
  102.                     case allegato:
  103.                         //non ci sono vincoli
  104.                         break;
  105.                     case specificaSemiformale:
  106.                         tipiAmmessi = TipiDocumentoSemiformale.toEnumNameArray();
  107.                         tipiAmmessiLabel=TipiDocumentoSemiformale.toStringArray();
  108.                         break;
  109.                     default:
  110.                         break;
  111.                 }
  112.             }
  113.            
  114.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  115.             // dati
  116.             if (acHelper.isEditModeInProgress()) {
  117.                 // setto la barra del titolo
  118.                 List<Parameter> lstParam = new ArrayList<>();
  119.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
  120.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_ALLEGATI_DI+ titleAS,
  121.                         AccordiCooperazioneCostanti.SERVLET_NAME_AC_ALLEGATI_LIST,
  122.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, idAccordo),
  123.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())));
  124.                 lstParam.add(ServletUtils.getParameterAggiungi());
  125.                
  126.                 ServletUtils.setPageDataTitle(pd, lstParam);

  127.                 // preparo i campi
  128.                 List<DataElement> dati = new ArrayList<>();
  129.                
  130.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  131.                 dati = acHelper.addAllegatoToDati(TipoOperazione.ADD, idAccordo, ruolo, ruoli, tipiAmmessi,
  132.                         tipiAmmessiLabel, dati);
  133.                
  134.                 pd.setDati(dati);

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

  140.            
  141.             Documento documento = new Documento();
  142.             documento.setRuolo(RuoliDocumento.valueOf(ruolo).toString());
  143.             documento.setByteContenuto(ff.getFileData());
  144.             documento.setFile(ff.getFileName());
  145.             switch (RuoliDocumento.valueOf(ruolo)) {
  146.                 case allegato:
  147.                     documento.setTipo(ff.getFileName().substring(ff.getFileName().lastIndexOf('.')+1, ff.getFileName().length()));
  148.                     break;
  149.                 case specificaSemiformale:
  150.                     documento.setTipo(TipiDocumentoSemiformale.valueOf(tipoFile).getNome());                
  151.                     break;
  152.                 default:
  153.                     break;
  154.             }
  155.            
  156.            
  157.             documento.setIdProprietarioDocumento(ac.getId());
  158.            
  159.             // Controlli sui campi immessi
  160.             boolean isOk = archiviHelper.accordiAllegatiCheckData(TipoOperazione.ADD,ff,documento,ProprietariDocumento.accordoCooperazione, pf);
  161.             if (!isOk) {
  162.                 // setto la barra del titolo
  163.                 List<Parameter> lstParam = new ArrayList<>();
  164.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
  165.                 lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_ALLEGATI_DI+ titleAS,
  166.                         AccordiCooperazioneCostanti.SERVLET_NAME_AC_ALLEGATI_LIST,
  167.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, idAccordo),
  168.                         new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())));
  169.                 lstParam.add(ServletUtils.getParameterAggiungi());
  170.                
  171.                 ServletUtils.setPageDataTitle(pd, lstParam);

  172.                 // preparo i campi
  173.                 List<DataElement> dati = new ArrayList<>();

  174.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  175.                
  176.                 dati = acHelper.addAllegatoToDati(TipoOperazione.ADD, idAccordo, ruolo, ruoli, tipiAmmessi,
  177.                         tipiAmmessiLabel, dati);
  178.                
  179.                 pd.setDati(dati);
  180.                
  181.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  182.                
  183.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
  184.                         ForwardParams.ADD());
  185.             }

  186.             //inserimento documento in accordo
  187.            
  188.             switch (RuoliDocumento.valueOf(ruolo)) {
  189.                 case allegato:
  190.                     ac.addAllegato(documento);
  191.                     break;
  192.                 case specificaSemiformale:
  193.                     ac.addSpecificaSemiformale(documento);
  194.                     break;
  195.                 default:
  196.                     break;
  197.             }
  198.            
  199.            
  200.             // effettuo le operazioni
  201.             acCore.performUpdateOperation(userLogin, acHelper.smista(), ac);

  202.             // Preparo la lista
  203.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  204.            
  205.             List<Documento> lista = acCore.accordiCoopAllegatiList(idAccordoLong, ricerca);

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

  207.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  208.            
  209.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
  210.                     ForwardParams.ADD());
  211.         } catch (Exception e) {
  212.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  213.                     AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
  214.                     ForwardParams.ADD());
  215.         }
  216.     }

  217.    
  218. }