I'm trying to create a meeting with attendees in Odoo, The attendees fields is many2many field. if I don't add it to the request, the meeting is created just fine without attendees. However , if I add the "partner_ids" key that corresponds to the many2many field. The meeting does not appear. Here are samples of what I tried :
// Attempt 1 : add them as an integer array
List<Integer> partnerIds= new ArrayList<>();
partnerIds.add(15403);
partnerIds.add(7567);
partnerIds.add(7564);
// Attempt 2 : add them in a hashmap array;
List<HashMap<String,Integer>> hashMapList= new ArrayList<>();
HashMap<String,Integer> hashMap= new HashMap<>();
hashMap.put("id",15401);
HashMap<String,Integer> hashMap2= new HashMap<>();
hashMap2.put("id",15400);
HashMap<String,Integer> hashMap3= new HashMap<>();
hashMap3.put("id",15399);
hashMapList.add(hashMap);
hashMapList.add(hashMap2);
hashMapList.add(hashMap3);
attempt 3 : add them into a list of objects as mentioned here
List<Object> testObj= new ArrayList<>();
//Object obj = new Object();
testObj.add(0);
testObj.add(0);
testObj.add(hashMapList);
List<Object> manyToManyRecord = new ArrayList<>();
manyToManyRecord.add(testObj);
Log.d("manyToManyRecord", manyToManyRecord.toString());
OdooValues values = new OdooValues();
values.put("opportunity_id",25619);
values.put("partner_ids", manyToManyRecord);
values.put("name", "App Discussion Meet ");
values.put("start", "2019-03-27 10:00:00");
values.put("stop", "2019-03-27 20:00:00");
values.put("allday", false);
values.put("day", 0);
values.put("user_id", 1);
values.put("active", true);
values.put("recurrent_id", 0);
values.put("x_project_latitude", 0);
values.put("x_project_longitude", 0);
values.put("description", "Test Meeting Description");
client.create("calendar.event", values, new IOdooResponse() {
#Override
public void onResult(OdooResult result) {
int serverId = result.getInt("result");
Log.d("Meeting Id", String.valueOf(serverId));
}
});
So where is the mistake I am making ? Any help with the steps is appreciated!
This solution worked for me :
//The 15401,15400... are static ids that were inputted for testing
values.put("partner_ids", asList(asList(6, 0, asList(15401,15400,15399))));
Related
I have a DynamoDb table named school-data in AWS. Below is the existing code to get all the school with a school's name:
private DynamoDBQueryExpression<School> createQueryBySchoolName(String schoolName) {
String matchSchoolName = "schoolName = :schoolName";
Map<String, AttributeValue> schoolNames = new HashMap<>();
schoolNames.put(":schoolName", new AttributeValue().withS(schoolName));
return new DynamoDBQueryExpression<School>()
.withIndexName("schoolName-index")
.withKeyConditionExpression(matchSchoolName)
.withExpressionAttributeValues(schoolNames)
.withConsistentRead(false);
}
The above query works fine. But Now I need to fetch all schools with a particular school name and their address . So, below are the 3 columns in the table:
id schoolName details
The data in details column looks like below:
{
"zone": "North",
"type": "Convent",
"address": {
"id": "138",
"street1": "123 Street",
"street2": "456 Road"
}
}
So, I need to fetch all the schools with name 'ABC' and address street1 as '123 Street'. So, I updated the above query as below:
private DynamoDBQueryExpression<School> createQueryBySchoolName(String schoolName) {
String matchSchoolName = "schoolName = :schoolName";
Map<String, AttributeValue> schoolNames = new HashMap<>();
schoolNames.put(":schoolName", new AttributeValue().withS(schoolName));
schoolNames.put(":streetName", new AttributeValue().withS("123 Street"));
return new DynamoDBQueryExpression<School>()
.withIndexName("schoolName-index")
.withKeyConditionExpression(matchSchoolName)
.withFilterExpression("details.address.street1 = :streetName")
.withExpressionAttributeValues(schoolNames)
.withConsistentRead(false);
}
But, this returns no data. Can you please let me know what am I doing wrong?
You need to set HashKeyValues for the DynamoDBQueryExpression and add the page limit
private DynamoDBQueryExpression<School> createQueryBySchoolName(String schoolName) {
String matchSchoolName = "schoolName = :schoolName";
Map<String, AttributeValue> schoolNames = new HashMap<>();
schoolNames.put(":schoolName", new AttributeValue().withS(schoolName));
schoolNames.put(":streetName", new AttributeValue().withS("123 Street"));
return new DynamoDBQueryExpression<Voucher>()
.withHashKeyValues(schoolName)
.withIndexName("schoolName-index")
.withKeyConditionExpression(matchSchoolName)
.withFilterExpression("details.address.street1 = :streetName")
.withExpressionAttributeValues(schoolNames)
.withConsistentRead(false)
.withLimit(pPageSize);
}
.withHashKeyValues(schoolName) will only accept a Hash Key object as shown in this image
OK, very odd. Not come across this before from what I can remember.
OK, so the compiler is telling me that the following method should be void for some reason:
public static HashMap<String, ArrayList<FlightData>> mapper(ArrayList<String> lineBuffer) {
HashMap<String, ArrayList<FlightData>> mapdata = new HashMap<>(); //array list for Mapdata object
for (String flightData : lineBuffer) {
String[] str = flightData.split(",");
FlightData flight = new FlightData(str[0], str[1], str[2].toCharArray(), str[3].toCharArray(), new Date(Long.valueOf(str[4])), Long.valueOf(str[5]).longValue()); //creating the object
mapdata.get(flight.getFlightID()); //getting the flight data
if (mapdata.containsKey(flight.getFlightID())) { //checking if the data for the oject contains hash key Flightdata
mapdata.get(flight.getFlightID()).add(flight);
}
else if (mapdata.containsKey(flight.getFromID())) {
mapdata.get(flight.getFromID()).add(flight);
ArrayList<FlightData> noID2 = new ArrayList<>(); //creating an array for noID
noID2.add(flight);
mapdata.put(flight.getFlightID(), noID2);
}
else {
ArrayList<FlightData> noID = new ArrayList<>(); //creating an array for noID
noID.add(flight);
mapdata.put(flight.getFlightID(), noID);
// System.out.println(mapdata);
}
return mapdata;
}
Which is odd, because when I remove the additional if (if else to just else) its fine:
public static HashMap<String, ArrayList<FlightData>> mapper(ArrayList<String> lineBuffer) {
HashMap<String, ArrayList<FlightData>> mapdata = new HashMap<>(); //array list for Mapdata object
for (String flightData : lineBuffer) {
String[] str = flightData.split(",");
FlightData flight = new FlightData(str[0], str[1], str[2].toCharArray(), str[3].toCharArray(), new Date(Long.valueOf(str[4])), Long.valueOf(str[5]).longValue()); //creating the object
mapdata.get(flight.getFlightID()); //getting the flight data
if (mapdata.containsKey(flight.getFlightID())) { //checking if the data for the oject contains hash key Flightdata
mapdata.get(flight.getFlightID()).add(flight);
} else {
ArrayList<FlightData> noID = new ArrayList<>(); //creating an array for noID
noID.add(flight);
mapdata.put(flight.getFlightID(), noID);
}
// System.out.println(mapdata);
}
return mapdata;
}
I get the following:
the error is telling my missing return statement/type. Hence void suggestion. any ideas why??
Any help would be great.
Cheers,
Glenn
Yeah, so I'm an idiot and didn't spot that my return statement was inside my for loop... Just wow.
Cheers to all who commented with a response.
markspace
ayush Gupta
ifly6
apparently I'm blind.
Cheers guys.
Glenn
I'm using Java and Infusionsofts API to get a list of contacts based on the customer id. I can't figure out a way to do this. I'm using Googles Guava to use multimap but it's producing an error:
org.apache.xmlrpc.common.XmlRpcExtensionException: Serializable objects aren't supported, if isEnabledForExtensions() == false
So now i'm trying hashmap and i'm inserting "Id" as the key and the customer id as the value but there's always one entry in the hashmap.
How can I add to the parameters variable a map that contains:
["Id",11111]
["Id",22322]
["Id",44444]
List parameters = new ArrayList();
parameters.add(APP_ID);
parameters.add(TABLE_NAME);
parameters.add(LIMIT);
parameters.add(pageNumber);
HashMap<String, Integer> map = new HashMap<String, Integer>();
for(int customerId : customerIds){
map.put("Id", customerId);
}
//PROBLEM IS HERE
parameters.add(map);
//THIS IS THE PROBLEM, I NEED TO ADD ["Id", customerId] multiple
//times with the customerId being different but since there's a hashmap
//There's always 1 entry in the map
String[] fields = {"Email","FirstName"};
parameters.add(fields);
Object[] contacts = null;
try{
contacts = ( Object [] ) client.execute("DataService.query",parameters);
}catch(XmlRpcException e){
e.printStackTrace();
}
for (int i = 0; i < contacts.length; i++) {
Map contact = (Map) contacts[i];
System.out.println(contact+"\n\n");
}
I use following complex data structure.
departures = new TreeMap<String, Map<String, Set<MyObject>>>();
arrivals=new HashMap<String, Set<MyObject>>();
flights=new HashSet<MyObject>();
Then I use loops (I also tried other loops).
for(String dep: nizDep){
for(String arr: nizArr){
for(MyObject flight: _flights){
if(flight.getFrom().equalsIgnoreCase(dep)&&flight.getTo().equalsIgnoreCase(arr)){
flights.add(flight);
}
}
if(!flights.isEmpty()){
arrivals.put(arr, flights);
flights.clear();
}
}
if(!arrivals.isEmpty()){
departures.put(dep, arrivals);
arrivals.clear();
}
}
System.out.println(departures.size()); //result 14
System.out.println(departures.containsKey("Madrid")); //result true
arrivals=departures.get("Madrid");
System.out.println(arrivals.size()); //result 0, arrivals is empty. WHY?
My question is how to use this complex data structure and how to retrieve arrivals from departures?
System.out.println(arrivals.size()); //result 0, arrivals is empty. WHY?
BECAUSE When you call flights.clear(); after arrivals.put(arr, flights); or arrivals.clear(); after departures.put(dep, arrivals);, this clears your original objects(flights and arrivals). Please bring your initialization statements i.e.
Map<String, Set<MyObject>> arrivals=new HashMap<String, Set<MyObject>>();
Set<MyObject>(); flights=new HashSet<MyObject>();
within the for loops or replace that statement as below:
if(!flights.isEmpty()){
Set<MyObject> newflights=new HashSet<MyObject>();
newflights.addAll(flights); //copy elements to new set
arrivals.put(arr, newflights);
flights.clear();
}
Same you may do with departures.
Now for retrievals:
Set<String> arrivalKeys = departures.keySet();
Interator<String> arrIter = arrivalKeys.iterator();
while(arrIter.hasNext()){
String arrKey = arrIter.next();
Map<String, Set<MyObject>> arrivals = departures.get(arrKey );
//use your arrivals map object
}
Same you can do to retrieve flights from arrivals e.g.
for each arrivals retrieved as above:
Set<String> flightKeys = arrivals.keySet();
Interator<String> flIter = flightKeys.iterator();
while(flIter.hasNext()){
String flKey = flIter.next();
Set<MyObject> flights = arrivals.get(flKey );
//use your flights set object
}
arrivals=new HashMap<String, Set<MyObject>>();
departures = new TreeMap<String, Map<String, Set<MyObject>>>();
for(String dep: nizDep){
for(String arr: nizArr){
for(MyObject flight: _flights){
if(flight.getFrom().equalsIgnoreCase(dep)&&flight.getTo().equalsIgnoreCase(arr)){
flights=new HashSet<MyObject>();
flights.add(flight);
arrivals.put(arr, flights);
departures.put(dep, arrivals);
}
}
}
}
System.out.println(departures.size()); //result 14
if(departures.containsKey("Madrid")) {
arrivals=departures.get("Madrid");
System.out.println(arrivals.size());
}
In case you want to keep a one-to-one mapping between arrivals and flights, then this code works. In case you want to keep a global structure of maintaining the set of flights then you'll have to create another global gflights object and put every flights object into it.
I am using Blackberry Plug-in and i am using Rich Lists of blackberry.
I want to make lists appear the same number of times as there are entries in the database table.
I m using the below code but it shows only one name in list view.
I need to show all the entries in database into list view...Kindly help me..
I have already used list.add(); inside the for loop but it is showing Exception: java.lang.IllegalStateException: Field added to a manager while it is already parented.
public static void richlistshow(){
String name = null;
list = new RichList(mainManager, true, 2, 0);
Bitmap logoBitmap = Bitmap.getBitmapResource("delete.png");
delete = new BitmapField(logoBitmap, Field.FIELD_HCENTER);
for (int c = 0; c < target_list.size();c++){
City tar_city = new City();
tar_city = (City)target_list.elementAt(c);
name = tar_city.get_city_name().toString();
}
//adding lists to the screen
list.add(new Object[] {delete,name,"time-date"});
}
You didn't posted full codes you are working with. But following code may help you to get rid of IllegalStateException. You were adding same BitmapField instance for every list entries, which caused the exception.
public static void richlistshow() {
final Bitmap logoBitmap = Bitmap.getBitmapResource("delete.png");
list = new RichList(mainManager, true, 2, 0);
for (int c = 0; c < target_list.size(); c++) {
// create a new BitmapField for every entry.
// An UI Field can't have more than one parent.
final BitmapField delete = new BitmapField(logoBitmap, Field.FIELD_HCENTER);
City tar_city = (City) target_list.elementAt(c);
final String name = tar_city.get_city_name().toString();
// add to list
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
list.add(new Object[] { delete, name, "time-date" });
}
});
}
}