PorteApplicativeAzioneDel.java
/*
* GovWay - A customizable API Gateway
* https://govway.org
*
* Copyright (c) 2005-2024 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.pa;
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.openspcoop2.core.commons.Liste;
import org.openspcoop2.core.config.PortaApplicativa;
import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
import org.openspcoop2.core.registry.driver.IDAccordoFactory;
import org.openspcoop2.message.constants.ServiceBinding;
import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
import org.openspcoop2.web.ctrlstat.core.Utilities;
import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
import org.openspcoop2.web.lib.mvc.Costanti;
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;
/**
* PorteApplicativeAzioneDel
*
* @author Andrea Poli (apoli@link.it)
* @author Giuliano Pintori (pintori@link.it)
* @author $Author$
* @version $Rev$, $Date$
*
*/
public final class PorteApplicativeAzioneDel 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 {
PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
// prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
if(idAsps == null)
idAsps = "";
String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
int idInt = Integer.parseInt(idPorta);
String objToRemove = porteApplicativeHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
// Prendo la porta applicativa
PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
List<String> azioni = new ArrayList<>();
for (int i = 0; i < idsToRemove.size(); i++) {
String azione = idsToRemove.get(i);
azioni.add(azione);
}
StringBuilder inUsoMessage = new StringBuilder();
String userLogin = ServletUtils.getUserLoginFromSession(porteApplicativeHelper.getSession());
PorteApplicativeUtilities.deletePortaApplicativaAzioni(pa, porteApplicativeCore, porteApplicativeHelper,
inUsoMessage, org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE, azioni, userLogin);
// imposto msg di errore se presente
if (inUsoMessage.length()>0) {
pd.setMessage(inUsoMessage.toString());
}
String labelPerPorta = null;
if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
porteApplicativeHelper.getLabelAzioniDi(serviceBinding),
porteApplicativeHelper.getLabelAzioni(serviceBinding),
pa);
}
else {
labelPerPorta = porteApplicativeHelper.getLabelAzioniDi(serviceBinding)+pa.getNome();
}
// Preparo il menu
porteApplicativeHelper.makeMenu();
// ricarico la porta
pa = porteApplicativeCore.getPortaApplicativa(idInt);
// Prendo nome della porta applicativa
String nomePorta = pa.getNome();
List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
List<String> listaAzioni = pa.getAzione().getAzioneDelegataList();
// Preparo la lista
ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
int idLista = Liste.PORTE_APPLICATIVE_AZIONI;
ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
List<Parameter> listaParametriSessione = new ArrayList<>();
listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
porteApplicativeHelper.preparePorteAzioneList(ricerca,
listaAzioni, idPorta, parentPA, lstParam, nomePorta, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
listaParametriSessione, labelPerPorta, serviceBinding, aspc);
// imposto menu' contestuale
porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);
ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
// Forward control to the specified success URI
return ServletUtils.getStrutsForward (mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
ForwardParams.DEL());
} catch (Exception e) {
return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
ForwardParams.DEL());
}
}
}