<commit_before>package org.support.project.knowledge.control.open;

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

import org.support.project.common.exception.ParseException;
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.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.control.KnowledgeControlBase;
import org.support.project.knowledge.dao.CommentsDao;
import org.support.project.knowledge.dao.ExGroupsDao;
import org.support.project.knowledge.dao.KnowledgeHistoriesDao;
import org.support.project.knowledge.dao.KnowledgeItemValuesDao;
import org.support.project.knowledge.dao.KnowledgesDao;
import org.support.project.knowledge.dao.LikesDao;
import org.support.project.knowledge.dao.StocksDao;
import org.support.project.knowledge.dao.TagsDao;
import org.support.project.knowledge.dao.TemplateMastersDao;
import org.support.project.knowledge.entity.CommentsEntity;
import org.support.project.knowledge.entity.KnowledgeHistoriesEntity;
import org.support.project.knowledge.entity.KnowledgeItemValuesEntity;
import org.support.project.knowledge.entity.KnowledgesEntity;
import org.support.project.knowledge.entity.LikesEntity;
import org.support.project.knowledge.entity.StocksEntity;
import org.support.project.knowledge.entity.TagsEntity;
import org.support.project.knowledge.entity.TemplateItemsEntity;
import org.support.project.knowledge.entity.TemplateMastersEntity;
import org.support.project.knowledge.logic.DiffLogic;
import org.support.project.knowledge.logic.GroupLogic;
import org.support.project.knowledge.logic.KeywordLogic;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.logic.MarkdownLogic;
import org.support.project.knowledge.logic.TagLogic;
import org.support.project.knowledge.logic.TargetLogic;
import org.support.project.knowledge.logic.UploadedFileLogic;
import org.support.project.knowledge.vo.LikeCount;
import org.support.project.knowledge.vo.MarkDown;
import org.support.project.knowledge.vo.StockKnowledge;
import org.support.project.knowledge.vo.UploadFile;
import org.support.project.web.bean.LabelValue;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.dao.SystemConfigsDao;
import org.support.project.web.dao.UsersDao;
import org.support.project.web.entity.GroupsEntity;
import org.support.project.web.entity.SystemConfigsEntity;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.exception.InvalidParamException;

/**
 * ナレッジ操作のコントロール
 * 
 * @author Koda
 */
@DI(instance = Instance.Prototype)
public class KnowledgeControl extends KnowledgeControlBase {
    /** ログ */
    private static final Log LOG = LogFactory.getLog(KnowledgeControl.class);
    /** Cookieに保持する閲覧履歴の件数 */
    private static final int COOKIE_COUNT = 20;
    /** Cookieに保持する閲覧履歴の区切り文字 */
    private static final String COOKIE_SEPARATOR = "-";
    /** ナレッジ一覧に表示する件数 */
    public static final int PAGE_LIMIT = 50;
    /** お気に入りに表示する件数 */
    public static final int FAV_PAGE_LIMIT = 10;

    /**
     * ナレッジを表示
     * 
     * @return
     * @throws InvalidParamException
     * @throws ParseException
     */
    @Get
    public Boundary view() throws InvalidParamException, ParseException {
        // 共通処理呼の表示条件の保持の呼び出し
        setViewParam();
        
        Long knowledgeId = super.getPathLong(Long.valueOf(-1));
        
        SystemConfigsDao dao = SystemConfigsDao.get();
        SystemConfigsEntity config = dao.selectOnKey(SystemConfig.SYSTEM_URL, AppConfig.get().getSystemName());
        StringBuilder url = new StringBuilder();
        if (config == null) {
            url.append(HttpUtil.getContextUrl(getRequest()));
        } else {
            url.append(config.getConfigValue());
        }
        url.append("/knowledge/").append(knowledgeId);
        setAttribute("url", url.toString());

        KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();
        LoginedUser loginedUser = getLoginedUser();

        if (loginedUser == null) {
            KnowledgesEntity entity = KnowledgesDao.get().selectOnKey(knowledgeId);
            if (entity == null) {
                return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
            }

            if (!entity.getPublicFlag().equals(KnowledgeLogic.PUBLIC_FLAG_PUBLIC)) {
                return super.redirect(getRequest().getContextPath() + "/protect.knowledge/view/" + knowledgeId);
            }
        }

        KnowledgesEntity entity = knowledgeLogic.selectWithTags(knowledgeId, getLoginedUser());
        if (entity == null) {
            return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
        }

        // 今見たナレッジの情報をCookieに保存
        List<String> ids = new ArrayList<String>();
        ids.add(String.valueOf(knowledgeId));
        String history = getCookie(SystemConfig.COOKIE_KEY_HISTORY);<commit_msg>#384 Fix build knowledge view url<commit_after>package org.support.project.knowledge.control.open;

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

import org.support.project.common.exception.ParseException;
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.di.DI;
import org.support.project.di.Instance;
import org.support.project.knowledge.config.AppConfig;
import org.support.project.knowledge.config.SystemConfig;
import org.support.project.knowledge.control.KnowledgeControlBase;
import org.support.project.knowledge.dao.CommentsDao;
import org.support.project.knowledge.dao.ExGroupsDao;
import org.support.project.knowledge.dao.KnowledgeHistoriesDao;
import org.support.project.knowledge.dao.KnowledgeItemValuesDao;
import org.support.project.knowledge.dao.KnowledgesDao;
import org.support.project.knowledge.dao.LikesDao;
import org.support.project.knowledge.dao.StocksDao;
import org.support.project.knowledge.dao.TagsDao;
import org.support.project.knowledge.dao.TemplateMastersDao;
import org.support.project.knowledge.entity.CommentsEntity;
import org.support.project.knowledge.entity.KnowledgeHistoriesEntity;
import org.support.project.knowledge.entity.KnowledgeItemValuesEntity;
import org.support.project.knowledge.entity.KnowledgesEntity;
import org.support.project.knowledge.entity.LikesEntity;
import org.support.project.knowledge.entity.StocksEntity;
import org.support.project.knowledge.entity.TagsEntity;
import org.support.project.knowledge.entity.TemplateItemsEntity;
import org.support.project.knowledge.entity.TemplateMastersEntity;
import org.support.project.knowledge.logic.DiffLogic;
import org.support.project.knowledge.logic.GroupLogic;
import org.support.project.knowledge.logic.KeywordLogic;
import org.support.project.knowledge.logic.KnowledgeLogic;
import org.support.project.knowledge.logic.MarkdownLogic;
import org.support.project.knowledge.logic.TagLogic;
import org.support.project.knowledge.logic.TargetLogic;
import org.support.project.knowledge.logic.UploadedFileLogic;
import org.support.project.knowledge.vo.LikeCount;
import org.support.project.knowledge.vo.MarkDown;
import org.support.project.knowledge.vo.StockKnowledge;
import org.support.project.knowledge.vo.UploadFile;
import org.support.project.web.bean.LabelValue;
import org.support.project.web.bean.LoginedUser;
import org.support.project.web.boundary.Boundary;
import org.support.project.web.common.HttpStatus;
import org.support.project.web.common.HttpUtil;
import org.support.project.web.control.service.Get;
import org.support.project.web.control.service.Post;
import org.support.project.web.dao.SystemConfigsDao;
import org.support.project.web.dao.UsersDao;
import org.support.project.web.entity.GroupsEntity;
import org.support.project.web.entity.SystemConfigsEntity;
import org.support.project.web.entity.UsersEntity;
import org.support.project.web.exception.InvalidParamException;

/**
 * ナレッジ操作のコントロール
 * 
 * @author Koda
 */
@DI(instance = Instance.Prototype)
public class KnowledgeControl extends KnowledgeControlBase {
    /** ログ */
    private static final Log LOG = LogFactory.getLog(KnowledgeControl.class);
    /** Cookieに保持する閲覧履歴の件数 */
    private static final int COOKIE_COUNT = 20;
    /** Cookieに保持する閲覧履歴の区切り文字 */
    private static final String COOKIE_SEPARATOR = "-";
    /** ナレッジ一覧に表示する件数 */
    public static final int PAGE_LIMIT = 50;
    /** お気に入りに表示する件数 */
    public static final int FAV_PAGE_LIMIT = 10;

    /**
     * ナレッジを表示
     * 
     * @return
     * @throws InvalidParamException
     * @throws ParseException
     */
    @Get
    public Boundary view() throws InvalidParamException, ParseException {
        // 共通処理呼の表示条件の保持の呼び出し
        setViewParam();
        
        Long knowledgeId = super.getPathLong(Long.valueOf(-1));
        
        SystemConfigsDao dao = SystemConfigsDao.get();
        SystemConfigsEntity config = dao.selectOnKey(SystemConfig.SYSTEM_URL, AppConfig.get().getSystemName());
        StringBuilder url = new StringBuilder();
        if (config == null) {
            url.append(HttpUtil.getContextUrl(getRequest()));
        } else {
            url.append(config.getConfigValue());
        }
        url.append("/open.knowledge/view/").append(knowledgeId);
        setAttribute("url", url.toString());

        KnowledgeLogic knowledgeLogic = KnowledgeLogic.get();
        LoginedUser loginedUser = getLoginedUser();

        if (loginedUser == null) {
            KnowledgesEntity entity = KnowledgesDao.get().selectOnKey(knowledgeId);
            if (entity == null) {
                return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
            }

            if (!entity.getPublicFlag().equals(KnowledgeLogic.PUBLIC_FLAG_PUBLIC)) {
                return super.redirect(getRequest().getContextPath() + "/protect.knowledge/view/" + knowledgeId);
            }
        }

        KnowledgesEntity entity = knowledgeLogic.selectWithTags(knowledgeId, getLoginedUser());
        if (entity == null) {
            return sendError(HttpStatus.SC_404_NOT_FOUND, "NOT FOUND");
        }

        // 今見たナレッジの情報をCookieに保存
        List<String> ids = new ArrayList<String>();
        ids.add(String.valueOf(knowledgeId));
        String history = getCookie(SystemConfig.COOKIE_KEY_HISTORY);
{'fraction_non_alphanumeric': 0.11015378914211599, 'fraction_numerical': 0.0026866777839540485, 'mean_word_length': 4.140476190476191, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5328484', 'n_tokens_mistral': 3395, 'n_tokens_neox': 3270, 'n_words': 482}