1 64 65 package com.jcorporate.expresso.services.dbobj; 66 67 import com.jcorporate.expresso.core.db.DBException; 68 import com.jcorporate.expresso.core.dbobj.DBField; 69 import com.jcorporate.expresso.core.dbobj.DBObject; 70 71 82 public class RowGroupPerms extends DBObject { 83 84 public static final String GROUP_PERMISSIONS_TABLE_NAME = "ROW_GRP_PERMS"; 85 88 public static final String TABLE_NAME = "TARGET_TABLE"; 89 90 93 public static final String ROW_KEY = "ROW_KEY"; 94 95 96 99 public static final String GROUP = "PERM_GROUP"; 100 101 102 106 public static final String PERMISSIONS = "PERMISSIONS"; 107 108 111 public RowGroupPerms() throws DBException { 112 } 113 114 119 public RowGroupPerms(String table, String rowKey) throws DBException { 120 if (rowKey == null) { 122 throw new DBException("null row key"); 123 } 124 if (table == null) { 125 throw new DBException("null table name"); 126 } 127 128 if ((rowKey.length() + table.length()) > RowPermissions.sMaxKeyLen) { 129 throw new DBException("Cannot create row permissions for table: " 130 + this.getJDBCMetaData().getTargetTable() + " row: " + rowKey 131 + " because table name + row's ID (PK) exceeds maximum of " + RowPermissions.sMaxKeyLen); 132 } 133 134 setField(TABLE_NAME, table); 135 setField(ROW_KEY, rowKey); 136 } 137 138 144 public RowGroupPerms(String table, String rowKey, String grp) throws DBException { 145 if (rowKey == null) { 147 throw new DBException("null row key"); 148 } 149 if (table == null) { 150 throw new DBException("null table name"); 151 } 152 153 if (grp == null) { 154 throw new DBException("null grp name"); 155 } 156 157 if ((rowKey.length() + table.length() + grp.length()) > RowPermissions.sMaxKeyLen) { 158 throw new DBException("Cannot create row permissions for table: " 159 + this.getJDBCMetaData().getTargetTable() + " row: " + rowKey 160 + " because table name + row's ID (PK) exceeds maximum of " + RowPermissions.sMaxKeyLen); 161 } 162 163 setField(TABLE_NAME, table); 164 setField(ROW_KEY, rowKey); 165 setField(GROUP, grp); 166 } 167 168 172 public RowGroupPerms(RowGroupPerms model) throws DBException { 173 this(model.table(), model.getKey()); 174 group(model.group()); 175 permissions(model.permissions()); 176 } 177 178 181 public boolean canGroupAdministrate() throws DBException { 182 return (RowPermissions.GROUP_PERMISSION_MASK & permissions()) == RowPermissions.GROUP_PERMISSION_MASK; 183 } 184 185 188 public boolean canGroupRead() throws DBException { 189 return (RowPermissions.GROUP_READ_MASK & permissions()) == RowPermissions.GROUP_READ_MASK; 190 } 191 192 195 public boolean canGroupWrite() throws DBException { 196 return (RowPermissions.GROUP_WRITE_MASK & permissions()) == RowPermissions.GROUP_WRITE_MASK; 197 } 198 199 200 205 protected synchronized void setupFields() throws DBException { 206 setTargetTable(GROUP_PERMISSIONS_TABLE_NAME); 207 setDescription("RowGroupPermissons"); 208 addField(TABLE_NAME, DBField.VARCHAR_TYPE, 209 RowPermissions.MAX_TABLE_NAME_LENGTH, false, "Targettablename"); 210 213 addField(ROW_KEY, RowPermissions.sKeyType, RowPermissions.sMaxKeyLen, false, "Rowkey"); 214 addField(GROUP, DBField.CHAR_TYPE, UserGroup.GROUP_NAME_MAX_LEN, false, "Group"); 215 addField(PERMISSIONS, DBField.INT_TYPE, 0, true, "Permissionbits"); 216 217 addKey(TABLE_NAME); 218 addKey(ROW_KEY); 219 addKey(GROUP); 220 221 addIndex("tablerow", TABLE_NAME + "," + ROW_KEY, false); 222 } 223 224 225 228 public String group() throws DBException { 229 return this.getField(GROUP); 230 } 231 232 241 public void group(String group) throws DBException { 242 if (group == null) { 243 throw new DBException("null group name"); 244 } 245 246 String tablename = getField(TABLE_NAME); 247 String rowKey = getField(ROW_KEY); 248 if (tablename.length() + rowKey.length() + group.length() > RowPermissions.sMaxKeyLen) { 249 throw new DBException("Cannot create group row permissions for table: " 250 + tablename + ", row: " + rowKey 251 + ", group: " + group 252 + " because table name + rowKey + group exceeds maximum of " + RowPermissions.sMaxKeyLen); 253 } 254 setField(GROUP, group); 255 } 256 257 263 public void setDefaultPermissions() throws DBException { 264 permissions(RowPermissions.DEFAULT_PERMISSIONS); 265 group(RowPermissions.DEFAULT_PERMISSION_GROUP); 266 } 267 268 269 275 public void permissions(int perm) throws DBException { 276 setField(PERMISSIONS, perm); 277 } 278 279 285 public int permissions() throws DBException { 286 if (getField(PERMISSIONS).length() == 0) { 288 return 0; 289 } 290 return getFieldInt(PERMISSIONS); 291 } 292 293 298 public String table() throws DBException { 299 return getField(TABLE_NAME); 300 } 301 302 305 public void table(String targetTable) throws DBException { 306 setField(TABLE_NAME, targetTable); 307 } 308 309 312 public String key() throws DBException { 313 return getField(ROW_KEY); 314 } 315 316 319 public void key(String key) throws DBException { 320 setField(ROW_KEY, key); 321 } 322 } 323 | Popular Tags |