Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mycompany.samplehospital.model;
- import java.util.ArrayList;
- import java.util.List;
- import javax.xml.bind.annotation.XmlElement;
- import javax.xml.bind.annotation.XmlRootElement;
- /**
- *
- * @author sandeshpoudel
- */
- @XmlRootElement
- public class ChatBox {
- private String chatName;
- private String Password;
- private Integer chatBoxId;
- private ArrayList<User>AllowedUser;
- public ChatBox(Integer id,String chatName, String Password, ArrayList<User> Users) {
- this.chatName = chatName;
- this.Password = Password;
- setChatBoxId(id);
- this.AllowedUser = Users;
- }
- public ChatBox() {
- }
- @XmlElement
- public String getChatName() {
- return chatName;
- }
- public void setChatName(String chatName) {
- this.chatName = chatName;
- }
- @XmlElement
- public String getPassword() {
- return Password;
- }
- public void setPassword(String Password) {
- this.Password = Password;
- }
- @XmlElement
- public Integer getChatBoxId() {
- return chatBoxId;
- }
- public void setChatBoxId(Integer id) {
- this.chatBoxId=id;
- }
- @XmlElement
- public ArrayList<User> getUsers() {
- return AllowedUser;
- }
- public void setUsers(ArrayList<User> Users) {
- this.AllowedUser = Users;
- }
- }
- package com.mycompany.samplehospital.Services;
- import com.mycompany.samplehospital.model.ChatBox;
- import com.mycompany.samplehospital.model.User;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- /**
- *
- * @author sandeshpoudel
- */
- public class ChatBoxServices {
- private static final long serialVersionUID = 1L;
- private static final Map<Integer, User> users = AllServices.getUsers();
- private static final Map<Integer, ChatBox> chatBoxList = AllServices.getChatBox();
- ArrayList<User> userList ;
- public ChatBoxServices() throws Exception {
- userList= (ArrayList<User>) UserServices.getUsers();
- chatBoxList.put(1, new ChatBox(1,"case1", "case1password", userList));
- chatBoxList.put(2, new ChatBox(2,"case2", "case2password", userList));
- }
- public static List<ChatBox> getAllChatBOx() {
- return new ArrayList<>(chatBoxList.values());
- }
- public ChatBox getChatBox(int id) {
- return chatBoxList.get(id);
- }
- public static ChatBox addChatBox(ChatBox chatBox) {
- Integer size =chatBoxList.size();
- chatBox.setChatBoxId(size+1);
- chatBoxList.put(chatBox.getChatBoxId(), chatBox);
- return chatBox;
- }
- public ChatBox updateChatBox(ChatBox chatBox) {
- if (chatBox.getChatBoxId() < 1) {
- return null;
- }
- chatBoxList.put(chatBox.getChatBoxId(), chatBox);
- return chatBox;
- }
- public ChatBox removeChatBox(Integer id) {
- return chatBoxList.remove(id);
- }
- }
- package com.mycompany.samplehospital.resources;
- import com.mycompany.samplehospital.Services.ChatBoxServices;
- import com.mycompany.samplehospital.exception.objectNotFound;
- import com.mycompany.samplehospital.model.ChatBox;
- import java.util.List;
- import javax.ws.rs.Consumes;
- import javax.ws.rs.DELETE;
- import javax.ws.rs.GET;
- import javax.ws.rs.POST;
- import javax.ws.rs.PUT;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.Produces;
- import javax.ws.rs.core.MediaType;
- /**
- *
- * @author sandeshpoudel
- */
- @Path("/chatbox")
- public class ChatBoxResources {
- ChatBoxServices chatService;
- public ChatBoxResources() throws Exception {
- this.chatService = new ChatBoxServices();
- }
- @GET
- @Produces(MediaType.APPLICATION_XML)
- public List<ChatBox> getAllChatBOx() {
- return ChatBoxServices.getAllChatBOx();
- }
- @Path("/{ChatBoxId}")
- @GET
- @Produces(MediaType.APPLICATION_XML)
- public ChatBox getAlert(@PathParam("ChatBoxId") int ID) {
- ChatBox newChatBOx = chatService.getChatBox(ID);
- if (newChatBOx == null) {
- throw new objectNotFound("chat room not Found");
- }
- return newChatBOx;
- }
- @POST
- @Produces(MediaType.APPLICATION_XML)
- @Consumes(MediaType.APPLICATION_XML)
- public ChatBox addBox(ChatBox chat) {
- return ChatBoxServices.addChatBox(chat);
- }
- @PUT
- @Path("/{BoxId}")
- @Produces(MediaType.APPLICATION_XML)
- @Consumes(MediaType.APPLICATION_XML)
- public ChatBox updtaeUser(ChatBox chat) {
- ChatBox newBox = chatService.getChatBox(chat.getChatBoxId());
- if (newBox == null) {
- throw new objectNotFound(" chat box not Found");
- }
- return chatService.getChatBox(newBox.getChatBoxId());
- }
- @DELETE
- @Path("/{BOxId}")
- @Produces(MediaType.APPLICATION_XML)
- public List<ChatBox> delBOx(@PathParam("BOxId") int ID) {
- chatService.removeChatBox(ID);
- return ChatBoxServices.getAllChatBOx();
- }
- }
- <chatBoxes>
- <chatBox>
- <chatBoxId>1</chatBoxId>
- <chatName>case1</chatName>
- <password>case1password</password>
- </chatBox>
- <chatBox>
- <chatBoxId>2</chatBoxId>
- <chatName>case2</chatName>
- <password>case2password</password>
- </chatBox>
- </chatBoxes>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement