Skip to content

Commit

Permalink
Merge pull request #161 from support-project/develop
Browse files Browse the repository at this point in the history
Release v0.7.0 pre1
  • Loading branch information
koda-masaru committed Nov 22, 2015
2 parents f668f3c + b6cdd11 commit efe1a3b
Show file tree
Hide file tree
Showing 78 changed files with 2,928 additions and 268 deletions.
Binary file added document/database/A5M2_knowledge.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion document/database/knowledge.a5er
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ Field="テンプレートの種類ID","TYPE_ID","@INT","NOT NULL",0,"","",$FFFFF
Field="項目NO","ITEM_NO","@INT","NOT NULL",1,"","",$FFFFFFFF,""
Field="項目名","ITEM_NAME","@VARCHAR(32)","NOT NULL",,"","",$FFFFFFFF,""
Field="項目の種類","ITEM_TYPE","@INT","NOT NULL",,"","",$FFFFFFFF,""
Field="説明","DESCRIPTION","@VARCHAR(1024)",,,"","",$FFFFFFFF,""
EffectMode=None
Color=$000000
BkColor=$FFFFFF
ModifiedDateTime=20150910041108
ModifiedDateTime=20151027035632
Position="MAIN",1870,390

[Relation]
Expand Down
6 changes: 3 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.6.1</version>
<version>0.7.0-SNAPSHOT</version>
<name>webapp for knowledge</name>
<url>https://support-project.org/</url>

Expand All @@ -16,13 +16,13 @@
<dependency>
<groupId>org.support-project</groupId>
<artifactId>web</artifactId>
<version>0.6.0</version>
<version>0.7.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.support-project</groupId>
<artifactId>markedj</artifactId>
<version>1.0.4</version>
<version>1.0.5-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ private void crawl() throws Exception {
// タグを取得
List<TagsEntity> tagsEntities = TagsDao.get().selectOnKnowledgeId(knowledgesEntity.getKnowledgeId());
// Webアクセス
String content = logic.crawle(proxyConfigs, itemValue.getItemValue());
String content = null;
try {
content = logic.crawle(proxyConfigs, itemValue.getItemValue());
} catch (Exception e) {
LOG.error("crawl error:" + itemValue.getItemValue(), e);
// ステータス更新(エラー)
itemValue.setItemStatus(KnowledgeItemValuesEntity.STATUS_WEBACCESS_ERROR);
itemValuesDao.update(itemValue);
continue;
}
if (StringUtils.isNotEmpty(content)) {
LOG.info("[SUCCESS] " + itemValue.getItemValue());
// 全文検索エンジンにのみ、検索できるように情報登録
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.servlet.http.HttpServletRequest;

import org.apache.http.HttpStatus;
import org.support.project.common.bean.ValidateError;
import org.support.project.common.config.INT_FLAG;
import org.support.project.common.config.Resources;
Expand All @@ -17,7 +18,9 @@
import org.support.project.di.Instance;
import org.support.project.knowledge.dao.NotifyConfigsDao;
import org.support.project.knowledge.entity.NotifyConfigsEntity;
import org.support.project.web.bean.MessageResult;
import org.support.project.web.boundary.ForwardBoundary;
import org.support.project.web.boundary.JsonBoundary;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.logic.SanitizingLogic;

Expand Down Expand Up @@ -168,5 +171,7 @@ private boolean flagCheck(Integer check) {
return false;
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ protected String setViewParam() {
StringBuilder params = new StringBuilder();
params.append("?keyword=").append(getParamWithDefault("keyword", ""));
params.append("&tag=").append(getParamWithDefault("tag", ""));
params.append("&tagNames=").append(getParamWithDefault("tagNames", ""));
params.append("&user=").append(getParamWithDefault("user", ""));
params.append("&offset=").append(getParamWithDefault("offset", ""));
params.append("&tagNames=").append(getParamWithDefault("tagNames", ""));

if (super.getLoginedUser() != null) {
params.append("&group=").append(getParamWithDefault("group", ""));
params.append("&groupNames=").append(getParamWithDefault("groupNames", ""));
}

setAttribute("params", params.toString());
return params.toString();
}




}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package org.support.project.knowledge.control.admin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import net.arnx.jsonic.JSONException;

import org.apache.http.HttpStatus;
import org.support.project.common.bean.ValidateError;
import org.support.project.common.log.Log;
import org.support.project.common.log.LogFactory;
import org.support.project.common.util.StringUtils;
import org.support.project.knowledge.control.Control;
import org.support.project.knowledge.dao.TemplateMastersDao;
import org.support.project.knowledge.entity.ItemChoicesEntity;
import org.support.project.knowledge.entity.TemplateItemsEntity;
import org.support.project.knowledge.entity.TemplateMastersEntity;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.logic.TemplateLogic;
import org.support.project.web.annotation.Auth;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.config.MessageStatus;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.exception.InvalidParamException;
Expand All @@ -33,6 +42,15 @@ public Boundary list() {
// テンプレートの個数はあまり多く出来ないようにする(でないと登録の画面が微妙)
TemplateMastersDao mastersDao = TemplateMastersDao.get();
List<TemplateMastersEntity> templates = mastersDao.selectAll();
Collections.sort(templates, new Comparator<TemplateMastersEntity>() {
@Override
public int compare(TemplateMastersEntity o1, TemplateMastersEntity o2) {
if (!o1.getTypeId().equals(o2.getTypeId())) {
return o1.getTypeId().compareTo(o2.getTypeId());
}
return 0;
}
});
setAttribute("templates", templates);
return forward("list.jsp");
}
Expand All @@ -57,12 +75,12 @@ public Boundary view_add() {
@Auth(roles="admin")
public Boundary view_edit() throws InvalidParamException {
Integer id = super.getPathInteger();
TemplateMastersDao mastersDao = TemplateMastersDao.get();
TemplateMastersEntity entity = mastersDao.selectOnKey(id);
TemplateMastersEntity entity = TemplateLogic.get().loadTemplate(id);
if (entity == null) {
sendError(404, null);
}
setAttributeOnProperty(entity);
setAttribute("items", entity.getItems());

boolean editable = true;
if (KnowledgeLogic.TEMPLATE_TYPE_KNOWLEDGE == id || KnowledgeLogic.TEMPLATE_TYPE_BOOKMARK == id) {
Expand All @@ -72,38 +90,130 @@ public Boundary view_edit() throws InvalidParamException {
return forward("view_edit.jsp");
}


/**
* 登録
* リクエスト情報にあるテンプレートの情報を取得する
* 同時にバリデーションエラーもチェックし、もしバリデーションエラーが発生する場合、
* 引数のerrorsのリストに追加していく
*
* @param errors
* @return
* @throws InvalidParamException
* @throws IOException
* @throws JSONException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@Post
@Auth(roles="admin")
public Boundary create() throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException {
private TemplateMastersEntity loadParams(List<ValidateError> errors) throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException {
TemplateMastersEntity template = new TemplateMastersEntity();
Map<String, String> values = getParams();
List<ValidateError> errors = template.validate(values);
errors.addAll(template.validate(values));
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("view_add.jsp");
return null;
}
template = getParamOnProperty(TemplateMastersEntity.class);

TemplateMastersDao templateDao = TemplateMastersDao.get();
template = templateDao.insert(template);

super.setPathInfo(String.valueOf(template.getTypeId()));
String[] itemTypes = getParam("itemType", String[].class);
if (itemTypes != null) {
for (int i = 0; i < itemTypes.length; i++) {
String itemType = itemTypes[i]; // text_1 や radio_3 といった形式
if (itemType.indexOf("_") == -1) {
errors.add(new ValidateError("errors.invalid", "Request Data"));
return null;
}
String type = itemType.split("_")[0];
String itemId = itemType.split("_")[1];
if (!itemId.startsWith("item")) {
errors.add(new ValidateError("errors.invalid", "Request Data"));
return null;
}
String idx = itemId.substring(4);

if (!StringUtils.isInteger(idx)) {
errors.add(new ValidateError("errors.invalid", "Request Data"));
return null;
}
int typeNum = TemplateLogic.get().convType(type);
if (typeNum == -1) {
errors.add(new ValidateError("errors.invalid", "Request Data"));
return null;
}

String itemTitle = getParam("title_" + itemId);
String itemDescription = getParam("description_" + itemId);

TemplateItemsEntity itemsEntity = new TemplateItemsEntity();
itemsEntity.setTypeId(-1); // バリデーションエラー対策
itemsEntity.setItemNo(Integer.parseInt(idx));
itemsEntity.setItemType(typeNum);
itemsEntity.setItemName(itemTitle);
itemsEntity.setDescription(itemDescription);

errors.addAll(itemsEntity.validate());
if (!errors.isEmpty()) {
// エラーが発生した時点で抜ける
return null;
}
template.getItems().add(itemsEntity);

// 選択肢
if (typeNum == TemplateLogic.ITEM_TYPE_RADIO || typeNum == TemplateLogic.ITEM_TYPE_CHECKBOX) {
String[] choice_labels = getParam("label_item" + idx, String[].class);
String[] choice_values = getParam("value_item" + idx, String[].class);
if (choice_labels.length != choice_values.length) {
errors.add(new ValidateError("errors.invalid", "Request Data"));
return null;
}
for (int j = 0; j < choice_labels.length; j++) {
String label = choice_labels[j];
String value = choice_values[j];
ItemChoicesEntity choicesEntity = new ItemChoicesEntity();
choicesEntity.setTypeId(-1);
choicesEntity.setItemNo(-1);
choicesEntity.setChoiceLabel(label);
choicesEntity.setChoiceValue(value);
errors.addAll(itemsEntity.validate());
if (!errors.isEmpty()) {
// エラーが発生した時点で抜ける
return null;
}
itemsEntity.getChoices().add(choicesEntity);
}
}
}
}
return template;
}


/**
* 登録
* 画面遷移すると再度画面を作るのが面倒なので、Ajaxアクセスとする
* @return
* @throws InvalidParamException
* @throws IOException
* @throws JSONException
* @throws IllegalAccessException
* @throws InstantiationException
*/
@Post
@Auth(roles="admin")
public Boundary create() throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException {
List<ValidateError> errors = new ArrayList<ValidateError>();
TemplateMastersEntity template = loadParams(errors);
if (!errors.isEmpty()) {
return sendValidateError(errors);
}
template.setTypeId(null); //自動採番する
// 保存
template = TemplateLogic.get().addTemplate(template, getLoginedUser());

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

return view_edit();
// メッセージ送信
return sendMsg(MessageStatus.Success, HttpStatus.SC_OK, String.valueOf(template.getTypeId()), "message.success.insert");
}



/**
* 更新
* @return
Expand All @@ -116,32 +226,21 @@ public Boundary create() throws InstantiationException, IllegalAccessException,
@Post
@Auth(roles="admin")
public Boundary update() throws InstantiationException, IllegalAccessException, JSONException, IOException, InvalidParamException {
TemplateMastersEntity template = new TemplateMastersEntity();
Map<String, String> values = getParams();
List<ValidateError> errors = template.validate(values);
List<ValidateError> errors = new ArrayList<ValidateError>();
TemplateMastersEntity template = loadParams(errors);
if (!errors.isEmpty()) {
setResult(null, errors);
return forward("view_edit.jsp");
return sendValidateError(errors);
}

Integer typeId = getParam("typeId", Integer.class);
if (KnowledgeLogic.TEMPLATE_TYPE_KNOWLEDGE == typeId) {
// TODO 項目の増減はできない
} else if(KnowledgeLogic.TEMPLATE_TYPE_BOOKMARK == typeId) {
// TODO 項目の増減はできない
// 保存
try {
template = TemplateLogic.get().updateTemplate(template, getLoginedUser());
} catch (InvalidParamException e) {
// エラーメッセージ送信
return send(e.getMessageResult());
}

template = getParamOnProperty(TemplateMastersEntity.class);

TemplateMastersDao templateDao = TemplateMastersDao.get();
template = templateDao.save(template);

super.setPathInfo(String.valueOf(template.getTypeId()));

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

return view_edit();
// メッセージ送信
return sendMsg(MessageStatus.Success, HttpStatus.SC_OK, String.valueOf(template.getTypeId()), "message.success.update");
}


Expand All @@ -161,11 +260,7 @@ public Boundary delete() throws Exception {
return view_edit();
}

TemplateMastersEntity entity = dao.selectOnKey(typeId);
if (entity != null) {
dao.delete(entity);
}

TemplateLogic.get().deleteTemplate(typeId, getLoginedUser());
String successMsg = "message.success.delete";
setResult(successMsg, null);
return list();
Expand Down
Loading

0 comments on commit efe1a3b

Please sign in to comment.