RuoliApiHelper.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.core.config.rs.server.api.impl.ruoli;

  21. import org.openspcoop2.core.config.rs.server.api.impl.Enums;
  22. import org.openspcoop2.core.config.rs.server.api.impl.HttpRequestWrapper;
  23. import org.openspcoop2.core.config.rs.server.model.ContestoEnum;
  24. import org.openspcoop2.core.config.rs.server.model.FonteEnum;
  25. import org.openspcoop2.core.config.rs.server.model.Ruolo;
  26. import org.openspcoop2.core.config.rs.server.model.RuoloItem;
  27. import org.openspcoop2.core.registry.constants.RuoloTipologia;
  28. import org.openspcoop2.generic_project.exception.NotFoundException;
  29. import org.openspcoop2.web.ctrlstat.servlet.ruoli.RuoliCostanti;

  30. /**
  31.  * RuoliApiHelper
  32.  *
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  *
  36.  */
  37. public class RuoliApiHelper {
  38.    
  39.     public static void overrideRuoloParams(Ruolo body, HttpRequestWrapper wrap) {      
  40.         wrap.overrideParameter(RuoliCostanti.PARAMETRO_RUOLO_DESCRIZIONE, body.getDescrizione());
  41.         wrap.overrideParameter(RuoliCostanti.PARAMETRO_RUOLO_NOME, body.getNome());
  42.         wrap.overrideParameter(RuoliCostanti.PARAMETRO_RUOLO_NOME_ESTERNO, body.getIdentificativoEsterno());
  43.     }
  44.        

  45.     public static org.openspcoop2.core.registry.Ruolo apiRuoloToRuoloRegistro(Ruolo ruolo, String superUser) throws NotFoundException  {
  46.        
  47.         org.openspcoop2.core.registry.Ruolo regRuolo = new org.openspcoop2.core.registry.Ruolo();
  48.         regRuolo.setNome(ruolo.getNome());
  49.         regRuolo.setDescrizione(ruolo.getDescrizione());
  50.        
  51.         FonteEnum tipologiaFonte = ruolo.getFonte();
  52.         if (tipologiaFonte == null)
  53.             tipologiaFonte = FonteEnum.QUALSIASI;
  54.         regRuolo.setTipologia(Enums.apiFonteToRegistroTipologia(tipologiaFonte));
  55.        
  56.         ContestoEnum contesto = ruolo.getContesto();
  57.         if (contesto == null)
  58.             contesto = ContestoEnum.QUALSIASI;
  59.         regRuolo.setContestoUtilizzo(Enums.apiContestoToRegistroContesto(contesto));

  60.         if(regRuolo.getTipologia()!=null && (RuoloTipologia.QUALSIASI.equals(regRuolo.getTipologia()) || RuoloTipologia.ESTERNO.equals(regRuolo.getTipologia()))) {
  61.             String n = ruolo.getIdentificativoEsterno();
  62.             if(n!=null) {
  63.                 n = n.trim();
  64.             }
  65.             regRuolo.setNomeEsterno(n);
  66.         }
  67.        
  68.         regRuolo.setSuperUser(superUser);
  69.        
  70.         return regRuolo;
  71.     }
  72.    
  73.     public static Ruolo ruoloRegistroToApiRuolo(org.openspcoop2.core.registry.Ruolo ruolo) {
  74.         Ruolo ret = new Ruolo();
  75.        
  76.         ret.setContesto(Enums.registroContestoToApiContesto(ruolo.getContestoUtilizzo()));
  77.         ret.setDescrizione(ruolo.getDescrizione());
  78.         ret.setFonte(Enums.registroTipologiaToApiFonte(ruolo.getTipologia()));
  79.         ret.setIdentificativoEsterno(ruolo.getNomeEsterno());
  80.         ret.setNome(ruolo.getNome());
  81.        
  82.         return ret;
  83.     }
  84.    
  85.     public static RuoloItem ruoloApiToRuoloItem(Ruolo ruolo) {
  86.         RuoloItem ret = new RuoloItem();
  87.         ret.setContesto(ruolo.getContesto());
  88.         ret.setFonte(ruolo.getFonte());
  89.         ret.setNome(ruolo.getNome());
  90.        
  91.         return ret;
  92.     }
  93.    

  94. }