Skip to content

Commit

Permalink
メール通知が届かない #64
Browse files Browse the repository at this point in the history
通知メールはまとめて出す #75
グループのメンバー一覧が10件しか表示出来ない #70
  • Loading branch information
koda-masaru committed Jul 26, 2015
1 parent 4d3cfc3 commit 59fb9c4
Show file tree
Hide file tree
Showing 45 changed files with 507 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ protected static void configInit(String batName) {
AppConfig.initEnvKey(SystemConfig.KNOWLEDGE_ENV_KEY);
String envValue = System.getenv(SystemConfig.KNOWLEDGE_ENV_KEY);
LOG.info(batName + " is start.");
LOG.info("Env [" + SystemConfig.KNOWLEDGE_ENV_KEY + "] is [" + envValue + "].");
LOG.info("Config :" + PropertyUtil.reflectionToString(AppConfig.get()));
if (LOG.isDebugEnabled()) {
LOG.debug("Env [" + SystemConfig.KNOWLEDGE_ENV_KEY + "] is [" + envValue + "].");
LOG.debug("Config :" + PropertyUtil.reflectionToString(AppConfig.get()));
}
}

/**
Expand Down
65 changes: 37 additions & 28 deletions src/main/java/org/support/project/knowledge/bat/FileParseBat.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class FileParseBat extends AbstractBat {

public static final int PARSE_STATUS_WAIT = 0;
public static final int PARSE_STATUS_PARSING = 1;
public static final int PARSE_STATUS_ERROR_FINISHED = -100;
public static final int PARSE_STATUS_PARSED = 100;

public static final int PARSE_STATUS_NO_TARGET = -1;
Expand All @@ -52,10 +53,10 @@ public static void main(String[] args) throws Exception {
FileParseBat bat = new FileParseBat();
bat.dbInit();
bat.start();
LOG.info("finished");
}

private void start() throws Exception {
LOG.info("start");
KnowledgeFilesDao filesDao = KnowledgeFilesDao.get();
IndexLogic indexLogic = IndexLogic.get();
KnowledgesDao knowledgesDao = KnowledgesDao.get();
Expand All @@ -70,7 +71,8 @@ private void start() throws Exception {
// ナレッジを取得
KnowledgesEntity knowledgesEntity = knowledgesDao.selectOnKey(knowledgeFilesEntity.getKnowledgeId());
if (knowledgesEntity == null) {
// 紐づくナレッジが存在していないのであれば解析はしない
// 紐づくナレッジが存在していないのであれば解析はしない(例えば、一度添付ファイル付きのナレッジを登録後、ナレッジを削除した場合)
// ナレッジに紐づいていないファイルで、かつ更新日が24時間前のものは削除される
filesDao.changeStatus(knowledgeFilesEntity.getFileNo(), PARSE_STATUS_NO_TARGET, UPDATE_USER_ID);
continue;
}
Expand Down Expand Up @@ -110,33 +112,40 @@ private void start() throws Exception {
// パースステータスをパース中(1)に変更(もしパースでエラーが発生しても、次回から対象外になる)
filesDao.changeStatus(entity.getFileNo(), PARSE_STATUS_PARSING, UPDATE_USER_ID);

// パースを実行
Parser parser = ParserFactory.getParser(tmp.getAbsolutePath());
ParseResult result = parser.parse(tmp);
LOG.info("content text(length): " + result.getText().length());

// 全文検索エンジンへ登録
IndexingValue value = new IndexingValue();
value.setType(TYPE_FILE);
value.setId(ID_PREFIX + entity.getFileNo());
value.setTitle(entity.getFileName());
value.setContents(result.getText());
value.addUser(entity.getInsertUser());
if (knowledgesEntity.getPublicFlag() == null
|| KnowledgeLogic.PUBLIC_FLAG_PUBLIC == knowledgesEntity.getPublicFlag()) {
value.addUser(KnowledgeLogic.ALL_USER);
}
for (TagsEntity tagsEntity : tagsEntities) {
value.addTag(tagsEntity.getTagId());
try {
// パースを実行
Parser parser = ParserFactory.getParser(tmp.getAbsolutePath());
ParseResult result = parser.parse(tmp);
LOG.info("content text(length): " + result.getText().length());

// 全文検索エンジンへ登録
IndexingValue value = new IndexingValue();
value.setType(TYPE_FILE);
value.setId(ID_PREFIX + entity.getFileNo());
value.setTitle(entity.getFileName());
value.setContents(result.getText());
value.addUser(entity.getInsertUser());
if (knowledgesEntity.getPublicFlag() == null
|| KnowledgeLogic.PUBLIC_FLAG_PUBLIC == knowledgesEntity.getPublicFlag()) {
value.addUser(KnowledgeLogic.ALL_USER);
}
for (TagsEntity tagsEntity : tagsEntities) {
value.addTag(tagsEntity.getTagId());
}
value.setCreator(entity.getInsertUser());
value.setTime(entity.getUpdateDatetime().getTime()); // 更新日時をセットするので、更新日時でソート
indexLogic.save(value);

// パースステータスをパース完了に変更(もしパースでエラーが発生しても、次回から対象外になる)
filesDao.changeStatus(entity.getFileNo(), PARSE_STATUS_PARSED, UPDATE_USER_ID);

} catch (Exception e) {
// パースの解析でなんらかのエラー
filesDao.changeStatus(entity.getFileNo(), PARSE_STATUS_ERROR_FINISHED, UPDATE_USER_ID);
LOG.error("File parse error.", e);
throw e;
}
value.setCreator(entity.getInsertUser());
value.setTime(entity.getUpdateDatetime().getTime()); // 更新日時をセットするので、更新日時でソート
indexLogic.save(value);

// パースステータスをパース完了に変更(もしパースでエラーが発生しても、次回から対象外になる)
filesDao.changeStatus(entity.getFileNo(), PARSE_STATUS_PARSED, UPDATE_USER_ID);

// 正常に終了すれば、テンポラリを削除
// 終了すれば、テンポラリを削除
tmp.delete();
LOG.info("deleteed: " + tmp.getAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package org.support.project.knowledge.bat;

import java.util.List;

import org.apache.commons.lang.ClassUtils;
import org.support.project.common.config.Flag;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.NumberUtils;
import org.support.project.knowledge.dao.KnowledgeFilesDao;
import org.support.project.knowledge.dao.NotifyQueuesDao;
import org.support.project.knowledge.entity.NotifyQueuesEntity;
import org.support.project.web.dao.MailsDao;
import org.support.project.web.entity.MailsEntity;

public class KnowledgeFileClearBat extends AbstractBat {

Expand All @@ -17,6 +25,7 @@ public static void main(String[] args) {
KnowledgeFileClearBat bat = new KnowledgeFileClearBat();
bat.dbInit();
bat.start();
LOG.info("finished");
}

private void start() {
Expand All @@ -25,6 +34,23 @@ private void start() {
if (count > 0) {
LOG.debug("Knowledge Files deleted. Count: " + count + "");
}

// メール送信とNotifyのゴミ情報をクリア
List<NotifyQueuesEntity> notifyQueuesEntities = NotifyQueuesDao.get().physicalSelectAll();
for (NotifyQueuesEntity notifyQueuesEntity : notifyQueuesEntities) {
if (Flag.is(notifyQueuesEntity.getDeleteFlag())) {
// 削除フラグはONになっているのに、物理削除していないものは物理削除する(とっておいてもしかたない)
NotifyQueuesDao.get().physicalDelete(notifyQueuesEntity);
}
}

List<MailsEntity> mailsEntities = MailsDao.get().physicalSelectAll();
for (MailsEntity mailsEntity : mailsEntities) {
if (NumberUtils.is(mailsEntity.getStatus(), MailSendBat.MAIL_STATUS_SENDED)) {
// 送信済みになっているものは、削除
MailsDao.get().physicalDelete(mailsEntity);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void start() throws UnsupportedEncodingException, MessagingException, Inv
for (MailsEntity mailsEntity : entities) {
if (mailsEntity.getToAddress().matches(MAIL_FORMAT)) {
mailSend(mailConfigsEntity, mailsEntity);
// 正常に送信できたら、物理削除
dao.physicalDelete(mailsEntity);
} else {
mailsEntity.setStatus(MAIL_STATUS_FORMAT_ERROR);
dao.save(mailsEntity);
Expand Down
43 changes: 39 additions & 4 deletions src/main/java/org/support/project/knowledge/bat/NotifyMailBat.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,22 @@

public class NotifyMailBat extends AbstractBat {
/** ログ */
private static Log LOG = LogFactory.getLog(MailSendBat.class);
private static Log LOG = LogFactory.getLog(NotifyMailBat.class);

private static final String MAIL_CONFIG_DIR = "/org/support/project/knowledge/mail/";
private static final DateFormat DAY_FORMAT = new SimpleDateFormat("yyyyMMddHHmmss");


private List<Long> sendedCommentKnowledgeIds = new ArrayList<>();
private List<Long> sendedLikeKnowledgeIds = new ArrayList<>();

public static void main(String[] args) throws Exception {
initLogName("NotifyMailBat.log");
configInit(ClassUtils.getShortClassName(NotifyMailBat.class));

NotifyMailBat bat = new NotifyMailBat();
bat.dbInit();
bat.start();
LOG.info("finished");
}

/**
Expand All @@ -75,8 +79,8 @@ private void start() {
notifyLikeInsert(notifyQueuesEntity);
}
// 通知のキューから削除
notifyQueuesDao.delete(notifyQueuesEntity);
//notifyQueuesDao.physicalDelete(notifyQueuesEntity);
//notifyQueuesDao.delete(notifyQueuesEntity);
notifyQueuesDao.physicalDelete(notifyQueuesEntity); // とっておいてもしょうがないので物理削除
}
LOG.info("Notify process finished. count: " + notifyQueuesEntities.size());
}
Expand Down Expand Up @@ -114,6 +118,15 @@ private void notifyLikeInsert(NotifyQueuesEntity notifyQueuesEntity) {
KnowledgesDao knowledgesDao = KnowledgesDao.get();
KnowledgesEntity knowledge = knowledgesDao.selectOnKey(like.getKnowledgeId());

if (sendedLikeKnowledgeIds.contains(knowledge.getKnowledgeId())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Knowledge [" + knowledge.getKnowledgeId() + "] ");
}
return;
} else {
sendedLikeKnowledgeIds.add(knowledge.getKnowledgeId());
}

UsersDao usersDao = UsersDao.get();
UsersEntity likeUser = usersDao.selectOnKey(like.getInsertUser());

Expand Down Expand Up @@ -168,6 +181,10 @@ private void sendLikeMail(LikesEntity like, KnowledgesEntity knowledge, UsersEnt
contents = contents.replace("{URL}", makeURL(knowledge));

mailsEntity.setContent(contents);
if (LOG.isDebugEnabled()) {
LOG.debug("News email has been registered. [type] Like added. [knowledge]" + knowledge.getKnowledgeId().toString()
+ " [target] " + user.getMailAddress());
}
MailsDao.get().insert(mailsEntity);
}

Expand All @@ -181,6 +198,15 @@ private void notifyCommentInsert(NotifyQueuesEntity notifyQueuesEntity) {
KnowledgesDao knowledgesDao = KnowledgesDao.get();
KnowledgesEntity knowledge = knowledgesDao.selectOnKey(comment.getKnowledgeId());

if (sendedCommentKnowledgeIds.contains(knowledge.getKnowledgeId())) {
if (LOG.isDebugEnabled()) {
LOG.debug("Knowledge [" + knowledge.getKnowledgeId() + "] ");
}
return;
} else {
sendedCommentKnowledgeIds.add(knowledge.getKnowledgeId());
}

UsersDao usersDao = UsersDao.get();
UsersEntity commentUser = usersDao.selectOnKey(comment.getInsertUser());

Expand Down Expand Up @@ -284,6 +310,10 @@ private void sendCommentMail(CommentsEntity comment, KnowledgesEntity knowledge,
contents = contents.replace("{URL}", makeURL(knowledge));

mailsEntity.setContent(contents);
if (LOG.isDebugEnabled()) {
LOG.debug("News email has been registered. [type] comment added. [knowledge]" + knowledge.getKnowledgeId().toString()
+ " [target] " + user.getMailAddress());
}
MailsDao.get().insert(mailsEntity);
}

Expand Down Expand Up @@ -441,6 +471,11 @@ private void insertNotifyKnowledgeUpdateMailQue(KnowledgesEntity knowledge, User
contents = contents.replace("{URL}", makeURL(knowledge));

mailsEntity.setContent(contents);

if (LOG.isDebugEnabled()) {
LOG.debug("News email has been registered. [type] knowledge update. [knowledge]" + knowledge.getKnowledgeId().toString()
+ " [target] " + usersEntity.getMailAddress());
}
MailsDao.get().insert(mailsEntity);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ public class SystemConfig {
/** エクスポートのための設定値 */
public static final String DATA_EXPORT = "DATA_EXPORT";

/** 「公開」の情報であれば、ログインしなくても参照出来る */
public static final String SYSTEM_EXPOSE_TYPE = "SYSTEM_EXPOSE_TYPE";
/** 「公開」の情報であれば、ログインしなくても参照出来る */
public static final String SYSTEM_EXPOSE_TYPE_OPEN = "OPEN";
/** 全ての機能は、ログインしないとアクセス出来ない */
public static final String SYSTEM_EXPOSE_TYPE_CLOSE = "CLOSE";


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

import org.support.project.common.bean.ValidateError;
import org.support.project.common.util.StringUtils;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.control.Control;
import org.support.project.knowledge.logic.SystemConfigLogic;
import org.support.project.web.annotation.Auth;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpUtil;
Expand All @@ -20,6 +23,7 @@
import org.support.project.web.entity.MailConfigsEntity;
import org.support.project.web.entity.SystemConfigsEntity;

@DI(instance=Instance.Prototype)
public class ConfigControl extends Control {

/**
Expand Down Expand Up @@ -115,6 +119,12 @@ public Boundary system() {
dao.save(config);
}
setAttribute("systemurl", config.getConfigValue());

config = dao.selectOnKey(SystemConfig.SYSTEM_EXPOSE_TYPE, AppConfig.get().getSystemName());
if (config != null) {
setAttribute("system_open_type", config.getConfigValue());
}

return forward("system.jsp");
}

Expand Down Expand Up @@ -143,6 +153,19 @@ public Boundary save_params() {
config.setConfigValue(systemurl);
dao.save(config);

String system_open_type = getParam("system_open_type");
if (StringUtils.isNotEmpty(system_open_type)) {
config = new SystemConfigsEntity(SystemConfig.SYSTEM_EXPOSE_TYPE, AppConfig.get().getSystemName());
config.setConfigValue(system_open_type);
dao.save(config);

if (SystemConfig.SYSTEM_EXPOSE_TYPE_CLOSE.equals(system_open_type)) {
SystemConfigLogic.get().setClose(true);
} else {
SystemConfigLogic.get().setClose(false);
}
}

String successMsg = "message.success.save";
setResult(successMsg, errors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.support.project.common.serialize.SerializeUtils;
import org.support.project.common.wrapper.FileInputStreamWithDeleteWrapper;
import org.support.project.di.Container;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.bat.CreateExportDataBat;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
Expand All @@ -40,6 +42,7 @@
import org.support.project.web.entity.SystemConfigsEntity;
import org.support.project.web.logic.DBConnenctionLogic;

@DI(instance=Instance.Prototype)
public class DatabaseControl extends Control {

/* (non-Javadoc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.util.PasswordUtil;
import org.support.project.common.util.StringUtils;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.control.Control;
import org.support.project.web.annotation.Auth;
Expand All @@ -28,6 +30,7 @@
import org.support.project.web.exception.InvalidParamException;
import org.support.project.web.logic.LdapLogic;

@DI(instance=Instance.Prototype)
public class LdapControl extends Control {

private static final String NO_CHANGE_PASSWORD = "NO_CHANGE_PASSWORD-fXLSJ_V-ZJ2E-X6c2_iGCpkE"; //パスワードを更新しなかったことを表すパスワード
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.util.PasswordUtil;
import org.support.project.common.util.StringUtils;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.control.Control;
import org.support.project.web.annotation.Auth;
Expand All @@ -22,6 +24,7 @@
import org.support.project.web.dao.MailConfigsDao;
import org.support.project.web.entity.MailConfigsEntity;

@DI(instance=Instance.Prototype)
public class MailControl extends Control {

/**
Expand Down
Loading

0 comments on commit 59fb9c4

Please sign in to comment.