PorteDelegateAbilitazione.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.pd;
- import java.util.List;
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import org.apache.commons.lang.StringUtils;
- 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.PortaDelegata;
- import org.openspcoop2.core.config.PortaDelegataServizio;
- import org.openspcoop2.core.config.constants.StatoFunzionalita;
- import org.openspcoop2.core.id.IDPortaDelegata;
- import org.openspcoop2.core.id.IDServizio;
- import org.openspcoop2.core.id.IDSoggetto;
- import org.openspcoop2.core.mapping.MappingFruizionePortaDelegata;
- import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
- import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
- import org.openspcoop2.core.registry.driver.IDAccordoFactory;
- import org.openspcoop2.core.registry.driver.IDServizioFactory;
- import org.openspcoop2.message.constants.ServiceBinding;
- import org.openspcoop2.pdd.core.jmx.JMXUtils;
- import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
- import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
- import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
- 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.ctrlstat.servlet.aps.AccordiServizioParteSpecificaHelper;
- import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniHelper;
- import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
- 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.MessageType;
- import org.openspcoop2.web.lib.mvc.PageData;
- import org.openspcoop2.web.lib.mvc.ServletUtils;
- import org.openspcoop2.web.lib.mvc.TipoOperazione;
- /**
- * porteDelegateChange
- *
- * @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 PorteDelegateAbilitazione 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 {
-
- PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
- // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
- Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
- if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
-
- String changeAbilitato = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ABILITA);
- // String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
- String nomePorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA);
- String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
- int soggInt = Integer.parseInt(idsogg);
- String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
- if(idAsps == null)
- idAsps = "";
-
- String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
- if(idFruizione == null)
- idFruizione = "";
-
- String actionConferma = porteDelegateHelper.getParameter(Costanti.PARAMETRO_ACTION_CONFIRM);
-
- String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
- if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
- ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
- }
-
- String fromAPIPageInfo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_API_PAGE_INFO);
- boolean fromApi = Costanti.CHECK_BOX_ENABLED_TRUE.equalsIgnoreCase(fromAPIPageInfo);
-
- // check su oldNomePD
- PageData pdOld = ServletUtils.getPageDataFromSession(request, session);
- String oldNomePD = pdOld.getHidden(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OLD_NOME_PD);
- oldNomePD = (((oldNomePD != null) && !oldNomePD.equals("")) ? oldNomePD : nomePorta);
- // Preparo il menu
- porteDelegateHelper.makeMenu();
- // Prendo nome e tipo del soggetto
- PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
- SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
- AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
- AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
-
- IDSoggetto idSoggettoFruitore = null;
- if(porteDelegateCore.isRegistroServiziLocale()){
- org.openspcoop2.core.registry.Soggetto soggetto = soggettiCore.getSoggettoRegistro(soggInt);
- idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
- }else{
- org.openspcoop2.core.config.Soggetto soggetto = soggettiCore.getSoggetto(soggInt);
- idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
- }
- // Prendo la porta delegata
- IDPortaDelegata idpd = new IDPortaDelegata();
- idpd.setNome(oldNomePD);
- PortaDelegata oldPD = porteDelegateCore.getPortaDelegata(idpd);
-
- Long idAspsLong = -1L;
- if(idAsps.equals("")) {
- PortaDelegataServizio servizio2 = oldPD.getServizio();
- idAspsLong = servizio2.getId();
- } else {
- idAspsLong = Long.parseLong(idAsps);
- }
-
- AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idAspsLong);
- AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
- ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
-
- // in progress segnalo l'azione che si sta effettuando
- if(actionConferma == null) {
- String messaggio = porteDelegateHelper.getMessaggioConfermaModificaRegolaMappingFruizionePortaDelegata(fromApi, oldPD,serviceBinding,ServletUtils.isCheckBoxEnabled(changeAbilitato), true, true);
-
- pd.setMessage(messaggio, MessageType.CONFIRM);
-
- String[][] bottoni = {
- { Costanti.LABEL_MONITOR_BUTTON_ANNULLA,
- Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_PREFIX +
- Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_SUFFIX
-
- },
- { Costanti.LABEL_MONITOR_BUTTON_CONFERMA,
- Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_PREFIX +
- Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_SUFFIX }};
- pd.setBottoni(bottoni);
-
- }
- // se ho confermato effettuo la modifica altrimenti torno direttamente alla lista
- if(actionConferma != null && actionConferma.equals(Costanti.PARAMETRO_ACTION_CONFIRM_VALUE_OK)) {
- long idPA = oldPD.getId();
- PortaDelegata portaDelegata = (PortaDelegata) oldPD.clone();// new
- portaDelegata.setId(idPA);
- portaDelegata.setNome(nomePorta);
-
- // cambio solo la modalita'
- if(ServletUtils.isCheckBoxEnabled(changeAbilitato)) {
- portaDelegata.setStato(StatoFunzionalita.ABILITATO);
- }
- else{
- portaDelegata.setStato(StatoFunzionalita.DISABILITATO);
- }
- String userLogin = ServletUtils.getUserLoginFromSession(session);
- porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
-
- List<String> aliasJmx = porteDelegateCore.getJmxPdDAliases();
- if(aliasJmx!=null && !aliasJmx.isEmpty()) {
- for (String alias : aliasJmx) {
- String metodo = StatoFunzionalita.ABILITATO.equals(portaDelegata.getStato()) ?
- porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeMetodoEnablePortaDelegata(alias) :
- porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeMetodoDisablePortaDelegata(alias);
- try{
- String stato = porteDelegateCore.getInvoker().invokeJMXMethod(alias,
- porteDelegateCore.getJmxPdDConfigurazioneSistemaType(alias),
- porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeRisorsaConfigurazionePdD(alias),
- metodo,
- portaDelegata.getNome());
- if(stato==null) {
- throw new ServletException("Aggiornamento fallito");
- }
- if(
- !(
- JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO.equals(stato)
- ||
- (stato!=null && stato.startsWith(JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO_PREFIX))
- )
- ){
- throw new ServletException(stato);
- }
- }catch(Exception e){
- String msgErrore = "Errore durante l'aggiornamento dello stato della PortaDelegata '"+portaDelegata.getNome()+"' via jmx (jmxMethod '"+metodo+"') (node:"+alias+"): "+e.getMessage();
- ControlStationCore.logError(msgErrore, e);
- }
- }
- }
- }
- // Preparo la lista
- ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
- int idLista = -1;
- List<PortaDelegata> lista = null;
-
- switch (parentPD) {
- case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE:
- if(fromApi) {
- ErogazioniHelper apsHelper = new ErogazioniHelper(request, pd, session);
- apsHelper.prepareErogazioneChange(TipoOperazione.CHANGE, asps, idSoggettoFruitore);
- }
- else {
- idLista = Liste.CONFIGURAZIONE_FRUIZIONE;
- ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
- IDServizio idServizio2 = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
-
- List<MappingFruizionePortaDelegata> listaMapping = aspsCore.serviziFruitoriMappingList((long) Integer.parseInt(idFruizione), idSoggettoFruitore, idServizio2, ricerca);
- AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
- apsHelper.serviziFruitoriMappingList(listaMapping, idAsps, idsogg, idSoggettoFruitore, idFruizione, ricerca);
- }
- break;
- case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_SOGGETTO:
- idLista = Liste.PORTE_DELEGATE_BY_SOGGETTO;
- ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
- lista = porteDelegateCore.porteDelegateList(soggInt, ricerca);
- porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
- break;
- case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE:
- default:
- idLista = Liste.PORTE_DELEGATE;
- ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
- lista = porteDelegateCore.porteDelegateList(null, ricerca);
- porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
- break;
- }
- ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
-
- ForwardParams fwP = porteDelegateHelper.isModalitaCompleta() ? ForwardParams.OTHER("") : PorteDelegateCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE;
- // Forward control to the specified success URI
- return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_ABILITAZIONE,fwP);
- } catch (Exception e) {
- return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
- PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_ABILITAZIONE,
- ForwardParams.OTHER(""));
- }
- }
- }