Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Bosn committed May 28, 2014
1 parent 12bd26a commit 0a07d8e
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 27 deletions.
13 changes: 13 additions & 0 deletions src/com/taobao/rigel/rap/account/bo/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
public class Notification {
private long id;
private long userId;
private long targetUserId;
private short typeId;
private String param1;
private String param2;
private String param3;
private Date createTime;
private boolean isRead;


public String getCreateTimeStr() {
PrettyTime p = new PrettyTime(new Locale("zh"));
return p.format(this.createTime);
Expand Down Expand Up @@ -93,6 +95,17 @@ public User getUser() {
public void setUser(User user) {
this.user = user;
}

private User targetUser;


public User getTargetUser() {
return targetUser;
}

public void setTargetUser(User targetUser) {
this.targetUser = targetUser;
}



Expand Down
14 changes: 12 additions & 2 deletions src/com/taobao/rigel/rap/account/dao/impl/AccountDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public void readNotificationList(long userId) {
getSession().createQuery(hql).setLong("userId", userId).executeUpdate();
}

@SuppressWarnings("unchecked")
@Override
public boolean notificationExists(Notification notification) {
String hql = "from Notification where user.id = :userId and typeId = :typeId and param1 = :param1";
Expand All @@ -232,8 +233,17 @@ public boolean notificationExists(Notification notification) {
query.setLong("userId", notification.getUser().getId())
.setShort("typeId", notification.getTypeId())
.setString("param1", notification.getParam1());
int size = query.list().size();
return size > 0;
List<Notification> list =(List<Notification>) query.list();
int size = list.size();
if (size > 0) {
for (Notification o : list) {
o.setCreateTime(new Date());
session.update(o);
}
return true;
} else {
return false;
}
}

}
25 changes: 13 additions & 12 deletions src/com/taobao/rigel/rap/account/mapping/Notification.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.taobao.rigel.rap.account.bo">
<class name="Notification" table="tb_notification">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="param1" />
<property name="param2" />
<property name="param3" />
<property name="typeId" type="short">
<class name="Notification" table="tb_notification">
<id name="id" column="id">
<generator class="native" />
</id>
<property name="param1" />
<property name="param2" />
<property name="param3" />
<property name="typeId" type="short">
<column name="type_id" not-null="true">
<comment>项目相关ID</comment>
</column>
</property>
<property name="read" type="boolean">
<property name="read" type="boolean">
<column name="is_read" not-null="true">
<comment>项目相关ID</comment>
</column>
</property>
<property name="createTime" type="timestamp">
<property name="createTime" type="timestamp">
<column name="create_time" not-null="true">
<comment>创建时间</comment>
</column>
</property>
<many-to-one name="user" column="user_id" />
</class>
<many-to-one name="user" column="user_id" />
<many-to-one name="targetUser" column="target_user_id" />
</class>
</hibernate-mapping>
1 change: 1 addition & 0 deletions src/com/taobao/rigel/rap/project/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<bean id="projectMgr" class="com.taobao.rigel.rap.project.service.impl.ProjectMgrImpl">
<property name="projectDao" ref="projectDao" />
<property name="accountDao" ref="accountDao" />
<property name="accountMgr" ref="accountMgr" />
<property name="organizationDao" ref="organizationDao" />
</bean>
<bean id="projectDao" class="com.taobao.rigel.rap.project.dao.impl.ProjectDaoImpl" parent="baseDao" />
Expand Down
7 changes: 4 additions & 3 deletions src/com/taobao/rigel/rap/project/bo/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -471,21 +471,22 @@ public void removeParameter(int id, Session session) {
}
}

public void addMember(User user) {
public boolean addMember(User user) {
// if member added is the creator, ignore
if (user.getId() == getUser().getId())
return;
return false;
// if member already exists, ignore
boolean exist = false;
for (User item : getUserList()) {
if (item.getId() == user.getId()) {
exist = true;
}
}
if (exist) return;
if (exist) return false;
// validation complete, add this user
getUserList().add(user);
user.getJoinedProjectList().add(this);
return true;
}

public void removeMember(User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import java.util.List;
import java.util.Set;

import com.taobao.rigel.rap.account.bo.Notification;
import com.taobao.rigel.rap.account.bo.User;
import com.taobao.rigel.rap.account.dao.AccountDao;
import com.taobao.rigel.rap.account.service.AccountMgr;
import com.taobao.rigel.rap.common.ArrayUtils;
import com.taobao.rigel.rap.organization.bo.Group;
import com.taobao.rigel.rap.organization.dao.OrganizationDao;
Expand All @@ -22,6 +24,15 @@ public class ProjectMgrImpl implements ProjectMgr {

private ProjectDao projectDao;
private OrganizationDao organizationDao;
private AccountMgr accountMgr;

public AccountMgr getAccountMgr() {
return accountMgr;
}

public void setAccountMgr(AccountMgr accountMgr) {
this.accountMgr = accountMgr;
}

public OrganizationDao getOrganizationDao() {
return organizationDao;
Expand Down Expand Up @@ -108,7 +119,16 @@ public int updateProject(Project outerProject) {
for (String account : outerProject.getMemberAccountList()) {
User user = accountDao.getUser(account);
if (user != null) {
project.addMember(user);
boolean addSuccess = project.addMember(user);
if (addSuccess) {
Notification o = new Notification();
o.setTypeId((short)2);
o.setTargetUser(outerProject.getUser());
o.setUser(user);
o.setParam1(new Integer(outerProject.getId()).toString());
o.setParam2(outerProject.getName());
accountMgr.addNotification(o);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public String update() {
project.setId(getId());
project.setIntroduction(getDesc());
project.setName(getName());

project.setUser(getCurUser());
List<String> memberAccountList = new ArrayList<String>();
String[] list = getAccounts().split(",");
// format: mashengbo(大灰狼堡森), linpanhui(林攀辉),
Expand Down
15 changes: 13 additions & 2 deletions src/com/taobao/rigel/rap/workspace/web/action/WorkspaceAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,24 @@ public String checkIn() throws Exception {


// notification for doc change
for (User user : project.getUserList()) {
Notification notification = new Notification();
notification.setParam1(new Integer(id).toString());
notification.setParam2(project.getName());
notification.setTypeId((short)1);
notification.setTargetUser(getCurUser());
notification.setUser(user);
getAccountMgr().addNotification(notification);
}

Notification notification = new Notification();
notification.setParam1(new Integer(id).toString());
notification.setParam2(project.getName());
notification.setTypeId((short)1);
notification.setUser(getCurUser());
notification.setTargetUser(getCurUser());
notification.setUser(project.getUser());
getAccountMgr().addNotification(notification);

// generate one check-in of VSS mode submit
CheckIn checkIn = new CheckIn();
checkIn.setCreateDate(new Date());
Expand Down
12 changes: 7 additions & 5 deletions src/database/create-table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,20 @@ CREATE TABLE tb_notification
(
id int(10) AUTO_INCREMENT NOT NULL
PRIMARY KEY,
user_id int(10) NOT NULL,
type_id smallint NOT NULL, -- 1-project,
param1 varchar(128) NULL, -- 对应operator
param2 varchar(128) NULL,
user_id int(10) NOT NULL, -- 接受通知的用户id
target_user_id int(10) NOT NULL, -- 上下文用户id
type_id smallint NOT NULL, -- 1-文档修改,2-被加入新项目
param1 varchar(128) NULL, -- 1,2-项目id
param2 varchar(128) NULL, -- 1,2-项目名称
param3 text NULL,
create_time timestamp NOT NULL
DEFAULT now(),

is_read smallint NOT NULL
DEFAULT 0,

FOREIGN KEY(user_id) REFERENCES tb_user(id)
FOREIGN KEY(user_id) REFERENCES tb_user(id),
FOREIGN KEY(target_user_id) REFERENCES tb_user(id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE tb_corporation
Expand Down
7 changes: 6 additions & 1 deletion src/database/update.v0.9.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ CREATE TABLE tb_notification
DEFAULT 0,

FOREIGN KEY(user_id) REFERENCES tb_user(id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
)ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- add target_user_id
ALTER TABLE tb_notification
ADD COLUMN target_user_id int(10) NOT NULL

0 comments on commit 0a07d8e

Please sign in to comment.