Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft api #1120

Open
wants to merge 2 commits into
base: v1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.support.project.knowledge.control.api;

import net.arnx.jsonic.JSONException;

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

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.common.util.StringUtils;
import org.support.project.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.dao.DraftItemValuesDao;
import org.support.project.knowledge.dao.DraftKnowledgesDao;
import org.support.project.knowledge.entity.DraftKnowledgesEntity;
import org.support.project.knowledge.vo.api.Draft;
import org.support.project.web.bean.ApiParams;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.control.GetApiControl;
import org.support.project.web.control.service.Delete;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.control.service.Put;
import org.support.project.web.exception.InvalidParamException;
import org.support.project.web.filter.ControlManagerFilter;

@DI(instance = Instance.Prototype)
public class DraftsControl extends GetApiControl {
private static Log LOG = LogFactory.getLog(ControlManagerFilter.class);

@Get(path="api/drafts", publishToken="")
public Boundary index() {
return get();
}

@Override
public Boundary getList(ApiParams params) {
List<DraftKnowledgesEntity> draftsEntity = DraftKnowledgesDao.get().selectOnUser(super.getLoginUserId());
List<Draft> results = new ArrayList<>();

for (DraftKnowledgesEntity draftEntity : draftsEntity) {
Draft draft = new Draft();
PropertyUtil.copyPropertyValue(draftEntity, draft);
results.add(draft);
}

return send(HttpStatus.SC_200_OK, results);
}

@Override
public Boundary getSingle(String id) {
// TODO Auto-generated method stub
return null;
}

@Delete(path="api/drafts", checkReferer=false, subscribeToken="")
public Boundary delete() {
// TODO: almost same as DraftControl.delete().
// TODO: Can we unify these?

String draftIdStr = super.getPathString("");
if(StringUtils.isEmpty(draftIdStr)) {
send(HttpStatus.SC_204_NO_CONTENT);
}
Long draftId = Long.valueOf(draftIdStr);
DraftKnowledgesEntity draft = DraftKnowledgesDao.get().selectOnKey(draftId);
// アクセス可能かチェック
if (draft == null) {
return send(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
}
if (draft.getInsertUser().intValue() != getLoginUserId().intValue()) {
return send(HttpStatus.SC_403_FORBIDDEN, "FORBIDDEN");
}
DraftKnowledgesDao.get().physicalDelete(draft);
DraftItemValuesDao.get().deleteOnDraftId(draftId);

return send(HttpStatus.SC_200_OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public List<DraftKnowledgesEntity> selectOnUser(Integer loginUserId, int limit,
return super.executeQueryList(sql, DraftKnowledgesEntity.class, loginUserId, limit, offset);
}

@Aspect(advice = org.support.project.ormapping.transaction.Transaction.class)
public List<DraftKnowledgesEntity> selectOnUser(Integer loginUserId) {
String sql = "SELECT * FROM DRAFT_KNOWLEDGES WHERE INSERT_USER = ?";
return super.executeQueryList(sql, DraftKnowledgesEntity.class, loginUserId);
}

@Aspect(advice = org.support.project.ormapping.transaction.Transaction.class)
public DraftKnowledgesEntity selectOnKnowledgeAndUser(Long knowledgeId, Integer loginUserId) {
String sql = "SELECT * FROM DRAFT_KNOWLEDGES WHERE INSERT_USER = ? AND KNOWLEDGE_ID = ?";
Expand Down
120 changes: 120 additions & 0 deletions src/main/java/org/support/project/knowledge/vo/api/Draft.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.support.project.knowledge.vo.api;

import java.sql.Timestamp;

public class Draft {
/** 下書きID */
private Long draftId;
/** ナレッジID */
private Long knowledgeId;
/** タイトル */
private String title;
/** 内容 */
private String content;
/** 公開区分 */
private Integer publicFlag;
/** 公開対象 */
private String accesses;
/** 共同編集対象 */
private String editors;
/** タグ名称一覧 */
private String tagNames;
/** テンプレートの種類ID */
private Integer typeId;
/** 登録ユーザ */
private Integer insertUser;
/** 登録日時 */
private Timestamp insertDatetime;
/** 更新ユーザ */
private Integer updateUser;
/** 更新日時 */
private Timestamp updateDatetime;
/** 削除フラグ */
private Integer deleteFlag;

public Long getDraftId() {
return draftId;
}
public void setDraftId(Long draftId) {
this.draftId = draftId;
}
public Long getKnowledgeId() {
return knowledgeId;
}
public void setKnowledgeId(Long knowledgeId) {
this.knowledgeId = knowledgeId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Integer getPublicFlag() {
return publicFlag;
}
public void setPublicFlag(Integer publicFlag) {
this.publicFlag = publicFlag;
}
public String getAccesses() {
return accesses;
}
public void setAccesses(String accesses) {
this.accesses = accesses;
}
public String getEditors() {
return editors;
}
public void setEditors(String editors) {
this.editors = editors;
}
public String getTagNames() {
return tagNames;
}
public void setTagNames(String tagNames) {
this.tagNames = tagNames;
}
public Integer getTypeId() {
return typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public Integer getInsertUser() {
return insertUser;
}
public void setInsertUser(Integer insertUser) {
this.insertUser = insertUser;
}
public Timestamp getInsertDatetime() {
return insertDatetime;
}
public void setInsertDatetime(Timestamp insertDatetime) {
this.insertDatetime = insertDatetime;
}
public Integer getUpdateUser() {
return updateUser;
}
public void setUpdateUser(Integer updateUser) {
this.updateUser = updateUser;
}
public Timestamp getUpdateDatetime() {
return updateDatetime;
}
public void setUpdateDatetime(Timestamp updateDatetime) {
this.updateDatetime = updateDatetime;
}
public Integer getDeleteFlag() {
return deleteFlag;
}
public void setDeleteFlag(Integer deleteFlag) {
this.deleteFlag = deleteFlag;
}
}