プロジェクト

全般

プロフィール

Feature #733 » 0001-follow-follower-friends-refs-733.patch

yusuke kokubo, 2011/05/13 11:38

差分を表示:

src/com/appspot/skillmaps/client/service/AccountService.java
import com.appspot.skillmaps.shared.dto.UserListResultDto;
import com.appspot.skillmaps.shared.model.Login;
import com.appspot.skillmaps.shared.model.Profile;
import com.google.appengine.api.datastore.Key;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
......
String getSignUrl(String backUrl);
Profile[] getFollowing(Key key);
Profile[] getFollower(Key key);
Profile[] getFriends(Key key);
}
src/com/appspot/skillmaps/client/service/AccountServiceAsync.java
import com.appspot.skillmaps.shared.dto.UserListResultDto;
import com.appspot.skillmaps.shared.model.Login;
import com.appspot.skillmaps.shared.model.Profile;
import com.google.appengine.api.datastore.Key;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface AccountServiceAsync {
......
void getSignUrl(String backUrl, AsyncCallback<String> callback);
void getFollowing(Key key, AsyncCallback<Profile[]> callback);
void getFollower(Key key, AsyncCallback<Profile[]> callback);
void getFriends(Key key, AsyncCallback<Profile[]> callback);
}
src/com/appspot/skillmaps/server/controller/sys/CreateFollowingController.java
package com.appspot.skillmaps.server.controller.sys;
import java.util.List;
import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import com.appspot.skillmaps.server.meta.ProfileMeta;
import com.appspot.skillmaps.server.meta.SkillRelationMeta;
import com.appspot.skillmaps.shared.model.Following;
import com.appspot.skillmaps.shared.model.Profile;
import com.appspot.skillmaps.shared.model.SkillRelation;
public class CreateFollowingController extends Controller {
@Override
public Navigation run() throws Exception {
SkillRelationMeta m = SkillRelationMeta.get();
ProfileMeta pm = ProfileMeta.get();
List<SkillRelation> rels = Datastore.get(m);
for (SkillRelation rel : rels) {
Profile follower = Datastore.query(pm).limit(1).asSingle();
Profile following = rel.getSkill().getModel().getProfile();
Following f = new Following();
f.setFollowing(following.getKey());
f.setFollower(follower.getKey());
Datastore.put(f);
}
return null;
}
}
src/com/appspot/skillmaps/server/service/AccountServiceImpl.java
package com.appspot.skillmaps.server.service;
import java.util.ArrayList;
import java.util.List;
import org.slim3.datastore.Datastore;
......
import org.slim3.util.StringUtil;
import com.appspot.skillmaps.client.service.AccountService;
import com.appspot.skillmaps.server.meta.FollowingMeta;
import com.appspot.skillmaps.server.meta.IconMeta;
import com.appspot.skillmaps.server.meta.ProfileMeta;
import com.appspot.skillmaps.shared.dto.UserListResultDto;
import com.appspot.skillmaps.shared.model.Following;
import com.appspot.skillmaps.shared.model.Icon;
import com.appspot.skillmaps.shared.model.Login;
import com.appspot.skillmaps.shared.model.Profile;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
......
public class AccountServiceImpl implements AccountService {
private static final int USER_LISE_SIZE = 80;
FollowingMeta fm = FollowingMeta.get();
ProfileMeta pm = ProfileMeta.get();
@Override
......
UserService us = UserServiceFactory.getUserService();
return us.createLoginURL(backUrl);
}
@Override
public Profile[] getFollowing(Key key) {
List<Following> following = Datastore.query(fm).filter(fm.following.equal(key)).asList();
List<Key> keys = new ArrayList<Key>();
for (Following f : following) {
keys.add(f.getFollower());
}
return Datastore.get(pm, keys).toArray(new Profile[0]);
}
@Override
public Profile[] getFollower(Key key) {
List<Following> follower = Datastore.query(fm).filter(fm.follower.equal(key)).asList();
List<Key> keys = new ArrayList<Key>();
for (Following f : follower) {
keys.add(f.getFollowing());
}
return Datastore.get(pm, keys).toArray(new Profile[0]);
}
@Override
public Profile[] getFriends(Key key) {
List<Following> following = Datastore.query(fm).filter(fm.following.equal(key)).asList();
List<Following> follower = Datastore.query(fm).filter(fm.follower.equal(key)).asList();
List<Key> keys = new ArrayList<Key>();
for (Following f : follower) {
if (following.contains(f)){
keys.add(f.getFollowing());
}
}
return Datastore.get(pm, keys).toArray(new Profile[0]);
}
private UserListResultDto createUserListResultDto(
S3QueryResultList<Profile> result) {
src/com/appspot/skillmaps/shared/model/Following.java
package com.appspot.skillmaps.shared.model;
import java.io.Serializable;
import java.util.Date;
import com.google.appengine.api.datastore.Key;
import org.slim3.datastore.Attribute;
import org.slim3.datastore.CreationDate;
import org.slim3.datastore.Model;
import org.slim3.datastore.ModificationDate;
@Model(schemaVersion = 1)
public class Following implements Serializable {
private static final long serialVersionUID = 1L;
@Attribute(primaryKey = true)
private Key key;
@Attribute(version = true)
private Long version;
private Key following;
private Key follower;
@Attribute(listener=CreationDate.class)
private Date createdAt;
@Attribute(listener=ModificationDate.class)
private Date updatedAt;
/**
* Returns the key.
*
* @return the key
*/
public Key getKey() {
return key;
}
/**
* Sets the key.
*
* @param key
* the key
*/
public void setKey(Key key) {
this.key = key;
}
/**
* Returns the version.
*
* @return the version
*/
public Long getVersion() {
return version;
}
/**
* Sets the version.
*
* @param version
* the version
*/
public void setVersion(Long version) {
this.version = version;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
Following other = (Following) obj;
if (key == null) {
if (other.key != null) {
return false;
}
} else if (!key.equals(other.key)) {
return false;
}
return true;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Date getCreatedAt() {
return createdAt;
}
public void setUpdatedAt(Date updatedAt) {
this.updatedAt = updatedAt;
}
public Date getUpdatedAt() {
return updatedAt;
}
public void setFollowing(Key following) {
this.following = following;
}
public Key getFollowing() {
return following;
}
public void setFollower(Key follower) {
this.follower = follower;
}
public Key getFollower() {
return follower;
}
}
test/com/appspot/skillmaps/shared/model/FollowingTest.java
package com.appspot.skillmaps.shared.model;
import org.slim3.tester.AppEngineTestCase;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
public class FollowingTest extends AppEngineTestCase {
private Following model = new Following();
@Test
public void test() throws Exception {
assertThat(model, is(notNullValue()));
}
}
    (1-1/1)