Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package logic;
- /*
- __ _______ __ .___________. __ _______. _______..___________. __ __ .______ __ _______ .______ __ __ .___________. __ .___________. ____ __ ____ ______ .______ __ ___ _______.
- | | | ____| | | | |(_ ) / | / || || | | | | _ \ | | | \ | _ \ | | | | | | | | | | \ \ / \ / / / __ \ | _ \ | |/ / / |
- | | | |__ | | `---| |----` |/ | (----` | (----``---| |----`| | | | | |_) | | | | .--. | | |_) | | | | | `---| |----` | | `---| |----` \ \/ \/ / | | | | | |_) | | ' / | (----`
- | | | __| | | | | \ \ \ \ | | | | | | | ___/ | | | | | | | _ < | | | | | | | | | | \ / | | | | | / | < \ \
- | | | | | | | | .----) | .----) | | | | `--' | | | | | | '--' | | |_) | | `--' | | | | | | | \ /\ / | `--' | | |\ \----.| . \ .----) |
- |__| |__| |__| |__| |_______/ |_______/ |__| \______/ | _| |__| |_______/ |______/ \______/ |__| |__| |__| \__/ \__/ \______/ | _| `._____||__|\__\ |_______/
- __ .___________. __ _______. .__ __. ______ .___________. _______..___________. __ __ .______ __ _______
- | | | |(_ ) / | | \ | | / __ \ | | / || || | | | | _ \ | | | \
- | | `---| |----` |/ | (----` | \| | | | | | `---| |----` | (----``---| |----`| | | | | |_) | | | | .--. |
- | | | | \ \ | . ` | | | | | | | \ \ | | | | | | | ___/ | | | | | |
- | | | | .----) | | |\ | | `--' | | | .----) | | | | `--' | | | | | | '--' |
- |__| |__| |_______/ |__| \__| \______/ |__| |_______/ |__| \______/ | _| |__| |_______/
- */
- //import java.awt.List;
- import java.io.IOException;
- import java.lang.reflect.Array;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.concurrent.TimeUnit;
- import java.util.List;
- import org.apache.xmlrpc.XmlRpcException;
- import org.apache.xmlrpc.client.XmlRpcClient;
- import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
- import org.codehaus.jettison.json.JSONException;
- import com.thoughtworks.xstream.XStream;
- import messages.*;
- import rabbitMQ.Sender;
- public class triggerHelper {
- static int userid = 142;
- static String UUUID = "c5164143-b869-4afb-bfd1-1f96bd47ccfa"; //helper person not allowed
- static int userID = 100; //helper person not allowed
- static String namehelper = "test123654";
- static int invoicehelper = 12;
- static int productid =83;
- /* ************************************************************************************************************************************************************** */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- //newPersonFlow();
- //checkIfUUIDIsEmpty();
- //setPeronOnNotAllowedViaUserID(userID);
- //setPersonOnNotAllowedViaUserUUID(UUUID); // not working -> doesn't work with string inputs atm
- //setPersonOnNotAllowedViaUserName(namehelper); // not working -> doesn't work with string inputs atm
- //createProduct();
- //invoicehelperfunction(0006);
- //getPayment();
- //newProduct();
- //getStartValuesForProducts();
- //getStartValuesForPersons();
- //newPersonFlow();
- }
- /* ************************************************************************************************************************************************************** */
- //deze functie gaat het huidige producten aantal opzoeken
- public static int getStartValuesForProducts() throws XmlRpcException, MalformedURLException {
- //connection
- 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 ALL productid's
- final java.util.List<Object> ids= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "product.template", "search",
- Arrays.asList(Arrays.asList(
- )))));
- final java.util.List<Object> fields = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"product.template","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("id"));}})));
- //System.out.println(ids);
- List list = (List)ids;
- int maxvaluefromproductlist = (int)Collections.max(list);
- //System.out.println(maxvaluefromproductlist);
- return maxvaluefromproductlist;
- }
- public static int getStartValuesForPersons() throws XmlRpcException, MalformedURLException{
- //connection
- 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 ALL productid's
- 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(
- )))));
- 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("id"));}})));
- //System.out.println(ids);
- List list = (List)ids;
- int maxvaluefrompersonlist = (int)Collections.max(list);
- //System.out.println(maxvaluefrompersonlist);
- return maxvaluefrompersonlist;
- }
- 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
- //USER VOOR UPDATE
- 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);
- System.out.println("USER POLLING SYSTEM");
- 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 + ":");
- ///DONT TOUCH ABOVE
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(userid),
- new HashMap() {{ put("x_isallowed", true);
- }}
- )
- ));
- //DONT TOUCH BELOW
- 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 {
- //USER WRD UPDATED HIER
- 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);
- }}
- )
- ));
- //UPDATED USER MESSAGE
- 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);
- for (Object object : fields1) {
- HashMap<String,Object> result = (HashMap) object;
- 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();
- 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");
- }
- public static void setPeronOnNotAllowedViaUserID(int userID) throws Exception{
- //connection stuff
- 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))))));
- 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 + ":");
- System.out.println("User before function: ");
- 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","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(userID),
- new HashMap() {{ put("x_isallowed", false); }}
- )
- ));
- System.out.println("set user to not allowed");
- // get record name after having changed it
- Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "name_get",
- Arrays.asList(Arrays.asList(userID))
- )));
- 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","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields1);
- 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"));
- }}
- )));
- for (Object object : fields) {
- HashMap<String,Object> result = (HashMap) object;
- message msg = new message();
- 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()),
- false,
- false,
- //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);
- }
- }
- }
- public static void setPersonOnNotAllowedViaUserUUID(String UUUID) throws Exception, XmlRpcException{
- 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> xuuid= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("x_uuid", "=", UUUID))))));
- if (xuuid != null && !xuuid.isEmpty()){
- //System.out.print("userid: " + userid + " is not empty \n");
- System.out.println("Person found for UUID: " + UUUID + ":");
- System.out.println("User before function: ");
- final java.util.List<Object> fields = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(xuuid),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(UUUID),
- new HashMap() {{ put("x_isallowed", false); }}
- )
- ));
- System.out.println("set user to not allowed");
- // get record name after having changed it
- Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "name_get",
- Arrays.asList(Arrays.asList(UUUID))
- )));
- final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(xuuid),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields1);
- message msg = new message();
- //hier de message die moet doorgestuurd worden
- //values van de persoon opvragen die zijn allowed op false moet gezet worden
- //momenteel hardcoded message
- newPerson p = new newPerson("x_uuid","Bezoeker","TESTMESSAGE " + userid + " TEST","De program manager","zijn adress","testmail@verbeeck.be",true,false,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);
- }
- }
- public static void setPersonOnNotAllowedViaUserName(String name) throws Exception{
- //connection stuff
- 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("name", "=", namehelper))))));
- if (ids != null && !ids.isEmpty()){
- //System.out.print("userid: " + userid + " is not empty \n");
- int displayhelp = userID;
- System.out.println("Person found with name: " + namehelper + ":");
- System.out.println("User before function: ");
- 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","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(namehelper),
- new HashMap() {{ put("x_isallowed", false); }}
- )
- ));
- System.out.println("set user to not allowed");
- // get record name after having changed it
- Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "name_get",
- Arrays.asList(Arrays.asList(userID))
- )));
- 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","Bezoeker","name","street","email","x_isactive","x_isallowed","version","timestamp"));}})));
- System.out.println(fields1);
- message msg = new message();
- //hier de message die moet doorgestuurd worden
- //values van de persoon opvragen die zijn allowed op false moet gezet worden
- //momenteel hardcoded message
- newPerson p = new newPerson("x_uuid","Bezoeker","TESTMESSAGE " + userid + " TEST","De program manager","zijn adress","testmail@verbeeck.be",true,false,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);
- }
- }
- public static void checkIfUUIDIsEmpty () throws XmlRpcException, IOException, JSONException {
- 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)));
- }
- });
- }
- };
- int heelper = userid -1;
- 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", "=", heelper),
- Arrays.asList("x_uuid", "!=", false))))));
- if (ids != null && !ids.isEmpty()){
- //System.out.print("UUID for userid: " + userid + " is not empty \n");
- System.out.println("UUID for userid " + heelper + ": ");
- 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"));}})));
- System.out.println(fields);
- // System.out.print("looks for userid: " + "70" + " for the next search\n");
- } else {
- int helpuserid = userid -1;
- 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(helpuserid);
- //fetches UUID for userid
- String n = UUIDHelper.createUUID(useridhelper);
- //update the user and adds UUID
- System.out.println(helpuserid);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(userid),
- new HashMap() {{ put("x_uuid", n); }}
- )
- ));
- /*
- // get record name after having changed it
- Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "name_get",
- Arrays.asList(Arrays.asList(userid))
- )));
- */
- System.out.println("UUID MADE FOR USERID" + helpuserid + "\n\n\n\n\n");
- //System.out.println("UUID for userID: " + "70" + " is empty\n");
- //System.out.println("using userid: " + userid + " for the next search");
- }
- }
- public static void newProduct() throws Exception{
- //CONNECTION
- 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
- //USER VOOR UPDATE
- final java.util.List<Object> ids= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "product.template", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("id", "=", productid))))));
- System.out.println("product POLLING SYSTEM");
- if (ids != null && !ids.isEmpty()){
- int displayhelp = productid;
- System.out.println("product found for productid: " + displayhelp + ":");
- final java.util.List<Object> productuuids = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"product.template","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_productuuid","id","display_name","name"));}})));
- System.out.println("BEFORE LOOP -- > ");
- System.out.println(productuuids.toString());
- for (Object object : productuuids) {
- HashMap<String,Object> result = (HashMap) object;
- String uuidproducthelper = result.get("x_productuuid").toString();
- System.out.println(uuidproducthelper);
- if (uuidproducthelper.isEmpty()) {
- //product already has a productuuid skips it
- final java.util.List<Object> fields2 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"product.template","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_productuuid"));}})));
- System.out.println("UUID ALREADY EXISTS SKIP");
- }
- else {
- //product doesn't have a uuid yet + add a uuid
- System.out.println("THERE IS NO UUID YET FOR THIS Product\n");
- System.out.println("FETCHING UUID FOR THIS Product\n");
- //helper userid -> to string
- String productidhelper = Integer.toString(productid);
- //fetches UUID for userid
- String n = UUIDHelper.createUUID(productidhelper);
- System.out.println(n);
- System.out.println(productid);
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "product.template", "write",
- Arrays.asList(
- Arrays.asList(productid),
- new HashMap() {{ put("x_productuuid", n);}}
- )
- ));
- //UPDATED USER MESSAGE
- System.out.println("Product found for productid: " + productid + ":");
- final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"product.template","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("x_productuuid","id","display_name","name"));}})));
- System.out.println(fields1);
- for (Object objectuuid : fields1) {
- HashMap<String,Object> resultuuid = (HashMap) objectuuid;
- System.out.println("UUID MADE FOR PRODUCTID: " + productid + " END OF UUIDFLOW\n\n" );
- System.out.println("Building and sending message...\n\n");
- //BUILD MESSAGES
- message msg = new message();
- newProduct k = new newProduct(
- resultuuid.get("x_productuuid").toString(), //uuid
- resultuuid.get("display_name").toString(), //name
- resultuuid.get("name").toString(), //descpription
- 1.0,
- //(Double)resultuuid.get("price_unit"), //price
- 1, //version
- UUIDHelper.getCurrentDate() //Date
- );
- XStream x = new XStream();
- x.alias("message",message.class);
- msg.setBody(k);
- msg.setMessageType("newProduct");
- x.alias("newProduct", newProduct.class);
- String toSend=x.toXML(msg);
- Sender.Send(toSend);
- }
- }
- }
- productid++;
- }
- else
- {
- System.out.println("NO PRODUCT WAS FOUND");
- System.out.println("LOOKING AGAIN IN 5 SECONDS");
- System.out.println("looks for product id: " + productid);
- }
- }
- public static void createProduct() throws XmlRpcException, MalformedURLException {
- //connection
- 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)));
- }
- });
- }
- };
- final Integer id = (Integer) models.execute("execute_kw",Arrays.asList(db,uid,password,"product.product","create",Arrays.asList(new HashMap() {{
- put("name","productnametest");
- put("list_price","1000000");
- }
- })));
- }
- public static String invoicehelperfunction(int invoicehelper) {
- String nozero ="";
- String onezero ="0";
- String twozeroes ="00";
- String threezeroes="000";
- String zeroes;
- if (invoicehelper > 9 && invoicehelper <= 99) {
- return zeroes = twozeroes;
- } if (invoicehelper > 99 && invoicehelper <= 999) {
- return zeroes = onezero;
- } if (invoicehelper >999)
- {
- return zeroes = nozero;
- } else {
- return zeroes = threezeroes;
- }
- }
- public static void getPayment() throws XmlRpcException, IOException, JSONException{
- //bevat een id
- String invoicebase = "INV/2018/";
- String zeroes = invoicehelperfunction(invoicehelper);
- String fullinvoicepath = invoicebase + zeroes + invoicehelper;
- System.out.println("INVOICE POLLING SYSTEM");
- System.out.println("will search for: " + fullinvoicepath);
- //connection
- 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)));
- }
- });
- }
- };
- final java.util.List<Object> ids= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "account.invoice", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("number", "=", fullinvoicepath))))));
- if (ids != null && !(ids.isEmpty())) {
- final java.util.List<Object> fields1 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"account.invoice","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("number","account_id","partner_id","amount_total","id","invoice_line_ids"));}})));
- System.out.println(fields1);
- for (Object object : fields1) {
- HashMap<String,Object> result = (HashMap) object;
- List accountidhelper = Arrays.asList((Object[])result.get("partner_id"));
- List invoicelineshelperprint = Arrays.asList((Object[])result.get("invoice_line_ids"));
- System.out.println(accountidhelper);
- System.out.println(invoicelineshelperprint);
- int idhelper = (int)result.get("id");
- System.out.println(idhelper);
- Integer startLoop = (Integer)invoicelineshelperprint.get(0);
- Integer endLoop = (Integer)invoicelineshelperprint.get(invoicelineshelperprint.size()-1);
- System.out.println(startLoop);
- System.out.println(endLoop);
- //foreach of the list here
- //hier haalt hij alle informatie uit de invoice
- for(int i=startLoop; i < endLoop; i++) {
- final java.util.List<Object> ids1= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "account.invoice.line", "search",
- Arrays.asList(Arrays.asList(
- Arrays.asList("id", "=", i))))));
- //name = description in odoo, display name = name
- final java.util.List<Object> fields11 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"account.invoice.line","read",Arrays.asList(ids1),
- new HashMap()
- {{put("fields",Arrays.asList("id","price_unit","name","display_name","quantity","x_productuuid","product_id"));}})));
- for (Object objectProd : fields11) {
- HashMap<String,Object> resultProd = (HashMap) objectProd;
- //System.out.println(fields11);
- List ProductenData = Arrays.asList((Object[])resultProd.get("product_id"));
- System.out.println("Product ID: "+Arrays.asList((Object[])resultProd.get("product_id")));
- String notallowedinteger = "71";
- System.out.println("RESULTPROD: " + resultProd.get("product_id"));
- Object prodhelperr = resultProd.get("product_id");
- // randomhelper = ((List<Object>) prodhelperr).get(0);
- // System.out.println("RANDOMHELPER: " + randomhelper);
- if (resultProd.get("product_id").toString() != notallowedinteger) {
- //continue the job as usual
- } else {
- //BAN THE USER
- //start newperson message flow
- System.out.println("ai ai ai BANHAMMER INC\n");
- //Set the user to not allowed in our system first
- //first we need the person his ID
- System.out.println("find the person his id!: \n");
- Integer useriid = (Integer)accountidhelper.get(0);
- System.out.println("USERIIIIIIIIIIIIIIIIIDDDDDDDDDDDD " + useriid);
- /*
- //then we update the person
- System.out.println("it's update time!\n");
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(userid),
- new HashMap() {{
- put("x_isallowed", false);
- put("x_isactive", false);
- }}
- )
- ));
- System.out.println("show me the user!!!!\n");
- 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
- ))))));
- //update the version
- //then send out the updated message with version
- }
- //System.out.println("product ID :" + resultProd.get("product_id"));
- /*
- for (Object object5 : fields11) {
- HashMap<String,Object> result10 = (HashMap) object5;
- List productuuidhelper;
- double quantity
- productuuidhelper = Arrays.asList((Object[])result10.get("product_id"));
- quantity = (double) result10.get("quantity");
- System.out.println(productuuidhelper);
- System.out.println(quantity);
- // uuid opvragen van de productuuidhelper
- final java.util.List<Object> fields9000 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"account.invoice.line","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields9000",Arrays.asList("x_productuuid","name"));}})));
- for (Object object6 : fields9000) {
- HashMap<String,Object> result11 = (HashMap) object6;
- String productuuidhelperhelper = result11.get("x_productuuid").toString();
- System.out.println(productuuidhelperhelper);
- }
- */
- }
- //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- }
- }
- Integer useriid = (Integer)accountidhelper.get(0);
- //ophalen van de UUID voor de persoon waarover het gaat
- final java.util.List<Object> ids11= Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "search",
- Arrays.asList(Arrays.asList(
- //partneridhelper gelijk stellen aan de id uit de list partner_id
- Arrays.asList("id", "=", useriid/* partneridhelper */ ))))));
- //name = description in odoo, display name = name
- final java.util.List<Object> fields111 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"res.partner","read",Arrays.asList(ids11),
- new HashMap()
- {{put("fields",Arrays.asList("x_uuid"));}})));
- for (Object object2 : fields111) {
- HashMap<String,Object> results = (HashMap) object2;
- System.out.println(fields111);
- String uuidinvoicehelper = results.get("x_uuid").toString();
- System.out.println("zoekt naar uuid voor persoon met userid : " + useriid);
- System.out.println(uuidinvoicehelper);
- }
- }
- invoicehelper++;
- } else {
- System.out.println("there is no invoice for this number, trying again in 5 seconds... \n");
- }
- System.out.print("looks for invoicenumber: " + fullinvoicepath + " in the next search\n\n ________________________________________________________________________________________________________ \n\n");
- }
- }
- /* ************************************************************************************************************************************************************** */
- // create user
- /*
- final Integer id = (Integer) models.execute("execute_kw",Arrays.asList(db,uid,password,"res.partner","create",Arrays.asList(new HashMap() {{
- put("name",userid);
- put("email","example@gmail.com");
- put("phone","5151516151");
- put("city","Brussels");
- put("zip","1000");
- put("street","Jan van Doorslaerlaan1");
- put("TaxId","161161884655");
- put("customer",true);
- put("employee",false);
- put("active",true);
- put("x_isRegistered",true);
- }
- })));
- */
- /* ************************************************************************************************************************************************************** */
- //Update
- /*
- models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "write",
- Arrays.asList(
- Arrays.asList(37),
- new HashMap() {{ put("x_isRegistered", false); }}
- )
- ));
- // get record name after having changed it
- Arrays.asList((Object[])models.execute("execute_kw", Arrays.asList(
- db, uid, password,
- "res.partner", "name_get",
- Arrays.asList(Arrays.asList(37))
- )));
- */
- /* ******************************************************************************************************************************************************************* */
- /*
- newPerson p = new newPerson(
- "x_uuid",
- "Bezoeker",
- "TESTMESSAGE " + userid + " TEST",
- "De program manager",
- "zijn adress",
- "testmail@verbeeck.be",
- true,
- true,
- 1,
- UUIDHelper.getCurrentDate());
- */
- //List prodhelper = Arrays.asList((Object[])result.get("product_id"));
- /*
- final java.util.List<Object> fields11 = Arrays.asList((Object[])models.execute
- ("execute_kw",Arrays.asList(db,uid,password,"account.invoice.report","read",Arrays.asList(ids),
- new HashMap()
- {{put("fields",Arrays.asList("number","display_name","account_line_id","account_id","partner_id","amount_total","id","invoice_line_ids","nbr","price_total","product_id","product_qty"));}})));
- System.out.println(fields11);
- List accountidhelper2 = Arrays.asList((Object[])result.get("partner_id"));
- List accountidhelper3 = Arrays.asList((Object[])result.get("account_line_id"));
- System.out.println(accountidhelper2);
- System.out.println(accountidhelper3);
- */
- /*
- foreach (invoicelineshelperprint){
- }
- */
- /*
- int[] invoicelineidshelper = {28,29,30,31,32};
- for(int i=1; i<11; i++) {
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement