AccordiServizioParteComuneResourcesRepresentationList.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.apc;

  21. import java.util.List;

  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import javax.servlet.http.HttpSession;

  25. import org.apache.commons.lang.StringUtils;
  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.openspcoop2.core.commons.Liste;
  31. import org.openspcoop2.core.registry.AccordoServizioParteComune;
  32. import org.openspcoop2.core.registry.Resource;
  33. import org.openspcoop2.core.registry.ResourceRepresentation;
  34. import org.openspcoop2.core.registry.ResourceRequest;
  35. import org.openspcoop2.core.registry.ResourceResponse;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * AccordiServizioParteComuneResourcesRepresentationList
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  *
  50.  */
  51. public final class AccordiServizioParteComuneResourcesRepresentationList extends Action {

  52.     @Override
  53.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  54.         HttpSession session = request.getSession(true);

  55.         // Inizializzo PageData
  56.         PageData pd = new PageData();

  57.         GeneralHelper generalHelper = new GeneralHelper(session);

  58.         GeneralData gd = generalHelper.initGeneralData(request);

  59.         try {

  60.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();

  61.             AccordiServizioParteComuneHelper apcHelper = new AccordiServizioParteComuneHelper(request, pd, session);

  62.             String id = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID);
  63.             int idAccordo = Integer.parseInt(id);
  64.             String nomeRisorsa = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_RESOURCES_NOME);

  65.             String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  66.             if("".equals(tipoAccordo))
  67.                 tipoAccordo = null;

  68.             String statusResponseS = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_RESOURCES_RESPONSE_STATUS);
  69.             Integer statusResponse = null;
  70.             try {
  71.                 if(StringUtils.isNotEmpty(statusResponseS))
  72.                     statusResponse = Integer.parseInt(statusResponseS);
  73.             }catch(Exception e) {
  74.                 statusResponse = null;
  75.             }

  76.             String isReq = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_RESOURCE_REQUEST);
  77.             boolean isRequest = ServletUtils.isCheckBoxEnabled(isReq);

  78.             // Preparo il menu
  79.             apcHelper.makeMenu();
  80.            
  81.             // Prendo l'id della risorsa
  82.             Long idRisorsa = 0L;
  83.             Resource res =  null;
  84.             AccordoServizioParteComune as = apcCore.getAccordoServizioFull(idAccordo);
  85.             for (int i = 0; i < as.sizeResourceList(); i++) {
  86.                 res = as.getResource(i);
  87.                 if (nomeRisorsa.equals(res.getNome())) {
  88.                     idRisorsa = res.getId();
  89.                     break;
  90.                 }
  91.             }
  92.            
  93.             Long idResponse = null;
  94.             ResourceRequest resourceRequest = null;
  95.             ResourceResponse resourceResponse = null;
  96.             if(res!=null) {
  97.                 if(isRequest) {
  98.                     resourceRequest = res.getRequest();
  99.                 } else {
  100.                     if(res.getResponseList() != null) {
  101.                         for (int i = 0; i < res.getResponseList().size(); i++) {
  102.                             resourceResponse = res.getResponse(i);
  103.                             if (statusResponse!=null && (resourceResponse.getStatus() == statusResponse.intValue())) {
  104.                                 idResponse = resourceResponse.getId();
  105.                                 break;
  106.                             }
  107.                         }
  108.                     }
  109.                 }
  110.             }
  111.                        

  112.             // Controllo i criteri di ricerca e recupero eventuali parametri
  113.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  114.             int idLista = isRequest ? Liste.ACCORDI_API_RESOURCES_REPRESENTATION_REQUEST : Liste.ACCORDI_API_RESOURCES_REPRESENTATION_RESPONSE;

  115.             ricerca = apcHelper.checkSearchParameters(idLista, ricerca);

  116.             List<ResourceRepresentation> lista = apcCore.accordiResourceRepresentationsList(idRisorsa, isRequest, idResponse, ricerca);

  117.             apcHelper.prepareAccordiResourcesRepresentationsList(id, as, lista, ricerca, tipoAccordo, isRequest, res, resourceRequest, resourceResponse);
  118.            
  119.             // salvo l'oggetto ricerca nella sessione
  120.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

  121.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  122.             return ServletUtils.getStrutsForward(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_RESOURCES_REPRESENTATIONS, ForwardParams.LIST());

  123.         } catch (Exception e) {
  124.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  125.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_RESOURCES_REPRESENTATIONS, ForwardParams.LIST());
  126.         }
  127.     }
  128. }