Source code: org/mitre/cvw/CVWGroup.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 import javax.swing.JFrame;
11
12 /**
13 * This class represents the Group object on the CVW server.
14 * @version 1.0
15 * @author Deb Ercolini
16 */
17 public class CVWGroup extends CVWContainer {
18
19 String ownerName;
20 boolean systemAllUsers = false;
21
22 /**
23 * Constructor
24 */
25 CVWGroup() {
26 super(CVWObject.GROUP);
27 }
28
29 /**
30 * Opens the group for either editing or viewing depending on the perms sent in.
31 * @param perms either 0 or 1 ... 0 is not editable
32 * @param fullPath
33 */
34 public void open(String perms, String fullPath) {
35
36 if (fullPath != null && fullPath.equals("All users")) {
37 systemAllUsers = true;
38 setChanged();
39 notifyObservers("contents");
40 }
41 }
42
43 /**
44 * Returns the detail name of the group which is the ownerName.
45 * @return the ownerName of this group
46 */
47 public String getDetailName() {
48 return ownerName;
49 }
50
51 /**
52 * Returns the raw detail name of the group which is the ownerName.
53 * @return the ownerName of this group
54 */
55 public String getRawDetailName() {
56 return ownerName;
57 }
58
59 /**
60 * Sets the raw detail name of the group
61 * @param detailName the owner name of the group
62 */
63 public void setRawDetailName(String detailName) {
64 ownerName = detailName;
65 }
66
67 /* dage - returns vector of CVWObjects
68 * members of the group!!!
69 * 6/1/98 - user superclass method if not system users
70 */
71 /**
72 * If this is the "All Users" system group, return an empty vector,
73 * else call the superclass method.
74 * @return a vector of CVWObjects which is the contents of this group
75 */
76 public Vector getContents() {
77 if (systemAllUsers)
78 //return groupManager.getSystemUsers();
79 return new Vector(0);
80 else
81 return super.getContents();
82 }
83
84 /**
85 * Returns the title of the third tabbed panel in the get info dialog box,
86 * "e;Members"e;.
87 * @return "e;Members"e;
88 */
89 public String has3rdPanel() {
90 return "Members";
91 }
92
93 /**
94 * Returns an instance of the ObjectOwnerPanel which will be the third
95 * tab in a get info dialog box. This is the panel where the members of
96 * this group are displayed.
97 * @param diag the parent window the panel will go in
98 * @param perms whether the current user has permissions to edit this group
99 * @return the third tabbed panel in the get info dialog box
100 * @see ObjectAccessPanel
101 */
102 public ObjectOwnerPanel get3rdPanel(FolderDialog diag, String perms) {
103 return new ObjectAccessPanel(this, diag, perms);
104 }
105
106 /**
107 * Changes the members list of the group by sending an MCP to the CVW server.
108 * @param u a vector of CVWUsers
109 * @param g a vector of CVWGroups
110 */
111 public void updateMembers(Vector u, Vector g) {
112 // System.err.println("update owners: " + u.size() + " " + g.size());
113 Vector newV = buildObjNumStrVector(u, g);
114 Vector oldV = new Vector(contents.length);
115 String delStr = "", addStr = "";
116 for (int i = 0; i< contents.length; i++) {
117 oldV.addElement(contents[i].strValue());
118 }
119 String oNum;
120 for (int i=0;i<newV.size();i++) {
121 oNum = (String)newV.elementAt(i);
122 if (!oldV.contains(oNum))
123 addStr += oNum + " ";
124 }
125 for (int i=0;i<oldV.size();i++) {
126 oNum = (String)oldV.elementAt(i);
127 if (!newV.contains(oNum))
128 delStr += oNum + " ";
129 }
130
131 if (addStr.length() > 0) {
132 addStr = "\"" + addStr.trim() + "\"";
133 //System.err.println("#$#cvw-group-add-member " +
134 CVWServerComm.sendMCPCmdToServer("#$#cvw-group-add-member",
135 "group: " + objNum.strValue() +
136 " members: " + addStr);
137 }
138
139 if (delStr.length() > 0) {
140 delStr = "\"" + delStr.trim() + "\"";
141 //System.err.println("#$#cvw-group-del-member " +
142 CVWServerComm.sendMCPCmdToServer("#$#cvw-group-del-member",
143 "group: " + objNum.strValue() +
144 " members: " + delStr);
145 }
146
147 }
148
149 /**
150 * Processes the results from changing the members list on the CVW server.
151 * 9/5/97 dage --
152 * <br> MCP receive cvw-group-add-member-result
153 * <br> MCP receive cvw-group-del-member-result
154 * @param err 0 if no error
155 * @param type 0 for ADD and 1 for DEL
156 * @param memList the original list of object numbers sent to CVW server
157 * @param invalidList list of object numbers CVW server detected as invalid
158 * @param errList list of object numbers CVW server detected an error with
159 */
160 public void updateMembersResult(String err, int type, String memList, String invalidList, String errList) {
161 if (err.equals("0")) return;
162 int error = Integer.parseInt(err);
163 switch (error) {
164 case 1: //obj to be added was already a member
165 case 2: // no permission
166 case 3: // obj to be added is not a valid user/group
167 case 5: // group object is really not a group!!!
168 System.err.println("error in updateMembers: " + err);
169 break;
170 case 4: // group object has been deleted
171 CVWCoordinator jcvw = CVWCoordinator.getInstance();
172 java.awt.Frame f = getObjectFrame();
173 jcvw.displayError(f, "Group \""+ name + "\" no longer exists.", "Group Members Error");
174 GroupManager.getInstance().requestSystemGroups();
175 break;
176 }
177 }
178
179
180 public void startOpen() {
181 startInfoDialog(MEMBERS);
182 }
183
184 /**
185 * Upon creating an object, open it for the user automatically
186 *
187 * @see CVWObject#objectCreateResult
188 */
189 public void autoOpenObject() {
190 startOpen();
191 }
192
193
194 /**
195 * Starts the process of opening a get info dialog box. Sets the metaDataType
196 * so that when the CVW server sends MCP the correct tabbed panel will be in focus.
197 * <br> MCP send cvw-object-detail-request
198 *
199 * @param type metaDataType to denote which tabbed panel should be opened
200 *
201 * @see #getInfo
202 */
203 public void startInfoDialog (int type) {
204 super.startInfoDialog(type);
205 CVWServerComm.sendMCPCmdToServer("#$#cvw-object-open",
206 "object: " + objNum.strValue());
207 }
208
209
210 // RJT 9/2/98
211 /* 9/13/98 dage - moved from GroupMangerFrame object
212 */
213 /**
214 * Invokes the CVWGroupCommDialog for private communication to this group
215 * @param cvwCmd either CVWCommand.SAY_PRIVATE or CVWCommand.PAGE
216 * @see CVWGroupCommDialog
217 */
218 public void groupPage(int cvwCmd) {
219 //System.err.println( " in page " + cvwCmd);
220 if (WindowMgr.getWindowMgr().objectWindowExists("org.mitre.cvw.CVWGroupCommDialog", getObjNum()))
221 return;
222 java.awt.Frame f = getObjectFrame();
223 new CVWGroupCommDialog(f, this, cvwCmd);
224 }
225
226 /**
227 * Returns this group to the group manager.
228 */
229 public void returnToGroupMgr() {
230 returnToGroupMgr(null);
231 }
232
233 /**
234 * Returns this group to the group manager.
235 * @param frame the frame to display any error dialog to
236 */
237 public void returnToGroupMgr(JFrame frame) {
238 CVWObject grpM = GroupManager.getCVWGroupMgr(); //cache.get("#97");
239 if (grpM == null) {
240 System.err.println("Couldnt find Group Manager.");
241 return;
242 }
243 moveObject(grpM, frame);
244 }
245
246
247 }
248