Skip to content

Commit

Permalink
Merge pull request #78 from support-project/develop
Browse files Browse the repository at this point in the history
リリースするのでmasterにマージします
  • Loading branch information
koda-masaru committed Aug 10, 2015
2 parents 9ea4ace + 869e894 commit 67377a9
Show file tree
Hide file tree
Showing 112 changed files with 4,313 additions and 581 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"highlightjs": "8.3.0",
"bootbox": "4.3.0",
"bootstrap-tagsinput": "0.4.2",
"bootstrap3-typeahead": "3.1.1",
"bootstrap-fileinput": "4.1.6",
"jquery-file-upload": "9.8.1",
"teambox.free-file-icons": "teambox/Free-file-icons",
Expand Down
18 changes: 15 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.support-project</groupId>
<artifactId>knowledge</artifactId>
<packaging>war</packaging>
<version>0.5.2</version>
<version>0.5.3</version>
<name>webapp for knowledge</name>
<url>https://support-project.org/</url>

Expand All @@ -16,7 +16,7 @@
<dependency>
<groupId>org.support-project</groupId>
<artifactId>web</artifactId>
<version>0.5.2</version>
<version>0.5.3</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -78,7 +78,13 @@
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.6</version>
<version>1.9</version>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-debug-all</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand All @@ -98,6 +104,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
27 changes: 27 additions & 0 deletions src/main/java/org/support/project/knowledge/bat/AbstractBat.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
package org.support.project.knowledge.bat;

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.");
if (LOG.isDebugEnabled()) {
LOG.debug("Env [" + SystemConfig.KNOWLEDGE_ENV_KEY + "] is [" + envValue + "].");
LOG.debug("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 @@ -37,16 +38,18 @@ public class CreateExportDataBat extends AbstractBat {
public static final String DATA_DIR = "DataExport";

public static void main(String[] args) throws Exception {
LOG.trace("start");
AppConfig.initEnvKey("KNOWLEDGE_HOME");
initLogName("CreateExportDataBat.log");
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 @@ -17,10 +18,11 @@ public class DataTransferBat extends AbstractBat implements Runnable {
private boolean serverStarted = false;

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

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

Expand Down
69 changes: 40 additions & 29 deletions src/main/java/org/support/project/knowledge/bat/FileParseBat.java
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 @@ -35,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 @@ -45,15 +47,16 @@ public class FileParseBat extends AbstractBat {
public static final String ID_PREFIX = "FILE-";

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

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 @@ -68,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 @@ -108,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,22 +1,31 @@
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.knowledge.config.AppConfig;
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 {

/** ログ */
private static Log LOG = LogFactory.getLog(KnowledgeFileClearBat.class);

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

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 @@ -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 @@ -54,7 +55,8 @@ public class MailSendBat extends AbstractBat {
+ "@" + "[a-zA-Z0-9][a-zA-Z0-9\\-]*(\\.[a-zA-Z0-9\\-]+)*$";

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

MailSendBat bat = new MailSendBat();
bat.dbInit();
Expand All @@ -75,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 All @@ -87,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
Loading

0 comments on commit 67377a9

Please sign in to comment.