google-app-engine,collections,objectify , Objectify: Filter by an attribute of collection entries?


Objectify: Filter by an attribute of collection entries?

Question:

Tag: google-app-engine,collections,objectify

I'm using Objectify on Google's AppEngine. I have the following Entity-Model:

@Entity
public class ChallengeEntity {

    @Id
    private Long id;

    @Index
    public List<ChallengeParticipant> participants;
}

The Participant (not an entity... should it be one?)

public class ChallengeParticipant {
    @Load
    public Ref<UserEntity> user;

    // ... participant-specific attributes
}

And the User-Entity:

@Entity
public class UserEntity {

    @Id
    Long id;

    @Index
    public String email = "";
}

Now how would I find all challenges for a given user-email? Something along:

ofy().load().type(ChallengeEntity.class).filter("participants.user.email", "[email protected]")

I am willing to adapt my entity-model to GAE's needs... how may I support this query efficiently and keep a nice model?

Thanks alot


Answer:

Assuming your list of ChallengeParticipant is reasonably bounded (a few hundred at most) and you aren't at risk of hitting the 1M per-entity size limit, you're probably best leaving it as embedded.

To perform your query, first lookup the person by email, then filter by person:

UserEntity user = // load user (or get the key) by email
ofy().load().type(ChallengeEntity.class).filter("participants.user", user);

Note that you need to @Index the ChallengeParticipant.user field, not the ChallengeEntity.participants list.


Related:


Mapping a list to Map Java 8 stream and groupingBy


java,collections,lambda,java-8
I have this simple Bean class: public class Book { public Book(Map<String, String> attribute) { super(); this.attribute = attribute; } //key is isbn, val is author private Map<String, String> attribute; public Map<String, String> getAttribute() { return attribute; } public void setAttribute(Map<String, String> attribute) { this.attribute = attribute; } } In...

upload CSV file to database on Google app engine using Python


python,database,google-app-engine,csv,upload
I'm a newbie in python and started learning it from about a week. I was looking into couple of tasks one of which was to upload a file (.txt or .jpg) to a bucket on GAE. I was able to solve it by following couple of tutorials online, but i'm...

Converting collection to array with no extra memory


java,arrays,performance,memory,collections
I need to convert Map into 2D array, so I've wrote this piece of code but it eats a lot of memory and I can't figure out why. private DataItem[][] convertDataToArrays(boolean[] filter, Map<Integer, List<T>> dataSet) double[] data = new double[sizeOfNewVector]; DataItem[][] reducedData = new DataItem[dataSet.size()][]; for (int i = dataSet.size()...

Using counter on array for one value while keeping index of other values


python,collections
After reading the answers on this question How to count the frequency of the elements in a list? I was wondering how to count the frequency of something, and at the same time retreive some extra information, through something like an index. For example a = ['fruit','Item#001'] b = ['fruit','Item#002']...

GAE/P: Migrating to NDB efficiently


python,google-app-engine,app-engine-ndb
I'm finally upgrading from db to ndb (it is a much bigger headache than I anticipated...). I used a lot of ReferenceProperty and I've converted these to KeyProperty. Now, every place where I used a ReferenceProperty I need to add an explicit get because it was previously done for me...

Java Generic Map with Generic Type as key/ values


java,generics,collections
I want to write a method which takes a Map as an parameter, which can contain any object as its value. I am trying to implement it using generics, but I am unable to implement it. Below is the code that I have tried so far. This code as two...

Java - Create sublist from a list based on suffix


java,arraylist,collections,iterator,sublist
I'm trying to create sublists from a list based on the suffix. public class Test { public static void main(String args[]) { List<List<String>> subList = new ArrayList<List<String>>(); List<String> myList = new ArrayList<String>(); myList.add("Text_1"); myList.add("XYZ_3"); myList.add("ABC_1"); myList.add("Text_2"); myList.add("Text_3"); myList.add("XYZ_1"); myList.add("XYZ_2"); myList.add("ABC_2"); for (String item : myList) { List<String> tempList = new...

LoDash - DeepFlatten array of objects


javascript,collections,lodash,flatten
I have the following collection. Each object may have a children array of objects, which may have a children array of objects and so on... [ { "name": "John", "age": 24, "children": [ { "name": "Jack", "age": 53, "children": [ { "name": "Jenny", "age": 88 } ] } ] },...

GAE Managed VMs: Possible to use C-based Python libraries with standard runtime?


python,google-app-engine
I'm building a background module for my app in Python 2.7, but it needs to use C-based external libraries such as OpenCV. While GAE only "directly" supports pure Python libraries, I understand that using a managed VM removes that constraint. What I'm not quite clear on, after reading the documentation,...

How can you get the Google+ Profile of the current user when using Google Cloud Endpoint's (Java) built in authentication?


google-app-engine,google-plus,google-cloud-endpoints
My Setup Backend: Google App Engine (Java) w/ Google Cloud Endpoints using Endpoint's built in authentication Frontend: AngularJS web app Problem I need to get the Google+ profile for my users. The keyword "me" can generally be used to get the current user's Google+ profile, however since all the authentication,...

Delete single model from collection in Backbone.View


javascript,backbone.js,collections,model
var PlayersView = Backbone.View.extend({ collection: players, //collection of players el: "#playersList", //I bind to the class render: function () { this.$el.html(""); for (var i=0; i<this.collection.size(); i++) { var player = this.collection.at(i); this.$el.append("<li "+"value='"+player.get("id")+"'>"+player.get("names")[0]+" "+player.get("surnames")[0]+" <a href='#' class='edit'>[edit]</a>"+"</li>"); } //what I render is in the picture below return this; }, events:...

How to get public link for the uploaded file on google cloud storage in local dev server(Google App engine+JAVA)


java,google-app-engine,file-upload,google-cloud-platform
I am trying to upload the image files using gcs client library+java in local google app engine dev server. Images are uploaded successfully and i can see the entries created in local datastore under localhost:8888/_ah/admin/datastore How to get the public key for the uploaded images so that i can show...

GAE DOMDocument::load(): I/O warning : failed to load external entity


javascript,php,json,google-app-engine
I'm trying to move an existing webapp on GAE. At the moment the app is running on my local SDK. When the app perform a compatibility check, it returns an error (read by FIREBUG ): This is the code of the js who fails: function checkConfig(){ // Launch the configuration...

PLSQL move data from csv list stored in varchar2 to a collection of integers


sql,oracle,collections,plsql
Oracle Express 11G R2: In PLSQL I have a varchar2 containing a CSV list of values like this: vList:='1212,3232,3232,4343,54545,65654,65665,65654,788787' I would like to move these into a collection, so i create a new type: CREATE TYPE INTEGER_TT AS TABLE OF INTEGER; then declare my variable: my_list INTEGER_TT; What is the...

Java generic usage error


java,collections,java-generics
The code below uses simple generics and compiles correctly. When I try to create a object of type McDelayQueue, I get an error. public class McDelayQueue<E extends Delayed & IValue<K>, K> extends DelayQueue<E> { final Set keys = Collections.newSetFromMap(new ConcurrentHashMap<K, Boolean>()); @Override public E take() throws InterruptedException { E data...

VBA Debugger shows only 256 elements of a collection


excel-vba,debugging,collections
the title explains my problem. Im working on an excelmakro and my questions is, is there an option that the debugger shows all elements like it does with an array? And if not, is the only workaround the storage of my classobjects in an array after inflating the collection? I...

add subitems to meteor document


mongodb,meteor,collections,insert-update
I have a meteor collection "list" that has the following data structure. "list" : [ { "_id" : "id", "author" : "authorId", "createdOn" : "DateTime", "description" : "description", "items" : [ { "item1" : { "itemComplete" : "Boolean", "itemName" : "item name", "itemDescription" : "item description", } }, { "item2"...

Merge two or more T in List based on condition


c#,linq,collections
I have the below class: public class FactoryOrder { public string Text { get; set; } public int OrderNo { get; set; } } and collection holding the list of FactoryOrders List<FactoryOrder>() here is the sample data FactoryOrder("Apple",20) FactoryOrder("Orange",21) FactoryOrder("WaterMelon",42) FactoryOrder("JackFruit",51) FactoryOrder("Grapes",71) FactoryOrder("mango",72) FactoryOrder("Cherry",73) My requirement is to merge the...

why java API prevents us to call add and remove together?


java,list,collections,listiterator
As per Java API- IllegalStateException - if neither next nor previous have been called, or remove or add have been called after the last call to next or previous remove()- Removes from the list the last element that was returned by next() or previous() (optional operation). This call can only...

Iterator for an array list of Class


java,collections,iterator,listiterator
Am New to Java so please bear with me if my question seems to be silly. I am learning collections,I have written a program which will store student names id and marks.I am storing all these in a Arraylist. Using for loop I am able to print the values in...

Objectify - should I create an entity super class?


java,google-app-engine,objectify
Is there any reason why shouldn't all my entities be subclasses of one generic ModelEntity object? @Entity public class ModelEntity { @Id Long id; } @Subclass public class User extends ModelEntity { @Index String username; } The advantages are clear: there is code common to all entities (like id, date,...

IllegalArgumentException: expected primitive class, but got: class UUID


android,google-app-engine,google-cloud-endpoints
My app is using GAE endpoints. My model has UUID. And once i try to send it Android app it encounters illegalArgument exception. Anyone has got recommendations how to handle endpoints model with UUID on android app with Google App Engine endpoints? 06-14 23:26:49.560 27462-27488/com.example E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1...

Google Appengine - Entity class is not enhanced


google-app-engine
If I change an Entity class in a an appengine project in eclipse, in run time I get this error Found Meta-Data for [classpath] but this class is not enhanced!! Please enhance the class before running DataNucleus. Even when I undo the changes and re-run the local srv i get...

App Engine - NDB query with projection requires subproperty?


google-app-engine,gae-datastore,app-engine-ndb,google-app-engine-python
I have the following objects: class Address(ndb.Model): type = ndb.StringProperty() # E.g., 'home', 'work' street = ndb.StringProperty() city = ndb.StringProperty() class Friend(ndb.Model): first_name = ndb.StringProperty() # E.g., 'home', 'work' last_name = ndb.StringProperty() class Contact(ndb.Model): name = ndb.StringProperty() addresses = ndb.StructuredProperty(Address, repeated=True) friends = ndb.StructuredProperty(Friend, repeated=True) And now to optimize the...

Backbone.js collection fetch not setting response objects as models


backbone.js,collections,fetch
When fetching a collection, my api response has 10 objects, but the resulting Backbone collection only has 1 model with an attributes array containing the 10 response objects....to put it another way, the fetch is not creating models out of the objects in my response...and I don't know why. Model...

viewing google app engine Python logging messages in CodeEnvy


python,google-app-engine,logging,cloud
I'm trying to move my GAE development to the cloud. So far Codeenvy has the richest toolset however I'm struggling with one small issue. when I use the python logging library I don't know where to view these messages! def post(self): self.response.write('Processing form data...') feedback = self.request.get('content') logging.info(feedback) I assumed...

getting a value from a map in java with index


java,collections
The item shown below is the result obtained from debugging a map {0={PRODUCT_TYPE.PRODUCT_AMT=200}} To store this value in a string I have used this code String amountCheck=(String) productsFieldMap.get("PRODUCT_TYPE.PRODUCT_AMT"); However this does not seems to work. Can anyone suggest me a way to do this? The productsFieldMap represents the map where...

serving GAE applications over http


java,google-app-engine,ssl
I have implemented an application on GAE which can be accessible through https://<my_app_id>.appspot.com. Now I have a custom domain registered with Register.com. As described in GAE documentation I have mapped my custom domain to https://<my_app_id>.appspot.com and I see my application getting served from my custom domain. But I see requests...

Designing an API on top of BigQuery


google-app-engine,bigdata,google-bigquery
I have an AppEngine app that tracks user various sorts of impression data across several websites. Currently we're gathering roughly 40 million records a month and the main BigQuery table is closing in on 15Gb in size after 6 weeks of gathering data and our estimates show that within 6...

Trying to download a file using Dropbox Java API in the GAE


java,google-app-engine
I have an XML file on Dropbox that I want to access from my Google App Engine using the Dropbox Java API. After a bit of playing around I find the GAE doesn't support FileOutputStream. FileOutputStream outputStream = new FileOutputStream("myFile.txt"); try { DbxEntry.File downloadedFile = client.getFile("/myFile.txt", null, outputStream); System.out.println("Metadata: "...

jquery google app engine


jquery,google-app-engine
I have an issue where the Javascript file that I have uploaded does not work. My code is below. app.yaml has: - url: /js static_dir: /js index.html has: <script type="text/javascript" src="/js/script.js"></script> script.js has: $(document).ready(function(){ $('img').click(function(){ $(this).fadeOut('slow'); }); $('p').click(function(){ $(this).fadeOut('slow'); }); alert("hi"); }); and not even the alert comes out...

Scaling non-default version of Google App Engine Backend


python,google-app-engine
I have a live app that uses Google App Engine (python) for the backend. The app is pointing https://my-app.appspot.com. Because the API has changed significantly, I've set up a new version of the backend, 'v2', and am pointing the new app to https://v2.my-app.appspot.com. I see now in the docs, that...

What is the equivalent of BlobstoreLineInputReader for targeting Google Cloud Storage?


python,google-app-engine,mapreduce,pipeline
This is a python appengine question, mapreduce library 1.9.21 . I have code writing lines to a blob in the local blobstore, then processing that using mapreduce BlobstoreLineInputReader. Given that the files api is going away, I thought I'd retarget all my processing to cloud storage. I would expect to...

Loop by Object inside another Object in Java


java,list,oop,collections
I'm not sure how to ask this in word so here's an example : Building class have a data like this : Map<Season, List<Info>> infosBySeason = new TreeMap<Season, List<Info>>(); What I'd like to do is loop for each Building, print by Season infos. Like : Season 1 : Building 1...

Returning an Iterator from String[] [duplicate]


java,arrays,collections
This question already has an answer here: Iterator of Object[] 2 answers I have a class foo with a field String[] bar. I want foo to implement Iterable<String>. So I'm writing @Override public Iterator<String> iterator() { // ToDo - return some function of `bar` } What can I put...

Sending mail by Unauthorised sender in Google AppEngine


python,google-app-engine,email,sendmail
I've got a Google AppEngine Python application connected with my domain. I want to be able to send emails from any email, like: [email protected] So I use sendmail() and set mailobject.sender = "[email protected]", but it does not work. Also I made a receive function, but I don't want to receive...

Entity Framework, Code First, Update independent association (Collection)


c#,entity-framework,collections,ef-code-first
to explain the problem I have a simple model with a class Person: public class Person { public int Id { get; set; } public virtual string Name { get; set; } } and a class School with a collection of Persons: public class School { public int Id {...

Getting user credentials using Google+ API


android,google-app-engine,google-api,google-api-java-client
I am trying to include Google sign in in my android application using Google+ Api. I am able to take account details from the user but once signed in I am getting null when requesting for username using call: Plus.PeopleApi.getCurrentPerson(mGoogleApiClient).getDisplayName() And Logcat shows: BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/plus/v1/people/me...

GAE Python PyML ImportError: No module named _ckernel


python,google-app-engine,pyml
I'm trying to import PyML on Google App Engine as a requirement for another library, however I am getting the following import error: File "/base/data/home/apps/s~myapp/uno.385079313378714244/PyML/__init__.py", line 4, in <module> from PyML.containers import * File "/base/data/home/apps/s~myapp/uno.385079313378714244/PyML/containers/__init__.py", line 3, in <module> VectorDataSet = __import__('PyML.containers.vectorDatasets', fromlist=['']).VectorDataSet File...

“Segmentize” collection with lodash


javascript,collections,lodash
I have a collection col1 var col1 = [1, 8, 9, 10, 2, 54, 7]; I have another collection col2 var col2 = [1, 8, 23, 9, 46, 10, 2, 54, 78, 7] ...that I know it contains every element of col1, plus some other elements I want to...

What is the best way to iterate two hashmap in same loop in java?


java,data-structures,collections
What's the best way to iterate over the below two maps together? I want to compare two maps values which are strings and have to get the keys and values. HashMap<String, String> map1; HashMap<String, String> map2; ...

joining two collections in C# or JavaScript


javascript,c#,linq,collections
I have two objects of "pseudotype" Hash(int key, list values) that I need to combine into one based on the key. For example, [{1, {a, b, c}}, {2, {apple, pear}}, {3, {blue, red}}] and [{2, {tomato}}, {3, {pink, red}}, {4, {x, y, z}}] The result that I need is: [{1,...

How to convert single element list to java 8 optional


java,collections,java-8,optional
How to nicely convert list containing one or zero elements to Optional? The ugly code: List<Integer> integers = new ArrayList<>(); Optional<Integer> optional = integers.size() == 0 ? Optional.empty() : Optional.of(integers.get(0)); ...

Google App Engine datastore: filter()


python,google-app-engine
I'm trying to retrieve an entry from Google App Engine's datastore using the filter() method as follows: result = Sender.all().filter("email =", email).filter("source_address =", source).filter("dest_address =", dest).filter("food_type =", food_type) Then, if such an entry exists, I change the value of one of the columns in that entry. Otherwise, I'm displaying an...

Do we HAVE to generate and use client libraries to use Google App Engine's Endpoints?


ios,swift,rest,google-app-engine,google-cloud-endpoints
I am currently developing an Swift iOS app with GAE Endpoints for the RESTful API. It seems like all the tutorials and documents make you generate and use client libraries if you need to use the API on the client side. I was wondering if it's possible for me to...

GAE webapp2 delete all UserTokens (drop all sessios) for specific user


python,google-app-engine,webapp2
I want to drop all user sessions when user resets his password, but I can't find a way to do that. My idea was to get all UserTokens of the specific user and delete them, but it seems impossible, because of user = model.StringProperty(required=True, indexed=False) in UserToken model Any ideas...

Why doesn't my sample throw ConcurrentModificationException [duplicate]


java,collections,concurrentmodification
This question already has an answer here: Why isn't this code causing a ConcurrentModificationException? 4 answers I wrote this example following a test ConcurrentModificationException concept: public class Person { String name; public Person(String name) { this.name = name; } } public static void main(String[] args) { List<Person> l =...

Merge multiple lists based on List priority


java,sorting,collections,priority
I have couple of lists where each list has different priority. When i merge these lists i should get with height priority on top. Assume i have 3 lists and different objects value common in 3 lists should come first and then the top priority list should be appended vice...

No module named _mysql - Google App Engine & Django


python,mysql,django,google-app-engine
First of all I'm working on Mac (Yosemite). I've created a simple Django project with Google App Engine. I'm using Cloud SQL in production and MySQL in development environment as recommended in the docs. The project uses virtualenv on my dev machine of course. I can run the project with...

Search for key in Map when the values are in ArrayList [closed]


java,arraylist,collections,hashmap,key-value
I am new to the collections in Java , I have a HashMap<String, List<String>>. I want to search for a key from the Map when a value is given. The map stores the data of a state as key and its cities as the list. So it is assumed that...