SoggettiUtilities.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.soggetti;

  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.Set;

  24. import org.openspcoop2.core.commons.ErrorsHandlerCostant;
  25. import org.openspcoop2.core.id.IDSoggetto;
  26. import org.openspcoop2.core.registry.Soggetto;
  27. import org.openspcoop2.protocol.engine.utils.DBOggettiInUsoUtils;
  28. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  29. import org.openspcoop2.web.ctrlstat.servlet.pdd.PddCore;
  30. import org.openspcoop2.web.ctrlstat.servlet.utenti.UtentiCore;
  31. import org.openspcoop2.web.lib.mvc.Costanti;
  32. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  33. /**
  34.  * SoggettiUtilities
  35.  *
  36.  * @author Andrea Poli (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  *
  40.  */
  41. public class SoggettiUtilities {

  42.     public static List<Object> getOggettiDaAggiornare(SoggettiCore soggettiCore,
  43.             String oldnomeprov,String nomeprov,
  44.             String oldtipoprov,String tipoprov,
  45.             SoggettoCtrlStat sog) throws Exception{
  46.        
  47.         // Oggetti da modificare (per riflettere la modifica sul connettore)
  48.         SoggettoUpdateUtilities soggettoUpdateUtilities =
  49.                 new SoggettoUpdateUtilities(soggettiCore, oldnomeprov, nomeprov, oldtipoprov, tipoprov, sog);

  50.         // Soggetto
  51.         // aggiungo il soggetto da aggiornare
  52.         soggettoUpdateUtilities.addSoggetto();

  53.         // Servizi Applicativi
  54.         // Se e' cambiato il tipo o il nome del soggetto devo effettuare la modifica dei servizi applicativi
  55.         // poiche il cambio si riflette sul nome dei connettori del servizio applicativo
  56.         soggettoUpdateUtilities.checkServiziApplicativi();

  57.         // Accordi di Cooperazione
  58.         // Se e' cambiato il tipo o il nome del soggetto devo effettuare la modifica degli accordi di cooperazione:
  59.         // - soggetto referente
  60.         // - soggetti partecipanti
  61.         soggettoUpdateUtilities.checkAccordiCooperazione();

  62.         // Accordi di Servizio Parte Comune
  63.         // Se e' cambiato il tipo o il nome del soggetto devo effettuare la modifica degli accordi di servizio
  64.         // poiche il cambio si riflette sul soggetto gestore
  65.         soggettoUpdateUtilities.checkAccordiServizioParteComune();

  66.         // Accordi di Servizio Parte Specifica
  67.         // Se e' cambiato il tipo o il nome del soggetto devo effettuare la modifica dei servizi
  68.         // poiche il cambio si riflette sul nome dei connettori del servizio
  69.         soggettoUpdateUtilities.checkAccordiServizioParteSpecifica();

  70.         // Porte Delegate
  71.         // Se e' cambiato il tipo o il nome del soggetto devo effettuare la modifica delle porte delegate
  72.         // poiche il cambio si riflette sul nome della porta delegata
  73.         soggettoUpdateUtilities.checkPorteDelegate();

  74.         // Porte Applicative
  75.         // Se e' cambiato il tipo o il nome del soggetto virtuale devo effettuare la modifica delle porte applicative
  76.         // poiche il cambio si riflette all'interno delle informazioni delle porte applicative
  77.         soggettoUpdateUtilities.checkPorteApplicative();    

  78.         // Fruitori nei servizi
  79.         soggettoUpdateUtilities.checkFruitori();
  80.        
  81.         // Check Policy Globali
  82.         soggettoUpdateUtilities.checkPolicyGlobali();
  83.        
  84.         // Check Regole di Proxy Pass
  85.         soggettoUpdateUtilities.checkConfigurazione();
  86.        
  87.         return soggettoUpdateUtilities.getOggettiDaAggiornare();
  88.     }
  89.    
  90.     public static SoggettiDelStatus deleteSoggetto(Soggetto soggettoRegistro, org.openspcoop2.core.config.Soggetto soggettoConfig, String userLogin,
  91.             SoggettiCore soggettiCore, SoggettiHelper soggettiHelper, StringBuilder inUsoMessage, String newLine) throws Exception {
  92.        
  93.         PddCore pddCore = new PddCore(soggettiCore);
  94.         UtentiCore utentiCore = new UtentiCore(soggettiCore);
  95.        
  96.         boolean deleteOperativo = false;
  97.         boolean delete = false;
  98.        
  99.         IDSoggetto idSoggetto = null;
  100.         if(soggettiCore.isRegistroServiziLocale()){
  101.             idSoggetto = new IDSoggetto(soggettoRegistro.getTipo(), soggettoRegistro.getNome());
  102.             soggettoConfig = soggettiCore.getSoggetto(idSoggetto);
  103.         }
  104.         else{
  105.             idSoggetto = new IDSoggetto(soggettoConfig.getTipo(), soggettoConfig.getNome());
  106.         }
  107.         boolean soggettoInUso = false;
  108.         boolean normalizeObjectIds = !soggettiHelper.isModalitaCompleta();
  109.         HashMap<ErrorsHandlerCostant, List<String>> whereIsInUso = new HashMap<ErrorsHandlerCostant, List<String>>();
  110.         boolean verificaRuoli = false;
  111.         if(soggettiCore.isRegistroServiziLocale()){
  112.             soggettoInUso = soggettiCore.isSoggettoInUso(soggettoRegistro, whereIsInUso, normalizeObjectIds, verificaRuoli);
  113.         }else{
  114.             soggettoInUso = soggettiCore.isSoggettoInUso(soggettoConfig, whereIsInUso, normalizeObjectIds, verificaRuoli);
  115.         }


  116.         if (soggettoInUso) {
  117.             inUsoMessage.append(DBOggettiInUsoUtils.toString(idSoggetto, whereIsInUso, true, newLine, normalizeObjectIds));
  118.             inUsoMessage.append(newLine);

  119.         }
  120.         else if(soggettoConfig.isDominioDefault()) {
  121.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(idSoggetto.getTipo());
  122.             inUsoMessage.append("Il Soggetto '"+soggettiHelper.getLabelNomeSoggetto(protocollo, idSoggetto)+"',  essendo il soggeto predefinito per il profilo '"+
  123.                     soggettiHelper.getLabelProtocollo(protocollo)+"', non è eliminabile");
  124.             inUsoMessage.append(newLine);
  125.             inUsoMessage.append(newLine);
  126.         }
  127.         else {
  128.             SoggettoCtrlStat sog = new SoggettoCtrlStat(soggettoRegistro, soggettoConfig);
  129.             soggettiCore.performDeleteOperation(userLogin, soggettiHelper.smista(), sog);
  130.             delete = true;
  131.            
  132.             if(soggettoRegistro!=null && !pddCore.isPddEsterna(soggettoRegistro.getPortaDominio())) {
  133.                
  134.                 // sistemo utenze dopo l'aggiornamento
  135.                 IDSoggetto idSoggettoSelezionato = new IDSoggetto(soggettoRegistro.getTipo(), soggettoRegistro.getNome());
  136.                 utentiCore.modificaSoggettoUtilizzatoConsole(idSoggettoSelezionato.toString(), null); // annullo selezione
  137.                
  138.                 deleteOperativo = true;
  139.             }
  140.         }
  141.        
  142.         SoggettiDelStatus delStatus = new SoggettiDelStatus();
  143.         delStatus.setDeletedOperativo(deleteOperativo);
  144.         delStatus.setDeleted(delete);
  145.         return delStatus;
  146.        
  147.     }
  148.    
  149.     public static boolean soggettiCheckData(SoggettiCore soggettiCore, SoggettiHelper soggettiHelper,
  150.             String newLine,
  151.             String oldnomeprov, String oldtipoprov, boolean privato,
  152.             TipoOperazione tipoOp, String id, String tipoprov, String nomeprov, String codiceIpa, String pdUrlPrefixRewriter, String paUrlPrefixRewriter,
  153.             Soggetto soggettoOld, boolean isSupportatoAutenticazioneSoggetti, String descrizione, String portaDominio) throws Exception {
  154.        
  155.         // Controlli sui campi immessi
  156.         boolean isOk = soggettiHelper.soggettiCheckData(tipoOp, id, tipoprov, nomeprov, codiceIpa, pdUrlPrefixRewriter, paUrlPrefixRewriter,
  157.                 soggettoOld, isSupportatoAutenticazioneSoggetti, descrizione, portaDominio);

  158.         if(isOk){
  159.             // check change tipo/nome con gestione workflow abilitata
  160.             if(soggettiCore.isRegistroServiziLocale() && soggettiHelper.isShowGestioneWorkflowStatoDocumenti()){
  161.                 if( (!oldnomeprov.equals(nomeprov)) || (!oldtipoprov.equals(tipoprov)) ){
  162.                     HashMap<ErrorsHandlerCostant, String> whereIsInUso = new HashMap<>();
  163.                     if (soggettiCore.isSoggettoInUsoInPackageFinali(soggettoOld, whereIsInUso)) {
  164.                         Set<ErrorsHandlerCostant> keys = whereIsInUso.keySet();
  165.                         String tipoNome = soggettoOld.getTipo() + "/" + soggettoOld.getNome();
  166.                         StringBuilder bf = new StringBuilder();
  167.                         bf.append("Tipo o Nome del soggetto ");
  168.                         bf.append(tipoNome);
  169.                         bf.append(" non modificabile poiche' :"+newLine);
  170.                         for (ErrorsHandlerCostant key : keys) {
  171.                             String msg = whereIsInUso.get(key);

  172.                             if (ErrorsHandlerCostant.IN_USO_IN_SERVIZI.toString().equals(key.toString())) {
  173.                                 bf.append("- erogatore di Servizi in uno stato finale: " + msg + newLine);
  174.                             }
  175.                             else if (ErrorsHandlerCostant.POSSIEDE_FRUITORI.toString().equals(key.toString())) {
  176.                                 bf.append("- fruitore in uno stato finale: " + msg + newLine);
  177.                             }
  178.                             else if (ErrorsHandlerCostant.IS_REFERENTE.toString().equals(key.toString())) {
  179.                                 bf.append("- referente di un accordo di servizio in uno stato finale: " + msg + newLine);
  180.                             }
  181.                             else if (ErrorsHandlerCostant.IS_REFERENTE_COOPERAZIONE.toString().equals(key.toString())) {
  182.                                 bf.append("- referente di un accordo di cooperazione in uno stato finale: " + msg + newLine);
  183.                             }
  184.                             else if (ErrorsHandlerCostant.IS_PARTECIPANTE_COOPERAZIONE.toString().equals(key.toString())) {
  185.                                 bf.append("- soggetto partecipante di un accordo di cooperazione in uno stato finale: " + msg + newLine);
  186.                             }

  187.                         }// chiudo for

  188.                         bf.append(newLine);
  189.                         isOk = false;
  190.                         soggettiHelper.getPd().setMessage(bf.toString(), Costanti.MESSAGE_TYPE_INFO);
  191.                     }
  192.                 }
  193.             }
  194.         }

  195.         if(isOk &&
  196.             // check visibilita
  197.             soggettiCore.isRegistroServiziLocale() && soggettiCore.isShowFlagPrivato() && privato) {
  198.             HashMap<ErrorsHandlerCostant, String> whereIsInUso = new HashMap<>();
  199.             if (soggettiCore.isSoggettoInUsoInPackagePubblici(soggettoOld, whereIsInUso)) {
  200.                 Set<ErrorsHandlerCostant> keys = whereIsInUso.keySet();
  201.                 String tipoNome = soggettoOld.getTipo() + "/" + soggettoOld.getNome();
  202.                 StringBuilder bf = new StringBuilder();
  203.                 bf.append("Visibilita' del soggetto ");
  204.                 bf.append(tipoNome);
  205.                 bf.append(" non impostabile a privata poichè :"+newLine);
  206.                 for (ErrorsHandlerCostant key : keys) {
  207.                     String msg = whereIsInUso.get(key);

  208.                     if (ErrorsHandlerCostant.IN_USO_IN_SERVIZI.toString().equals(key.toString())) {
  209.                         bf.append("- erogatore di Servizi con visibilita' pubblica: " + msg + newLine);
  210.                     }
  211.                     else if (ErrorsHandlerCostant.POSSIEDE_FRUITORI.toString().equals(key.toString())) {
  212.                         bf.append("- fruitore di servizi con visibilita' pubblica: " + msg + newLine);
  213.                     }
  214.                     else if (ErrorsHandlerCostant.IS_REFERENTE.toString().equals(key.toString())) {
  215.                         bf.append("- referente di un accordo di servizio con visibilita' pubblica: " + msg + newLine);
  216.                     }
  217.                     else if (ErrorsHandlerCostant.IS_REFERENTE_COOPERAZIONE.toString().equals(key.toString())) {
  218.                         bf.append("- referente di un accordo di cooperazione con visibilita' pubblica: " + msg + newLine);
  219.                     }
  220.                     else if (ErrorsHandlerCostant.IS_PARTECIPANTE_COOPERAZIONE.toString().equals(key.toString())) {
  221.                         bf.append("- soggetto partecipante di un accordo di cooperazione con visibilita' pubblica: " + msg + newLine);
  222.                     }

  223.                 }// chiudo for

  224.                 bf.append("<br>");
  225.                 isOk = false;
  226.                 soggettiHelper.getPd().setMessage(bf.toString(),Costanti.MESSAGE_TYPE_INFO);
  227.             }
  228.         }
  229.        
  230.         return isOk;
  231.     }
  232. }