AccordiCooperazioneAllegatiAdd.java
- /*
- * GovWay - A customizable API Gateway
- * https://govway.org
- *
- * Copyright (c) 2005-2025 Link.it srl (https://link.it).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3, as published by
- * the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
- package org.openspcoop2.web.ctrlstat.servlet.ac;
- import java.util.ArrayList;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.struts.action.Action;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionForward;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.upload.FormFile;
- import org.openspcoop2.core.registry.AccordoCooperazione;
- import org.openspcoop2.core.registry.Documento;
- import org.openspcoop2.core.registry.constants.ProprietariDocumento;
- import org.openspcoop2.core.registry.constants.RuoliDocumento;
- import org.openspcoop2.core.registry.constants.TipiDocumentoSemiformale;
- import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
- import org.openspcoop2.protocol.sdk.IProtocolFactory;
- import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
- import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
- import org.openspcoop2.web.ctrlstat.servlet.FileUploadForm;
- import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
- import org.openspcoop2.web.ctrlstat.servlet.archivi.ArchiviHelper;
- import org.openspcoop2.web.lib.mvc.DataElement;
- import org.openspcoop2.web.lib.mvc.ForwardParams;
- import org.openspcoop2.web.lib.mvc.GeneralData;
- import org.openspcoop2.web.lib.mvc.PageData;
- import org.openspcoop2.web.lib.mvc.Parameter;
- import org.openspcoop2.web.lib.mvc.ServletUtils;
- import org.openspcoop2.web.lib.mvc.TipoOperazione;
- /**
- * accordiCoopAllegatiAdd
- *
- * @author Andrea Poli (apoli@link.it)
- * @author Stefano Corallo (corallo@link.it)
- * @author Sandra Giangrandi (sandra@link.it)
- * @author $Author$
- * @version $Rev$, $Date$
- *
- */
- public final class AccordiCooperazioneAllegatiAdd extends Action {
- @SuppressWarnings("incomplete-switch")
- @Override
- public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
- HttpSession session = request.getSession(true);
-
- // Inizializzo PageData
- PageData pd = new PageData();
- GeneralHelper generalHelper = new GeneralHelper(session);
- // Inizializzo GeneralData
- GeneralData gd = generalHelper.initGeneralData(request);
- String userLogin = ServletUtils.getUserLoginFromSession(session);
- try {
-
- FileUploadForm fileUpload = (FileUploadForm) form;
-
- AccordiCooperazioneHelper acHelper = new AccordiCooperazioneHelper(request, pd, session);
- ArchiviHelper archiviHelper = new ArchiviHelper(request, pd, session);
- String idAccordo = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID);
- long idAccordoLong = Long.parseLong(idAccordo);
- String ruolo = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_RUOLO);
- String tipoFile = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_FILE);
- FormFile ff = fileUpload.getTheFile();
- /**String tipoSICA = acHelper.getParameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_TIPO_SICA);
- if("".equals(tipoSICA))
- tipoSICA = null;*/
-
- AccordiCooperazioneCore acCore = new AccordiCooperazioneCore();
- // Preparo il menu
- acHelper.makeMenu();
- // Prendo il nome
- AccordoCooperazione ac = acCore.getAccordoCooperazione(idAccordoLong);
- String titleAS = acHelper.getLabelIdAccordoCooperazione(ac);
- IProtocolFactory<?> pf = ProtocolFactoryManager.getInstance().getProtocolFactoryByOrganizationType(ac.getSoggettoReferente().getTipo());
-
- String[] ruoli = {RuoliDocumento.allegato.toString(),RuoliDocumento.specificaSemiformale.toString()};
-
- String[] tipiAmmessi = null;
- String[] tipiAmmessiLabel = null;
-
- if(ruolo!=null && !"".equals(ruolo)){
- switch (RuoliDocumento.valueOf(ruolo)) {
- case allegato:
- //non ci sono vincoli
- break;
- case specificaSemiformale:
- tipiAmmessi = TipiDocumentoSemiformale.toEnumNameArray();
- tipiAmmessiLabel=TipiDocumentoSemiformale.toStringArray();
- break;
- default:
- break;
- }
- }
-
- // Se idhid = null, devo visualizzare la pagina per l'inserimento
- // dati
- if (acHelper.isEditModeInProgress()) {
- // setto la barra del titolo
- List<Parameter> lstParam = new ArrayList<>();
- lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
- lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_ALLEGATI_DI+ titleAS,
- AccordiCooperazioneCostanti.SERVLET_NAME_AC_ALLEGATI_LIST,
- new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, idAccordo),
- new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())));
- lstParam.add(ServletUtils.getParameterAggiungi());
-
- ServletUtils.setPageDataTitle(pd, lstParam);
- // preparo i campi
- List<DataElement> dati = new ArrayList<>();
-
- dati.add(ServletUtils.getDataElementForEditModeFinished());
- dati = acHelper.addAllegatoToDati(TipoOperazione.ADD, idAccordo, ruolo, ruoli, tipiAmmessi,
- tipiAmmessiLabel, dati);
-
- pd.setDati(dati);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
-
- return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
- ForwardParams.ADD());
- }
-
- Documento documento = new Documento();
- documento.setRuolo(RuoliDocumento.valueOf(ruolo).toString());
- documento.setByteContenuto(ff.getFileData());
- documento.setFile(ff.getFileName());
- switch (RuoliDocumento.valueOf(ruolo)) {
- case allegato:
- documento.setTipo(ff.getFileName().substring(ff.getFileName().lastIndexOf('.')+1, ff.getFileName().length()));
- break;
- case specificaSemiformale:
- documento.setTipo(TipiDocumentoSemiformale.valueOf(tipoFile).getNome());
- break;
- default:
- break;
- }
-
-
- documento.setIdProprietarioDocumento(ac.getId());
-
- // Controlli sui campi immessi
- boolean isOk = archiviHelper.accordiAllegatiCheckData(TipoOperazione.ADD,ff,documento,ProprietariDocumento.accordoCooperazione, pf);
- if (!isOk) {
- // setto la barra del titolo
- List<Parameter> lstParam = new ArrayList<>();
- lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE, AccordiCooperazioneCostanti.SERVLET_NAME_ACCORDI_COOPERAZIONE_LIST));
- lstParam.add(new Parameter(AccordiCooperazioneCostanti.LABEL_ACCORDI_COOPERAZIONE_ALLEGATI_DI+ titleAS,
- AccordiCooperazioneCostanti.SERVLET_NAME_AC_ALLEGATI_LIST,
- new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_ID, idAccordo),
- new Parameter(AccordiCooperazioneCostanti.PARAMETRO_ACCORDI_COOPERAZIONE_NOME, ac.getNome())));
- lstParam.add(ServletUtils.getParameterAggiungi());
-
- ServletUtils.setPageDataTitle(pd, lstParam);
- // preparo i campi
- List<DataElement> dati = new ArrayList<>();
- dati.add(ServletUtils.getDataElementForEditModeFinished());
-
- dati = acHelper.addAllegatoToDati(TipoOperazione.ADD, idAccordo, ruolo, ruoli, tipiAmmessi,
- tipiAmmessiLabel, dati);
-
- pd.setDati(dati);
-
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
-
- return ServletUtils.getStrutsForwardEditModeCheckError(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
- ForwardParams.ADD());
- }
- //inserimento documento in accordo
-
- switch (RuoliDocumento.valueOf(ruolo)) {
- case allegato:
- ac.addAllegato(documento);
- break;
- case specificaSemiformale:
- ac.addSpecificaSemiformale(documento);
- break;
- default:
- break;
- }
-
-
- // effettuo le operazioni
- acCore.performUpdateOperation(userLogin, acHelper.smista(), ac);
- // Preparo la lista
- ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
-
- List<Documento> lista = acCore.accordiCoopAllegatiList(idAccordoLong, ricerca);
- acHelper.prepareAccordiCoopAllegatiList(ac, ricerca, lista);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
-
- return ServletUtils.getStrutsForwardEditModeFinished(mapping, AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
- ForwardParams.ADD());
- } catch (Exception e) {
- return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
- AccordiCooperazioneCostanti.OBJECT_NAME_AC_ALLEGATI,
- ForwardParams.ADD());
- }
- }
-
- }