import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwzom1Web</p>
 * <p>Description : Modification zone de portage.
	* </p>
 * <p>Copyright : Copyright (c) 2013</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>06/02/2013</i>
 * @version 1.0
 */
 
public class Jwlwzom1Web {
	private static final int TAILLE = 40;
	
	/**
	 * <p>Titre : setZonePortage</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>06/02/2013</i>
	 * @version 1.0
	 */
	public static Jwlwzom1 setZonePortage(
		String cd_zpo[],
		String type_portage[],
		String zpo_ordre[],
		String zpo_libelle[],
		String zpo_date_debut_fictif[],
		String protect_date_debut_fictif[],
		String zpo_date_debut[],
		String protect_date_debut[],
		String zpo_date_fin[],
		String protect_date_fin[],
		String zpo_top_valid[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwzom1 jwlwzom1 		  = new Jwlwzom1(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwzom1.Nwlwzom1Axwebent vWebent = jwlwzom1.new Nwlwzom1Axwebent();
		vWebent.dbid 			  = new BigDecimal (Constantes.DBID);
		vWebent.cible_exploitant  = Constantes.CD_CIBLE;
		vWebent.groupe_exploitant = groupe_exploitant;
		vWebent.numero_session 	  = new BigDecimal (numero_session);
		vWebent.utilisateur    	  = utilisateur;
		vWebent.transaction 	  = "WLWSTLST";
		vWebent.fonction 		  = "MODIF";
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwzom1.setNwlwzom1Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwzom1.Nwlwzom1Awlwzom1 vLwzom1 				= jwlwzom1.new Nwlwzom1Awlwzom1();
		Jwlwzom1.Nwlwzom1Awlwzom1Demande vLwzom1Demande = jwlwzom1.new Nwlwzom1Awlwzom1Demande();
		
		String tab_cd_zpo[] 			  = new String[TAILLE];
		String tab_type_portage[] 		  = new String[TAILLE];
		String tab_libelle_type_portage[] = new String[TAILLE];
		String tab_zpo_libelle[] 		  = new String[TAILLE];
		String tab_protect_date_debut_fictif[] = new String[TAILLE];
		String tab_protect_date_debut[] 	   = new String[TAILLE];
		String tab_protect_date_fin[] 		   = new String[TAILLE];
		String tab_zpo_top_valid[] 			   = new String[TAILLE];
		
		BigDecimal tab_zpo_ordre[]			  = new BigDecimal[TAILLE];
		BigDecimal tab_zpo_date_debut_fictif[]= new BigDecimal[TAILLE];
		BigDecimal tab_zpo_date_debut[]		  = new BigDecimal[TAILLE];
		BigDecimal tab_zpo_date_fin[]  		  = new BigDecimal[TAILLE];
		
		for (int i = 0; i < cd_zpo.length; i++) {
			tab_cd_zpo[i] = cd_zpo[i];
			tab_type_portage[i] = type_portage[i];
			tab_zpo_libelle[i] = zpo_libelle[i];
			tab_protect_date_debut_fictif[i] = protect_date_debut_fictif[i];
			tab_protect_date_debut[i] = protect_date_debut[i];
			tab_protect_date_fin[i] = protect_date_fin[i];
			tab_zpo_top_valid[i] = zpo_top_valid[i];
			
			tab_zpo_ordre[i] = null ;
			tab_zpo_date_debut_fictif[i] = null ;
			tab_zpo_date_debut[i] = null ;
			tab_zpo_date_fin[i] = null ;
			if(!"".equals(zpo_ordre[i]) && zpo_ordre[i]!=null){
				tab_zpo_ordre[i] = new BigDecimal(zpo_ordre[i]);
			}
			if(!"".equals(zpo_date_debut_fictif[i]) && zpo_date_debut_fictif[i]!=null){
				tab_zpo_date_debut_fictif[i] = new BigDecimal(zpo_date_debut_fictif[i]);
			}
			if(!"".equals(zpo_date_debut[i]) && zpo_date_debut[i]!=null){
				tab_zpo_date_debut[i] = new BigDecimal(zpo_date_debut[i]);
			}
			if(!"".equals(zpo_date_fin[i]) && zpo_date_fin[i]!=null){
				tab_zpo_date_fin[i] = new BigDecimal(zpo_date_fin[i]);
			}
		}
				
		vLwzom1Demande.cd_zpo     	 		 	 = tab_cd_zpo;
		vLwzom1Demande.type_portage  		 	 = tab_type_portage;
		vLwzom1Demande.zpo_libelle			 	 = tab_zpo_libelle;
		vLwzom1Demande.protect_date_debut_fictif = tab_protect_date_debut_fictif;
		vLwzom1Demande.protect_date_debut 		 = tab_protect_date_debut;
		vLwzom1Demande.protect_date_fin 		 = tab_protect_date_fin;
		vLwzom1Demande.zpo_top_valid 			 = tab_zpo_top_valid;
		
		vLwzom1Demande.zpo_ordre     		 = tab_zpo_ordre;
		vLwzom1Demande.zpo_date_debut_fictif = tab_zpo_date_debut_fictif;
		vLwzom1Demande.zpo_date_debut   	 = tab_zpo_date_debut;	
		vLwzom1Demande.zpo_date_fin 		 = tab_zpo_date_fin;
				
		vLwzom1.demande = vLwzom1Demande;
		
		jwlwzom1.setNwlwzom1Awlwzom1(vLwzom1);
		
		// CALL SERVER
		jwlwzom1.nwlwzom1();
		
		// Verification du code retour
		vWebent = jwlwzom1.getNwlwzom1Axwebent();
		System.out.println("Code retour nwlwzom1() = " + vWebent.code_retour.intValue());
		
		if(vWebent.code_retour.intValue() != 0){
			for(int i=0; i < vWebent.nb_ano.intValue(); i++){
			   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] :  " + vWebent.t_ano[i].lib_ano.trim() + " ");
		   	}
		}
		else{
			System.out.println ("Suite normale ...");
		}
		
		return jwlwzom1;
	   } // End setZonePortage
	/**
	 * <p>Titre : createZonePortage</p>
	 * <p>Copyright : Copyright (c) 2013</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>06/02/2013</i>
	 * @version 1.0
	 */
	public static Jwlwzom1 createZonePortage(
			String cd_zpo_creat,
			String type_portage_creat,
			String zpo_ordre_creat,
			String zpo_libelle_creat,
			String zpo_date_debut_fictif_creat,
			String zpo_date_debut_creat,
			String zpo_date_fin_creat,
			String zpo_top_valid_creat,
			String zpo_date_creat,
			String zpo_usr_crea,
			String groupe_exploitant,
			String numero_session,
			String utilisateur,
			String cd_cible,
			String cd_stegrp,
			Broker broker) throws BrokerException {
			// Initialisation des variables en entrees
		    Jwlwzom1 jwlwzom1 		  = new Jwlwzom1(broker, Constantes.SERVER_ADRESSE);	
			// Initialisation de la vWebent depuis les informations de connexion
			Jwlwzom1.Nwlwzom1Axwebent vWebent = jwlwzom1.new Nwlwzom1Axwebent();
			vWebent.dbid 			  = new BigDecimal (Constantes.DBID);
			vWebent.cible_exploitant  = Constantes.CD_CIBLE;
			vWebent.groupe_exploitant = groupe_exploitant;
			vWebent.numero_session 	  = new BigDecimal (numero_session);
			vWebent.utilisateur    	  = utilisateur;
			vWebent.transaction 	  = "WLWSTLST";
			vWebent.fonction 		  = "CREAT";
			vWebent.cd_cible 		  = cd_cible;
			vWebent.cd_stegrp 		  = cd_stegrp;
			vWebent.cd_application 	  = Constantes.CD_APPLICATION;
			jwlwzom1.setNwlwzom1Axwebent (vWebent);
			
			// Initialisation de la demande (tous a vide pour l instant)
			Jwlwzom1.Nwlwzom1Awlwzom1 vLwzom1 				= jwlwzom1.new Nwlwzom1Awlwzom1();
			Jwlwzom1.Nwlwzom1Awlwzom1Creation vLwzom1Demande = jwlwzom1.new Nwlwzom1Awlwzom1Creation();
			
			vLwzom1Demande.cd_zpo_creat   	   		    = cd_zpo_creat;
			vLwzom1Demande.type_portage_creat  			= type_portage_creat;	
			vLwzom1Demande.zpo_libelle_creat  		    = zpo_libelle_creat;
			vLwzom1Demande.zpo_top_valid_creat   		= zpo_top_valid_creat;
			vLwzom1Demande.zpo_usr_crea  				= zpo_usr_crea;
			
			
			if(!"".equals(zpo_ordre_creat) && zpo_ordre_creat!=null){
				vLwzom1Demande.zpo_ordre_creat = new BigDecimal(zpo_ordre_creat);
			}
			
			if(!"".equals(zpo_date_debut_fictif_creat) && zpo_date_debut_fictif_creat!=null){
				vLwzom1Demande.zpo_date_debut_fictif_creat = new BigDecimal(zpo_date_debut_fictif_creat);
			}
			
			if(!"".equals(zpo_date_debut_creat) && zpo_date_debut_creat!=null){
				vLwzom1Demande.zpo_date_debut_creat = new BigDecimal(zpo_date_debut_creat);
			}
			
			if(!"".equals(zpo_date_fin_creat) && zpo_date_fin_creat!=null){
				vLwzom1Demande.zpo_date_fin_creat = new BigDecimal(zpo_date_fin_creat);
			}
			
			if(!"".equals(zpo_date_creat) && zpo_date_creat!=null){
				vLwzom1Demande.zpo_date_creat = new BigDecimal(zpo_date_creat);
			}
			
			vLwzom1.creation = vLwzom1Demande;
			
			jwlwzom1.setNwlwzom1Awlwzom1(vLwzom1);
			
			// CALL SERVER
			jwlwzom1.nwlwzom1();
			
			// Verification du code retour
			vWebent = jwlwzom1.getNwlwzom1Axwebent();
			System.out.println("Code retour nwlwzom1() = " + vWebent.code_retour.intValue());
			
			if(vWebent.code_retour.intValue() != 0){
				for(int i=0; i < vWebent.nb_ano.intValue(); i++){
				   System.out.println(vWebent.t_ano[i].code_ano + "[" + vWebent.t_ano[i].type_ano + "] :  " + vWebent.t_ano[i].lib_ano.trim() + " ");
			   	}
			}
			else{
				System.out.println ("Suite normale ...");
			}
			
			return jwlwzom1;
	   } // End createZonePortage
	
	   
	   /**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2013</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2013</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA82");
			Broker broker 				    	= JxweblogWeb.logonBroker();
			Jxweblog jxweblog 				    = JxweblogWeb.getConnexion(broker);
			Jxweblog.NxweblogAxwebent connexion = jxweblog.getNxweblogAxwebent();
			
			String groupe_exploitant = connexion.groupe_exploitant;
			String numero_session 	 = Integer.toString(connexion.numero_session.intValue());
			String utilisateur 		 = connexion.utilisateur;
			String cd_cible 		 = connexion.cd_cible;
			String cd_stegrp 		 = connexion.cd_stegrp;
			
			
			//Test de MODIFICATION
			//---------Donnee Test---------------
			String cd_zpo[] 	    	  = new String[TAILLE];
			String type_portage[] 		  = new String[TAILLE];
			String zpo_ordre[]    		  = new String[TAILLE];
			String zpo_libelle[] 		  = new String[TAILLE];
			String zpo_date_debut_fictif[] 	   = new String[TAILLE];
			String protect_date_debut_fictif[] = new String[TAILLE];
			String zpo_date_debut[] 	= new String[TAILLE];
			String protect_date_debut[] = new String[TAILLE];
			String zpo_date_fin[] 		= new String[TAILLE];
			String protect_date_fin[] 	= new String[TAILLE];
			String zpo_top_valid[] 		= new String[TAILLE];
			
			//---------Donnee Test---------------
			
			setZonePortage(cd_zpo, type_portage, zpo_ordre,
					zpo_libelle,
					zpo_date_debut_fictif,
					protect_date_debut_fictif,
					zpo_date_debut, protect_date_debut,
					zpo_date_fin, protect_date_fin, zpo_top_valid,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			
			//Test de CREATION
			//---------Donnee Test---------------
			/*String cd_zpo_creat		  		  = "3701";
			String type_portage_creat 		  = "N";
			String zpo_ordre_creat 	  		  = "TEST ZPO";
			String zpo_libelle_creat 		  = "20130207";
			String zpo_date_debut_fictif_creat= "20130207";
			String zpo_date_debut_creat		  = "20781228";
			String zpo_date_fin_creat  		  = "";
			String zpo_top_valid_creat        = "";
			String zpo_date_creat 			  = "";
			String zpo_usr_crea				  = "";
			//---------Donnee Test---------------
			
			createZonePortage(cd_zpo_creat, type_portage_creat, zpo_ordre_creat,
					zpo_libelle_creat, zpo_date_debut_fictif_creat, 
					zpo_date_debut_creat, zpo_date_fin_creat, zpo_top_valid_creat,
					zpo_date_creat, zpo_usr_crea, groupe_exploitant, numero_session,
					utilisateur, cd_cible, cd_stegrp, broker);
			*/
		}			
}