AccordiServizioParteComuneAllegatiView.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.apc;
- import java.util.List;
- import java.util.ArrayList;
- 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.openspcoop2.core.registry.AccordoServizioParteComune;
- import org.openspcoop2.core.registry.Documento;
- import org.openspcoop2.core.registry.driver.IDAccordoFactory;
- import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
- import org.openspcoop2.web.ctrlstat.core.Utilities;
- import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
- import org.openspcoop2.web.ctrlstat.servlet.apc.api.ApiCostanti;
- import org.openspcoop2.web.ctrlstat.servlet.archivi.ArchiviCore;
- 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;
- /**
- * accordiAllegatiView
- *
- * @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 AccordiServizioParteComuneAllegatiView extends Action {
- @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);
- try {
-
- AccordiServizioParteComuneHelper apcHelper = new AccordiServizioParteComuneHelper(request, pd, session);
- String idAllegato = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ALLEGATI_ID_ALLEGATO);
- String idAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ALLEGATI_ID_ACCORDO);
-
- long idAllegatoLong = Long.parseLong(idAllegato);
- long idAccordoLong = Long.parseLong(idAccordo);
-
- String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
- if("".equals(tipoAccordo))
- tipoAccordo = null;
-
- AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
- ArchiviCore archiviCore = new ArchiviCore(apcCore);
- // Preparo il menu
- apcHelper.makeMenu();
- // Prendo il nome
- AccordoServizioParteComune as = apcCore.getAccordoServizioFull(idAccordoLong);
- String labelASTitle = apcHelper.getLabelIdAccordo(as);
-
- Documento doc = archiviCore.getDocumento(idAllegatoLong,true);
- StringBuilder contenutoAllegato = new StringBuilder();
- String errore = Utilities.getTestoVisualizzabile(doc.getByteContenuto(),contenutoAllegato);
-
- IDAccordoFactory idAccordoFactory = IDAccordoFactory.getInstance();
- String uri = idAccordoFactory.getUriFromAccordo(as);
- Parameter pTipoAccordo = AccordiServizioParteComuneUtilities.getParametroAccordoServizio(tipoAccordo);
- Parameter pIdAccordo = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID, idAccordo);
- Parameter pNomeAccordo = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_NOME, uri);
-
- Boolean isModalitaVistaApiCustom = ServletUtils.getBooleanAttributeFromSession(ApiCostanti.SESSION_ATTRIBUTE_VISTA_APC_API, session, request, false).getValue();
- List<Parameter> listaParams = apcHelper.getTitoloApc(TipoOperazione.ADD, as, tipoAccordo, labelASTitle, null, false);
-
- String labelAllegati = (isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) ? AccordiServizioParteComuneCostanti.LABEL_ALLEGATI : AccordiServizioParteComuneCostanti.LABEL_ALLEGATI + " di " + labelASTitle;
-
- listaParams.add(new Parameter(labelAllegati, AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_ALLEGATI_LIST, pIdAccordo, pNomeAccordo, pTipoAccordo));
- listaParams.add(new Parameter(doc.getFile(), null));
-
- // setto la barra del titolo
- ServletUtils.setPageDataTitle(pd, listaParams);
-
- // preparo i campi
- List<Object> dati = new ArrayList<>();
- dati.add(ServletUtils.getDataElementForEditModeFinished());
- apcHelper.addAccordiAllegatiToDati(dati,TipoOperazione.OTHER,idAccordo,
- null,null,null,null,tipoAccordo,null,
- idAllegato,doc,as,errore,contenutoAllegato,null);
-
- pd.setDati(dati);
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
-
- return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_ALLEGATI,
- AccordiServizioParteComuneCostanti.TIPO_OPERAZIONE_VIEW);
-
- } catch (Exception e) {
- return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
- AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_ALLEGATI, AccordiServizioParteComuneCostanti.TIPO_OPERAZIONE_VIEW);
- }
- }
- }