import java.math.BigDecimal;

import com.softwareag.entirex.aci.Broker;
import com.softwareag.entirex.aci.BrokerException;

/**
 * <p>Titre : Jwlwcdm5Web</p>
 * <p>Description : Mise a jour des parametre press plus.
 * </p>
 * <p>Copyright : Copyright (c) 2012</p>
 * <p>Societe : ENSOR</p>
 * @author AR & DR & PY <i>27/09/2012</i>
 * @version 1.0
 */
 
public class Jwlwcdm5Web {

	/**
	 * <p>Titre : getParamPressPlus</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>27/09/2012</i>
	 * @version 1.0
	 */
	 public static Jwlwcdm5 getParamPressPlus(
				String fonction,
				String f_cd_cible,
				String f_id_cmd,
				String f_id_sscmd,
				String f_id_sscmd_item,
				String f_top_presse_plus,
				String groupe_exploitant,
				String numero_session,
				String utilisateur,
				String cd_cible,
				String cd_stegrp,
				Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm5 jwlwcdm5 = new Jwlwcdm5(broker, Constantes.SERVER_ADRESSE);
			
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm5.Nwlwcdm5Axwebent vWebent = jwlwcdm5.new Nwlwcdm5Axwebent();
		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 		  = fonction;
		vWebent.cd_cible 		  = cd_cible;
		vWebent.cd_stegrp 		  = cd_stegrp;
		vWebent.cd_application 	  = Constantes.CD_APPLICATION;
		jwlwcdm5.setNwlwcdm5Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm5.Nwlwcdm5Awlwcdm5 vLwcdm5 					= jwlwcdm5.new Nwlwcdm5Awlwcdm5();
		Jwlwcdm5.Nwlwcdm5Awlwcdm5Demande vLwcdm5Demande = jwlwcdm5.new Nwlwcdm5Awlwcdm5Demande();
		Jwlwcdm5.Nwlwcdm5Awlwcdm5Reponse vLwcdm5Reponse = jwlwcdm5.new Nwlwcdm5Awlwcdm5Reponse();
		vLwcdm5Demande.cd_cible   = f_cd_cible;
		
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm5Demande.id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_id_sscmd) && f_id_sscmd!=null){
			vLwcdm5Demande.id_sscmd = new BigDecimal(f_id_sscmd);
		}
		if(!"".equals(f_id_sscmd_item) && f_id_sscmd_item!=null){
			vLwcdm5Demande.id_sscmd_item = new BigDecimal(f_id_sscmd_item);
		}
		
		if(!"".equals(f_top_presse_plus) && f_top_presse_plus!=null){
			vLwcdm5Reponse.top_presse_plus = f_top_presse_plus;
		}
		
		
		vLwcdm5.reponse = vLwcdm5Reponse;
		vLwcdm5.demande = vLwcdm5Demande;
		
		jwlwcdm5.setNwlwcdm5Awlwcdm5(vLwcdm5);
		
		// CALL SERVER
		jwlwcdm5.nwlwcdm5();
		
		// Verification du code retour
		vWebent = jwlwcdm5.getNwlwcdm5Axwebent();
		System.out.println("Code retour nwlwcdm5() = " + 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{
			//affichage de reponse
			Jwlwcdm5.Nwlwcdm5Awlwcdm5 jwlwcdm5Reponse = jwlwcdm5.getNwlwcdm5Awlwcdm5() ;
			Jwlwcdm5.Nwlwcdm5Awlwcdm5Reponse reponse  = jwlwcdm5Reponse.reponse;
			System.out.println("top_presse_plus=" + reponse.top_presse_plus) ;
			System.out.println("poids="	  		  + reponse.poids) ;
			System.out.println("nb_ligne_mar="	  + reponse.nb_ligne_mar) ;
			
			for (int i = 0; i < reponse.nb_ligne_mar; i++) {
				System.out.println("----- ligne_ref ["+i+"] ----------");
				System.out.println("cd_margeur="	+ reponse.ligne_ref[i].cd_margeur) ;
				System.out.println("poids_plus="    + reponse.ligne_ref[i].poids_plus) ;
				System.out.println("cpt_plus=" 		+ reponse.ligne_ref[i].cpt_plus) ;
				System.out.println("libelle_plus="  + reponse.ligne_ref[i].libelle_plus) ;
			}
			
		}
		return jwlwcdm5;
	   } // End getParamPressPlus
	   
	//FIN  INTERROGATION
	
	
	/**
	 * <p>Titre : setParamPressPlus</p>
	 * <p>Copyright : Copyright (c) 2012</p>
	 * <p>Societe : ENSOR</p>
	 * @author AR & DR & PY <i>27/09/2012</i>
	 * @version 1.0
	 */
	public static Jwlwcdm5 setParamPressPlus(
		String f_cd_cible,
		String f_id_cmd,
		String f_id_sscmd,
		String f_id_sscmd_item,
		String f_top_presse_plus,
		String f_poids,
		String f_cd_margeur[],
		String f_poids_plus[],
		String f_libele_plus[],
		String groupe_exploitant,
		String numero_session,
		String utilisateur,
		String cd_cible,
		String cd_stegrp,
		Broker broker) throws BrokerException {
		// Initialisation des variables en entrees
	    Jwlwcdm5 jwlwcdm5 		  = new Jwlwcdm5(broker, Constantes.SERVER_ADRESSE);	
		// Initialisation de la vWebent depuis les informations de connexion
		Jwlwcdm5.Nwlwcdm5Axwebent vWebent = jwlwcdm5.new Nwlwcdm5Axwebent();
		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;
		jwlwcdm5.setNwlwcdm5Axwebent (vWebent);
		
		// Initialisation de la demande (tous a vide pour l instant)
		Jwlwcdm5.Nwlwcdm5Awlwcdm5 vLwcdm5 				= jwlwcdm5.new Nwlwcdm5Awlwcdm5();
		Jwlwcdm5.Nwlwcdm5Awlwcdm5Demande vLwcdm5Demande = jwlwcdm5.new Nwlwcdm5Awlwcdm5Demande();
		Jwlwcdm5.Nwlwcdm5Awlwcdm5Reponse vLwcdm5reponse = jwlwcdm5.new Nwlwcdm5Awlwcdm5Reponse();
		
		vLwcdm5Demande.cd_cible = f_cd_cible;
		if(!"".equals(f_id_cmd) && f_id_cmd!=null){
			vLwcdm5Demande.id_cmd = new BigDecimal(f_id_cmd);
		}
		if(!"".equals(f_id_sscmd) && f_id_sscmd!=null){
			vLwcdm5Demande.id_sscmd = new BigDecimal(f_id_sscmd);
		}
		if(!"".equals(f_id_sscmd_item) && f_id_sscmd_item!=null){
			vLwcdm5Demande.id_sscmd_item = new BigDecimal(f_id_sscmd_item);
		}
		if(!"".equals(f_top_presse_plus) && f_top_presse_plus!=null){
			 vLwcdm5reponse.top_presse_plus = f_top_presse_plus;
		}
		if(!"".equals(f_poids) && f_poids!=null){
			 vLwcdm5reponse.poids = new BigDecimal(f_poids);
		}
		
		int nbref = f_cd_margeur.length;
		System.out.println("nb ligne_ref="+ nbref) ;
		Jwlwcdm5.Nwlwcdm5Awlwcdm5ReponseLigne_ref[] ligne_ref = new Jwlwcdm5.Nwlwcdm5Awlwcdm5ReponseLigne_ref[10];
		for(int i=0;i< nbref;i++){
			ligne_ref[i] = jwlwcdm5.new Nwlwcdm5Awlwcdm5ReponseLigne_ref() ;
			ligne_ref[i].cd_margeur   = f_cd_margeur[i];
			ligne_ref[i].libelle_plus = f_libele_plus[i];
			
			if(!"".equals(f_poids_plus[i]) && f_poids_plus[i]!=null){
				ligne_ref[i].poids_plus = new BigDecimal(f_poids_plus[i]);
			}
		}
		vLwcdm5reponse.ligne_ref = ligne_ref;
		vLwcdm5.reponse = vLwcdm5reponse;
		
		vLwcdm5.demande = vLwcdm5Demande;
		
		jwlwcdm5.setNwlwcdm5Awlwcdm5(vLwcdm5);
		
		// CALL SERVER
		jwlwcdm5.nwlwcdm5();
		
		// Verification du code retour
		vWebent = jwlwcdm5.getNwlwcdm5Axwebent();
		System.out.println("Code retour nwlwcdm5() = " + 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 jwlwcdm5;
	   } // End setParamPressPlus
	   
	
	   /**
		 * <p>Titre : main</p>
		 * <p>Description : Programme principal de tests</p>
		 * <p>Copyright : Copyright (c) 2012</p>
		 * <p>Societe : ENSOR</p>
		 * @author AR & DR & PY <i>25/03/2012</i>
		 * @version 1.0
		 */
	   public static void main(String[] args) throws BrokerException {
			Constantes.loadProperties("LW") ;
			JxweblogWeb.setUtilisateur ("MADAA02");
			JxweblogWeb.setPassword ("MADAA62");
			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 INTEROGATION
			//---------Donnee Test---------------	
			/*String fonction          = "MODIF";
			String f_cd_cible        = "50";
			String f_id_cmd          = "683";
			String f_id_sscmd        = "999";
			String f_id_sscmd_item   = "98";
			String f_top_presse_plus = "M";
			String f_poids ="100" ;
			//---------Donnee Test---------------
			//****TEST SELECTION TOP PRESSE PLUS
			getParamPressPlus(fonction,
					f_cd_cible, f_id_cmd, f_id_sscmd, f_id_sscmd_item, f_top_presse_plus,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			//Test de MODIFICATION
			String f_cd_margeur[]  = {"pr", "01", "02", "03", "04", "05", "06", "07", "08"};
			String f_poids_plus[]  = {"1", "1", "1", "1", "1", "1", "1", "1", "1"};
			String f_libele_plus[] = {"guide4","e","e","e","e","e","e","e","e"};
			
			
			setParamPressPlus( f_cd_cible, f_id_cmd, f_id_sscmd, f_id_sscmd_item, f_top_presse_plus, f_poids,
					f_cd_margeur, f_poids_plus, f_libele_plus,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
					
			
			//****TEST VISUALISATION
			fonction          = "VISU";
			getParamPressPlus(fonction,
					f_cd_cible, f_id_cmd, f_id_sscmd, f_id_sscmd_item, f_top_presse_plus,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
			*/
			
			//****TEST VISUALISATION
			String fonction   = "VISU";
			String f_cd_cible = "50";
			String f_id_cmd   = "692";
			String f_id_sscmd = "999";
			String f_id_sscmd_item 	 = "99";
			String f_top_presse_plus = "M";
			
			getParamPressPlus(fonction,
					f_cd_cible, f_id_cmd, f_id_sscmd,
					f_id_sscmd_item, f_top_presse_plus,
					groupe_exploitant, numero_session, utilisateur, cd_cible, cd_stegrp, broker);
				
		}			
}