1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.IOException ; 43 import java.sql.SQLException ; 44 import java.util.LinkedList ; 45 import java.util.List ; 46 47 import javax.servlet.ServletException ; 48 import javax.servlet.http.HttpServletRequest ; 49 import javax.servlet.http.HttpServletResponse ; 50 51 import org.apache.log4j.Logger; 52 import org.dspace.app.webui.util.JSPManager; 53 import org.dspace.app.webui.util.UIUtil; 54 import org.dspace.authorize.AuthorizeException; 55 import org.dspace.content.Item; 56 import org.dspace.content.ItemIterator; 57 import org.dspace.content.SupervisedItem; 58 import org.dspace.content.WorkspaceItem; 59 import org.dspace.core.Context; 60 import org.dspace.core.LogManager; 61 import org.dspace.eperson.Group; 62 import org.dspace.handle.HandleManager; 63 import org.dspace.workflow.WorkflowItem; 64 import org.dspace.workflow.WorkflowManager; 65 66 72 public class MyDSpaceServlet extends DSpaceServlet 73 { 74 75 private static Logger log = Logger.getLogger(MyDSpaceServlet.class); 76 77 78 public static final int MAIN_PAGE = 0; 79 80 81 public static final int REMOVE_ITEM_PAGE = 1; 82 83 84 public static final int PREVIEW_TASK_PAGE = 2; 85 86 87 public static final int PERFORM_TASK_PAGE = 3; 88 89 90 public static final int REJECT_REASON_PAGE = 4; 91 92 protected void doDSGet(Context context, HttpServletRequest request, 93 HttpServletResponse response) throws ServletException , IOException , 94 SQLException , AuthorizeException 95 { 96 showMainPage(context, request, response); 98 } 99 100 protected void doDSPost(Context context, HttpServletRequest request, 101 HttpServletResponse response) throws ServletException , IOException , 102 SQLException , AuthorizeException 103 { 104 int step = UIUtil.getIntParameter(request, "step"); 106 107 switch (step) 108 { 109 case MAIN_PAGE: 110 processMainPage(context, request, response); 111 112 break; 113 114 case REMOVE_ITEM_PAGE: 115 processRemoveItem(context, request, response); 116 117 break; 118 119 case PREVIEW_TASK_PAGE: 120 processPreviewTask(context, request, response); 121 122 break; 123 124 case PERFORM_TASK_PAGE: 125 processPerformTask(context, request, response); 126 127 break; 128 129 case REJECT_REASON_PAGE: 130 processRejectReason(context, request, response); 131 132 break; 133 134 default: 135 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 136 .getRequestLogInfo(request))); 137 JSPManager.showIntegrityError(request, response); 138 } 139 } 140 141 protected void processMainPage(Context context, HttpServletRequest request, 147 HttpServletResponse response) throws ServletException , IOException , 148 SQLException , AuthorizeException 149 { 150 String buttonPressed = UIUtil.getSubmitButton(request, "submit_own"); 151 152 WorkspaceItem workspaceItem; 154 155 try 156 { 157 int wsID = Integer.parseInt(request.getParameter("workspace_id")); 158 workspaceItem = WorkspaceItem.find(context, wsID); 159 } 160 catch (NumberFormatException nfe) 161 { 162 workspaceItem = null; 163 } 164 165 WorkflowItem workflowItem; 167 168 try 169 { 170 int wfID = Integer.parseInt(request.getParameter("workflow_id")); 171 workflowItem = WorkflowItem.find(context, wfID); 172 } 173 catch (NumberFormatException nfe) 174 { 175 workflowItem = null; 176 } 177 178 boolean ok = false; 180 181 if (buttonPressed.equals("submit_new")) 182 { 183 response.sendRedirect(response.encodeRedirectURL(request 185 .getContextPath() 186 + "/submit")); 187 ok = true; 188 } 189 else if (buttonPressed.equals("submit_own")) 190 { 191 showPreviousSubmissions(context, request, response); 193 ok = true; 194 } 195 else if (buttonPressed.equals("submit_resume")) 196 { 197 String wsID = request.getParameter("workspace_id"); 199 response.sendRedirect(response.encodeRedirectURL(request 200 .getContextPath() 201 + "/submit?resume=" + wsID)); 202 ok = true; 203 } 204 else if (buttonPressed.equals("submit_delete")) 205 { 206 if (workspaceItem != null) 208 { 209 log.info(LogManager.getHeader(context, "confirm_removal", 210 "workspace_item_id=" + workspaceItem.getID())); 211 212 request.setAttribute("workspace.item", workspaceItem); 213 JSPManager.showJSP(request, response, 214 "/mydspace/remove-item.jsp"); 215 } 216 else 217 { 218 log.warn(LogManager.getHeader(context, "integrity_error", 219 UIUtil.getRequestLogInfo(request))); 220 JSPManager.showIntegrityError(request, response); 221 } 222 223 ok = true; 224 } 225 else if (buttonPressed.equals("submit_claim")) 226 { 227 if (workflowItem != null) 229 { 230 log.info(LogManager.getHeader(context, "view_workflow", 231 "workflow_id=" + workflowItem.getID())); 232 233 request.setAttribute("workflow.item", workflowItem); 234 JSPManager.showJSP(request, response, 235 "/mydspace/preview-task.jsp"); 236 ok = true; 237 } 238 } 239 else if (buttonPressed.equals("submit_perform")) 240 { 241 if (workflowItem != null) 243 { 244 log.info(LogManager.getHeader(context, "view_workflow", 245 "workflow_id=" + workflowItem.getID())); 246 247 request.setAttribute("workflow.item", workflowItem); 248 JSPManager.showJSP(request, response, 249 "/mydspace/perform-task.jsp"); 250 ok = true; 251 } 252 } 253 else if (buttonPressed.equals("submit_return")) 254 { 255 if (workflowItem != null) 257 { 258 log.info(LogManager.getHeader(context, "unclaim_workflow", 259 "workflow_id=" + workflowItem.getID())); 260 261 WorkflowManager.unclaim(context, workflowItem, context 262 .getCurrentUser()); 263 264 showMainPage(context, request, response); 265 context.complete(); 266 ok = true; 267 } 268 } 269 270 if (ok == false) 271 { 272 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 273 .getRequestLogInfo(request))); 274 JSPManager.showIntegrityError(request, response); 275 } 276 } 277 278 288 private void processRemoveItem(Context context, HttpServletRequest request, 289 HttpServletResponse response) throws ServletException , IOException , 290 SQLException , AuthorizeException 291 { 292 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 293 294 WorkspaceItem workspaceItem; 296 297 try 298 { 299 int wsID = Integer.parseInt(request.getParameter("workspace_id")); 300 workspaceItem = WorkspaceItem.find(context, wsID); 301 } 302 catch (NumberFormatException nfe) 303 { 304 workspaceItem = null; 305 } 306 307 if (workspaceItem == null) 308 { 309 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 310 .getRequestLogInfo(request))); 311 JSPManager.showIntegrityError(request, response); 312 313 return; 314 } 315 316 if (buttonPressed.equals("submit_delete")) 318 { 319 log.info(LogManager.getHeader(context, "remove_submission", 321 "workspace_item_id=" + workspaceItem.getID() + ",item_id=" 322 + workspaceItem.getItem().getID())); 323 workspaceItem.deleteAll(); 324 showMainPage(context, request, response); 325 context.complete(); 326 } 327 else 328 { 329 showMainPage(context, request, response); 331 } 332 } 333 334 344 private void processPreviewTask(Context context, 345 HttpServletRequest request, HttpServletResponse response) 346 throws ServletException , IOException , SQLException , 347 AuthorizeException 348 { 349 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 350 351 WorkflowItem workflowItem; 353 354 try 355 { 356 int wfID = Integer.parseInt(request.getParameter("workflow_id")); 357 workflowItem = WorkflowItem.find(context, wfID); 358 } 359 catch (NumberFormatException nfe) 360 { 361 workflowItem = null; 362 } 363 364 if (workflowItem == null) 365 { 366 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 367 .getRequestLogInfo(request))); 368 JSPManager.showIntegrityError(request, response); 369 370 return; 371 } 372 373 if (buttonPressed.equals("submit_start")) 374 { 375 WorkflowManager.claim(context, workflowItem, context 377 .getCurrentUser()); 378 379 request.setAttribute("workflow.item", workflowItem); 381 JSPManager.showJSP(request, response, "/mydspace/perform-task.jsp"); 382 context.complete(); 383 } 384 else 385 { 386 showMainPage(context, request, response); 388 } 389 } 390 391 401 private void processPerformTask(Context context, 402 HttpServletRequest request, HttpServletResponse response) 403 throws ServletException , IOException , SQLException , 404 AuthorizeException 405 { 406 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 407 408 WorkflowItem workflowItem; 410 411 try 412 { 413 int wfID = Integer.parseInt(request.getParameter("workflow_id")); 414 workflowItem = WorkflowItem.find(context, wfID); 415 } 416 catch (NumberFormatException nfe) 417 { 418 workflowItem = null; 419 } 420 421 if (workflowItem == null) 422 { 423 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 424 .getRequestLogInfo(request))); 425 JSPManager.showIntegrityError(request, response); 426 427 return; 428 } 429 430 if (buttonPressed.equals("submit_approve")) 431 { 432 Item item = workflowItem.getItem(); 433 434 WorkflowManager.advance(context, workflowItem, context 436 .getCurrentUser()); 437 438 String handle = HandleManager.findHandle(context, item); 443 444 if (handle != null) 445 { 446 String displayHandle = HandleManager.getCanonicalForm(handle); 447 448 request.setAttribute("handle", displayHandle); 449 JSPManager.showJSP(request, response, 450 "/mydspace/in-archive.jsp"); 451 } 452 else 453 { 454 JSPManager.showJSP(request, response, 455 "/mydspace/task-complete.jsp"); 456 } 457 458 context.complete(); 459 } 460 else if (buttonPressed.equals("submit_reject")) 461 { 462 log.info(LogManager.getHeader(context, "get_reject_reason", 464 "workflow_id=" + workflowItem.getID() + ",item_id=" 465 + workflowItem.getItem().getID())); 466 467 request.setAttribute("workflow.item", workflowItem); 468 JSPManager 469 .showJSP(request, response, "/mydspace/reject-reason.jsp"); 470 } 471 else if (buttonPressed.equals("submit_edit")) 472 { 473 log.info(LogManager.getHeader(context, "edit_workflow_item", 475 "workflow_id=" + workflowItem.getID() + ",item_id=" 476 + workflowItem.getItem().getID())); 477 478 response.sendRedirect(response.encodeRedirectURL(request 481 .getContextPath() 482 + "/submit?workflow=" + workflowItem.getID())); 483 } 484 else if (buttonPressed.equals("submit_pool")) 485 { 486 WorkflowManager.unclaim(context, workflowItem, context 488 .getCurrentUser()); 489 showMainPage(context, request, response); 490 context.complete(); 491 } 492 else 493 { 494 showMainPage(context, request, response); 497 } 498 } 499 500 510 private void processRejectReason(Context context, 511 HttpServletRequest request, HttpServletResponse response) 512 throws ServletException , IOException , SQLException , 513 AuthorizeException 514 { 515 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 516 517 WorkflowItem workflowItem; 519 520 try 521 { 522 int wfID = Integer.parseInt(request.getParameter("workflow_id")); 523 workflowItem = WorkflowItem.find(context, wfID); 524 } 525 catch (NumberFormatException nfe) 526 { 527 workflowItem = null; 528 } 529 530 if (workflowItem == null) 531 { 532 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 533 .getRequestLogInfo(request))); 534 JSPManager.showIntegrityError(request, response); 535 536 return; 537 } 538 539 if (buttonPressed.equals("submit_send")) 540 { 541 String reason = request.getParameter("reason"); 542 543 WorkspaceItem wsi = WorkflowManager.reject(context, workflowItem, 544 context.getCurrentUser(), reason); 545 546 wsi.setStageReached(SubmitServlet.REVIEW_SUBMISSION); 549 wsi.update(); 550 551 JSPManager 552 .showJSP(request, response, "/mydspace/task-complete.jsp"); 553 context.complete(); 554 } 555 else 556 { 557 request.setAttribute("workflow.item", workflowItem); 558 JSPManager.showJSP(request, response, "/mydspace/perform-task.jsp"); 559 } 560 } 561 562 568 578 private void showMainPage(Context context, HttpServletRequest request, 579 HttpServletResponse response) throws ServletException , IOException , 580 SQLException , AuthorizeException 581 { 582 log.info(LogManager.getHeader(context, "view_mydspace", "")); 583 584 List ownedList = WorkflowManager.getOwnedTasks(context, context 586 .getCurrentUser()); 587 WorkflowItem[] owned = new WorkflowItem[ownedList.size()]; 588 owned = (WorkflowItem[]) ownedList.toArray(owned); 589 590 List pooledList = WorkflowManager.getPooledTasks(context, context 592 .getCurrentUser()); 593 WorkflowItem[] pooled = new WorkflowItem[pooledList.size()]; 594 pooled = (WorkflowItem[]) pooledList.toArray(pooled); 595 596 WorkflowItem[] workflowItems = WorkflowItem.findByEPerson(context, 598 context.getCurrentUser()); 599 600 WorkspaceItem[] workspaceItems = WorkspaceItem.findByEPerson(context, 602 context.getCurrentUser()); 603 604 Group[] memberships = context.getCurrentUser().getGroupMemberships(); 606 607 SupervisedItem[] supervisedItems = SupervisedItem.findbyEPerson( 608 context, context.getCurrentUser()); 609 610 request.setAttribute("mydspace.user", context.getCurrentUser()); 612 request.setAttribute("workspace.items", workspaceItems); 613 request.setAttribute("workflow.items", workflowItems); 614 request.setAttribute("workflow.owned", owned); 615 request.setAttribute("workflow.pooled", pooled); 616 request.setAttribute("group.memberships", memberships); 617 request.setAttribute("supervised.items", supervisedItems); 618 619 JSPManager.showJSP(request, response, "/mydspace/main.jsp"); 621 } 622 623 633 private void showPreviousSubmissions(Context context, 634 HttpServletRequest request, HttpServletResponse response) 635 throws ServletException , IOException , SQLException , 636 AuthorizeException 637 { 638 ItemIterator subs = Item.findBySubmitter(context, context 639 .getCurrentUser()); 640 641 List subList = new LinkedList (); 643 644 while (subs.hasNext()) 645 { 646 subList.add(subs.next()); 647 } 648 649 Item[] items = new Item[subList.size()]; 650 651 for (int i = 0; i < subList.size(); i++) 652 { 653 items[i] = (Item) subList.get(i); 654 } 655 656 log.info(LogManager.getHeader(context, "view_own_submissions", "count=" 657 + items.length)); 658 659 request.setAttribute("user", context.getCurrentUser()); 660 request.setAttribute("items", items); 661 662 JSPManager.showJSP(request, response, "/mydspace/own-submissions.jsp"); 663 } 664 } 665 | Popular Tags |