/src/com/bosv/controller/Acrm.java
Java | 352 lines | 259 code | 73 blank | 20 comment | 3 complexity | 3193861043cf6f2fe883ab934edf62aa MD5 | raw file
- package com.bosv.controller;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import com.alibaba.fastjson.JSON;
- import com.bosv.bean.Comment;
- import com.bosv.bean.Favorite;
- import com.bosv.bean.Message;
- import com.bosv.bean.Topic;
- import com.bosv.bean.User;
- import com.bosv.service.CommentService;
- import com.bosv.service.FavoritesService;
- import com.bosv.service.FriendsService;
- import com.bosv.service.MesssageService;
- import com.bosv.service.NewsGroupService;
- import com.bosv.service.NewsService;
- import com.bosv.service.NodeSectionService;
- import com.bosv.service.NodeService;
- import com.bosv.service.TopicService;
- import com.bosv.service.UserService;
- import com.bosv.web.ActionContext;
- import com.bosv.web.Mapping;
- public class Acrm {
-
-
- private final Log log = LogFactory.getLog(getClass());
-
-
- /*
- * /api/news_sections
- */
- @Mapping("/api/news_sections")
- public String newsSections(){
- //HttpServletRequest request = ActionContext.getActionContext().getHttpServletRequest();
- NodeSectionService nodeSectionService = new NodeSectionService();
- ArrayList nodeSection = nodeSectionService.getNodeSection();
- return JSON.toJSONString(nodeSection);
- }
-
-
-
-
-
-
-
- //TODO:DONE
- @Mapping("/api/news_groups")
- public String listNewsGroups() {
- NewsGroupService newGroupService = new NewsGroupService();
- ArrayList newsgroups = newGroupService.getNewGroup();
- return JSON.toJSONString(newsgroups);
- }
- @Mapping("/api/news_group_add")
- public String addNewsGroup() {
- return "";
- }
- @Mapping("/api/news_group_delete")
- public String deleteNewsGroup() {
- return "";
- }
- @Mapping("/api/news_group_update")
- public String updateNewsGroup() {
- return "";
- }
-
- //TODO:DONE
- @Mapping("/api/news")
- public String listNews() {
- NewsService newsService = new NewsService();
- ArrayList news = newsService.getNews();
- return JSON.toJSONString(news);
- }
- @Mapping("/api/news_add")
- public String addNews() {
- return "";
- }
- @Mapping("/api/news_delete")
- public String deleteNews() {
- return "";
- }
- @Mapping("/api/news_update")
- public String updateNews() {
- return "";
- }
- @Mapping("/api/nodes")
- public String listNodes() {
- NodeService nodeService = new NodeService();
- ArrayList node = nodeService.getNode();
- return JSON.toJSONString(node);
- }
- @Mapping("/api/node_add")
- public String addNode() {
- return "helloworld";
- }
- @Mapping("/api/node_delete")
- public String deleteNode() {
- return "";
- }
- @Mapping("/api/node_update")
- public String updateNode() {
- return "";
- }
- @Mapping("/api/topic/$1")
- public String listTopics(int id) {
- TopicService ts = new TopicService();
- Topic result = ts.getTopicByID(id);
- System.out.println("user:" +result.getUser().getEmail());
-
- return JSON.toJSONString(result);
- }
-
-
- @Mapping("/api/topic_add")
- public String addTopic() {
- return "";
- }
- @Mapping("/api/topic_delete")
- public String deleteTopic() {
- return "";
- }
- @Mapping("/api/topic_update")
- public String updateTopic() {
- return "";
- }
- @Mapping("/api/comments/topic/$1")
- public String listComments(int tid) {
- //根据topic id 返回topic的comment
- CommentService cs = new CommentService();
- ArrayList<Comment> result = cs.getTopicByID(tid);
- return JSON.toJSONString(result);
- }
- @Mapping("/api/comment_post")
- public String postComment() {
- return "";
- }
- @Mapping("/api/comment_delete")
- public String deleteComment() {
- return "";
- }
- @Mapping("/api/my_information")
- public String getMyInformation() {
- return "";
- }
- @Mapping("/api/my_information_update")
- public String updateMyInformation() {
- return "";
- }
- @Mapping("/api/favorites/$1")
- public String listFavorites(int uid) {
- FavoritesService fs = new FavoritesService();
- ArrayList<Favorite> result = fs.getUserFavorites(uid);
- return JSON.toJSONString(result);
- }
- @Mapping("/api/favorite_add")
- public String addFavorite() {
- return "";
- }
- @Mapping("/api/favorite_delete")
- public String deleteFavorite() {
- return "";
- }
- @Mapping("/api/friends/$1")
- public String listFriends(int uid) {
- FriendsService fs = new FriendsService();
- ArrayList<User> result = fs.getFriends(uid);
- return JSON.toJSONString(result);
- }
- @Mapping("/api/friend_add")
- public String addFriend() {
- return "";
- }
- @Mapping("/api/friend_delete")
- public String deleteFriend() {
- return "";
- }
- @Mapping("/api/friend_update")
- public String updateFriend() {
- return "";
- }
- @Mapping("/api/messages/$1")
- public String listMessages(int uid) {
- // 返回用户的所有留言
- MesssageService ms = new MesssageService();
- ArrayList<Message> result = ms.getUserMessage(uid);
- return JSON.toJSONString(result);
- }
- @Mapping("/api/message_post")
- public String postMessage() {
- return "";
- }
- @Mapping("/api/message_delete")
- public String deleteMessage() {
- return "";
- }
- @Mapping("/api/level_credit")
- public String getLevelCredit() {
- return "";
- }
- @Mapping("/api/level_credit_update")
- public String updateLevelCredit() {
- return "";
- }
- @Mapping("/api/exchanges")
- public String listExchanges() {
- return "";
- }
- @Mapping("/api/exchange_add")
- public String addExchange() {
- return "";
- }
- @Mapping("/api/exchange_update")
- public String updateExchange() {
- return "";
- }
- @Mapping("/api/exchange_delete")
- public String deleteExchange() {
- return "";
- }
- @Mapping("/api/informations")
- public String listInformations() {
- return "";
- }
- @Mapping("/api/information_add")
- public String addInformation() {
- return "";
- }
- @Mapping("/api/information_update")
- public String updateInformation() {
- return "";
- }
- @Mapping("/api/information_delete")
- public String deleteInformatione() {
- return "";
- }
-
- /**
- *
- * 函数功能∶ 查询指定ID用户信息<br/>
- * 开发人员: @author Left <br/>
- * 创建时间:2013-3-25下午6:20:08 <br/>
- * 相关参数:<br/>
- * @param id
- * @return<br/>
- * 修改记录∶ <br/>
- *
- */
- @Mapping("/api/user/$1")
- public String getUserInfoByID(int id){
- UserService us = new UserService();
- User user = us.selectUserByID(id);
- return JSON.toJSONString(user);
- }
-
-
- @Mapping("/api/reg")
- public String regUser(){
- HttpServletRequest request = ActionContext.getActionContext().getHttpServletRequest();
-
- User user = new User();
- user.setEmail(request.getParameter("email"));
- user.setName(request.getParameter("name"));
- user.setPassword(request.getParameter("password"));
- user.setLocation(request.getParameter("location"));
- user.setMobile(request.getParameter("mobile"));
- user.setAvatarUrl(request.getParameter("avatarUrl"));
-
- if(StringUtils.isNotBlank(request.getParameter("gender"))){
- user.setGender(Integer.parseInt(request.getParameter("gender")));
- }
- if(StringUtils.isNotBlank(request.getParameter("registerNo"))){
- user.setRegisterNo(Integer.parseInt(request.getParameter("registerNo")));
- }
- UserService us = new UserService();
- HashMap result = new HashMap();
-
- if(us.checkUserIsUseable(user)){
- try {
- user = us.regUser(user);
- } catch (Exception e) {
- e.printStackTrace();
- result.put("message_type", 1);
- result.put("message", "未知错误,注册失败");
- result.put("register_no", -1);
- }
- result.put("message_type", 0);
- result.put("message", "注册成功");
- //TODO: register_no ? 现在返回user的id
- result.put("register_no", user.getId()); //
- }else{
- result.put("message_type", 1);
- result.put("message", "账号被已占用,注册失败");
- result.put("register_no", -1);
- }
- return JSON.toJSONString(result);
- }
-
- }