Source code: org/mitre/cvw/CVWRoom.java
1 /*
2 * Copyright (c) 1996-2000. The MITRE Corporation (http://www.mitre.org/).
3 * All rights reserved.
4 * CVW comes with ABSOLUTELY NO WARRANTY. See license for details.
5 */
6
7 package org.mitre.cvw;
8
9 import java.util.*;
10
11 /**
12 * This class represents a room on the CVW server.
13 * @version
14 * @author Deb Ercolini
15 */
16 public class CVWRoom extends CVWContainer {
17
18 transient CVWObjNum floor;
19
20
21 /**
22 * Constructor
23 */
24 public CVWRoom() {
25 super(CVWObject.ROOM);
26 }
27
28 /**
29 * Constructor
30 * @param flr the object number for the floor this room is on
31 */
32 public CVWRoom(String flr) {
33 super(CVWObject.ROOM);
34 if (flr != null)
35 floor = new CVWObjNum(flr);
36 }
37
38 public CVWFloor getFloor() {
39 if (floor == null)
40 return null;
41 return (CVWFloor)CVWCache.getInstance().get(floor);
42 }
43
44 /**
45 * Move the user to this room.
46 *
47 * @see CVWRoom
48 */
49 public void moveTo() {
50 CVWCoordinator.getInstance().moveTo("destination: " + getObjNumStr());
51 }
52
53 /**
54 * Sends the owner access list to the CVW server when the user has changed
55 * the permissions of this object.
56 * Invoked when the user changes the access to this object which are users
57 * who are allowed in the room.
58 * 9/5/97
59 * <br> MCP send cvw-access-set-acl
60 * @param u vector of CVWObjects (CVWUsers)
61 * @param g vector of CVWObjects (CVWGroups)
62 */
63 public void updateACL(Vector u, Vector g) {
64 if (typeValue != ROOM) {
65 System.err.println("err no acl: " + objNum.strValue());
66 return;
67 }
68
69 //System.err.println("update acl: " + u.size() + " " + g.size());
70 Vector newV = buildObjNumStrVector(u, g);
71 String newACL = newObjNumString(contents, newV);
72 if (newACL == null)
73 return;
74 //System.err.println("#$#cvw-access-set-acl " +
75 CVWServerComm.sendMCPCmdToServer("#$#cvw-access-set-acl",
76 "object: " + objNum.strValue() +
77 " acl: " + newACL);
78 }
79
80 /**
81 * Processes the results of the setting the the acl of the object.
82 * This is currently only used by CVWRoom.
83 * <br> MCP receive cvw-access-set-acl-result
84 *
85 * @param err the error code from the CVW server, 0 denotes no error
86 * @param aclList space delimited list of object numbers sent to the CVW server
87 */
88 public void updateACLResult(String err, String aclList) {
89 System.err.println("error in updateACL: " + err);
90 }
91
92 /**
93 * Returns the title of the third tabbed panel in the get info dialog box,
94 * "e;Access"e;.
95 * @return "e;Access"e;
96 */
97 public String has3rdPanel() {
98 return "Access";
99 }
100
101 /**
102 * Returns an instance of the ObjectOwnerPanel which will be the third
103 * tab in a get info dialog box. This is the panel where the users who
104 * are allowed in this room are displayed.
105 *
106 * @param diag the parent window the panel will go in
107 * @param perms whether the current user has permissions to edit this group
108 * @return the third tabbed panel in the get info dialog box
109 *
110 * @see ObjectAccessPanel
111 */
112
113 public ObjectOwnerPanel get3rdPanel(FolderDialog diag, String perms) {
114 return new ObjectAccessPanel(this, diag, perms);
115 }
116
117 /**
118 * Opens this room with the Access panel open, who can enter the room.
119 * @see #startInfoDialog
120 */
121 public void startOpen() {
122 startInfoDialog(ACL);
123 }
124
125 /**
126 * Opens this room get info dialog box to the appropriate panel showing.
127 * <br> MCP send cvw-object-info-request
128 * <br> MCP send cvw-access-get-acl
129 * @param metaDataType the panel to open the dialog box to
130 */
131 public void startInfoDialog(int metaDataType) {
132 super.startInfoDialog(metaDataType);
133 CVWServerComm.sendMCPCmdToServer("#$#cvw-access-get-acl", "object: " + getObjNumStr());
134 }
135
136 /********* admit user to this room methods ********/
137
138 /**
139 * Process a request from another user for the current user to come to this locked room.
140 * User has a choice to either accept and go now, accept and go later, or decline.
141 * <br> MCP receive cvw-access-admit-request
142 * @param mcp the MCPCommand sent from the CVW server
143 */
144 public void requestAdmitUserCommand(MCPCommand mcp) {
145 String from = mcp.get("from");
146 String start = mcp.get("start");
147 String expire = mcp.get("expire");
148 CVWObject user = CVWCache.getInstance().get(from);
149 if (user != null)
150 from= user.name;
151 boolean delayAcceptOnly = false; //only show delay accept button
152 long startL = 0;
153 String time = "now";
154 Date startDate;
155 if (start.equals("0")) { // now
156 startDate = new Date();
157 startL = startDate.getTime();
158 }
159 else {
160 startL = DateUtils.convertDateFromServer(start);
161 startDate = new Date(startL);
162 //time = startDate.toString();
163 time = DateUtils.formatDateTime(startDate);
164 delayAcceptOnly = true;
165 }
166 long expireL = DateUtils.convertDateFromServer(expire);
167 float durL = (float)(expireL - startL) / 3600;
168 durL /= 1000;
169 int duration = Math.round(durL);
170 String hours = " hours";
171 if (duration == 1)
172 hours = " hour";
173 String msg = from+ " is requesting your presence in room \"" + name + "\".";
174 msg = msg + " This is valid for " + duration + hours + " starting " + time + ".";
175 jcvw.displayPrvSysMsg(msg);
176 AdmitRequestDialog request = new AdmitRequestDialog(jcvw, msg, false, delayAcceptOnly, mcp);
177 request.pack();
178 request.setVisible(true);
179 }
180
181
182 /**
183 * Process result of this user requesting another user's presense in this room.
184 * <br> MCP receive cvw-access-admit-request-result
185 * @param mcp the MCPCommand sent from the CVW server
186 */
187 public void requestAdmitUserResult(MCPCommand mcp) {
188 String error = mcp.get("error");
189 int err;
190 String msg;
191 try {
192 err = Integer.parseInt(error);
193 } catch (Exception e) {
194 System.err.println(e);
195 err = 99;
196 }
197 String user = mcp.get("user");
198 if (err != 10) { //name is not a valid user
199 CVWObject obj = CVWCache.getInstance().get(user);
200 if (obj != null)
201 user = obj.name;
202 }
203 boolean prob = false;
204 switch(err) {
205 case 0:
206 msg = user + " accepted your invitation.";
207 break;
208
209 case 1:
210 msg = user + " declined your invitation.";
211 break;
212 case 2:
213 msg = user + " did not respond to your invitation.";
214 break;
215 case 3:
216 msg = user + " did not get your invitiation because " + user +
217 " is currently busy " + mcp.get("message");
218 break;
219 case 4:
220 msg = user + " is not connected.";
221 break;
222 case 5:
223 msg = user + " accepted your invitation, will join you later.";
224 break;
225 case 6:
226 msg = user + " is running a client that doesn't support locked room access.";
227 break;
228 case 7:
229 prob = true;
230 msg = "You do not have permission to admit anyone into this room.";
231 break;
232 case 8:
233 msg = user + " accepted your invitation. (This room is public)";
234 break;
235 case 9:
236 msg = user + " accepted your invitation, will join you later. (This room is public)";
237 break;
238 case 10:
239 prob = true;
240 msg = user + " is not a valid user name.";
241 break;
242 default:
243 prob = true;
244 msg = "Unknown server error: " + error;
245 }
246
247 if (prob)
248 jcvw.displayScrollbackError(msg);
249 else
250 jcvw.displayPrvSysMsg(msg);
251 }
252
253 /**
254 * Processes a key to this room being automatically revoked from the CVW server
255 * because it has expired.
256 * @param key the object number of the room key
257 * @param when the date time stamp of when the server revoked it (long int)
258 */
259 public void revokeAdmitKey(String key, String when) {
260 CVWObject kObj = CVWCache.getInstance().get(key);
261 if (kObj != null)
262 key = kObj.name;
263 jcvw.displayPrvSysMsg("Your access key \"" + key + "\" to room \"" + name + "\" has been revoked.");
264 }
265
266 /********* end admit user to this room methods ********/
267
268 /**
269 * Returns a string representing the state of this component.
270 *
271 * @return a string representation of this component's state.
272 */
273 public String paramString() {
274 return (super.paramString() +
275 ",floor=" + floor.strValue());
276 }
277
278 }
279