Start a new topic

Data store access from Google App Engine using the Java SDK requires user login?

I'm trying to access a collection in Kinvey using the new Java SDK from Google App Enigne. I'm following the guide here: http://devcenter.kinvey.com/java/guides/datastore and I am getting a NullPointerException: No Active User - please login a user by calling myClient.user().login();



I'm trying to access a datastore that was primarily used by the Google App Engine business logic to store and update date. It is not directly used by the users in anyway. I was able to do this using the collection_access module that was part of the Kinvey App Engine SDK.



What's the best way to do this with the Java SDK?

Hey,



Since you don't need to worry about managing a user's lifecycle and your app engine code is in a controlled environment, we recommend authenticating with your app's `appkey` as the username and `master secret` as the password:



myJavaClient.user().loginBlocking(MY_APP_KEY, MY_MASTER_SECRET).execute();
Thanks Edward,



That worked. However, I also need to make an update to the User collection from Google App Engine, and being logged in with the AppKey and MasterSecret does not seem to allow this. In fact it looks like you can't query the User collection at all, even if logged in as the user, without using the .user() methods.



Is there a better way to update/modify the User collection from Google App Engine without logging in as the User and without using the .user() methods?
Is there a reason you don't want to use the `.user()` methods?



For example, this method lets you pass a `Query` object and returns an array of users: http://devcenter.kinvey.com/android/reference/api/java/reference/com/kinvey/java/User.html#retrieveBlocking(com.kinvey.java.Query)

Thanks Edwards,



Ah, I think that's what I was looking for, however, that method returns a Retrieve Request, how do I then get the User I am querying for?



Here's a bit more detail:



I created a query

Query userQuery = javaClient.query();

userQuery.equals("customer_id", 12345);



javaClient.user().retrieveBlocking(userQuery).execute();



This returns a retrieve request, so how do I execute this request?
I guess the documentation describes it differently. But I was able to resolve this simply by casting the return value of the retrieveBlocking() method to a User [].



So essentially what worked for me was:



Query userQuery = javaClient.query();

userQuery.equals("customer_id", 12345);



User user[] = (User[]) javaClient.user().retrieveBlocking(userQuery).execute();





Edward, thanks for your help.

Is there a similar way to delete a user from the system? I am able to update the user, but deleting the user returns an "abstractKinveyClient must not be null"



I tried the following:



Query userQuery = javaClient.query();

userQuery.equals("customer_id", 12345);



User user[] = (User[]) javaClient.user().retrieveBlocking(userQuery).execute();



with the above code in place,



// this works

User updatedUser = javaClient.user().updateBlocking(user[0]).execute();



// this does not work

user[0].deleteBlocking(true).execute();

Login or Signup to post a comment