Knowledgeの実装と仕組み - cmknet/knowledge GitHub Wiki

Knowledgeの実装や仕組みについて解説します。

リクエスト処理の流れ

knowledge_control

knowledgeは、MVCアーキテクチャで実装されています。 基本的に、Controlがリクエストを受け、Logicがエンティティを処理、JSPがビューとして結果を返します。 もしくは、API用の場合は、結果をJSONで返します。

要素 概要
Control リクエストを受け、必要なLogicに処理を依頼する
Logic 業務処理。データの検索・登録等を行う
JSP JSP。ページの表示処理を行う

サーブレットフィルタ

knowledgeは、ほとんどの機能をサーブレットフィルタを起点として動作します。

サーブレットフィルタは、web.xmlで定義しています。

ブラウザから受け付けたURLは、以下のフィルタを通して、処理すべきフィルタが実行されます。

以下のフィルタの中で一番重要なのは、ControlFilterです。 ControlFilterが、URLから実行するControlを判断・実行してブラウザに結果を返します。

フィルタ 概要
EncodingFilter リクエストのエンコーディングを設定するフィルタ
SeqFilter レスポンスのヘッダを設定するフィルタ
LoggingFilter リクエストのログを出力するフィルタ
ApiFilter WebAPIの場合に、トークンにより認証を行うフィルタ
AuthenticationFilter 認証を行うためのフィルタ
MultipartFilter multipart/form-dataを処理するためのフィルタ
MaintenanceModeFilter メンテナンスモード時に管理者のみアクセス可能にするフィルタ
ControlFilter Controlクラスのメソッドを実行するフィルタ

Control(コントローラ)

ブラウザからのリクストをServletコンテナが受け、ControlFilterがURLから対応するControlのメソッドを実行します。

Controlは、以下の二種類に分かれます。

  • ページ用のControl(JSPにフォワードしてHTMLを返す)
  • API用のControl(JSONを返す)

Controlは、以下の処理を行います。

  • Controlは、Logicクラスの処理を実行して、データの検索・登録処理などを行います。
  • Logicクラスを実行した後、ページまたはAPIの結果を返します。
    • ページの場合、ビュー(JSP)にフォワードして、結果をHTMLとしてブラウザに返します。
    • APIの場合、結果をJSONとしてブラウザに返します。

以下のディレクトリにControlのソースが格納されています。

knowledge/src/main/java/org/support/project/knowledge/control

Controlクラスの一覧は以下の通りです。尚、ページURLは、ControlクラスURL/メソッド名になります。

Controlクラス名 ControlクラスURL 備考
IndexControl index
admin.AggregateControl admin.aggregate
admin.ConfigControl admin.config
admin.CustomServiceControl admin.customservice
admin.DatabaseControl admin.database
admin.LdapControl admin.ldap
admin.LoggingControl admin.logging
admin.MailControl admin.mail
admin.MailhookControl admin.mailhook
admin.MailTemplateControl admin.mailtemplate
admin.NoticeControl admin.notice
admin.PinControl admin.pin
admin.ProxyControl admin.proxy
admin.SystemConfigControl admin.systemconfig
admin.TemplateControl admin.template
admin.UsersControl admin.users
admin.WebhookControl admin.webhook
api.AttachControl api.attach JSON形式
api.GroupsControl api.groups JSON形式
api.KnowledgesControl api.knowledges JSON形式
api.SampleControl api.sample JSON形式
api.UsersControl api.users JSON形式
open.AccountControl open.account
open.EmojiControl open.emoji
open.EventControl open.event
open.FileControl open.file
open.IntervalControl open.interval
open.KnowledgeControl open.knowledge ナレッジの一覧ページなど
open.LanguageControl open.language
open.LicenseControl open.license
open.NoticeControl open.notice
open.PasswordInitializationControl open.passwordinitialization
open.SignupControl open.signup
open.SurveyControl open.survey
open.TagControl open.tag
open.ThemaControl open.thema
open.api/KnowledgeSearchControl open.api.knowledgesearch JSON形式
open.api/UserApiControl open.api.userapi JSON形式
protect.AccountControl protect.account
protect.ConfigControl protect.config
protect.ConnectControl protect.connect
protect.DraftControl protect.draft
protect.EventControl protect.event
protect.FileControl protect.file
protect.GroupControl protect.group
protect.KnowledgeControl protect.knowledge ナレッジの編集ページなど
protect.NotificationControl protect.notification
protect.NotifyControl protect.notify
protect.StockControl protect.stock
protect.SurveyControl protect.survey
protect.TargetControl protect.target
protect.TokenControl protect.token

Logic(ロジック)

Controlから実行され、データの検索や登録などの処理を担います。

  • トランザクション境界はLogicに対して行われており、Logicが実行されるとAOPでトランザクション開始されます。
  • データのアクセスはDaoクラスを通して、エンティティの取得・操作を行います。
  • 全文検索は、Apache Luceneを使っており、ナレッジの検索を行います。

以下のディレクトリにLogicのソースが格納されています。

knowledge/src/main/java/org/support/project/knowledge/logic

ロジッククラスの一覧は以下の通りです。

ロジッククラス 備考
AccountLogic
AddUserProcessLogic
AggregateLogic
CompressLogic
CrawlerLogic
DatabaseLogic
DataTransferLogic
DiffLogic
EventsLogic
GroupLogic
HttpLogic
IdenticonLogic
IndexLogic 全文検索ロジック
KeywordLogic
KnowledgeAuthenticationLogic
KnowledgeDataEditLogic
KnowledgeDataSelectLogic
KnowledgeLogic ナレッジの登録、検索等
LikeLogic
LogManageLogic
MailEventLogic
MailhookLogic
MailLogic
MarkdownLogic
NotificationLogic
NotifyCommentLogic
NotifyLogic
PasswordInitializationLogic
ServiceConfigLogic
SlideLogic
SurveyLogic
SystemConfigLogic
TagLogic
TargetLogic
TemplateLogic
TimeZoneLogic
UploadedFileLogic
WebhookLogic
activity.ActivityLogic

JSP(ビュー)

Controlがリクエストの属性に設定したデータを取得し、HTMLを生成します。

  • リクエストからデータを取得して、HTMLを生成

以下のディレクトリにJSPのソースが格納されています。

knowledge/src/main/webapp/WEB-INF/views

大別すると、以下のフォルダに分かれます。

  • commons : 共通ページ
  • admin : 管理用ページ
  • auth : 認証用ページ
  • open : デフォルトでは認証しなくても参照可能なページ
  • protect : 認証が必須のページ

jspファイルの一覧は以下の通りです。

jspファイル 備考
admin/aggregate/index.jsp
admin/config/analytics.jsp
admin/config/config.jsp
admin/config/system.jsp
admin/customservice/config.jsp
admin/database/connection.jsp
admin/database/export.jsp
admin/database/index.jsp
admin/database/reindexing.jsp
admin/ldap/config.jsp
admin/ldap/list.jsp
admin/logging/index.jsp
admin/mail/config.jsp
admin/mailhook/config.jsp
admin/mailhook/hook.jsp
admin/mailtemplate/index.jsp
admin/notice/list.jsp
admin/pin/index.jsp
admin/proxy/config.jsp
admin/systemconfig/index.jsp
admin/template/edit.jsp
admin/template/include_template_label.jsp
admin/template/list.jsp
admin/users/accept_list.jsp
admin/users/list.jsp
admin/users/view_add.jsp
admin/users/view_edit.jsp
admin/webhook/config.jsp
auth/authorizerError.jsp
auth/form.jsp
commons/maintenance.jsp
commons/migrate.jsp
commons/errors/badrequest.jsp
commons/errors/error.jsp
commons/errors/forbidden.jsp
commons/errors/jsp_error.jsp
commons/errors/not_found.jsp
commons/errors/server_error.jsp
commons/errors/unauthorized.jsp
commons/layout/commonFooter.jsp
commons/layout/commonHeader.jsp
commons/layout/commonNavbar.jsp
commons/layout/commonScripts.jsp
commons/layout/layoutMain.jsp
commons/layout/layoutNoMenu.jsp
commons/layout/layoutTop.jsp
commons/notice/notice.jsp
index/index.jsp
open/account/account.jsp
open/emoji/cheatsheet.jsp
open/emoji/nature.jsp
open/emoji/objects.jsp
open/emoji/people.jsp
open/emoji/places.jsp
open/emoji/symbols.jsp
open/knowledge/events.jsp ※参照不可
open/knowledge/histories.jsp 更新履歴ページ
open/knowledge/history.jsp 更新履歴詳細ページ
open/knowledge/likes.jsp いいねページ
open/knowledge/list.jsp ナレッジ一覧ページ
open/knowledge/popularity.jsp ナレッジ人気ページ
open/knowledge/search.jsp ナレッジ複合検索ページ
open/knowledge/show_history.jsp ナレッジ閲覧履歴ページ
open/knowledge/stocks.jsp ナレッジストックページ
open/knowledge/view.jsp ナレッジ詳細ページ
open/knowledge/partials/common_list.jsp
open/knowledge/partials/common_sub_list.jsp
open/knowledge/partials/partials-list-scripts.jsp
open/knowledge/partials/partials-list-styles.jsp
open/knowledge/partials/partials-view-attach-files.jsp
open/knowledge/partials/partials-view-comment-edit.jsp
open/knowledge/partials/partials-view-comment-list.jsp
open/knowledge/partials/partials-view-count.jsp
open/knowledge/partials/partials-view-editor.jsp
open/knowledge/partials/partials-view-main-contents.jsp
open/knowledge/partials/partials-view-menu-buttons.jsp
open/knowledge/partials/partials-view-modal-answer-survey.jsp
open/knowledge/partials/partials-view-modal-stock.jsp
open/knowledge/partials/partials-view-public-flag.jsp
open/knowledge/partials/partials-view-scripts.jsp
open/knowledge/partials/partials-view-stock.jsp
open/knowledge/partials/partials-view-styles.jsp
open/knowledge/partials/partials-view-tag.jsp
open/knowledge/partials/partials-view-template.jsp
open/knowledge/partials/partials-view-toc.jsp
open/knowledge/partials/selectUserDialog.jsp
open/language/index.jsp
open/license/index.jsp
open/notice/list.jsp
open/passwordinitialization/forgot_pass_request.jsp
open/passwordinitialization/forgot_pass_result.jsp
open/passwordinitialization/password_reset.jsp
open/passwordinitialization/reset_result.jsp
open/signup/mail_sended.jsp
open/signup/provisional_registration.jsp
open/signup/signup.jsp
open/signup/signup_done.jsp
open/tag/dialog.jsp
open/tag/list.jsp
open/thema/highlight.jsp
open/thema/list.jsp
open/thema/thema.jsp
protect/account/changekey.jsp
protect/account/complete.jsp
protect/account/index.jsp
protect/account/saveresult.jsp
protect/account/targets.jsp
protect/account/withdrawal.jsp
protect/config/index.jsp
protect/connect/config.jsp
protect/connect/index.jsp
protect/group/add_group.jsp
protect/group/dialog.jsp
protect/group/edit_group.jsp
protect/group/groups.jsp
protect/group/mygroups.jsp
protect/group/view_group.jsp
protect/knowledge/edit.jsp ナレッジ編集ページ
protect/knowledge/edit_comment.jsp
protect/knowledge/markdown.jsp
protect/knowledge/partials/partials-edit-attach.jsp
protect/knowledge/partials/partials-edit-buttons.jsp
protect/knowledge/partials/partials-edit-editor-modal.jsp
protect/knowledge/partials/partials-edit-editormain.jsp
protect/knowledge/partials/partials-edit-meta.jsp
protect/knowledge/partials/partials-edit-scripts.jsp
protect/knowledge/partials/partials-edit-styles.jsp
protect/knowledge/partials/partials-edit-topinfo.jsp
protect/knowledge/partials/partials-edit-viewer-modal.jsp
protect/notification/list.jsp
protect/notification/not_found.jsp
protect/notification/view.jsp
protect/notify/index.jsp
protect/notify/test.jsp
protect/stock/add.jsp
protect/stock/edit.jsp
protect/stock/knowledge.jsp
protect/stock/list.jsp
protect/survey/answers.jsp
protect/survey/edit.jsp
protect/token/index.jsp