Advertisement
Guest User

fuckodoo

a guest
May 27th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.26 KB | None | 0 0
  1. public static void newPersonFlow() throws Exception {
  2.    
  3.                 final String url = "http://10.3.50.48:8069",
  4.                 db = "KassaGroepC",
  5.                 username ="ricardo.mayorga.mera@student.ehb.be",
  6.                 password = "opiq188";
  7.                 final XmlRpcClient client = new XmlRpcClient();
  8.                 final XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
  9.                 common_config.setServerURL(
  10.                 new URL(String.format("%s/xmlrpc/2/common", url)));
  11.                 int uid =  (int) client.execute(common_config,"authenticate",Arrays.asList(db,username, password, Collections.emptyMap()));
  12.                 final XmlRpcClient models = new XmlRpcClient() {
  13.                     {
  14.                     setConfig (new XmlRpcClientConfigImpl() {
  15.                         {
  16.                         setServerURL(new URL (String.format("%s/xmlrpc/2/object", url)));
  17.                         }
  18.                     });
  19.                 }
  20.             };     
  21.            
  22.             //search and read      
  23.             final java.util.List<Object> ids= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
  24.                         db, uid, password,
  25.                         "res.partner", "search",
  26.                         Arrays.asList(Arrays.asList(
  27.                         Arrays.asList("id", "=", userid))))));
  28.                         //System.out.println(ids);
  29.             if (ids != null && !ids.isEmpty()){
  30.                
  31.                     //System.out.print("userid: " + userid + " is not empty \n");
  32.                     int displayhelp = userid;
  33.                     System.out.println("Person found for userid: "  + displayhelp + ":");
  34.                     final java.util.List<Object> fields = Arrays.asList((Object[])models.execute
  35.                             ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
  36.                             new HashMap()
  37.                             {{put("fields",Arrays.asList("x_uuid","role","name","lastname","street","email","x_isactive","x_isallowed","x_isregistered","version","timestamp"));}})));
  38.                             System.out.println(fields);
  39.  
  40. final java.util.List<Object> uuids = Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
  41.         db, uid, password,
  42.         "res.partner", "search",
  43.         Arrays.asList(Arrays.asList(
  44.         Arrays.asList("id", "=", userid),
  45.         Arrays.asList("x_uuid", "!=", false))))));
  46.  
  47. if (ids != null && !uuids.isEmpty()){
  48.     int useridhelper = userid;
  49.     //System.out.print("UUID for userid: " + userid + " is not empty \n");
  50.     System.out.println("UUID for userid " + useridhelper + ": ");
  51.     final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
  52.             ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
  53.             new HashMap()
  54.             {{put("fields",Arrays.asList("x_uuid"));}})));
  55.            System.out.println(fields1);
  56.            // System.out.print("looks for userid: " + "70" + " for the next search\n");
  57.    
  58. } else {
  59.     System.out.println("THERE IS NO UUID YET FOR THIS PERSON\n");
  60.     System.out.println("FETCHING UUID FOR THIS PERSON\n");
  61.     //helper userid -> to string
  62.     String useridhelper = Integer.toString(userid);
  63.     //fetches UUID for userid
  64.     String n = UUIDHelper.createUUID(useridhelper);
  65.     //update the user and adds UUID
  66.     System.out.println(userid);
  67.     models.execute("execute_kw", Arrays.asList(
  68.             db, uid, password,
  69.             "res.partner", "write",
  70.             Arrays.asList(
  71.                 Arrays.asList(userid),
  72.                 new HashMap() {{ put("x_uuid", n);
  73.                                  put("x_isallowed", true);
  74.                                  put("x_isregistered", true);
  75.                                  put("x_isactive", true);
  76.                                  }}
  77.             )
  78.         ));
  79.    
  80.    
  81.     System.out.println("Person found for userid: "  + displayhelp + ":");
  82.     final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
  83.             ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
  84.             new HashMap()
  85.             {{put("fields",Arrays.asList("x_uuid","role","name","lastname","street","email","x_isactive","x_isallowed","x_isregistered","version","timestamp"));}})));
  86.             System.out.println(fields1);
  87.                            
  88.     System.out.println("UUID MADE FOR USERID: " + userid + " END OF FLOW\n\n" );
  89.     System.out.println("Building and sending message...\n\n");
  90.    
  91.     //newPerson messageuitsturen
  92.     message msg = new message();
  93.  
  94.     Odoo o = new Odoo();
  95.     List<Object> id1= Arrays.asList((Object[])o.models.execute("execute_kw", Arrays.asList(
  96.             o.db, o.uid, o.password,
  97.             "res.partner", "search",
  98.             Arrays.asList(Arrays.asList(
  99.             Arrays.asList("id", "=", userid))))));
  100.     List<Object> fields11 = Arrays.asList((Object[])o.models.execute("execute_kw",Arrays.asList(o.db,o.uid,o.password,"res.partner","read",
  101.             Arrays.asList(id1),
  102.             new HashMap() {{
  103.                 put("fields",Arrays.asList("name","x_uuid","street"));
  104.             }}
  105.             )));
  106.         System.out.println(fields);
  107.     for (Object object : fields) {
  108.        HashMap<String,Object> result = (HashMap) object;
  109.      
  110.  
  111.       // TimeUnit.SECONDS.sleep(1);
  112.        
  113.      newPerson p = new newPerson(
  114.              result.get("x_uuid").toString(),
  115.              "visitor",
  116.              result.get("name").toString(),
  117.              "even een test achternaam",
  118.              result.get("street").toString(),
  119.              result.get("email").toString(),
  120.              //Boolean.valueOf(result.get("x_isactive").toString()),
  121.              true,
  122.              Boolean.valueOf(result.get("x_isallowed").toString()),
  123.              1,
  124.              UUIDHelper.getCurrentDate());
  125.      
  126.      XStream x = new XStream();
  127.      x.alias("message",message.class);
  128.      msg.setBody(p);
  129.      msg.setMessageType("newPerson");
  130.      x.alias("newPerson", newPerson.class);
  131.      String toSend=x.toXML(msg);
  132.      Sender.Send(toSend);  
  133.      
  134.     }
  135.    
  136.  
  137. }                                      
  138. userid++;              
  139.             } else {
  140.                 System.out.println("userid: " + userid + " is empty, trying again in 5 seconds...\n");
  141.                 //System.out.println("using userid: " + userid + " for the next search");
  142.             }    
  143.  
  144.             System.out.print("looks for userid: " + userid + " in the next search\n\n ________________________________________________________________________________________________________ \n\n");
  145.  
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement