Skip to content

Commit

Permalink
#840 Change cp point add
Browse files Browse the repository at this point in the history
  • Loading branch information
koda-masaru committed Sep 8, 2017
1 parent 3594bbb commit 52e7dba
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.support.project.knowledge.dao.NotifyConfigsDao;
import org.support.project.knowledge.entity.NotifyConfigsEntity;
import org.support.project.knowledge.vo.UserConfigs;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.boundary.ForwardBoundary;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.logic.NotificationLogic;
Expand Down Expand Up @@ -184,6 +185,12 @@ protected UserConfigs getUserConfigs() {
if (userConfigs == null) {
userConfigs = new UserConfigs();
}
LoginedUser login = getLoginedUser();
if (login != null) {
userConfigs.setLocale(login.getLocale());
} else {
userConfigs.setLocale(getLocale());
}
return userConfigs;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void doFilter(ServletRequest servletrequest, ServletResponse servletrespo
if (StringUtils.isInteger(offset)) {
userConfig.setTimezoneOffset(Integer.parseInt(offset));
}
userConfig.setLocale(HttpUtil.getLocale(req));
req.setAttribute(UserConfig.REQUEST_USER_CONFIG_KEY, userConfig);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
public abstract class AbstractAddPointForCommentProcessor extends AbstractActivityProcessor {
private static final Log LOG = LogFactory.getLog(AbstractAddPointForCommentProcessor.class);
private CommentsEntity comment;
private KnowledgesEntity parentKnowledge;
/**
* @return the comment
*/
Expand All @@ -25,8 +26,12 @@ public CommentsEntity getComment() {
*/
public void setComment(CommentsEntity comment) {
this.comment = comment;
this.parentKnowledge = KnowledgesDao.get().selectOnKey(getComment().getKnowledgeId());
}

public KnowledgesEntity getParentKnowledge() {
return parentKnowledge;
}

protected abstract Activity getActivity();
protected abstract TypeAndPoint getTypeAndPointForActivityExecuter();
protected abstract TypeAndPoint getTypeAndPointForCommentOwner();
Expand All @@ -44,12 +49,22 @@ public void execute() throws Exception {
+ " [comment]" + getComment().getCommentNo());
return;
}
KnowledgesEntity parentKnowledge = KnowledgesDao.get().selectOnKey(getComment().getKnowledgeId());
if (parentKnowledge == null) {
LOG.info("Knowledge is not found. [comment] " + getComment().getCommentNo() + " [knowledge]" + getComment().getKnowledgeId());
return;
}

TypeAndPoint exec = getTypeAndPointForActivityExecuter();
TypeAndPoint owner = getTypeAndPointForCommentOwner();
TypeAndPoint knowledge = getTypeAndPointForKnowledge();
if (exec == null && owner == null && knowledge == null) {
// ポイントをつける対象が無いので、処理終了
LOG.info("This activity is not add point. [Activity]" + getActivity().toString() + " [user]" + eventUser.getUserId()
+ " [comment]" + getComment().getCommentNo());
return;
}


LOG.info("activity process started. [Activity]" + getActivity().toString() + " [user]" + eventUser.getUserId()
+ " [comment]" + getComment().getCommentNo());

Expand All @@ -62,7 +77,6 @@ public void execute() throws Exception {
String.valueOf(getComment().getCommentNo()));

// 実行したユーザのポイントアップ
TypeAndPoint exec = getTypeAndPointForActivityExecuter();
if (exec != null) {
int point = addPointForUser(
eventUser.getUserId(), // ターゲットは、実行したユーザ
Expand All @@ -72,7 +86,6 @@ public void execute() throws Exception {
logmsg.append("\n\tAdd event user: [id]" + eventUser.getUserId() + " [type]" + exec.type + " [add]" + exec.point + " [result]" + point);
}
// コメントの登録者のポイントをアップ
TypeAndPoint owner = getTypeAndPointForCommentOwner();
if (owner != null) {
int point = addPointForUser(
getComment().getInsertUser(), // ターゲットは登録者
Expand All @@ -82,7 +95,6 @@ public void execute() throws Exception {
logmsg.append("\n\tAdd owner user: [id]" + getComment().getInsertUser() + " [type]" + owner.type + " [add]" + owner.point + " [result]" + point);
}
// 記事のポイントアップ(コメントにはポイントをもっていないので、親のナレッジのポイントをアップ)
TypeAndPoint knowledge = getTypeAndPointForKnowledge();
if (knowledge != null) {
int point = addPointForKnowledge(
parentKnowledge.getKnowledgeId(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.support.project.knowledge.logic.activity;

import org.bouncycastle.jcajce.provider.asymmetric.dsa.DSASigner.noneDSA;
import org.support.project.aop.Aspect;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,15 @@ private String getActivityMsg(PointUserHistoriesEntity history, Map<Long, Activi
return resources.getResource("knowledge.activity.type.21.do.show", activity.getTarget());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_SHOWN_BY_OHER) {
return resources.getResource("knowledge.activity.type.22.shown", activity.getTarget(), activity.getUserName());

} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_DO_LIKE) {
return resources.getResource("knowledge.activity.type.31.do.like", activity.getTarget(), activity.getUserName());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_LIKED_BY_OHER) {
return resources.getResource("knowledge.activity.type.32.liked", activity.getTarget(), activity.getUserName());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_DO_STOCK) {
return resources.getResource("knowledge.activity.type.41.do.stock", activity.getTarget(), activity.getUserName());
} else if (history.getType() == ActivityProcessor.TYPE_KNOWLEDGE_STOCKED_BY_OHER) {
return resources.getResource("knowledge.activity.type.42.stocked", activity.getTarget(), activity.getUserName());
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public interface ActivityProcessor {
public static final int TYPE_KNOWLEDGE_DO_JOIN_EVENT = 61;
public static final int TYPE_KNOWLEDGE_JOINED_BY_OHER = 62;
public static final int TYPE_KNOWLEDGE_JOINED = 63;



public static final int TYPE_COMMENT_DO_INSERT = 1011;
public static final int TYPE_COMMENT_INSERTED = 1013;
public static final int TYPE_COMMENT_DO_LIKE = 1031;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.dao.CommentsDao;
import org.support.project.knowledge.logic.KnowledgeLogic;

/**
*
Expand All @@ -24,12 +25,30 @@ public static CommentInsertActivity get() {

private int point = 0;

private int getKnowledgePoint() {
if (getParentKnowledge().getPublicFlag() == KnowledgeLogic.PUBLIC_FLAG_PRIVATE) {
// 非公開の記事にポイントをつけてもポイントにはならない
return 0;
}
int point = 0;
if (getParentKnowledge().getPublicFlag() == KnowledgeLogic.PUBLIC_FLAG_PUBLIC) {
point = 20;
} else if (getParentKnowledge().getPublicFlag() == KnowledgeLogic.PUBLIC_FLAG_PROTECT) {
point = 10;
}
return point;
}

private int getPoint() {
if (point != 0) {
return point;
}
if (getParentKnowledge().getPublicFlag() == KnowledgeLogic.PUBLIC_FLAG_PRIVATE) {
// 非公開の記事にポイントをつけてもポイントにはならない
return 0;
}
// 指定の記事に登録した、ユニークなユーザ数によりポイントを変える
int point = 20;
int point = getKnowledgePoint();
long count = CommentsDao.get().selectUniqueUserCountOnKnowledgeId(getComment().getKnowledgeId());
int add = 0;
if (count > 100) {
Expand All @@ -54,15 +73,23 @@ protected Activity getActivity() {
}
@Override
protected TypeAndPoint getTypeAndPointForActivityExecuter() {
return new TypeAndPoint(TYPE_COMMENT_DO_INSERT, 20);
int point = getKnowledgePoint();
if (point == 0) {
return null;
}
return new TypeAndPoint(TYPE_COMMENT_DO_INSERT, point);
}
@Override
protected TypeAndPoint getTypeAndPointForCommentOwner() {
return null;
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
return new TypeAndPoint(TYPE_COMMENT_INSERTED, getPoint());
int point = getPoint();
if (point == 0) {
return null;
}
return new TypeAndPoint(TYPE_COMMENT_INSERTED, point);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ protected Activity getActivity() {
}
@Override
protected TypeAndPoint getTypeAndPointForActivityExecuter() {
if (eventUser.getUserId().intValue() == getComment().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_COMMENT_DO_LIKE, 2);
}
@Override
protected TypeAndPoint getTypeAndPointForCommentOwner() {
if (eventUser.getUserId().intValue() == getComment().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_COMMENT_LIKED_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getParentKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_COMMENT_LIKED, getPoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ protected TypeAndPoint getTypeAndPointForActivityExecuter() {
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledgeOwner() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_ANSWERD_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_ANSWERD, getPoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ protected TypeAndPoint getTypeAndPointForActivityExecuter() {
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledgeOwner() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_JOINED_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_JOINED, getPoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ protected TypeAndPoint getTypeAndPointForActivityExecuter() {
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledgeOwner() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_LIKED_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_LIKED, getPoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,23 @@ private int getPoint() {
}
@Override
protected TypeAndPoint getTypeAndPointForActivityExecuter() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_DO_SHOW, 1);
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledgeOwner() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_SHOWN_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_SHOWN, getPoint());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ protected TypeAndPoint getTypeAndPointForActivityExecuter() {
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledgeOwner() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_STOCKED_BY_OHER, getPoint());
}
@Override
protected TypeAndPoint getTypeAndPointForKnowledge() {
if (eventUser.getUserId().intValue() == getKnowledge().getInsertUser().intValue()) {
return null;
}
return new TypeAndPoint(TYPE_KNOWLEDGE_STOCKED, getPoint());
}

Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/appresource.properties
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,12 @@ knowledge.maintenance.migrate.title=Database migration
knowledge.maintenance.migrate.message=You can execute database migration. recommend to backup database data.

knowledge.activity.type.11.do.insert=This user posted #{1}
knowledge.activity.type.13.inserted=#{1} was posted by {2}
knowledge.activity.type.21.do.show=This user showed #{1}
knowledge.activity.type.22.shown=#{1} was shown by {2}
knowledge.activity.type.23.shown=#{1} was shown by {2}
knowledge.activity.type.31.do.like=This user liked #{1}
knowledge.activity.type.32.liked=#{1} was liked by {2}
knowledge.activity.type.41.do.stock=This user stocked #{1}
knowledge.activity.type.42.stocked=#{1} was stocked by {2}

knowledge.activity.type.13.inserted=#{1} was posted by {2}
knowledge.activity.type.23.shown=#{1} was shown by {2}
10 changes: 7 additions & 3 deletions src/main/resources/appresource_ja.properties
Original file line number Diff line number Diff line change
Expand Up @@ -853,11 +853,15 @@ knowledge.maintenance.do.migrate.no.login=メンテナンス管理を実行(管
knowledge.maintenance.migrate.title=Database migration
knowledge.maintenance.migrate.message=DBのマイグレーションを実行します。事前にDBのバックアップを取ることをオススメします。

knowledge.activity.type.11.do.insert=このユーザが #{1} の記事を投稿しました
knowledge.activity.type.13.inserted=#{1} の記事が、{2} によって投稿されました
knowledge.activity.type.11.do.insert=#{1} の記事を投稿しました
knowledge.activity.type.21.do.show=#{1} の記事を参照しました
knowledge.activity.type.22.shown=このユーザが投稿した #{1} の記事を、{2} が参照しました
knowledge.activity.type.23.shown=#{1} の記事を、{2} が参照しました
knowledge.activity.type.31.do.like=#{1} の記事にいいねを押しました
knowledge.activity.type.32.liked=このユーザが投稿した #{1} の記事を、{2} がいいね!を押しました
knowledge.activity.type.41.do.stock=#{1} の記事をストックしました
knowledge.activity.type.42.stocked=このユーザが投稿した #{1} の記事を、{2} ストックしました

knowledge.activity.type.13.inserted=#{1} の記事が、{2} によって投稿されました
knowledge.activity.type.23.shown=#{1} の記事を、{2} が参照しました


0 comments on commit 52e7dba

Please sign in to comment.