Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void newPersonFlow() throws Exception {
- final String url = "http://10.3.50.48:8069",
- db = "KassaGroepC",
- username ="ricardo.mayorga.mera@student.ehb.be",
- password = "opiq188";
- final XmlRpcClient client = new XmlRpcClient();
- final XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
- common_config.setServerURL(
- new URL(String.format("%s/xmlrpc/2/common", url)));
- int uid = (int) client.execute(common_config,"authenticate",Arrays.asList(db,username, password, Collections.emptyMap()));
- final XmlRpcClient models = new XmlRpcClient() {
- {
- setConfig (new XmlRpcClientConfigImpl() {
- {
- setServerURL(new URL (String.format("%s/xmlrpc/2/object", url)));
- }
- });
- }
- };
- //search and read
- final java.util.List<Object> ids= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("id", "=", userid))))));
- //System.out.println(ids);
- if (ids != null && !ids.isEmpty()){
- //System.out.print("userid: " + userid + " is not empty \n");
- int displayhelp = userid;
- System.out.println("Person found for userid: " + displayhelp + ":");
- final java.util.List<Object> fields = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid","role","name","lastname","street","email","x_isactive","x_isallowed","x_isregistered","version","timestamp"));}})));
- System.out.println(fields);
- final java.util.List<Object> uuids = Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("id", "=", userid),
- Arrays.asList("x_uuid", "!=", false))))));
- if (ids != null && !uuids.isEmpty()){
- int useridhelper = userid;
- //System.out.print("UUID for userid: " + userid + " is not empty \n");
- System.out.println("UUID for userid " + useridhelper + ": ");
- final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid"));}})));
- System.out.println(fields1);
- // System.out.print("looks for userid: " + "70" + " for the next search\n");
- } else {
- System.out.println("THERE IS NO UUID YET FOR THIS PERSON\n");
- System.out.println("FETCHING UUID FOR THIS PERSON\n");
- //helper userid -> to string
- String useridhelper = Integer.toString(userid);
- //fetches UUID for userid
- String n = UUIDHelper.createUUID(useridhelper);
- //update the user and adds UUID
- System.out.println(userid);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(userid),
- new HashMap() {{ put("x_uuid", n);
- put("x_isallowed", true);
- put("x_isregistered", true);
- put("x_isactive", true);
- }}
- )
- ));
- System.out.println("Person found for userid: " + displayhelp + ":");
- final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid","role","name","lastname","street","email","x_isactive","x_isallowed","x_isregistered","version","timestamp"));}})));
- System.out.println(fields1);
- System.out.println("UUID MADE FOR USERID: " + userid + " END OF FLOW\n\n" );
- System.out.println("Building and sending message...\n\n");
- //newPerson messageuitsturen
- message msg = new message();
- Odoo o = new Odoo();
- List<Object> id1= Arrays.asList((Object[])o.models.execute("execute_kw", Arrays.asList(
- o.db, o.uid, o.password,
- "res.partner", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("id", "=", userid))))));
- List<Object> fields11 = Arrays.asList((Object[])o.models.execute("execute_kw",Arrays.asList(o.db,o.uid,o.password,"res.partner","read",
- Arrays.asList(id1),
- new HashMap() {{
- put("fields",Arrays.asList("name","x_uuid","street"));
- }}
- )));
- System.out.println(fields);
- for (Object object : fields) {
- HashMap<String,Object> result = (HashMap) object;
- // TimeUnit.SECONDS.sleep(1);
- newPerson p = new newPerson(
- result.get("x_uuid").toString(),
- "visitor",
- result.get("name").toString(),
- "even een test achternaam",
- result.get("street").toString(),
- result.get("email").toString(),
- //Boolean.valueOf(result.get("x_isactive").toString()),
- true,
- Boolean.valueOf(result.get("x_isallowed").toString()),
- 1,
- UUIDHelper.getCurrentDate());
- XStream x = new XStream();
- x.alias("message",message.class);
- msg.setBody(p);
- msg.setMessageType("newPerson");
- x.alias("newPerson", newPerson.class);
- String toSend=x.toXML(msg);
- Sender.Send(toSend);
- }
- }
- userid++;
- } else {
- System.out.println("userid: " + userid + " is empty, trying again in 5 seconds...\n");
- //System.out.println("using userid: " + userid + " for the next search");
- }
- System.out.print("looks for userid: " + userid + " in the next search\n\n ________________________________________________________________________________________________________ \n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement