とりあえず版だけど、newFetchPeopleRequestのサーバ側実装ができた。
友達一覧取得できた。
一応そんときのGadgetのxml。
- <?xml version="1.0" encoding="UTF-8"?>
- <Module>
- <ModulePrefs title="友達一覧取得">
- <Require feature="opensocial-0.8" />
- <Require feature="dynamic-height" />
- </ModulePrefs>
- <Content type="html" view="home,profile,canvas"><![CDATA[
- <div id='friends_list'></div>
- <script type="text/javascript">
- function requestGetOwnerProfile() {
- var params = {};
- params[opensocial.DataRequest.PeopleRequestFields.PROFILE_DETAILS] = [
- opensocial.Person.Field.ID,
- opensocial.Person.Field.NICKNAME,
- opensocial.Person.Field.THUMBNAIL_URL,
- opensocial.Person.Field.PROFILE_URL
- ];
- // params[opensocial.DataRequest.PeopleRequestFields.FILTER] = opensocial.DataRequest.FilterType.HAS_APP;
- var req = opensocial.newDataRequest();
- var idSpecParam = {};
- idSpecParam[opensocial.IdSpec.Field.USER_ID] = opensocial.IdSpec.PersonId.OWNER;
- idSpecParam[opensocial.IdSpec.Field.GROUP_ID] = opensocial.IdSpec.GroupId.FRIENDS;
- var idSpec = opensocial.newIdSpec(idSpecParam);
- req.add(req.newFetchPeopleRequest(idSpec, params), "get_friends");
- req.send(handleRequestGetFriendsProfile);
- };
- function handleRequestGetFriendsProfile(data) {
- var friends = data.get("get_friends");
- if (friends.hadError()) {
- //Handle error using viewer.getError()...
- document.getElementById('friends_list').innerHTML = 'エラーだよーん';
- return;
- }
- var data = friends.getData();
- var out = document.createElement('ul');
- data.each(function(friend) {
- var li = document.createElement('li');
- var thumbnailUrl = friend.getField(opensocial.Person.Field.THUMBNAIL_URL);
- li.innerHTML = '<img src="'+thumbnailUrl+'" />'+friend.getField(opensocial.Person.Field.NICKNAME);
- out.appendChild(li);
- });
- document.getElementById('friends_list').appendChild(out);
- // 自動調節
- gadgets.window.adjustHeight();
- };
- gadgets.util.registerOnLoadHandler(requestGetOwnerProfile);
- </script>
- ]]>
- </Content>
- </Module>
うーん。すばらしい。
サーバ側のSQLは悲惨な感じ。
以下、PersonServiceとDAOの間のロジック。
- public List<Person> getPeople(List<String> userLoginIds, String paramGroupType, String paramGroupId, CollectionOptions collectionOptions, SecurityToken token, Set<String> fields) {
- List<Person> result = new ArrayList<Person>();
- logger.info("getPeople開始:");
- if (logger.isDebugEnabled()) {
- logger.debug("collectionOptions:sortBy:[" + collectionOptions.getSortBy() + "]");
- logger.debug("collectionOptions:sortOrder:[" + collectionOptions.getSortOrder() + "]");
- logger.debug("collectionOptions:filter:[" + collectionOptions.getFilter() + "]");
- logger.debug("collectionOptions:filterOperation:[" + collectionOptions.getFilterOperation() + "]");
- logger.debug("collectionOptions:filterValue:[" + collectionOptions.getFilterValue() + "]");
- logger.debug("collectionOptions:first:[" + collectionOptions.getFirst() + "]");
- logger.debug("collectionOptions:max:[" + collectionOptions.getMax() + "]");
- logger.debug("collectionOptions:updatedSince:[" + collectionOptions.getUpdatedSince() + "]");
- }
- String filter = collectionOptions.getFilter();
- String filterValue = "";
- if ("hasApp".equalsIgnoreCase(filter)) {
- filterValue = "" + token.getModuleId();
- }
- else {
- filterValue = collectionOptions.getFilterValue();
- }
- ExtendedGmsPerson[] gmsPersons = gmsPersonDao.peopleGet(
- userLoginIds,
- paramGroupType,
- paramGroupId,
- collectionOptions.getSortBy(),
- collectionOptions.getSortOrder().toString(),
- filter,
- collectionOptions.getFilterOperation().toString(),
- filterValue,
- collectionOptions.getFirst(),
- collectionOptions.getMax(),
- collectionOptions.getUpdatedSince());
- if (logger.isDebugEnabled()) {
- logger.debug("count:[" + gmsPersons.length + "]");
- }
- int length = gmsPersons.length;
- for (int ii=0; ii<length; ii++) {
- result.add(mapToPerson(gmsPersons[ii], fields, PERMIT_LEVEL_ANONYMOUS, token));
- }
- logger.info("getPeople終了:");
- return result;
- }
mapToPersonはDAOのValueObjectからShindigのPersonオブジェクトにマップするメソッド。
項目はとりあえずANONYMOUSの場合の項目しか返さない。多分あとで公開レベルに応じて
処理をわけなきゃいけなさそう。
- filter=hasApp
でリクエストが来たら、検索結果のPersonのうち、同じガジェットをインストールしている
人のみ返す。
また、上記のコードからじゃわからないけど、
- filter=isFriendsWith
が来た場合には、filterValueに友達IDが入っているものとして、
検索結果のうち、友達にfilterValueの友達IDの人がいるPersonのみ返す。
(isFriendsWithは良くわからない。。)
- filter=all
の場合にはフィルタ処理は何もしない。
- filter=topFriends
の場合には、二度手間だけど、検索結果のうち、友達のみ返す。
groupIdがfriends以外のときのみ有効。
で、filterと関連するへぼSQLの一部。
- <!-- for Filter -->
- <dynamic>
- <isEqual property="filter" compareValue="all">
- </isEqual>
- <isEqual property="filter" compareValue="hasApp" prepend="AND">
- exists (
- select
- 'X'
- from
- gms_user_gadget
- where
- gms_user_gadget.module_id = #filterValue#
- and gms_user_gadget.gms_person_id = friends.id
- )
- </isEqual>
- <isEqual property="filter" compareValue="topFriends" prepend="AND">
- <!-- UserIdに指定された人々の友達 -->
- exists (
- select
- 'X'
- from
- gms_friend ff1,
- gms_person pp1
- where
- pp1.id = ff1.gms_person_id
- and pp1.login_id IN
- <iterate property="loginId"
- open="(" close=")" conjunction="," >
- #loginId[]#
- </iterate>
- and ff1.friend_id = friends.id
- )
- </isEqual>
- <isEqual property="filter" compareValue="isFriendsWith">
- exists (
- select
- 'X'
- from
- gms_friend ff2
- where
- ff2.gms_person_id = friends.id
- and ff2.friend_id = #filterValue#
- )
- </isEqual>
- <!-- ここから項目検索 -->
- <isEqual property="filter" compareValue="id" prepend="AND">
- <isEqual property="filterOperation" compareValue="contains">
- friends.id like '%$filterValue$%'
- </isEqual>
- <isEqual property="filterOperation" compareValue="equals">
- friends.id = #filterValue#
- </isEqual>
- <isEqual property="filterOperation" compareValue="startsWith">
- friends.id like '$filterValue$%'
- </isEqual>
- <isEqual property="filterOperation" compareValue="present">
- friends.id = #filterValue#
- </isEqual>
- </isEqual>
- <!-- ここまで。続きは随時追加 -->
- </dynamic>
なんだかもう、混乱。。。
ところで、firstとmaxというパラメータが指定できて、
ページングできそうなんだけど、そうすると総件数がほしいような。
どうやって取得するんだろう。
.
0 コメント:
コメントを投稿