Skip to content

Commit

Permalink
- Websiteの情報を記事としたい #7
Browse files Browse the repository at this point in the history
- テンプレートを使った登録 #27
    - 登録するナレッジの種類を今までどおりの「knowledge」と、Webサイトの情報である「bookmark」で選択可能にした
    - 「bookmark」の場合、登録したURLに書かれるコンテンツの内容で検索可能にした
    - 「knowledge」と「bookmark」を切り替えの部分でテンプレート選択の機能を作成
        - DBにテンプレート設定すると、登録するナレッジの種類が増える
        - テンプレート登録/編集の画面は無いので、今のところ、初期データの「knowledge」と「bookmark」のみ

- ユーザのLDAP認証 #8
    - BaseDNが固定になる問題を修正

- コメント欄でも添付ファイルをつけたい #39
    - 添付ファイルをつけれるようにした
  • Loading branch information
koda-masaru committed Sep 18, 2015
1 parent d9d53ca commit 908f645
Show file tree
Hide file tree
Showing 129 changed files with 6,914 additions and 751 deletions.
806 changes: 318 additions & 488 deletions document/database/knowledge.a5er

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@
<version>1.5.0</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
</dependency>


</dependencies>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package org.support.project.knowledge.bat;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
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.MimeTypeException;
import org.apache.tika.mime.MimeTypes;
import org.support.project.common.config.ConfigLoader;
import org.support.project.common.log.Log;
Expand All @@ -18,17 +21,24 @@
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.IndexType;
import org.support.project.knowledge.dao.KnowledgeFilesDao;
import org.support.project.knowledge.dao.KnowledgeItemValuesDao;
import org.support.project.knowledge.dao.KnowledgesDao;
import org.support.project.knowledge.dao.TagsDao;
import org.support.project.knowledge.dao.TemplateItemsDao;
import org.support.project.knowledge.dao.TemplateMastersDao;
import org.support.project.knowledge.entity.KnowledgeFilesEntity;
import org.support.project.knowledge.entity.KnowledgeItemValuesEntity;
import org.support.project.knowledge.entity.KnowledgesEntity;
import org.support.project.knowledge.entity.TagsEntity;
import org.support.project.knowledge.indexer.IndexingValue;
import org.support.project.knowledge.logic.CrawlerLogic;
import org.support.project.knowledge.logic.IndexLogic;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.parser.Parser;
import org.support.project.knowledge.parser.ParserFactory;
import org.support.project.knowledge.vo.ParseResult;
import org.support.project.web.dao.ProxyConfigsDao;
import org.support.project.web.entity.ProxyConfigsEntity;

public class FileParseBat extends AbstractBat {
/** ログ */
Expand All @@ -45,6 +55,7 @@ public class FileParseBat extends AbstractBat {

public static final int TYPE_FILE = IndexType.KnowledgeFile.getValue();
public static final String ID_PREFIX = "FILE-";
public static final String WEB_ID_PREFIX = "WEB-";

public static void main(String[] args) throws Exception {
initLogName("FileParseBat.log");
Expand All @@ -58,6 +69,60 @@ public static void main(String[] args) throws Exception {
}

private void start() throws Exception {
fileParse();
crawl();
}

private void crawl() throws Exception {
KnowledgeItemValuesDao itemValuesDao = KnowledgeItemValuesDao.get();
List<KnowledgeItemValuesEntity> itemValues = itemValuesDao.selectOnTypeIdAndItemNoAndStatus(
TemplateMastersDao.TYPE_ID_BOOKMARK, TemplateItemsDao.ITEM_ID_BOOKMARK_URL, KnowledgeItemValuesEntity.STATUS_SAVED);
if (itemValues != null && !itemValues.isEmpty()) {
ProxyConfigsEntity proxyConfigs = ProxyConfigsDao.get().selectOnKey(AppConfig.get().getSystemName());
if (proxyConfigs == null) {
proxyConfigs = new ProxyConfigsEntity();
}
LOG.info("web target count: " + itemValues.size());
CrawlerLogic logic = CrawlerLogic.get();
for (KnowledgeItemValuesEntity itemValue : itemValues) {
KnowledgesEntity knowledgesEntity = KnowledgesDao.get().selectOnKey(itemValue.getKnowledgeId());
if (knowledgesEntity == null) {
continue;
}
// タグを取得
List<TagsEntity> tagsEntities = TagsDao.get().selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
// Webアクセス
String content = logic.crawle(proxyConfigs, itemValue.getItemValue());
if (StringUtils.isNotEmpty(content)) {
LOG.info("[SUCCESS] " + itemValue.getItemValue());
// 全文検索エンジンにのみ、検索できるように情報登録
IndexingValue value = new IndexingValue();
value.setType(IndexType.bookmarkContent.getValue());
value.setId(WEB_ID_PREFIX + itemValue.getKnowledgeId());
value.setTitle(itemValue.getItemValue());
value.setContents(content);

value.addUser(knowledgesEntity.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(knowledgesEntity.getInsertUser());
value.setTime(knowledgesEntity.getUpdateDatetime().getTime()); // 更新日時をセットするので、更新日時でソート
IndexLogic.get().save(value);

// ステータス更新
itemValue.setItemStatus(KnowledgeItemValuesEntity.STATUS_WEBACCESSED);
itemValuesDao.update(itemValue);
}
}
}
}

private void fileParse() throws FileNotFoundException, IOException, MimeTypeException, Exception {
KnowledgeFilesDao filesDao = KnowledgeFilesDao.get();
IndexLogic indexLogic = IndexLogic.get();
KnowledgesDao knowledgesDao = KnowledgesDao.get();
Expand All @@ -67,7 +132,7 @@ private void start() throws Exception {
List<KnowledgeFilesEntity> filesEntities = filesDao.selectWaitStateFiles();
AppConfig appConfig = ConfigLoader.load(AppConfig.APP_CONFIG, AppConfig.class);
File tmpDir = new File(appConfig.getTmpPath());
LOG.info("target count: " + filesEntities.size());
LOG.info("file target count: " + filesEntities.size());

for (KnowledgeFilesEntity knowledgeFilesEntity : filesEntities) {
// ナレッジを取得
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/support/project/knowledge/config/AuthType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.support.project.knowledge.config;

public enum AuthType {
None,
Basic,
Digest,
NTLM,
Samba,
Form;

public int getValue() {
return ordinal();
}

public static AuthType getType(int type) {
AuthType[] values = values();
return values[type];
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
public enum IndexType {
knowledge,
KnowledgeFile,
KnowledgeComment;
KnowledgeComment,
bookmarkContent;


public int getValue() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@DI(instance=Instance.Prototype)
public class MailControl extends Control {
private static final String NO_CHANGE_PASSWORD = "NO_CHANGE_PASSWORD-fXLSJ_V-ZJ2E-GBAghu_usb-gtaG"; //パスワードを更新しなかったことを表すパスワード

/**
* メールの設定画面を表示
Expand All @@ -38,9 +39,10 @@ public Boundary config() {
MailConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName());
if (entity == null) {
entity = new MailConfigsEntity();
} else {
entity.setSmtpPassword(NO_CHANGE_PASSWORD); // パスワードは送らない
}
entity.setSystemName(AppConfig.get().getSystemName());
entity.setSmtpPassword(""); // パスワードは送らない
setAttributeOnProperty(entity);

return forward("config.jsp");
Expand Down Expand Up @@ -80,13 +82,19 @@ public Boundary save() throws InvalidKeyException, NoSuchAlgorithmException, NoS
}

MailConfigsEntity entity = super.getParams(MailConfigsEntity.class);
MailConfigsDao dao = MailConfigsDao.get();

// パスワードは暗号化する
String salt = PasswordUtil.getSalt();
entity.setSmtpPassword(PasswordUtil.encrypt(entity.getSmtpPassword(), salt));
entity.setSalt(salt);
if (entity.getSmtpPassword().equals(NO_CHANGE_PASSWORD)) {
MailConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
entity.setSmtpPassword(db.getSmtpPassword());
entity.setSalt(db.getSalt());
} else {
// パスワードは暗号化する
String salt = PasswordUtil.getSalt();
entity.setSmtpPassword(PasswordUtil.encrypt(entity.getSmtpPassword(), salt));
entity.setSalt(salt);
}

MailConfigsDao dao = MailConfigsDao.get();
entity = dao.save(entity);
setAttributeOnProperty(entity);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package org.support.project.knowledge.control.admin;

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

import org.support.project.common.bean.ValidateError;
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.PasswordUtil;
import org.support.project.common.util.StringUtils;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.AuthType;
import org.support.project.knowledge.control.Control;
import org.support.project.knowledge.logic.CrawlerLogic;
import org.support.project.web.annotation.Auth;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.dao.ProxyConfigsDao;
import org.support.project.web.entity.ProxyConfigsEntity;

public class ProxyControl extends Control {
/** ログ */
private static Log LOG = LogFactory.getLog(ProxyControl.class);

private static final String NO_CHANGE_PASSWORD = "NO_CHANGE_PASSWORD-fXLSJ_V-ZJ2E-GHUuagFASR-gtaG"; //パスワードを更新しなかったことを表すパスワード

/**
* 設定画面を表示
* @return
*/
@Get
@Auth(roles="admin")
public Boundary config() {
ProxyConfigsDao dao = ProxyConfigsDao.get();
ProxyConfigsEntity entity = dao.selectOnKey(AppConfig.get().getSystemName());
if (entity != null) {
entity.setProxyAuthPassword(NO_CHANGE_PASSWORD);
setAttributeOnProperty(entity);
}
setAttribute("systemName", AppConfig.get().getSystemName());
return forward("config.jsp");
}

@Post
@Auth(roles="admin")
public Boundary save() throws Exception {
List<ValidateError> errors = new ArrayList<>();
errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

String type = getParam("proxyAuthType");
//認証がONの場合のチェック
if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
ValidateError error = new ValidateError("errors.required", getResource("label.auth.id"));
errors.add(error);
}
if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
ValidateError error = new ValidateError("errors.required", getResource("label.auth.password"));
errors.add(error);
}
}
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("config.jsp");
}

ProxyConfigsEntity entity = super.getParamOnProperty(ProxyConfigsEntity.class);
ProxyConfigsDao dao = ProxyConfigsDao.get();

if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
// パスワード変更無し
ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
entity.setProxyAuthPassword(db.getProxyAuthPassword());
entity.setProxyAuthSalt(db.getProxyAuthSalt());
} else {
// パスワードは暗号化する
String salt = PasswordUtil.getSalt();
entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
entity.setProxyAuthSalt(salt);
}

entity = dao.save(entity);

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


@Post
@Auth(roles="admin")
public Boundary test() throws Exception {
try {
ProxyConfigsEntity entity = null;
String testUrl = getParam("testUrl");
Integer testType = getParam("testType", Integer.class);
if (INT_FLAG.OFF.getValue() == testType.intValue()) {
entity = new ProxyConfigsEntity();
} else {
List<ValidateError> errors = new ArrayList<>();
errors.addAll(ProxyConfigsEntity.get().validate(getParams()));

String type = getParam("proxyAuthType");
//認証がONの場合のチェック
if (!type.equals(String.valueOf(AuthType.None.getValue()))) {
if (StringUtils.isEmpty(getParam("proxyAuthUserId"))) {
ValidateError error = new ValidateError("errors.required", getResource("label.auth.id"));
errors.add(error);
}
if (StringUtils.isEmpty(getParam("proxyAuthPassword"))) {
ValidateError error = new ValidateError("errors.required", getResource("label.auth.password"));
errors.add(error);
}
}
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("config.jsp");
}

entity = super.getParamOnProperty(ProxyConfigsEntity.class);
ProxyConfigsDao dao = ProxyConfigsDao.get();

if (entity.getProxyAuthPassword().equals(NO_CHANGE_PASSWORD)) {
// パスワード変更無し
ProxyConfigsEntity db = dao.selectOnKey(AppConfig.get().getSystemName());
entity.setProxyAuthPassword(db.getProxyAuthPassword());
entity.setProxyAuthSalt(db.getProxyAuthSalt());
} else {
// パスワードは暗号化する
String salt = PasswordUtil.getSalt();
entity.setProxyAuthPassword(PasswordUtil.encrypt(entity.getProxyAuthPassword(), salt));
entity.setProxyAuthSalt(salt);
}
}

// 確認用のURLで通信出来るか確認
CrawlerLogic crawlerLogic = CrawlerLogic.get();
String content = crawlerLogic.crawle(entity, testUrl);
setAttribute("content", content);

addMsgInfo("knowledge.proxy.test.done");

} catch(Exception e) {
LOG.warn("knowledge.proxy.test.fail", e);
addMsgError("knowledge.proxy.test.fail");
addMsgError(e.getClass().getSimpleName());
if (StringUtils.isNotEmpty(e.getMessage())) {
addMsgError(e.getMessage());
}
}
return forward("config.jsp");
}


@Post
@Auth(roles="admin")
public Boundary delete() throws Exception {
ProxyConfigsDao dao = ProxyConfigsDao.get();
dao.physicalDelete(AppConfig.get().getSystemName()); // 物理削除で消してしまう

ProxyConfigsEntity entity = new ProxyConfigsEntity();
entity.setSystemName(AppConfig.get().getSystemName());
setAttributeOnProperty(entity);

addMsgInfo("message.success.delete.target", getResource("knowledge.proxy.title"));

return forward("config.jsp");
}

}
Loading

0 comments on commit 908f645

Please sign in to comment.