1 40 package org.dspace.authorize; 41 42 import java.sql.SQLException ; 43 import java.util.Date ; 44 45 import org.dspace.content.DSpaceObject; 46 import org.dspace.core.Constants; 47 import org.dspace.core.Context; 48 import org.dspace.eperson.EPerson; 49 import org.dspace.eperson.Group; 50 import org.dspace.storage.rdbms.DatabaseManager; 51 import org.dspace.storage.rdbms.TableRow; 52 53 59 public class ResourcePolicy 60 { 61 62 private Context myContext; 63 64 65 private TableRow myRow; 66 67 75 ResourcePolicy(Context context, TableRow row) 76 { 77 myContext = context; 78 myRow = row; 79 } 80 81 91 public static ResourcePolicy find(Context context, int id) 92 throws SQLException 93 { 94 TableRow row = DatabaseManager.find(context, "ResourcePolicy", id); 95 96 if (row == null) 97 { 98 return null; 99 } 100 else 101 { 102 return new ResourcePolicy(context, row); 103 } 104 } 105 106 112 public static ResourcePolicy create(Context context) throws SQLException , 113 AuthorizeException 114 { 115 TableRow row = DatabaseManager.create(context, "ResourcePolicy"); 118 119 return new ResourcePolicy(context, row); 120 } 121 122 126 public void delete() throws SQLException 127 { 128 DatabaseManager.delete(myContext, myRow); 131 } 132 133 138 public int getID() 139 { 140 return myRow.getIntColumn("policy_id"); 141 } 142 143 148 public int getResourceType() 149 { 150 return myRow.getIntColumn("resource_type_id"); 151 } 152 153 157 public void setResource(DSpaceObject o) 158 { 159 setResourceType(o.getType()); 160 setResourceID(o.getID()); 161 } 162 163 169 public void setResourceType(int mytype) 170 { 171 myRow.setColumn("resource_type_id", mytype); 172 } 173 174 180 public int getResourceID() 181 { 182 return myRow.getIntColumn("resource_id"); 183 } 184 185 191 public void setResourceID(int myid) 192 { 193 myRow.setColumn("resource_id", myid); 194 } 195 196 199 public int getAction() 200 { 201 return myRow.getIntColumn("action_id"); 202 } 203 204 207 public String getActionText() 208 { 209 int myAction = myRow.getIntColumn("action_id"); 210 211 if (myAction == -1) 212 { 213 return "..."; 214 } 215 else 216 { 217 return Constants.actionText[myAction]; 218 } 219 } 220 221 226 public void setAction(int myid) 227 { 228 myRow.setColumn("action_id", myid); 229 } 230 231 234 public int getEPersonID() 235 { 236 return myRow.getIntColumn("eperson_id"); 237 } 238 239 244 public EPerson getEPerson() throws SQLException 245 { 246 int eid = myRow.getIntColumn("eperson_id"); 247 248 if (eid == -1) 249 { 250 return null; 251 } 252 253 return EPerson.find(myContext, eid); 254 } 255 256 261 public void setEPerson(EPerson e) 262 { 263 if (e != null) 264 { 265 myRow.setColumn("eperson_id", e.getID()); 266 } 267 else 268 { 269 myRow.setColumnNull("eperson_id"); 270 } 271 } 272 273 278 public int getGroupID() 279 { 280 return myRow.getIntColumn("epersongroup_id"); 281 } 282 283 288 public Group getGroup() throws SQLException 289 { 290 int gid = myRow.getIntColumn("epersongroup_id"); 291 292 if (gid == -1) 293 { 294 return null; 295 } 296 else 297 { 298 return Group.find(myContext, gid); 299 } 300 } 301 302 307 public void setGroup(Group g) 308 { 309 if (g != null) 310 { 311 myRow.setColumn("epersongroup_id", g.getID()); 312 } 313 else 314 { 315 myRow.setColumnNull("epersongroup_id"); 316 } 317 } 318 319 325 public boolean isDateValid() 326 { 327 Date sd = getStartDate(); 328 Date ed = getEndDate(); 329 330 if ((sd == null) && (ed == null)) 332 { 333 return true; 334 } 335 336 Date now = new Date (); 338 339 if (sd != null) 341 { 342 if (now.before(sd)) 344 { 345 return false; 346 } 347 } 348 349 if (ed != null) 351 { 352 if (now.after(sd)) 354 { 355 return false; 356 } 357 } 358 359 return true; } 362 363 369 public java.util.Date getStartDate() 370 { 371 return myRow.getDateColumn("start_date"); 372 } 373 374 380 public void setStartDate(java.util.Date d) 381 { 382 myRow.setColumn("start_date", d); 383 } 384 385 390 public java.util.Date getEndDate() 391 { 392 return myRow.getDateColumn("end_date"); 393 } 394 395 401 public void setEndDate(java.util.Date d) 402 { 403 myRow.setColumn("end_date", d); 404 } 405 406 409 public void update() throws SQLException 410 { 411 DatabaseManager.update(myContext, myRow); 413 } 414 } 415 | Popular Tags |