我正在使用Google端点编写一款安卓游戏。
我们想检查facebook用户朋友的用户是否也使用我们的应用程序(每个用户在游戏中获取自己的ID,他的facebook id是实体用户的字符串字段)。
所以我将朋友facebook ids的列表放到List中,并希望使用端点将其传递给服务器并进行类型的查询:select n from User n where n.facebookId IN ("+listOfFriends+")
问题是我无法将List传递给端点。
我制作了容器类:
@Entity
public class StringsListContainer {
private List<String> listString;
public List<String> getStringsList() {
return listString;
}
public void setStringsList(List<String> objectsList) {
this.listString = objectsList;
}
public StringsListContainer(List<String> listString) {
this.listString = listString;
}
}
在UserEndpoints中,我的Api是:
@SuppressWarnings({ "unchecked", "unused" })
@ApiMethod(name = "getTopFriendsForUser")
public CollectionResponse<User> getTopFriendsForUser(
@Nullable @Named("cursor") String cursorString,
@Nullable @Named("limit") Integer limit,
StringsListContainer friendsLine) {
System.out.println( "In getTopFriendsForUser endpoint" );
EntityManager mgr = null;
Cursor cursor = null;
List<User> execute= new ArrayList<User>();
//next will go in chunks depending on size of StringsList
for(String s : friendsLine.getStringsList())
{
if(listOfFriends.isEmpty()) {
listOfFriends = "'" + s + "'";
} else {
listOfFriends = listOfFriends + ",'" + s + "'";
}
}
System.out.println( listOfFriends.toString());
try {
mgr = getEntityManager();
Query query = mgr.createQuery("select n from User n where n.facebookId IN ("+listOfFriends+")");
if (cursorString != null && cursorString != "") {
cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
}
if (limit != null) {
query.setFirstResult(0);
query.setMaxResults(limit);
}
execute = (List<User>) query.getResultList();
cursor = JPACursorHelper.getCursor(execute);
if (cursor != null)
cursorString = cursor.toWebSafeString();
for (User obj : execute)
;
System.out.println("Ending");
} finally {
mgr.close();
}
return CollectionResponse.<User> builder().setItems(execute)
.setNextPageToken(cursorString).build();
}
我生成客户端库并从客户端调用它,如下所示:
CollectionResponseUser response = endpoint.getTopFriendsForUser(friendsList).execute();
我仍然遇到The method getTopFriendsForUser() in the type Userendpoint is not applicable for the arguments (StringsListContainer)
错误
任何人都可以建议如何解决这个问题? 或者也许有更好的方法来检查它?