1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.controller.ControllerRequest; 68 import com.jcorporate.expresso.core.db.DBConnection; 69 import com.jcorporate.expresso.core.db.DBException; 70 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 71 import com.jcorporate.expresso.core.i18n.Messages; 72 73 import java.util.Iterator ; 74 import java.util.List ; 75 import java.util.Vector ; 76 77 78 85 public class UserGroup 86 extends SecurityDBObject { 87 88 public static final String GROUP_NAME_FIELD = "GroupName"; 89 public static final String GROUP_DESCRIPTION = "Descrip"; 90 public static final int GROUP_NAME_MAX_LEN = 10; 91 public static final int GROUP_DESCRIP_MAX_LEN = 80; 92 public static final String TABLE_NAME = "USERROLES"; 93 94 100 public static final String ALL_USERS_GROUP = "Everybody"; 101 public static final String DEMO_GROUP = "Demo"; 102 103 106 public static final String UNKNOWN_USERS_GROUP = "Nobody"; 107 public static final String NOT_REG_USERS_GROUP = "NotReg"; 108 public static final String ADMIN_GROUP = "Admin"; 109 110 111 116 public UserGroup() throws DBException { 117 } 118 119 125 public UserGroup(int uid) throws DBException { 126 super(uid); 127 } 128 129 135 public UserGroup(ControllerRequest request) throws DBException { 136 super(request); 137 } 138 139 144 public UserGroup(DBConnection localConnection) throws DBException { 145 if (localConnection != null) { 146 setConnection(localConnection); 147 } 148 } 149 150 155 protected void checkAllReferredToBy() 156 throws DBException { 157 referredToBy(new DBObjSecurity(SecuredDBObject.SYSTEM_ACCOUNT), 158 GROUP_NAME_FIELD, 159 "This Group (" + getField(GROUP_NAME_FIELD) + 160 ") is in use by a Database Object security entry"); 161 referredToBy(new ControllerSecurity(SecuredDBObject.SYSTEM_ACCOUNT), 162 GROUP_NAME_FIELD, 163 "This Group (" + getField(GROUP_NAME_FIELD) + 164 ") is in use by a Controller security entry"); 165 referredToBy(new JobSecurity(SecuredDBObject.SYSTEM_ACCOUNT), 166 GROUP_NAME_FIELD, 167 "This Group (" + getField(GROUP_NAME_FIELD) + 168 ") is in use by a Job security entry"); 169 referredToBy(new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT), 170 GROUP_NAME_FIELD, 171 "This Group (" + getField(GROUP_NAME_FIELD) + 172 ") still has members "); 173 referredToBy(new GroupNest(SecuredDBObject.SYSTEM_ACCOUNT), 174 GroupNest.FLD_GROUPNAME, 175 "This Group (" + getField(GROUP_NAME_FIELD) + 176 ") is in use by a Group Member Nesting entry"); 177 referredToBy(new GroupNest(SecuredDBObject.SYSTEM_ACCOUNT), 178 GroupNest.FLD_MEMBEROF, 179 "This Group (" + getField(GROUP_NAME_FIELD) + 180 ") is in use by a Group Member Nesting entry"); 181 } 182 183 184 188 public void delete() 189 throws DBException { 190 GroupMembers groupMList = new GroupMembers(SecuredDBObject.SYSTEM_ACCOUNT); 191 groupMList.setDataContext(getDataContext()); 192 groupMList.setField(GROUP_NAME_FIELD, getField(GROUP_NAME_FIELD)); 193 194 GroupMembers groupM = null; 195 196 for (Iterator e = groupMList.searchAndRetrieveList().iterator(); 197 e.hasNext();) { 198 groupM = (GroupMembers) e.next(); 199 groupM.delete(); 200 } 201 202 super.delete(); 203 } 204 205 206 209 protected synchronized void setupFields() 210 throws DBException { 211 setTargetTable(TABLE_NAME); 212 setDescription("DBuserGroup"); 213 setCharset("ISO-8859-1"); 214 addField(GROUP_NAME_FIELD, "char", GROUP_NAME_MAX_LEN, false, "groupName"); 215 addField(GROUP_DESCRIPTION, "varchar", GROUP_DESCRIP_MAX_LEN, true, "groupDescrip"); 216 addField("LoginEvent", "char", 30, true, "loginEvent"); 217 setStringFilter(GROUP_NAME_FIELD, "stripFilter"); 218 setStringFilter("LoginEvent", "stripFilter"); 219 setStringFilter(GROUP_DESCRIPTION, "standardFilter"); 220 addKey(GROUP_NAME_FIELD); 221 setLookupObject("LoginEvent", 222 "com.jcorporate.expresso.services.dbobj.Event"); 223 addDetail("com.jcorporate.expresso.services.dbobj.GroupMembers", 224 GROUP_NAME_FIELD, GROUP_NAME_FIELD); 225 } 226 227 228 234 public Vector getValues() 235 throws DBException { 236 return getValuesDefault(GROUP_NAME_FIELD, GROUP_DESCRIPTION); 237 } 238 239 240 243 public synchronized void populateDefaultValues() 244 throws DBException { 245 UserGroup oneGroup = new UserGroup(); 246 oneGroup.setDataContext(getDataContext()); 247 oneGroup.setField(GROUP_NAME_FIELD, DEMO_GROUP); 248 249 if (!oneGroup.find()) { 250 oneGroup.setField(GROUP_NAME_FIELD, DEMO_GROUP); 251 oneGroup.setField(GROUP_DESCRIPTION, "Demonstration Group"); 252 oneGroup.add(); 253 } 254 255 oneGroup.clear(); 256 oneGroup.setField(GROUP_NAME_FIELD, ALL_USERS_GROUP); 257 258 if (!oneGroup.find()) { 259 oneGroup.setField(GROUP_NAME_FIELD, ALL_USERS_GROUP); 260 oneGroup.setField(GROUP_DESCRIPTION, Messages.getString("All_Users")); 261 oneGroup.add(); 262 } 263 } 264 265 271 public String getGroupName() throws DBException { 272 return getField(GROUP_NAME_FIELD); 273 } 274 275 281 public void setGroupName(String groupName) throws DBException { 282 setField(GROUP_NAME_FIELD, groupName); 283 } 284 285 290 public static UserGroup getGroup(String groupname) throws DBException { 291 UserGroup result = null; 292 if (groupname != null && groupname.length() > 0) { 293 UserGroup oneGroup = new UserGroup(); 294 oneGroup.setDBName(DBConnection.DEFAULT_DB_CONTEXT_NAME); 295 oneGroup.setGroupName(groupname); 296 if (oneGroup.find()) { 297 result = oneGroup; 298 } 299 } 300 301 return result; 302 } 303 304 310 public String getGroupDescription() throws DBException { 311 return getField(GROUP_DESCRIPTION); 312 } 313 314 319 public static List getAllGroups() throws DBException { 320 UserGroup search = new UserGroup(); 321 return search.searchAndRetrieveList(); 322 } 323 } | Popular Tags |