Skip to content

Commit

Permalink
- メール通知が届かない #64
Browse files Browse the repository at this point in the history
   - 不具合解析用にログを追加
-  ユーザのLDAP認証 #8
-  Group の作成でグループに属するメンバーを Group 作成者側で自由に設定 #63
-  HTML Titleに記事タイトルを含める #65
-  コードブロックの中では<>を許すように変更 #66
-  ALL USERS グループの作成 #67
   -  記事作成者以外にも編集ができるような機能が欲しい #43
  • Loading branch information
koda-masaru committed Jul 16, 2015
1 parent c2583a6 commit 4d3cfc3
Show file tree
Hide file tree
Showing 69 changed files with 1,676 additions and 391 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<artifactId>diffutils</artifactId>
<version>1.2.1</version>
</dependency>

<dependency>
<groupId>org.pegdown</groupId>
<artifactId>pegdown</artifactId>
<version>1.5.0</version>
</dependency>

</dependencies>

Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/support/project/knowledge/bat/AbstractBat.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,32 @@

import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.PropertyUtil;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.web.logic.DBConnenctionLogic;

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

public static void initLogName(String logname) {
Logger log = Logger.getRootLogger();
FileAppender appendar= (FileAppender) log.getAppender("APP_FILEOUT");
appendar.setFile(logname);
appendar.activateOptions();//変更の反映
}

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()));
}

/**
* コネクションの接続先がカスタマイズされていたら、バッチでもカスタマイズ先を参照する
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.List;

import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.lang.ClassUtils;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.serialize.SerializeUtils;
Expand Down Expand Up @@ -38,16 +39,17 @@ public class CreateExportDataBat extends AbstractBat {

public static void main(String[] args) throws Exception {
initLogName("CreateExportDataBat.log");
LOG.trace("start");
AppConfig.initEnvKey("KNOWLEDGE_HOME");
configInit(ClassUtils.getShortClassName(CreateExportDataBat.class));

CreateExportDataBat bat = new CreateExportDataBat();
bat.dbInit();
bat.start();
}


private void start() throws Exception {
super.dbInit();
SystemConfigsEntity entity = SystemConfigsDao.get().selectOnKey(SystemConfig.DATA_EXPORT, AppConfig.SYSTEM_NAME);
SystemConfigsEntity entity = SystemConfigsDao.get().selectOnKey(SystemConfig.DATA_EXPORT, AppConfig.get().getSystemName());
if (entity == null) {
send("[Fail] create fail. please try again.");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.support.project.knowledge.bat;

import org.apache.commons.lang.ClassUtils;
import org.h2.tools.Server;
import org.support.project.common.config.ConfigLoader;
import org.support.project.common.log.Log;
Expand All @@ -18,10 +19,10 @@ public class DataTransferBat extends AbstractBat implements Runnable {

public static void main(String[] args) throws Exception {
initLogName("DataTransferBat.log");
LOG.trace("start");
AppConfig.initEnvKey("KNOWLEDGE_HOME");
configInit(ClassUtils.getShortClassName(DataTransferBat.class));

DataTransferBat bat = new DataTransferBat();
bat.dbInit();
bat.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.nio.file.StandardCopyOption;
import java.util.List;

import org.apache.commons.lang.ClassUtils;
import org.apache.tika.mime.MimeType;
import org.apache.tika.mime.MimeTypes;
import org.support.project.common.config.ConfigLoader;
Expand Down Expand Up @@ -46,7 +47,7 @@ public class FileParseBat extends AbstractBat {

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

FileParseBat bat = new FileParseBat();
bat.dbInit();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.support.project.knowledge.bat;

import org.apache.commons.lang.ClassUtils;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.dao.KnowledgeFilesDao;

public class KnowledgeFileClearBat extends AbstractBat {
Expand All @@ -12,8 +12,7 @@ public class KnowledgeFileClearBat extends AbstractBat {

public static void main(String[] args) {
initLogName("KnowledgeFileClearBat.log");
LOG.trace("start");
AppConfig.initEnvKey("KNOWLEDGE_HOME");
configInit(ClassUtils.getShortClassName(KnowledgeFileClearBat.class));

KnowledgeFileClearBat bat = new KnowledgeFileClearBat();
bat.dbInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import org.apache.commons.lang.ClassUtils;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.PasswordUtil;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class MailSendBat extends AbstractBat {

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

MailSendBat bat = new MailSendBat();
bat.dbInit();
Expand All @@ -76,7 +77,7 @@ public static void main(String[] args) throws Exception {
public void start() throws UnsupportedEncodingException, MessagingException, InvalidKeyException, NoSuchAlgorithmException,
NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(org.support.project.knowledge.config.AppConfig.SYSTEM_NAME);
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName());
if (mailConfigsEntity == null) {
// メールの設定が登録されていなければ、送信処理は終了
return;
Expand Down
51 changes: 42 additions & 9 deletions src/main/java/org/support/project/knowledge/bat/NotifyMailBat.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Locale;
import java.util.UUID;

import org.apache.commons.lang.ClassUtils;
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.config.LocaleConfigLoader;
import org.support.project.common.log.Log;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class NotifyMailBat extends AbstractBat {

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

NotifyMailBat bat = new NotifyMailBat();
bat.dbInit();
Expand All @@ -77,6 +78,7 @@ private void start() {
notifyQueuesDao.delete(notifyQueuesEntity);
//notifyQueuesDao.physicalDelete(notifyQueuesEntity);
}
LOG.info("Notify process finished. count: " + notifyQueuesEntities.size());
}

/**
Expand All @@ -86,7 +88,7 @@ private void start() {
*/
private String makeURL(KnowledgesEntity knowledge) {
SystemConfigsDao dao = SystemConfigsDao.get();
SystemConfigsEntity config = dao.selectOnKey(SystemConfig.SYSTEM_URL, AppConfig.SYSTEM_NAME);
SystemConfigsEntity config = dao.selectOnKey(SystemConfig.SYSTEM_URL, AppConfig.get().getSystemName());
if (config == null) {
return "";
}
Expand Down Expand Up @@ -131,17 +133,23 @@ private void notifyLikeInsert(NotifyQueuesEntity notifyQueuesEntity) {

private void sendLikeMail(LikesEntity like, KnowledgesEntity knowledge, UsersEntity likeUser, UsersEntity user, MailConfig config) {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(org.support.project.knowledge.config.AppConfig.SYSTEM_NAME);
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName());
if (mailConfigsEntity == null) {
// メールの設定が登録されていなければ、送信処理は終了
LOG.info("mail config is not exists.");
return;
}
if (!StringUtils.isEmailAddress(user.getMailAddress())) {
// 送信先のメールアドレスが不正なので、送信処理は終了
LOG.warn("mail targget [" + user.getMailAddress() + "] is wrong.");
return;
}

MailsEntity mailsEntity = new MailsEntity();
String mailId = idGenu("Notify");
mailsEntity.setMailId(mailId);
mailsEntity.setStatus(MailSendBat.MAIL_STATUS_UNSENT);
mailsEntity.setToAddress(user.getUserKey());
mailsEntity.setToAddress(user.getMailAddress());
mailsEntity.setToName(user.getUserName());

String title = config.getTitle();
Expand Down Expand Up @@ -240,17 +248,23 @@ private void notifyCommentInsert(NotifyQueuesEntity notifyQueuesEntity) {
*/
private void sendCommentMail(CommentsEntity comment, KnowledgesEntity knowledge, UsersEntity commentUser, UsersEntity user, MailConfig config) {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(org.support.project.knowledge.config.AppConfig.SYSTEM_NAME);
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName());
if (mailConfigsEntity == null) {
// メールの設定が登録されていなければ、送信処理は終了
LOG.info("mail config is not exists.");
return;
}
if (!StringUtils.isEmailAddress(user.getMailAddress())) {
// 送信先のメールアドレスが不正なので、送信処理は終了
LOG.warn("mail targget [" + user.getMailAddress() + "] is wrong.");
return;
}

MailsEntity mailsEntity = new MailsEntity();
String mailId = idGenu("Notify");
mailsEntity.setMailId(mailId);
mailsEntity.setStatus(MailSendBat.MAIL_STATUS_UNSENT);
mailsEntity.setToAddress(user.getUserKey());
mailsEntity.setToAddress(user.getMailAddress());
mailsEntity.setToName(user.getUserName());

String title = config.getTitle();
Expand Down Expand Up @@ -360,9 +374,22 @@ private void notifyPublicKnowledgeUpdate(NotifyQueuesEntity notifyQueuesEntity,
* @param users
*/
private void notifyKnowledgeUpdateToUsers(NotifyQueuesEntity notifyQueuesEntity, KnowledgesEntity knowledge, List<UsersEntity> users) {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName());
if (mailConfigsEntity == null) {
// メールの設定が登録されていなければ、送信処理は終了
LOG.info("mail config is not exists.");
return;
}

for (UsersEntity usersEntity : users) {
if (!StringUtils.isEmailAddress(usersEntity.getMailAddress())) {
// 送信先のメールアドレスが不正なのでこのユーザにはメール送信しない
LOG.warn("mail targget [" + usersEntity.getMailAddress() + "] is wrong.");
continue;
}
if (LOG.isTraceEnabled()) {
LOG.trace("[Notify] " + usersEntity.getUserKey());
LOG.trace("[Notify] " + usersEntity.getMailAddress());
}
Locale locale = usersEntity.getLocale();
MailConfig config = null;
Expand All @@ -385,17 +412,23 @@ private void notifyKnowledgeUpdateToUsers(NotifyQueuesEntity notifyQueuesEntity,
*/
private void insertNotifyKnowledgeUpdateMailQue(KnowledgesEntity knowledge, UsersEntity usersEntity, MailConfig config) {
MailConfigsDao mailConfigsDao = MailConfigsDao.get();
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(org.support.project.knowledge.config.AppConfig.SYSTEM_NAME);
MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(AppConfig.get().getSystemName());
if (mailConfigsEntity == null) {
// メールの設定が登録されていなければ、送信処理は終了
LOG.info("mail config is not exists.");
return;
}
if (!StringUtils.isEmailAddress(usersEntity.getMailAddress())) {
// 送信先のメールアドレスが不正なので、送信処理は終了
LOG.warn("mail targget [" + usersEntity.getMailAddress() + "] is wrong.");
return;
}

MailsEntity mailsEntity = new MailsEntity();
String mailId = idGenu("Notify");
mailsEntity.setMailId(mailId);
mailsEntity.setStatus(MailSendBat.MAIL_STATUS_UNSENT);
mailsEntity.setToAddress(usersEntity.getUserKey());
mailsEntity.setToAddress(usersEntity.getMailAddress());
mailsEntity.setToName(usersEntity.getUserName());
String title = config.getTitle();
title = title.replace("{KnowledgeId}", knowledge.getKnowledgeId().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import org.apache.commons.lang.ClassUtils;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.dao.KnowledgesDao;
Expand All @@ -15,7 +16,7 @@ public class ReIndexingBat extends AbstractBat {

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

ReIndexingBat bat = new ReIndexingBat();
bat.dbInit(); //カスタマイズDBが設定されていてばそれを参照
Expand All @@ -24,7 +25,7 @@ public static void main(String[] args) throws Exception {

private void start() throws Exception {
out("start");
SystemConfigsEntity entity = SystemConfigsDao.get().selectOnKey(SystemConfig.RE_INDEXING, AppConfig.SYSTEM_NAME);
SystemConfigsEntity entity = SystemConfigsDao.get().selectOnKey(SystemConfig.RE_INDEXING, AppConfig.get().getSystemName());
if (entity != null) {
String[] values = entity.getConfigValue().split(",");
Long start = Long.valueOf(values[0].substring("start=".length()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.support.project.knowledge.config;

import java.util.ArrayList;
import java.util.List;

import org.support.project.common.config.ConfigLoader;
import org.support.project.common.util.StringUtils;
import org.support.project.web.bean.LabelValue;


public class AppConfig extends org.support.project.web.config.AppConfig {
Expand All @@ -18,8 +14,6 @@ public static AppConfig get() {
}
private static AppConfig appConfig = null;

public static final String SYSTEM_NAME = "knowledge";

private String indexPath;

private boolean convIndexPath = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.support.project.knowledge.config;

public class SystemConfig {
public static final String ROLE_ADMIN = "admin";
public static final String ROLE_USER = "user";
public static final String KNOWLEDGE_ENV_KEY = "KNOWLEDGE_HOME";

/** ユーザ登録のやりかたを判定するシステム設定のラベル */
public static final String USER_ADD_TYPE = "USER_ADD_TYPE";
Expand Down
Loading

0 comments on commit 4d3cfc3

Please sign in to comment.