Advertisement
Guest User

Untitled

a guest
Mar 8th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. package com.mycompany.samplehospital.model;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import javax.xml.bind.annotation.XmlElement;
  6. import javax.xml.bind.annotation.XmlRootElement;
  7.  
  8. /**
  9. *
  10. * @author sandeshpoudel
  11. */
  12. @XmlRootElement
  13. public class ChatBox {
  14. private String chatName;
  15. private String Password;
  16. private Integer chatBoxId;
  17.  
  18. private ArrayList<User>AllowedUser;
  19.  
  20. public ChatBox(Integer id,String chatName, String Password, ArrayList<User> Users) {
  21. this.chatName = chatName;
  22. this.Password = Password;
  23. setChatBoxId(id);
  24. this.AllowedUser = Users;
  25.  
  26.  
  27. }
  28.  
  29. public ChatBox() {
  30. }
  31.  
  32.  
  33. @XmlElement
  34. public String getChatName() {
  35. return chatName;
  36. }
  37.  
  38. public void setChatName(String chatName) {
  39. this.chatName = chatName;
  40. }
  41. @XmlElement
  42. public String getPassword() {
  43. return Password;
  44. }
  45.  
  46. public void setPassword(String Password) {
  47. this.Password = Password;
  48. }
  49. @XmlElement
  50. public Integer getChatBoxId() {
  51. return chatBoxId;
  52. }
  53.  
  54. public void setChatBoxId(Integer id) {
  55. this.chatBoxId=id;
  56.  
  57.  
  58. }
  59. @XmlElement
  60. public ArrayList<User> getUsers() {
  61. return AllowedUser;
  62. }
  63.  
  64. public void setUsers(ArrayList<User> Users) {
  65. this.AllowedUser = Users;
  66. }
  67.  
  68.  
  69. }
  70.  
  71. package com.mycompany.samplehospital.Services;
  72.  
  73. import com.mycompany.samplehospital.model.ChatBox;
  74. import com.mycompany.samplehospital.model.User;
  75. import java.util.ArrayList;
  76. import java.util.List;
  77. import java.util.Map;
  78.  
  79. /**
  80. *
  81. * @author sandeshpoudel
  82. */
  83. public class ChatBoxServices {
  84.  
  85. private static final long serialVersionUID = 1L;
  86. private static final Map<Integer, User> users = AllServices.getUsers();
  87. private static final Map<Integer, ChatBox> chatBoxList = AllServices.getChatBox();
  88. ArrayList<User> userList ;
  89.  
  90. public ChatBoxServices() throws Exception {
  91. userList= (ArrayList<User>) UserServices.getUsers();
  92. chatBoxList.put(1, new ChatBox(1,"case1", "case1password", userList));
  93. chatBoxList.put(2, new ChatBox(2,"case2", "case2password", userList));
  94. }
  95.  
  96. public static List<ChatBox> getAllChatBOx() {
  97. return new ArrayList<>(chatBoxList.values());
  98.  
  99. }
  100.  
  101. public ChatBox getChatBox(int id) {
  102. return chatBoxList.get(id);
  103. }
  104.  
  105. public static ChatBox addChatBox(ChatBox chatBox) {
  106. Integer size =chatBoxList.size();
  107. chatBox.setChatBoxId(size+1);
  108.  
  109. chatBoxList.put(chatBox.getChatBoxId(), chatBox);
  110. return chatBox;
  111.  
  112. }
  113.  
  114. public ChatBox updateChatBox(ChatBox chatBox) {
  115. if (chatBox.getChatBoxId() < 1) {
  116. return null;
  117. }
  118. chatBoxList.put(chatBox.getChatBoxId(), chatBox);
  119. return chatBox;
  120. }
  121.  
  122. public ChatBox removeChatBox(Integer id) {
  123. return chatBoxList.remove(id);
  124. }
  125.  
  126. }
  127.  
  128. package com.mycompany.samplehospital.resources;
  129.  
  130. import com.mycompany.samplehospital.Services.ChatBoxServices;
  131. import com.mycompany.samplehospital.exception.objectNotFound;
  132. import com.mycompany.samplehospital.model.ChatBox;
  133. import java.util.List;
  134. import javax.ws.rs.Consumes;
  135. import javax.ws.rs.DELETE;
  136. import javax.ws.rs.GET;
  137. import javax.ws.rs.POST;
  138. import javax.ws.rs.PUT;
  139. import javax.ws.rs.Path;
  140. import javax.ws.rs.PathParam;
  141. import javax.ws.rs.Produces;
  142. import javax.ws.rs.core.MediaType;
  143.  
  144. /**
  145. *
  146. * @author sandeshpoudel
  147. */
  148. @Path("/chatbox")
  149. public class ChatBoxResources {
  150.  
  151. ChatBoxServices chatService;
  152.  
  153. public ChatBoxResources() throws Exception {
  154. this.chatService = new ChatBoxServices();
  155. }
  156.  
  157. @GET
  158. @Produces(MediaType.APPLICATION_XML)
  159. public List<ChatBox> getAllChatBOx() {
  160. return ChatBoxServices.getAllChatBOx();
  161.  
  162. }
  163.  
  164. @Path("/{ChatBoxId}")
  165.  
  166. @GET
  167. @Produces(MediaType.APPLICATION_XML)
  168. public ChatBox getAlert(@PathParam("ChatBoxId") int ID) {
  169.  
  170. ChatBox newChatBOx = chatService.getChatBox(ID);
  171. if (newChatBOx == null) {
  172. throw new objectNotFound("chat room not Found");
  173.  
  174. }
  175. return newChatBOx;
  176.  
  177. }
  178.  
  179. @POST
  180. @Produces(MediaType.APPLICATION_XML)
  181. @Consumes(MediaType.APPLICATION_XML)
  182.  
  183. public ChatBox addBox(ChatBox chat) {
  184.  
  185. return ChatBoxServices.addChatBox(chat);
  186.  
  187. }
  188.  
  189. @PUT
  190. @Path("/{BoxId}")
  191.  
  192. @Produces(MediaType.APPLICATION_XML)
  193. @Consumes(MediaType.APPLICATION_XML)
  194.  
  195. public ChatBox updtaeUser(ChatBox chat) {
  196. ChatBox newBox = chatService.getChatBox(chat.getChatBoxId());
  197. if (newBox == null) {
  198. throw new objectNotFound(" chat box not Found");
  199.  
  200. }
  201.  
  202. return chatService.getChatBox(newBox.getChatBoxId());
  203.  
  204. }
  205.  
  206. @DELETE
  207. @Path("/{BOxId}")
  208. @Produces(MediaType.APPLICATION_XML)
  209.  
  210. public List<ChatBox> delBOx(@PathParam("BOxId") int ID) {
  211. chatService.removeChatBox(ID);
  212. return ChatBoxServices.getAllChatBOx();
  213.  
  214. }
  215.  
  216. }
  217.  
  218. <chatBoxes>
  219. <chatBox>
  220. <chatBoxId>1</chatBoxId>
  221. <chatName>case1</chatName>
  222. <password>case1password</password>
  223. </chatBox>
  224. <chatBox>
  225. <chatBoxId>2</chatBoxId>
  226. <chatName>case2</chatName>
  227. <password>case2password</password>
  228. </chatBox>
  229. </chatBoxes>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement