How do I pass the arraylist to google cloud endpoint? It doesn't seem to work.
Edit start ----
Here is the signature of the endpoint with arraylist as input
public CollectionResponse<String> listDevices(#Named("devices") ArrayList<String> devices)
However when I iterate over this arraylist, I get all the records condensed into one. So even though I pass 10 strings, I get only one in my endpoint.
Edit end ----
I read somewhere that I should create a wrapper entity for arraylist and then pass it.
Edit start ----
So I created the entity containing the arraylist
#Entity
public class DEviceList {
ArrayList<String> devices;
}
and modified the signature as -
public CollectionResponse<String> listDevices(DeviceList devices)
Is it possible to pass object of DeviceList from client even though it not #Named? Can you provide the syntax?
My understanding is that since it's an entity it cannot be #Named, so while calling I need to inject it.
But google allows only three injected types -
1. com.google.appengine.api.users.User
2. javax.servlet.http.HttpServletRequest
3. javax.servlet.ServletContext
So above signature would not work.
So I changed the signature to -
public CollectionResponse<String> listDevices(HttpServletRequest request)
and inside I could get the entity as
DeviceList deviceList = (DeviceList)request.getAttribute("deviceList");
However I am not sure how to call this endpoint from the android client?
How I do pass the entity object using HTTPServletRequest?
Edit end ----
How do I do that? Can anyone cite an example?
The way you word your question, it seems the call is silently failing. That can't be. You must be receiving some kind of exception or log somewhere which could help you identify your issue better. You could read this article to refresh on cloud endpoint APIs and android.
If you are having trouble passing an arraylist of objects from your client to the API, I would suggest checking some things:
does the argument type in the API match what is being sent from the client? Do they both have access to the class definition?
if the data type inside the arraylist is a primitive, and it still fails, perhaps the advice you read "somewhere" was referring to the need (although I don't think this is the case) to use a wrapper object which simply contains one field - the arraylist, and pass that along the line?
If either the reminder to check your logs/error messages or any other info in this answer helped you resolve the issue, please remember to accept it, but not without first editing your post to explain how you resolved your issue.
Related
I need a little help with an issue in App Inventor 2. The case is that I have a JSON result that is parsed, and then have it stored in a tinyDB tag as a list (storeparseData).
Problem is that, I have this function done as screen initiates, so to have the tinyDB tag populated with that JSON list and then searched for a specific value on user request.
As the app is running and I input a search criteria, I get the following error "The arguments [empty-string] are the wrong number of arguments for GetValue". I suppose that, it finds nothing yet to be stored in the tinyDB tag to search for, cause the JSON data take some time to be fetched and parsed.
Here is what I have done for now for checking if the stored list is in the tinyDB:
Here I check the stored list in tinyDB for an item:
So how can I check if the tinyDB is populated in this tag with the JSON results list, so I can then have it searched? Is this possible in App Inventor 2?
Please someone advise on this issue with a sample code blocks if possible, or a similar tutorial, if there is any. Thank you all in advance for your answers.
This looks very strange... a complicated if then else structure, loads of empty sockets and your comparison if "storeparsedData" = <empty string> always will be false... obviously this does not make sense...
it looks like you are thinking too complicated?
what about this:
As already recommended in my answer to your other question you should learn how to work with lists...
how to work with lists
how to work with list of lists (pdf) by appinventor.org
see also An example of a complex List of Lists
Also doing some more tutorials might help to learn some more basics...
To answer your question "Can you explain why you've chosen to create an empty list there.": if you are working with lists as in the example and you are trying to read a list from TinyDB, then you also have to think about what should happen, if that tag is not available in TinyDB (for example after starting the app the first time). And for lists, in this case an empty list should be returned. Note: the is list empty? block always expects a list. If you set valueIfTagNotThere to an empty string, then you will get a runtime error...
You can use Clock function to delay the time. Firstly, just set the global DelayCountdown to specific number in "when Screen1.Initialize" part. Then, by using "when Clock1.Timer" function, you just need to add another check whether the DelayCountdown is equal to zero before you do another function.
I have a parseobject which consists of many objects, notably an array of consisting of ParseUser pointers.
When an individual clicks a button, the array should remove a certain User.
I don't get how to do this,
I have tried:
mRideEdit.removeAll("Participant", (Collection) childuser);
Where mRideEdit is my ParseClass, Participant is the array consisting of ParseUsers, and childuser is the user I want to remove
Please help,
I've recently faced the same problem.
It originates from how the ParseObjects (including ParseUser) are saved on the server.
If you look at the console, you'll see it is actually an array of strings created from the JSONObject toString method.
The simple answer is - You're using it wrong.
There is no sense in saving objects in such a way (though it's very intuitive).
As you probably noticed - you don't receive them as objects with the getJSONArray method either and have to get them from their objectIds.
The best way to do this is using relations.
If you're set on avoiding relations, what I'd suggest is saving them as strings from the get go (objectId). That way add, addUnique and removeAll will work just fine.
Hope this helps.
i have been searching for a while for a solution to my problem without success.
I have an application in which I receive information for a particular entity in my database from different services, so I am using greenDAOs insertOrReplace methods so whenever the entity already exists in my DB it gets updated instead of recreated.
So far so good.
The problem is.. let's say for example sake my entity is called User, with fields id, title, and displayName.
So in the first call I get a JSON object containing a user with only its id and title fields, so I insert it into the DB and naturally the displayName gets inserted as NULL.
Afterwards from another service I get another JSON containing the same user (same id field), but it comes with the displayName as well, but doesn't include the title info at all.
So whenever I run the insertOrReplace on the DAO object automatically generated by greenDAO, the user gets updated but as the title info was not present, when it gets updated the title field gets reset to NULL, so I end up losing data.
Unfortunately I am unable to change the data being returned from the services, and haven't been able to fix this issue. I find it hard to believe there is no easy way to tell the DAO object to update only certain fields and no all of them.
I was looking at the code generated by greenDAO and in the dao objects generated there is a bindValues method which gets called before the query gets executed, and apparently it filters out the NULL properties from the object, but either way it gets updated with the NULL value.
I was able to come up with some sort of fix by modifying the final dao object being generated by adding some methods from the parent class, but I don't think this is a good solution because I would have to do this for all the dao objects. (I know it's possible to define a custom superclass but this only applies for the entity object and not the DAO one).
I would really appreciate if someone has any idea on how I could resolve this, and sorry for the long explanation, I just wanted to be clear on my issue.
Thanks.
First of all: I wouldn't tamper with the generated code unless you really know what you are doing. Modifications may have effects on caches and data-integrity.
Generally you are following this (insert-or)-update-approach if you are using a ORM-Framework (like greendao):
Try to get the entity, that you want to modify from the db (maybe it is already in cache, so this may not be a real database operation)
If you don't have such an entity: create it
Modify the entity according to your needs
Insert or Update it in database (in greendao you would use insertOrReplace)
I am having a weird issue here.
The class Points I want to save data into, has two columns race and challenge which are relations to other classes with the same name.
I have asked this question on Parse.com forums as well
On the client side on Android, if I add the relation via pointsObject.put("race", raceObject), it throws an error saying that the type of "race" is Relation and I am providing a *Pointer
The iOS Counterpart of the app I am working on is completely able to save relations nicely - Happily Coded about 2 hours ago
When I use ParseRelation to add a one-to-many relationship, it takes only the first class as target class.
This code should explain:
ParseRelation<ParseObject> initiatorChallengeRelation = initiatorPoints.getRelation("Points");
initiatorChallengeRelation.add(challenge);
initiatorPoints.put("challenge", initiatorChallengeRelation);
ParseRelation<ParseObject> initiatorRaceRelation = initiatorPoints.getRelation("Points");
initiatorRaceRelation.add(race);
initiatorPoints.put("race", initiatorRaceRelation);
The first block of code sets the target class for the relation as "Challenge".
The second block tries to set the target class of the new ParseRelation object to "Race", but initiatorRaceRelation.add(race) is where it fails and throws an error : "IllegalArgumentException: Related object object must be of class Challenge, but Race was passed in."
I used Eclipse Debugger to check the data in the both Relation objects and found the thing about target classes being the same
Any help on where I might be going wrong?
I have been dealing with this issue since more than 12 hours and its really become a roadblock for me.
Any help would be deeply appreciated
Is Points a relation? From what you have mentioned, it seems so.
Assuming that initiatorPoints is a Points Object, you should get the challenge relation using
ParseRelation<ParseObject> initiatorChallengeRelation = initiatorPoints.getRelation("challenge"); //for challenge
then
initiatorChallengeRelation.add(challenge);
Similarly, for race
ParseRelation<ParseObject> initiatorRaceRelation = initiatorPoints.getRelation("race"); //for race
initiatorRaceRelation.add(race);
I think you need not even use initiatorPoints.put("challenge", initiatorChallengeRelation);
Once, you say
initiatorPoints.saveInBackground(callback), Parse updates the changes in the object by itself.
But do not forget to save the object once you have added the relation data. Hope this helps!
I have an Android Class called Receipt, it's modeled off a typical Receipt you'd get in a retail environment and includes the following Class variables:
receipt_number
date_ordered
date_paid
item_quantity
item_type
item_sku
item_price
total_price
customer_id
customer_name
clerk_id
clerk_name
Whew... there's a lot. I'm just becoming accustom to OOP and while I love the idea of using a Receipt data Class to store the properties of a Receipt, I fear I am using an object just for the sake of using an object and not using data Classes appropriately.
Why? Well, I have another method in another Class which I feed my Receipt object to. Once fed to this other Class, the Receipt data is used to fill out a View which allows the user to edit said Receipt (data from the Receipt fills out EditText boxes which can be changed, then saved). The problem is that the code is getting ridiculous for updating a Receipt. I've got a helper method in Receipt for virtually every variable above (e.g. setClerkId(), setCustomerName(), setItemSku(), etc. etc.) and when I update a Receipt, I find myself calling all these methods and it's turning into a huge rats nest.
Surely I am missing the boat here, and probably by a long-shot. There must be a more sane way to feed in all the values of my new Receipt (it's really an update of the old object) without manually updating each variable using a helper method? I guess I'd be a little bit surprised (no, a lot surprised) if this is the correct way of doing this.
Any push in the right direction would be much appreciated!
Thanks!
You are doing it right I guess. I an object has a lot of named properties then you'll have to do a lot of get/set.
You can simplify that if you don't need to access each individually if you put them all into single (or several) ArrayList<String>/String[] or even other objects. Whatever you feel is an appropriate representation of your data.
Or you take a HashMap instead of your class and store them like so:
HashMap<String, String> hashmap = new HashMap<String, String>();
hashmap.put("receipt_number", value);
String value = hashmap.get("receipt_number");
That results in a more dynamic way to store values.