1 40 package org.dspace.workflow; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 import java.util.ArrayList ; 45 import java.util.List ; 46 47 import org.apache.log4j.Logger; 48 import org.dspace.authorize.AuthorizeException; 49 import org.dspace.content.Collection; 50 import org.dspace.content.InProgressSubmission; 51 import org.dspace.content.Item; 52 import org.dspace.core.Context; 53 import org.dspace.core.LogManager; 54 import org.dspace.eperson.EPerson; 55 import org.dspace.history.HistoryManager; 56 import org.dspace.storage.rdbms.DatabaseManager; 57 import org.dspace.storage.rdbms.TableRow; 58 import org.dspace.storage.rdbms.TableRowIterator; 59 60 66 public class WorkflowItem implements InProgressSubmission 67 { 68 69 private static Logger log = Logger.getLogger(WorkflowItem.class); 70 71 72 private Item item; 73 74 75 private Context ourContext; 76 77 78 private TableRow wfRow; 79 80 81 private Collection collection; 82 83 84 private EPerson owner; 85 86 94 WorkflowItem(Context context, TableRow row) throws SQLException 95 { 96 ourContext = context; 97 wfRow = row; 98 99 item = Item.find(context, wfRow.getIntColumn("item_id")); 100 collection = Collection.find(context, wfRow 101 .getIntColumn("collection_id")); 102 103 if (wfRow.isColumnNull("owner")) 104 { 105 owner = null; 106 } 107 else 108 { 109 owner = EPerson.find(context, wfRow.getIntColumn("owner")); 110 } 111 112 context.cache(this, row.getIntColumn("workflow_id")); 114 } 115 116 127 public static WorkflowItem find(Context context, int id) 128 throws SQLException 129 { 130 WorkflowItem fromCache = (WorkflowItem) context.fromCache( 132 WorkflowItem.class, id); 133 134 if (fromCache != null) 135 { 136 return fromCache; 137 } 138 139 TableRow row = DatabaseManager.find(context, "workflowitem", id); 140 141 if (row == null) 142 { 143 if (log.isDebugEnabled()) 144 { 145 log.debug(LogManager.getHeader(context, "find_workflow_item", 146 "not_found,workflow_id=" + id)); 147 } 148 149 return null; 150 } 151 else 152 { 153 if (log.isDebugEnabled()) 154 { 155 log.debug(LogManager.getHeader(context, "find_workflow_item", 156 "workflow_id=" + id)); 157 } 158 159 return new WorkflowItem(context, row); 160 } 161 } 162 163 169 public static WorkflowItem[] findAll(Context c) throws SQLException 170 { 171 List wfItems = new ArrayList (); 172 TableRowIterator tri = DatabaseManager.queryTable(c, "workflowitem", 173 "SELECT * FROM workflowitem"); 174 175 while (tri.hasNext()) 177 { 178 TableRow row = tri.next(); 179 WorkflowItem wi = new WorkflowItem(c, row); 180 wfItems.add(wi); 181 } 182 183 tri.close(); 184 185 WorkflowItem[] wfArray = new WorkflowItem[wfItems.size()]; 186 wfArray = (WorkflowItem[]) wfItems.toArray(wfArray); 187 188 return wfArray; 189 } 190 191 203 public static WorkflowItem[] findByEPerson(Context context, EPerson ep) 204 throws SQLException 205 { 206 List wfItems = new ArrayList (); 207 208 TableRowIterator tri = DatabaseManager.queryTable(context, "workflowitem", 209 "SELECT workflowitem.* FROM workflowitem, item WHERE " + 210 "workflowitem.item_id=item.item_id AND " + 211 "item.submitter_id= ? " + 212 "ORDER BY workflowitem.workflow_id", 213 ep.getID()); 214 215 while (tri.hasNext()) 216 { 217 TableRow row = tri.next(); 218 219 WorkflowItem wi = (WorkflowItem) context.fromCache( 221 WorkflowItem.class, row.getIntColumn("workflow_id")); 222 223 if (wi == null) 224 { 225 wi = new WorkflowItem(context, row); 226 } 227 228 wfItems.add(wi); 229 } 230 231 tri.close(); 232 233 WorkflowItem[] wfArray = new WorkflowItem[wfItems.size()]; 234 wfArray = (WorkflowItem[]) wfItems.toArray(wfArray); 235 236 return wfArray; 237 } 238 239 249 public static WorkflowItem[] findByCollection(Context context, Collection c) 250 throws SQLException 251 { 252 List wsItems = new ArrayList (); 253 254 TableRowIterator tri = DatabaseManager.queryTable(context, "workflowitem", 255 "SELECT workflowitem.* FROM workflowitem WHERE " + 256 "workflowitem.collection_id= ? ", 257 c.getID()); 258 259 while (tri.hasNext()) 260 { 261 TableRow row = tri.next(); 262 263 WorkflowItem wi = (WorkflowItem) context.fromCache( 265 WorkflowItem.class, row.getIntColumn("workflow_id")); 266 267 if (wi == null) 269 { 270 wi = new WorkflowItem(context, row); 271 } 272 273 wsItems.add(wi); 274 } 275 276 tri.close(); 277 278 WorkflowItem[] wsArray = new WorkflowItem[wsItems.size()]; 279 wsArray = (WorkflowItem[]) wsItems.toArray(wsArray); 280 281 return wsArray; 282 } 283 284 289 public int getID() 290 { 291 return wfRow.getIntColumn("workflow_id"); 292 } 293 294 299 public EPerson getOwner() 300 { 301 return owner; 302 } 303 304 310 public void setOwner(EPerson ep) 311 { 312 owner = ep; 313 314 if (ep == null) 315 { 316 wfRow.setColumnNull("owner"); 317 } 318 else 319 { 320 wfRow.setColumn("owner", ep.getID()); 321 } 322 } 323 324 329 public int getState() 330 { 331 return wfRow.getIntColumn("state"); 332 } 333 334 340 public void setState(int newstate) 341 { 342 wfRow.setColumn("state", newstate); 343 } 344 345 348 public void update() throws SQLException , IOException , AuthorizeException 349 { 350 log.info(LogManager.getHeader(ourContext, "update_workflow_item", 352 "workflow_item_id=" + getID())); 353 354 item.update(); 356 357 DatabaseManager.update(ourContext, wfRow); 359 360 HistoryManager.saveHistory(ourContext, this, HistoryManager.MODIFY, 361 ourContext.getCurrentUser(), ourContext.getExtraLogInfo()); 362 } 363 364 367 public void deleteWrapper() throws SQLException , IOException , 368 AuthorizeException 369 { 370 ourContext.removeCached(this, getID()); 372 373 HistoryManager.saveHistory(ourContext, this, HistoryManager.REMOVE, 374 ourContext.getCurrentUser(), ourContext.getExtraLogInfo()); 375 376 WorkflowManager.deleteTasks(ourContext, this); 378 379 DatabaseManager.delete(ourContext, wfRow); 381 } 382 383 public Item getItem() 385 { 386 return item; 387 } 388 389 public Collection getCollection() 390 { 391 return collection; 392 } 393 394 public EPerson getSubmitter() throws SQLException 395 { 396 return item.getSubmitter(); 397 } 398 399 public boolean hasMultipleFiles() 400 { 401 return wfRow.getBooleanColumn("multiple_files"); 402 } 403 404 public void setMultipleFiles(boolean b) 405 { 406 wfRow.setColumn("multiple_files", b); 407 } 408 409 public boolean hasMultipleTitles() 410 { 411 return wfRow.getBooleanColumn("multiple_titles"); 412 } 413 414 public void setMultipleTitles(boolean b) 415 { 416 wfRow.setColumn("multiple_titles", b); 417 } 418 419 public boolean isPublishedBefore() 420 { 421 return wfRow.getBooleanColumn("published_before"); 422 } 423 424 public void setPublishedBefore(boolean b) 425 { 426 wfRow.setColumn("published_before", b); 427 } 428 } 429 | Popular Tags |