/** * 選択したストックに登録されたナレッジを取得 * * @return * @throws InvalidParamException */ @Get public Boundary knowledge() throws InvalidParamException { Long stockId = getParam("stockId", Long.class); Integer offset = getParam("offset", Integer.class); StocksDao stocksDao = StocksDao.get(); StocksEntity entity = stocksDao.selectOnKey(stockId); if (entity == null) { return sendError(HttpStatus.SC_404_NOT_FOUND, "Not Found"); } if (entity.getInsertUser().intValue() != getLoginUserId().intValue() && entity.getStockType().intValue() != StocksEntity.STOCKTYPE_PUBLIC) { return sendError(HttpStatus.SC_403_FORBIDDEN, "Forbidden"); } setAttributeOnProperty(entity); StockKnowledgesDao knowledgesDao = StockKnowledgesDao.get(); List<StockKnowledgesEntity> knowledges = knowledgesDao.selectOnStockIdWithKnowledgeInfo(stockId, offset * LIST_LIMIT, LIST_LIMIT); setAttribute("knowledges", knowledges); int previous = offset - 1; if (previous < 0) { previous = 0; } setAttribute("offset", offset); setAttribute("previous", previous); setAttribute("next", offset + 1); return forward("knowledge.jsp"); }
/** * ストック更新画面を表示 * * @return * @throws InvalidParamException */ @Get public Boundary edit() throws InvalidParamException { Long stockId = super.getPathLong(new Long(0)); StocksDao stocksDao = StocksDao.get(); StocksEntity stocksEntity = stocksDao.selectOnKey(stockId); setAttributeOnProperty(stocksEntity); return forward("edit.jsp"); }
/** * ストックの選択肢を一覧取得(JSON) * * @return * @throws InvalidParamException */ @Get public Boundary chooselist() throws InvalidParamException { Integer offset = super.getPathInteger(0); StocksDao stocksDao = StocksDao.get(); Long knowledgeId = getParam("knowledge_id", Long.class); List<Stock> stocks = stocksDao.selectMyStocksWithStocked( super.getLoginedUser(), knowledgeId, offset * LIST_LIMIT, LIST_LIMIT); return send(stocks); }
/** * ストック削除 * * @return * @throws InvalidParamException * @throws IOException * @throws JSONException * @throws IllegalAccessException * @throws InstantiationException */ @Post public Boundary delete() throws InvalidParamException, InstantiationException, IllegalAccessException, JSONException, IOException { StocksDao dao = StocksDao.get(); Long stockId = getParam("stockId", Long.class); dao.delete(stockId); String successMsg = "message.success.delete"; setResult(successMsg, null); return mylist(); }
/** * 自分の登録したストックの一覧を表示 * * <p>ストックは、 - Javascriptの参考になるナレッジをストックする - Newsのストック など、ストックするフォルダのような形で一覧を分けられるようにしようかと考えている * * <p>記事には「タグ」がついているが、「タグ」はナレッジの登録者が設定する。 ストックは、ナレッジの参照者が行うが、参照側でも自由に分類分けが出来たほうが良いかと思い、 この形にした。 * * @return * @throws InvalidParamException */ @Get public Boundary mylist() throws InvalidParamException { Integer offset = super.getPathInteger(0); StocksDao stocksDao = StocksDao.get(); List<StocksEntity> stocks = stocksDao.selectMyStocksWithKnowledgeCount( super.getLoginedUser(), offset * LIST_LIMIT, LIST_LIMIT); setAttribute("stocks", stocks); int previous = offset - 1; if (previous < 0) { previous = 0; } setAttribute("offset", offset); setAttribute("previous", previous); setAttribute("next", offset + 1); return forward("list.jsp"); }
/** * ストック登録 * * @return * @throws InvalidParamException * @throws IOException * @throws JSONException * @throws IllegalAccessException * @throws InstantiationException */ @Post public Boundary insert() throws InvalidParamException, InstantiationException, IllegalAccessException, JSONException, IOException { StocksEntity stocksEntity = super.getParamOnProperty(StocksEntity.class); stocksEntity.setStockType(StocksEntity.STOCKTYPE_PRIVATE); List<ValidateError> errors = stocksEntity.validate(); if (!errors.isEmpty()) { setResult(null, errors); return forward("add.jsp"); } stocksEntity = StocksDao.get().insert(stocksEntity); String successMsg = "message.success.save"; setResult(successMsg, errors); super.setPathInfo(stocksEntity.getStockId().toString()); return edit(); }