1 40 package org.dspace.app.webui.servlet; 41 42 import java.io.BufferedInputStream ; 43 import java.io.File ; 44 import java.io.FileInputStream ; 45 import java.io.IOException ; 46 import java.io.InputStream ; 47 import java.sql.SQLException ; 48 import java.util.ArrayList ; 49 import java.util.LinkedList ; 50 import java.util.List ; 51 52 import javax.servlet.ServletException ; 53 import javax.servlet.http.HttpServletRequest ; 54 import javax.servlet.http.HttpServletResponse ; 55 56 import org.apache.log4j.Logger; 57 import org.dspace.app.webui.util.DCInput; 58 import org.dspace.app.webui.util.DCInputsReader; 59 import org.dspace.app.webui.util.FileUploadRequest; 60 import org.dspace.app.webui.util.JSPManager; 61 import org.dspace.app.webui.util.SubmissionInfo; 62 import org.dspace.app.webui.util.UIUtil; 63 import org.dspace.authorize.AuthorizeException; 64 import org.dspace.content.Bitstream; 65 import org.dspace.content.BitstreamFormat; 66 import org.dspace.content.Bundle; 67 import org.dspace.content.Collection; 68 import org.dspace.content.Community; 69 import org.dspace.content.DCDate; 70 import org.dspace.content.DCPersonName; 71 import org.dspace.content.DCSeriesNumber; 72 import org.dspace.content.DCValue; 73 import org.dspace.content.FormatIdentifier; 74 import org.dspace.content.Item; 75 import org.dspace.content.MetadataField; 76 import org.dspace.content.WorkspaceItem; 77 import org.dspace.core.ConfigurationManager; 78 import org.dspace.core.Constants; 79 import org.dspace.core.Context; 80 import org.dspace.core.LogManager; 81 import org.dspace.eperson.EPerson; 82 import org.dspace.license.CreativeCommons; 83 import org.dspace.workflow.WorkflowItem; 84 import org.dspace.workflow.WorkflowManager; 85 86 130 public class SubmitServlet extends DSpaceServlet 131 { 132 134 135 public static final int SELECT_COLLECTION = 0; 136 137 138 public static final int INITIAL_QUESTIONS = 1; 139 140 141 public static final int EDIT_METADATA_1 = 2; 142 143 149 public static final int EDIT_METADATA_2 = 7; 150 151 156 public static final int UPLOAD_FILES = 8; 157 158 159 public static final int REVIEW_SUBMISSION = 9; 160 161 162 public static final int CC_LICENSE = 10; 163 164 165 public static final int GRANT_LICENSE = 11; 166 167 168 public static final int SUBMISSION_COMPLETE = 12; 169 170 174 175 public static final int SUBMISSION_CANCELLED = 101; 176 177 178 public static final int FILE_LIST = 102; 179 180 181 public static final int CHOOSE_FILE = 103; 182 183 184 public static final int GET_FILE_FORMAT = 104; 185 186 187 public static final int UPLOAD_ERROR = 105; 188 189 190 public static final int CHANGE_FILE_DESCRIPTION = 106; 191 192 196 public static final int VERIFY_PRUNE = 107; 197 198 199 private static Logger log = Logger.getLogger(SubmitServlet.class); 200 201 202 private DCInputsReader inputsReader; 203 204 public SubmitServlet() 205 throws ServletException 206 { 207 inputsReader = new DCInputsReader(); 209 } 210 211 protected void doDSGet(Context context, HttpServletRequest request, 212 HttpServletResponse response) throws ServletException , IOException , 213 SQLException , AuthorizeException 214 { 215 232 String workspaceID = request.getParameter("resume"); 233 234 if (workspaceID != null) 235 { 236 try 237 { 238 WorkspaceItem wi = WorkspaceItem.find(context, Integer 239 .parseInt(workspaceID)); 240 241 SubmissionInfo si = new SubmissionInfo(); 242 si.submission = wi; 243 doStep(context, request, response, si, INITIAL_QUESTIONS); 244 } 245 catch (NumberFormatException nfe) 246 { 247 log.warn(LogManager.getHeader(context, "bad_workspace_id", 248 "bad_id=" + workspaceID)); 249 JSPManager.showInvalidIDError(request, response, workspaceID, 250 -1); 251 } 252 253 return; 254 } 255 256 String workflowID = request.getParameter("workflow"); 257 258 if (workflowID != null) 259 { 260 try 261 { 262 WorkflowItem wi = WorkflowItem.find(context, Integer 263 .parseInt(workflowID)); 264 265 SubmissionInfo si = new SubmissionInfo(); 266 si.submission = wi; 267 doStep(context, request, response, si, INITIAL_QUESTIONS); 268 } 269 catch (NumberFormatException nfe) 270 { 271 log.warn(LogManager.getHeader(context, "bad_workflow_id", 272 "bad_id=" + workflowID)); 273 JSPManager 274 .showInvalidIDError(request, response, workflowID, -1); 275 } 276 277 return; 278 } 279 280 Community com = UIUtil.getCommunityLocation(request); 281 Collection col = UIUtil.getCollectionLocation(request); 282 283 if (col != null) 284 { 285 WorkspaceItem wi = WorkspaceItem.create(context, col, true); 288 289 SubmissionInfo si = new SubmissionInfo(); 291 si.submission = wi; 292 doStep(context, request, response, si, INITIAL_QUESTIONS); 293 context.complete(); 294 } 295 else 296 { 297 Collection[] collections; 298 299 if (com != null) 300 { 301 collections = Collection.findAuthorized(context, com, 303 Constants.ADD); 304 } 305 else 306 { 307 collections = Collection.findAuthorized(context, null, 309 Constants.ADD); 310 } 311 312 log.info(LogManager.getHeader(context, "select_collection", "")); 313 314 request.setAttribute("collections", collections); 315 JSPManager.showJSP(request, response, 316 "/submit/select-collection.jsp"); 317 } 318 } 319 320 protected void doDSPost(Context context, HttpServletRequest request, 321 HttpServletResponse response) throws ServletException , IOException , 322 SQLException , AuthorizeException 323 { 324 String contentType = request.getContentType(); 327 328 if ((contentType != null) 329 && (contentType.indexOf("multipart/form-data") != -1)) 330 { 331 processChooseFile(context, request, response); 333 334 return; 335 } 336 337 int step = UIUtil.getIntParameter(request, "step"); 339 340 if ((step == SELECT_COLLECTION) || (step == -1)) 344 { 345 processSelectCollection(context, request, response); 346 347 return; 348 } 349 350 SubmissionInfo subInfo = getSubmissionInfo(context, request); 352 353 if (subInfo == null) 354 { 355 362 if (request.getSession().getAttribute("removed_thesis") != null) 363 { 364 request.getSession().removeAttribute("removed_thesis"); 365 JSPManager.showJSP(request, response, 366 "/submit/thesis-removed-workaround.jsp"); 367 368 return; 369 } 370 else 371 { 372 376 step = -1; 377 } 378 } 379 380 if (step >= EDIT_METADATA_1 && step <= EDIT_METADATA_2) 381 { 382 processEditMetadata(context, request, response, subInfo, step); 383 return; 384 } 385 386 switch (step) 387 { 388 case INITIAL_QUESTIONS: 389 processInitialQuestions(context, request, response, subInfo); 390 391 break; 392 393 case GET_FILE_FORMAT: 394 processGetFileFormat(context, request, response, subInfo); 395 396 break; 397 398 case FILE_LIST: 399 processFileList(context, request, response, subInfo); 400 401 break; 402 403 case UPLOAD_ERROR: 404 processUploadError(context, request, response, subInfo); 405 406 break; 407 408 case CHANGE_FILE_DESCRIPTION: 409 processChangeFileDescription(context, request, response, subInfo); 410 411 break; 412 413 case REVIEW_SUBMISSION: 414 processReview(context, request, response, subInfo); 415 416 break; 417 418 case CC_LICENSE: 419 processCC(context, request, response, subInfo); 420 421 break; 422 423 case GRANT_LICENSE: 424 processLicense(context, request, response, subInfo); 425 426 break; 427 428 case SUBMISSION_CANCELLED: 429 processCancellation(context, request, response, subInfo); 430 431 break; 432 433 case VERIFY_PRUNE: 434 processVerifyPrune(context, request, response, subInfo); 435 436 break; 437 438 default: 439 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 440 .getRequestLogInfo(request))); 441 JSPManager.showIntegrityError(request, response); 442 } 443 } 444 445 451 462 private void processSelectCollection(Context context, 463 HttpServletRequest request, HttpServletResponse response) 464 throws ServletException , IOException , SQLException , 465 AuthorizeException 466 { 467 if (request.getParameter("submit_cancel") != null) 471 { 472 response.sendRedirect(response.encodeRedirectURL(request 474 .getContextPath() 475 + "/mydspace")); 476 477 return; 478 } 479 480 int id = UIUtil.getIntParameter(request, "collection"); 482 Collection col = Collection.find(context, id); 483 484 if (col == null) 486 { 487 JSPManager.showInvalidIDError(request, response, request 488 .getParameter("collection"), Constants.COLLECTION); 489 } 490 else 491 { 492 WorkspaceItem wi = WorkspaceItem.create(context, col, true); 493 494 SubmissionInfo si = new SubmissionInfo(); 496 si.submission = wi; 497 doStep(context, request, response, si, INITIAL_QUESTIONS); 498 499 context.complete(); 500 } 501 } 502 503 515 private void processInitialQuestions(Context context, 516 HttpServletRequest request, HttpServletResponse response, 517 SubmissionInfo subInfo) throws ServletException , IOException , 518 SQLException , AuthorizeException 519 { 520 String buttonPressed = UIUtil.getSubmitButton(request, "submit_next"); 521 522 if (buttonPressed.equals("submit_cancel")) 524 { 525 doCancellation(request, response, subInfo, INITIAL_QUESTIONS, 526 INITIAL_QUESTIONS); 527 528 return; 529 } 530 531 boolean multipleTitles = UIUtil.getBoolParameter(request, 533 "multiple_titles"); 534 boolean publishedBefore = UIUtil.getBoolParameter(request, 535 "published_before"); 536 boolean multipleFiles = UIUtil.getBoolParameter(request, 537 "multiple_files"); 538 boolean isThesis = ConfigurationManager 539 .getBooleanProperty("webui.submit.blocktheses") 540 && UIUtil.getBoolParameter(request, "is_thesis"); 541 542 if (isWorkflow(subInfo)) 543 { 544 isThesis = false; 546 547 multipleFiles = true; 550 } 551 552 if (isThesis) 554 { 555 WorkspaceItem wi = (WorkspaceItem) subInfo.submission; 556 wi.deleteAll(); 557 558 request.getSession().setAttribute("removed_thesis", 560 new Boolean (true)); 561 562 JSPManager.showJSP(request, response, "/submit/no-theses.jsp"); 564 565 context.complete(); 566 567 return; 568 } 569 570 boolean willRemoveTitles = false; 573 boolean willRemoveDate = false; 574 boolean willRemoveFiles = false; 575 576 if (multipleTitles == false) 577 { 578 DCValue[] altTitles = subInfo.submission.getItem().getDC( 579 "title", "alternative", Item.ANY); 580 581 willRemoveTitles = altTitles.length > 0; 582 } 583 584 if (publishedBefore == false) 585 { 586 DCValue[] dateIssued = subInfo.submission.getItem().getDC("date", 587 "issued", Item.ANY); 588 DCValue[] citation = subInfo.submission.getItem().getDC( 589 "identifier", "citation", Item.ANY); 590 DCValue[] publisher = subInfo.submission.getItem().getDC( 591 "publisher", null, Item.ANY); 592 593 willRemoveDate = (dateIssued.length > 0) || (citation.length > 0) 594 || (publisher.length > 0); 595 } 596 597 if (multipleFiles == false) 598 { 599 Bundle[] bundles = subInfo.submission.getItem().getBundles( 602 "ORIGINAL"); 603 604 if (bundles.length > 0) 605 { 606 Bitstream[] bitstreams = bundles[0].getBitstreams(); 607 608 willRemoveFiles = bitstreams.length > 1; 609 } 610 } 611 612 if (willRemoveTitles || willRemoveDate || willRemoveFiles) 616 { 617 request.setAttribute("submission.info", subInfo); 619 request 620 .setAttribute("multiple.titles", 621 new Boolean (multipleTitles)); 622 request.setAttribute("published.before", new Boolean ( 623 publishedBefore)); 624 request.setAttribute("multiple.files", new Boolean (multipleFiles)); 625 request.setAttribute("will.remove.titles", new Boolean ( 626 willRemoveTitles)); 627 request.setAttribute("will.remove.date", 628 new Boolean (willRemoveDate)); 629 request.setAttribute("will.remove.files", new Boolean ( 630 willRemoveFiles)); 631 request.setAttribute("button.pressed", UIUtil.getSubmitButton( 632 request, "submit_next")); 633 634 JSPManager.showJSP(request, response, "/submit/verify-prune.jsp"); 635 } 636 else 637 { 638 subInfo.submission.setMultipleTitles(multipleTitles); 640 subInfo.submission.setPublishedBefore(publishedBefore); 641 642 if (!isWorkflow(subInfo)) 644 { 645 subInfo.submission.setMultipleFiles(multipleFiles); 646 } 647 648 subInfo.submission.update(); 649 650 if (buttonPressed.equals("submit_next")) 652 { 653 userHasReached(subInfo, EDIT_METADATA_1); 655 656 doStep(context, request, response, subInfo, EDIT_METADATA_1); 658 } 659 else 660 { 661 doStepJump(context, request, response, subInfo); 663 } 664 665 context.complete(); 666 } 667 } 668 669 681 private void processVerifyPrune(Context context, 682 HttpServletRequest request, HttpServletResponse response, 683 SubmissionInfo subInfo) throws ServletException , IOException , 684 SQLException , AuthorizeException 685 { 686 if (request.getParameter("do_not_proceed") != null) 687 { 688 doStep(context, request, response, subInfo, INITIAL_QUESTIONS); 690 691 return; 692 } 693 694 boolean multipleTitles = UIUtil.getBoolParameter(request, 697 "multiple_titles"); 698 boolean publishedBefore = UIUtil.getBoolParameter(request, 699 "published_before"); 700 701 boolean multipleFiles = (isWorkflow(subInfo) || UIUtil 705 .getBoolParameter(request, "multiple_files")); 706 707 Item item = subInfo.submission.getItem(); 708 709 if (!multipleTitles) 710 { 711 item.clearDC("title", "alternative", Item.ANY); 712 } 713 714 if (publishedBefore == false) 715 { 716 item.clearDC("date", "issued", Item.ANY); 717 item.clearDC("identifier", "citation", Item.ANY); 718 item.clearDC("publisher", null, Item.ANY); 719 } 720 721 if (multipleFiles == false) 722 { 723 Bundle[] bundles = item.getBundles("ORIGINAL"); 727 728 if (bundles.length > 0) 729 { 730 Bitstream[] bitstreams = bundles[0].getBitstreams(); 731 732 for (int i = 1; i < bitstreams.length; i++) 734 { 735 bundles[0].removeBitstream(bitstreams[i]); 736 } 737 } 738 } 739 740 subInfo.submission.setMultipleTitles(multipleTitles); 742 subInfo.submission.setPublishedBefore(publishedBefore); 743 744 if (!isWorkflow(subInfo)) 746 { 747 subInfo.submission.setMultipleFiles(multipleFiles); 748 } 749 750 subInfo.submission.update(); 751 752 if (request.getParameter("submit_next") != null) 755 { 756 userHasReached(subInfo, EDIT_METADATA_1); 758 759 doStep(context, request, response, subInfo, EDIT_METADATA_1); 761 762 context.complete(); 763 } 764 else 765 { 766 doStepJump(context, request, response, subInfo); 768 769 context.complete(); 770 } 771 } 772 773 787 private void processEditMetadata(Context context, 788 HttpServletRequest request, 789 HttpServletResponse response, 790 SubmissionInfo subInfo, 791 int curStep) 792 throws ServletException , IOException , SQLException , AuthorizeException 793 { 794 String buttonPressed = UIUtil.getSubmitButton(request, "submit_next"); 795 796 if (buttonPressed.equals("submit_cancel")) 798 { 799 doCancellation(request, response, subInfo, curStep, curStep); 800 return; 801 } 802 803 Item item = subInfo.submission.getItem(); 804 805 Collection c = subInfo.submission.getCollection(); 807 DCInput[] inputs = inputsReader.getInputs(c.getHandle()).getPageRows(curStep - EDIT_METADATA_1, 808 subInfo.submission.hasMultipleTitles(), 809 subInfo.submission.isPublishedBefore()); 810 811 for (int i = 0; i < inputs.length; i++) 813 { 814 String dcQualifier = inputs[i].getQualifier(); 815 if (dcQualifier == null && inputs[i].getInputType().equals("qualdrop_value")) 816 { 817 dcQualifier = Item.ANY; 818 } 819 item.clearMetadata(inputs[i].getSchema(), inputs[i].getElement(), dcQualifier, Item.ANY); 820 } 821 822 String fieldName; 824 boolean moreInput = false; 825 for (int j = 0; j < inputs.length; j++) 826 { 827 String dcElement = inputs[j].getElement(); 828 String dcQualifier = inputs[j].getQualifier(); 829 String dcSchema = inputs[j].getSchema(); 830 if (dcQualifier != null && ! dcQualifier.equals(Item.ANY)) 831 { 832 fieldName = dcSchema + "_" + dcElement + '_' + dcQualifier; 833 } 834 else 835 { 836 fieldName = dcSchema + "_" + dcElement; 837 } 838 839 String inputType = inputs[j].getInputType(); 840 if (inputType.equals("name")) 841 { 842 readNames(request, item, dcSchema, dcElement, dcQualifier, 843 inputs[j].getRepeatable()); 844 } 845 else if (inputType.equals("date")) 846 { 847 readDate(request, item, dcSchema, dcElement, dcQualifier); 848 } 849 else if (inputType.equals("series")) 850 { 851 readSeriesNumbers(request, item, dcSchema, dcElement, dcQualifier, 852 inputs[j].getRepeatable()); 853 } 854 else if (inputType.equals("qualdrop_value")) 855 { 856 List quals = getRepeatedParameter(request, dcSchema + "_" + dcElement + "_qualifier"); 857 List vals = getRepeatedParameter(request, dcSchema + "_" + dcElement + "_value"); 858 for (int z = 0; z < vals.size(); z++) 859 { 860 String thisQual = (String )quals.get(z); 861 if ( "".equals(thisQual) ) 862 { 863 thisQual = null; 864 } 865 String thisVal = (String )vals.get(z); 866 if (! buttonPressed.equals("submit_" + dcSchema + "_" + dcElement + "_remove_" + z) && 867 ! thisVal.equals("")) 868 { 869 item.addMetadata(dcSchema, dcElement, thisQual, null, thisVal); 870 } 871 } 872 } 873 else if (inputType.equals("dropdown")) 874 { 875 String [] vals = request.getParameterValues(fieldName); 876 if (vals != null) 877 { 878 for (int z = 0; z < vals.length; z++) 879 { 880 if (!vals[z].equals("")) 881 { 882 item.addMetadata(dcSchema, dcElement, dcQualifier, "en", vals[z]); 883 } 884 } 885 } 886 } 887 else if ((inputType.equals("onebox")) || (inputType.equals("twobox")) || 888 (inputType.equals("textarea"))) 889 { 890 readText(request, item, dcSchema, dcElement, dcQualifier, 891 inputs[j].getRepeatable(), "en"); 892 } 893 else 894 { 895 throw new ServletException ("Field "+ fieldName + 896 " has an unknown input type: " + inputType); 897 } 898 899 if (! moreInput && buttonPressed.equals("submit_" + fieldName + "_more")) 901 { 902 subInfo.moreBoxesFor = fieldName; 903 subInfo.jumpToField = fieldName; 904 moreInput = true; 905 } 906 } 907 908 int nextStep = -1; 909 if ( moreInput ) 910 { 911 nextStep = curStep; 912 } 913 914 if (buttonPressed.equals("submit_prev")) 915 { 916 nextStep = curStep-1; 918 } 919 else if (buttonPressed.equals("submit_next")) 920 { 921 String gotoField = null; 923 subInfo.missingFields = new ArrayList (); 924 for (int i = 0; i < inputs.length; i++) 926 { 927 String element = inputs[i].getElement(); 928 String qual = inputs[i].getQualifier(); 929 String schema = inputs[i].getSchema(); 930 log.info(" inner "+schema); 931 DCValue[] valArray = item.getMetadata(schema, element, qual, Item.ANY); 932 boolean isEmpty = (valArray.length == 0); 933 if (inputs[i].isRequired() && isEmpty) 934 { 935 subInfo.missingFields.add( new Integer (i) ); 936 if (qual != null && !qual.equals("*")) 937 { 938 gotoField = schema + "_" + element + '_' + qual; 939 } 940 else 941 { 942 gotoField = schema + "_" + element; 943 } 944 } 945 } 946 if (subInfo.missingFields.size() > 0 ) 948 { 949 subInfo.jumpToField = gotoField; 950 nextStep = curStep; 951 } 952 else 953 { 954 int lastMDPage = EDIT_METADATA_1 + inputsReader.getNumberInputPages(c.getHandle()) - 1; 956 if ( curStep == lastMDPage ) 957 { 958 curStep = EDIT_METADATA_2; 959 } 960 userHasReached(subInfo, curStep+1); 961 nextStep = curStep+1; 962 } 963 } 964 else if (buttonPressed.indexOf("remove") > -1) 965 { 966 nextStep = curStep; 968 } 969 970 subInfo.submission.update(); 972 973 if (nextStep != -1) 974 { 975 doStep(context, request, response, subInfo, nextStep); 976 } 977 else 978 { 979 doStepJump(context, request, response, subInfo); 980 } 981 982 context.complete(); 983 } 984 985 995 private void processChooseFile(Context context, HttpServletRequest request, 996 HttpServletResponse response) throws ServletException , IOException , 997 SQLException , AuthorizeException 998 { 999 File temp = null; 1000 FileUploadRequest wrapper = null; 1001 SubmissionInfo subInfo = null; 1002 boolean ok = false; 1003 String buttonPressed = null; 1004 BitstreamFormat bf = null; 1005 Bitstream b = null; 1006 1007 1012 try 1013 { 1014 wrapper = new FileUploadRequest(request); 1016 1017 subInfo = getSubmissionInfo(context, wrapper); 1018 buttonPressed = UIUtil.getSubmitButton(wrapper, "submit_next"); 1019 1020 if ((subInfo != null) && buttonPressed.equals("submit_next")) 1021 { 1022 Item item = subInfo.submission.getItem(); 1024 1025 temp = wrapper.getFile("file"); 1026 1027 if (temp != null && temp.length() > 0) 1028 { 1029 InputStream is = new BufferedInputStream ( 1031 new FileInputStream (temp)); 1032 1033 Bundle[] bundles = item.getBundles("ORIGINAL"); 1035 1036 if (bundles.length < 1) 1037 { 1038 b = item.createSingleBitstream(is, "ORIGINAL"); 1040 } 1041 else 1042 { 1043 b = bundles[0].createBitstream(is); 1045 } 1046 1047 String noPath = wrapper.getFilesystemName("file"); 1050 1051 while (noPath.indexOf('/') > -1) 1052 { 1053 noPath = noPath.substring(noPath.indexOf('/') + 1); 1054 } 1055 1056 while (noPath.indexOf('\\') > -1) 1057 { 1058 noPath = noPath.substring(noPath.indexOf('\\') + 1); 1059 } 1060 1061 b.setName(noPath); 1062 b.setSource(wrapper.getFilesystemName("file")); 1063 b.setDescription(wrapper.getParameter("description")); 1064 1065 bf = FormatIdentifier.guessFormat(context, b); 1067 1068 b.setFormat(bf); 1069 1070 b.update(); 1072 item.update(); 1073 1074 if (bf == null || !bf.isInternal()) 1075 { 1076 ok = true; 1077 } 1078 else 1079 { 1080 log.info("Attempt to upload file format marked as internal system use only"); 1081 } 1082 } 1083 } 1084 } 1085 catch (IOException ie) 1086 { 1087 log.warn(LogManager.getHeader(context, "upload_error", ""), ie); 1089 } 1090 1091 if (subInfo == null) 1092 { 1093 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 1096 .getRequestLogInfo(request))); 1097 } 1098 else if (buttonPressed.equals("submit_cancel")) 1099 { 1100 doCancellation(request, response, subInfo, 1101 SubmitServlet.CHOOSE_FILE, SubmitServlet.UPLOAD_FILES); 1102 } 1103 else if (buttonPressed.equals("submit_prev")) 1104 { 1105 if (subInfo.submission.getItem().getBundles("ORIGINAL").length > 0) 1111 { 1112 showUploadFileList(request, response, subInfo, false, false); 1114 } 1115 else 1116 { 1117 Collection c = subInfo.submission.getCollection(); 1119 int lastPage = EDIT_METADATA_1 + 1120 inputsReader.getNumberInputPages( c.getHandle() ) - 1; 1121 doStep(context, request, response, subInfo, lastPage); 1122 } 1123 } 1124 else if (buttonPressed.equals("submit_next")) 1125 { 1126 if (ok) 1128 { 1129 if (bf != null) 1131 { 1132 showUploadFileList(request, response, subInfo, true, false); 1134 } 1135 else 1136 { 1137 showGetFileFormat(context, request, response, subInfo, b); 1139 } 1140 1141 context.complete(); 1142 } 1143 else 1144 { 1145 showProgressAwareJSP(request, response, subInfo, 1148 "/submit/upload-error.jsp"); 1149 } 1150 } 1151 else 1152 { 1153 doStepJump(context, wrapper, response, subInfo); 1154 } 1155 1156 if (temp != null) 1158 { 1159 temp.delete(); 1160 } 1161 } 1162 1163 1175 private void processGetFileFormat(Context context, 1176 HttpServletRequest request, HttpServletResponse response, 1177 SubmissionInfo subInfo) throws ServletException , IOException , 1178 SQLException , AuthorizeException 1179 { 1180 String buttonPressed = UIUtil.getSubmitButton(request, "submit"); 1181 1182 if (subInfo.bitstream != null) 1183 { 1184 int typeID = UIUtil.getIntParameter(request, "format"); 1186 1187 BitstreamFormat format = BitstreamFormat.find(context, typeID); 1188 1189 if (format != null) 1190 { 1191 subInfo.bitstream.setFormat(format); 1192 } 1193 else 1194 { 1195 String userDesc = request.getParameter("format_description"); 1196 subInfo.bitstream.setUserFormatDescription(userDesc); 1197 } 1198 1199 subInfo.bitstream.update(); 1200 1201 if (buttonPressed.equals("submit")) 1202 { 1203 showUploadFileList(request, response, subInfo, true, false); 1204 } 1205 else 1206 { 1207 doStepJump(context, request, response, subInfo); 1208 } 1209 1210 context.complete(); 1211 } 1212 else 1213 { 1214 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 1215 .getRequestLogInfo(request))); 1216 JSPManager.showIntegrityError(request, response); 1217 } 1218 } 1219 1220 1232 private void processFileList(Context context, HttpServletRequest request, 1233 HttpServletResponse response, SubmissionInfo subInfo) 1234 throws ServletException , IOException , SQLException , 1235 AuthorizeException 1236 { 1237 String buttonPressed = UIUtil.getSubmitButton(request, "submit_next"); 1238 Item item = subInfo.submission.getItem(); 1239 1240 if (buttonPressed.equals("submit_cancel")) 1241 { 1242 doCancellation(request, response, subInfo, SubmitServlet.FILE_LIST, 1243 SubmitServlet.UPLOAD_FILES); 1244 } 1245 else if (buttonPressed.equals("submit_prev")) 1246 { 1247 Collection c = subInfo.submission.getCollection(); 1251 int lastPage = EDIT_METADATA_1 + 1252 inputsReader.getNumberInputPages( c.getHandle() ) - 1; 1253 doStep(context, request, response, subInfo, lastPage); 1254 } 1255 else if (buttonPressed.equals("submit_next")) 1256 { 1257 if (request.getParameter("primary_bitstream_id") != null) 1261 { 1262 Bundle[] bundles = item.getBundles("ORIGINAL"); 1263 bundles[0].setPrimaryBitstreamID(new Integer (request 1264 .getParameter("primary_bitstream_id")).intValue()); 1265 bundles[0].update(); 1266 } 1267 1268 userHasReached(subInfo, REVIEW_SUBMISSION); 1269 doStep(context, request, response, subInfo, REVIEW_SUBMISSION); 1270 context.complete(); 1271 } 1272 else if (buttonPressed.equals("submit_more")) 1273 { 1274 if (request.getParameter("primary_bitstream_id") != null) 1276 { 1277 Bundle[] bundles = item.getBundles("ORIGINAL"); 1278 bundles[0].setPrimaryBitstreamID(new Integer (request 1279 .getParameter("primary_bitstream_id")).intValue()); 1280 bundles[0].update(); 1281 context.commit(); 1282 } 1283 1284 showProgressAwareJSP(request, response, subInfo, "/submit/choose-file.jsp"); 1286 } 1287 else if (buttonPressed.equals("submit_show_checksums")) 1288 { 1289 showUploadFileList(request, response, subInfo, false, true); 1291 } 1292 else if (buttonPressed.startsWith("submit_describe_")) 1293 { 1294 Bitstream bitstream; 1296 1297 try 1299 { 1300 int id = Integer.parseInt(buttonPressed.substring(16)); 1301 bitstream = Bitstream.find(context, id); 1302 } 1303 catch (NumberFormatException nfe) 1304 { 1305 bitstream = null; 1306 } 1307 1308 if (bitstream == null) 1309 { 1310 log.warn(LogManager.getHeader(context, "integrity_error", 1312 UIUtil.getRequestLogInfo(request))); 1313 JSPManager.showIntegrityError(request, response); 1314 1315 return; 1316 } 1317 1318 subInfo.bitstream = bitstream; 1320 showProgressAwareJSP(request, response, subInfo, 1321 "/submit/change-file-description.jsp"); 1322 } 1323 else if (buttonPressed.startsWith("submit_remove_")) 1324 { 1325 Bitstream bitstream; 1327 1328 try 1330 { 1331 int id = Integer.parseInt(buttonPressed.substring(14)); 1332 bitstream = Bitstream.find(context, id); 1333 } 1334 catch (NumberFormatException nfe) 1335 { 1336 bitstream = null; 1337 } 1338 1339 if (bitstream == null) 1340 { 1341 log.warn(LogManager.getHeader(context, "integrity_error", 1343 UIUtil.getRequestLogInfo(request))); 1344 JSPManager.showIntegrityError(request, response); 1345 1346 return; 1347 } 1348 1349 Bundle[] bundles = bitstream.getBundles(); 1352 1353 bundles[0].removeBitstream(bitstream); 1354 1355 Bitstream[] bitstreams = bundles[0].getBitstreams(); 1356 1357 if (bitstreams.length < 1) 1359 { 1360 item.removeBundle(bundles[0]); 1361 item.update(); 1362 } 1363 1364 showFirstUploadPage(context, request, response, subInfo); 1365 context.complete(); 1366 } 1367 else if (buttonPressed.startsWith("submit_format_")) 1368 { 1369 Bitstream bitstream; 1371 1372 try 1374 { 1375 int id = Integer.parseInt(buttonPressed.substring(14)); 1376 bitstream = Bitstream.find(context, id); 1377 } 1378 catch (NumberFormatException nfe) 1379 { 1380 bitstream = null; 1381 } 1382 1383 if (bitstream == null) 1384 { 1385 log.warn(LogManager.getHeader(context, "integrity_error", 1387 UIUtil.getRequestLogInfo(request))); 1388 JSPManager.showIntegrityError(request, response); 1389 1390 return; 1391 } 1392 1393 subInfo.bitstream = bitstream; 1394 showGetFileFormat(context, request, response, subInfo, bitstream); 1395 } 1396 else 1397 { 1398 doStepJump(context, request, response, subInfo); 1399 } 1400 } 1401 1402 1414 private void processUploadError(Context context, 1415 HttpServletRequest request, HttpServletResponse response, 1416 SubmissionInfo subInfo) throws ServletException , IOException , 1417 SQLException , AuthorizeException 1418 { 1419 String buttonPressed = UIUtil.getSubmitButton(request, "submit_next"); 1420 1421 if (buttonPressed.equals("submit")) 1423 { 1424 showProgressAwareJSP(request, response, subInfo, 1425 "/submit/choose-file.jsp"); 1426 } 1427 else 1428 { 1429 doStepJump(context, request, response, subInfo); 1430 } 1431 } 1432 1433 1445 private void processChangeFileDescription(Context context, 1446 HttpServletRequest request, HttpServletResponse response, 1447 SubmissionInfo subInfo) throws ServletException , IOException , 1448 SQLException , AuthorizeException 1449 { 1450 if (subInfo.bitstream != null) 1451 { 1452 subInfo.bitstream.setDescription(request 1453 .getParameter("description")); 1454 subInfo.bitstream.update(); 1455 1456 if (request.getParameter("submit") != null) 1457 { 1458 showUploadFileList(request, response, subInfo, false, false); 1459 } 1460 else 1461 { 1462 doStepJump(context, request, response, subInfo); 1463 } 1464 1465 context.complete(); 1466 } 1467 else 1468 { 1469 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 1470 .getRequestLogInfo(request))); 1471 JSPManager.showIntegrityError(request, response); 1472 } 1473 } 1474 1475 1487 private void processCancellation(Context context, 1488 HttpServletRequest request, HttpServletResponse response, 1489 SubmissionInfo subInfo) throws ServletException , IOException , 1490 SQLException , AuthorizeException 1491 { 1492 String buttonPressed = UIUtil.getSubmitButton(request, "submit_back"); 1493 1494 if (buttonPressed.equals("submit_back")) 1495 { 1496 int previous = UIUtil.getIntParameter(request, "previous_step"); 1498 1499 doStep(context, request, response, subInfo, previous); 1500 } 1501 else if (buttonPressed.equals("submit_remove")) 1502 { 1503 WorkspaceItem wi = (WorkspaceItem) subInfo.submission; 1506 1507 wi.deleteAll(); 1508 1509 JSPManager.showJSP(request, response, 1510 "/submit/cancelled-removed.jsp"); 1511 1512 context.complete(); 1513 } 1514 else if (buttonPressed.equals("submit_keep")) 1515 { 1516 JSPManager.showJSP(request, response, "/submit/saved.jsp"); 1518 } 1519 else 1520 { 1521 doStepJump(context, request, response, subInfo); 1522 } 1523 } 1524 1525 1537 private void processReview(Context context, HttpServletRequest request, 1538 HttpServletResponse response, SubmissionInfo subInfo) 1539 throws ServletException , IOException , SQLException , 1540 AuthorizeException 1541 { 1542 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 1543 1544 if (buttonPressed.equals("submit_cancel")) 1545 { 1546 doCancellation(request, response, subInfo, REVIEW_SUBMISSION, 1547 REVIEW_SUBMISSION); 1548 } 1549 else if (buttonPressed.equals("submit_next")) 1550 { 1551 if (!isWorkflow(subInfo)) 1554 { 1555 int nextStep = CreativeCommons.isEnabled() ? CC_LICENSE 1557 : GRANT_LICENSE; 1558 userHasReached(subInfo, nextStep); 1559 doStep(context, request, response, subInfo, nextStep); 1560 context.complete(); 1561 } 1562 else 1563 { 1564 request.setAttribute("workflow.item", subInfo.submission); 1568 JSPManager.showJSP(request, response, 1569 "/mydspace/perform-task.jsp"); 1570 } 1571 } 1572 else if (buttonPressed.equals("submit_prev")) 1573 { 1574 doStep(context, request, response, subInfo, UPLOAD_FILES); 1576 } 1577 else 1578 { 1579 doStepJump(context, request, response, subInfo); 1580 } 1581 } 1582 1583 1595 private void processLicense(Context context, HttpServletRequest request, 1596 HttpServletResponse response, SubmissionInfo subInfo) 1597 throws ServletException , IOException , SQLException , 1598 AuthorizeException 1599 { 1600 String buttonPressed = UIUtil.getSubmitButton(request, "submit_cancel"); 1601 1602 if (buttonPressed.equals("submit_grant")) 1603 { 1604 log.info(LogManager.getHeader(context, "accept_license", 1606 getSubmissionLogInfo(subInfo))); 1607 1608 Item item = subInfo.submission.getItem(); 1610 EPerson submitter = context.getCurrentUser(); 1611 1612 String license = subInfo.submission.getCollection().getLicense(); 1614 1615 item.licenseGranted(license, submitter); 1616 1617 WorkflowManager.start(context, (WorkspaceItem) subInfo.submission); 1619 1620 showProgressAwareJSP(request, response, subInfo, "/submit/complete.jsp"); 1622 context.complete(); 1623 } 1624 else if (request.getParameter("submit_reject") != null) 1625 { 1626 log.info(LogManager.getHeader(context, "reject_license", 1628 getSubmissionLogInfo(subInfo))); 1629 1630 JSPManager.showJSP(request, response, 1632 "/submit/license-rejected.jsp"); 1633 } 1634 else 1635 { 1636 doStepJump(context, request, response, subInfo); 1637 } 1638 } 1639 1640 1652 private void processCC(Context context, HttpServletRequest request, 1653 HttpServletResponse response, SubmissionInfo subInfo) 1654 throws ServletException , IOException , SQLException , 1655 AuthorizeException 1656 { 1657 String buttonPressed = UIUtil.getSubmitButton(request, "submit_next"); 1658 1659 if (buttonPressed.equals("submit_cancel")) 1661 { 1662 doCancellation(request, response, subInfo, CC_LICENSE, CC_LICENSE); 1663 } 1664 else if (buttonPressed.equals("submit_prev")) 1665 { 1666 doStep(context, request, response, subInfo, REVIEW_SUBMISSION); 1668 } 1669 else if (buttonPressed.equals("submit_next")) 1670 { 1671 userHasReached(subInfo, GRANT_LICENSE); 1673 1674 doStep(context, request, response, subInfo, GRANT_LICENSE); 1676 context.complete(); 1677 } 1678 else if (buttonPressed.equals("submit_no_cc")) 1679 { 1680 CreativeCommons 1682 .removeLicense(context, subInfo.submission.getItem()); 1683 userHasReached(subInfo, GRANT_LICENSE); 1684 doStep(context, request, response, subInfo, GRANT_LICENSE); 1685 context.complete(); 1686 } 1687 else 1688 { 1689 String ccLicenseUrl = request.getParameter("cc_license_url"); 1692 if ((ccLicenseUrl != null) && (ccLicenseUrl.length() > 0)) 1693 { 1694 Item item = subInfo.submission.getItem(); 1695 1696 CreativeCommons.setLicense(context, item, ccLicenseUrl); 1698 1699 userHasReached(subInfo, GRANT_LICENSE); 1700 doStep(context, request, response, subInfo, GRANT_LICENSE); 1701 context.complete(); 1702 } 1703 else 1704 { 1705 doStepJump(context, request, response, subInfo); 1706 } 1707 } 1708 } 1709 1710 1716 1730 private void doStepJump(Context context, HttpServletRequest request, 1731 HttpServletResponse response, SubmissionInfo subInfo) 1732 throws ServletException , IOException , SQLException 1733 { 1734 String buttonPressed = UIUtil.getSubmitButton(request, ""); 1737 1738 if (request instanceof FileUploadRequest) 1742 { 1743 FileUploadRequest fur = (FileUploadRequest) request; 1744 request = fur.getOriginalRequest(); 1745 } 1746 1747 int nextStep = -1; 1748 1749 if (buttonPressed.startsWith("submit_jump_")) 1750 { 1751 try 1753 { 1754 nextStep = Integer.parseInt(buttonPressed.substring(12)); 1755 } 1756 catch (NumberFormatException ne) 1757 { 1758 nextStep = -1; 1760 } 1761 1762 if (nextStep <= SubmitServlet.SELECT_COLLECTION) 1765 { 1766 nextStep = -1; 1767 } 1768 1769 if (!isWorkflow(subInfo) && (nextStep > getStepReached(subInfo))) 1770 { 1771 nextStep = -1; 1772 } 1773 } 1774 1775 if (nextStep == -1) 1776 { 1777 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 1781 .getRequestLogInfo(request))); 1782 JSPManager.showIntegrityError(request, response); 1783 } 1784 else 1785 { 1786 doStep(context, request, response, subInfo, nextStep); 1788 } 1789 } 1790 1791 1808 private void doStep(Context context, HttpServletRequest request, 1809 HttpServletResponse response, SubmissionInfo subInfo, int step) 1810 throws ServletException , IOException , SQLException 1811 { 1812 Collection c = subInfo.submission.getCollection(); 1814 1815 if ( step >= EDIT_METADATA_1 && step <= EDIT_METADATA_2 ) 1816 { 1817 request.setAttribute( "submission.inputs", inputsReader.getInputs(c.getHandle())); 1819 request.setAttribute( "submission.page", new Integer (step) ); 1821 showProgressAwareJSP(request, response, subInfo, 1822 "/submit/edit-metadata.jsp"); 1823 return; 1824 } 1825 1826 switch (step) 1827 { 1828 case INITIAL_QUESTIONS: 1829 request.setAttribute( "submission.inputs", inputsReader.getInputs(c.getHandle())); 1831 showProgressAwareJSP(request, response, subInfo, 1832 "/submit/initial-questions.jsp"); 1833 break; 1834 1835 1836 1837 case UPLOAD_FILES: 1838 showFirstUploadPage(context, request, response, subInfo); 1839 1840 break; 1841 1842 case CHOOSE_FILE: 1843 showProgressAwareJSP(request, response, subInfo, 1844 "/submit/choose-file.jsp"); 1845 break; 1846 1847 case FILE_LIST: 1848 showUploadFileList(request, response, subInfo, false, false); 1849 break; 1850 1851 case REVIEW_SUBMISSION: 1852 request.setAttribute( "submission.inputs", inputsReader.getInputs(c.getHandle())); 1854 showProgressAwareJSP(request, response, subInfo, 1855 "/submit/review.jsp"); 1856 break; 1857 1858 case GRANT_LICENSE: 1859 request.setAttribute("license", c.getLicense()); 1860 showProgressAwareJSP(request, response, subInfo, 1861 "/submit/show-license.jsp"); 1862 break; 1863 1864 case CC_LICENSE: 1865 1866 Item item = subInfo.submission.getItem(); 1868 boolean exists = CreativeCommons.hasLicense(context, item); 1869 request.setAttribute("cclicense.exists", new Boolean (exists) ); 1870 showProgressAwareJSP(request, response, subInfo, 1871 "/submit/creative-commons.jsp"); 1872 break; 1873 1874 case SUBMISSION_COMPLETE: 1875 showProgressAwareJSP(request, response, subInfo, 1876 "/submit/complete.jsp"); 1877 break; 1878 1879 default: 1880 log.warn(LogManager.getHeader(context, "integrity_error", UIUtil 1881 .getRequestLogInfo(request))); 1882 JSPManager.showIntegrityError(request, response); 1883 } 1884 } 1885 1886 1900 private void doCancellation(HttpServletRequest request, 1901 HttpServletResponse response, SubmissionInfo subInfo, int step, 1902 int displayStep) throws ServletException , IOException , SQLException 1903 { 1904 if (isWorkflow(subInfo)) 1907 { 1908 request.setAttribute("workflow.item", subInfo.submission); 1909 JSPManager.showJSP(request, response, "/mydspace/perform-task.jsp"); 1910 } 1911 else 1912 { 1913 request.setAttribute("step", String.valueOf(step)); 1914 request.setAttribute("display.step", String.valueOf(displayStep)); 1915 showProgressAwareJSP(request, response, subInfo, "/submit/cancel.jsp"); 1916 } 1917 } 1918 1919 1933 private void showFirstUploadPage(Context context, 1934 HttpServletRequest request, HttpServletResponse response, 1935 SubmissionInfo subInfo) throws SQLException , ServletException , 1936 IOException 1937 { 1938 Bundle[] bundles = subInfo.submission.getItem().getBundles("ORIGINAL"); 1939 1940 if (bundles.length > 0) 1941 { 1942 showUploadFileList(request, response, subInfo, false, false); 1944 } 1945 else 1946 { 1947 doStep(context, request, response, subInfo, CHOOSE_FILE); 1949 } 1950 } 1951 1952 1966 private void showUploadFileList(HttpServletRequest request, 1967 HttpServletResponse response, SubmissionInfo subInfo, 1968 boolean justUploaded, boolean showChecksums) throws SQLException , 1969 ServletException , IOException 1970 { 1971 request.setAttribute("just.uploaded", new Boolean (justUploaded)); 1973 request.setAttribute("show.checksums", new Boolean (showChecksums)); 1974 1975 if (isWorkflow(subInfo) || subInfo.submission.hasMultipleFiles()) 1977 { 1978 showProgressAwareJSP(request, response, subInfo, 1979 "/submit/upload-file-list.jsp"); 1980 } 1981 else 1982 { 1983 showProgressAwareJSP(request, response, subInfo, 1985 "/submit/show-uploaded-file.jsp"); 1986 } 1987 } 1988 1989 2003 private void showGetFileFormat(Context context, HttpServletRequest request, 2004 HttpServletResponse response, SubmissionInfo subInfo, 2005 Bitstream bitstream) throws SQLException , ServletException , 2006 IOException 2007 { 2008 BitstreamFormat[] formats = BitstreamFormat.findNonInternal(context); 2009 2010 subInfo.bitstream = bitstream; 2011 2012 request.setAttribute("bitstream.formats", formats); 2013 2014 BitstreamFormat guess = FormatIdentifier 2016 .guessFormat(context, bitstream); 2017 2018 request.setAttribute("guessed.format", guess); 2019 2020 showProgressAwareJSP(request, response, subInfo, 2021 "/submit/get-file-format.jsp"); 2022 } 2023 2024 2030 2037 private void showProgressAwareJSP( 2038 HttpServletRequest request, 2039 HttpServletResponse response, 2040 SubmissionInfo subInfo, 2041 String jspPath) 2042 throws ServletException , IOException 2043 { 2044 subInfo.numMetadataPages = 2047 inputsReader.getNumberInputPages(subInfo.submission.getCollection().getHandle()); 2048 request.setAttribute("submission.info", subInfo); 2049 2050 JSPManager.showJSP(request, response, jspPath); 2051 } 2052 2053 2064 private SubmissionInfo getSubmissionInfo(Context context, 2065 HttpServletRequest request) throws SQLException 2066 { 2067 SubmissionInfo info = new SubmissionInfo(); 2068 2069 if (request.getParameter("workflow_id") != null) 2070 { 2071 int workflowID = UIUtil.getIntParameter(request, "workflow_id"); 2072 info.submission = WorkflowItem.find(context, workflowID); 2073 } 2074 else 2075 { 2076 int workspaceID = UIUtil.getIntParameter(request, 2077 "workspace_item_id"); 2078 info.submission = WorkspaceItem.find(context, workspaceID); 2079 } 2080 2081 if (info.submission == null) 2083 { 2084 return null; 2085 } 2086 2087 if (request.getParameter("bundle_id") != null) 2088 { 2089 int bundleID = UIUtil.getIntParameter(request, "bundle_id"); 2090 info.bundle = Bundle.find(context, bundleID); 2091 } 2092 2093 if (request.getParameter("bitstream_id") != null) 2094 { 2095 int bitstreamID = UIUtil.getIntParameter(request, "bitstream_id"); 2096 info.bitstream = Bitstream.find(context, bitstreamID); 2097 } 2098 2099 return info; 2100 } 2101 2102 2109 public static boolean isWorkflow(SubmissionInfo si) 2110 { 2111 return ((si.submission != null) && si.submission instanceof WorkflowItem); 2112 } 2113 2114 2121 public static String getSubmissionParameters(SubmissionInfo si) 2122 { 2123 String info = ""; 2124 2125 if (isWorkflow(si)) 2126 { 2127 info = info + "<input type=\"hidden\" name=\"workflow_id\" value=\"" 2128 + si.submission.getID() + "\"/>"; 2129 } 2130 else 2131 { 2132 info = info + "<input type=\"hidden\" name=\"workspace_item_id\" value=\"" 2133 + si.submission.getID() + "\"/>"; 2134 } 2135 2136 if (si.bundle != null) 2137 { 2138 info = info + "<input type=\"hidden\" name=\"bundle_id\" value=\"" 2139 + si.bundle.getID() + "\"/>"; 2140 } 2141 2142 if (si.bitstream != null) 2143 { 2144 info = info + "<input type=\"hidden\" name=\"bitstream_id\" value=\"" 2145 + si.bitstream.getID() + "\"/>"; 2146 } 2147 2148 return info; 2149 } 2150 2151 2159 public String getSubmissionLogInfo(SubmissionInfo si) 2160 { 2161 String info = ""; 2162 2163 if (isWorkflow(si)) 2164 { 2165 info = info + "workflow_id=" + si.submission.getID(); 2166 } 2167 else 2168 { 2169 info = info + "workspace_item_id" + si.submission.getID(); 2170 } 2171 2172 if (si.bundle != null) 2173 { 2174 info = info + ",bundle_id=" + si.bundle.getID(); 2175 } 2176 2177 if (si.bitstream != null) 2178 { 2179 info = info + ",bitstream_id=" + si.bitstream.getID(); 2180 } 2181 2182 return info; 2183 } 2184 2185 2196 private void userHasReached(SubmissionInfo subInfo, int step) 2197 throws SQLException , AuthorizeException, IOException 2198 { 2199 if (!isWorkflow(subInfo)) 2200 { 2201 WorkspaceItem wi = (WorkspaceItem) subInfo.submission; 2202 2203 if (step > wi.getStageReached()) 2204 { 2205 wi.setStageReached(step); 2206 wi.update(); 2207 } 2208 } 2209 } 2210 2211 2220 public static int getStepReached(SubmissionInfo subInfo) 2221 { 2222 if (isWorkflow(subInfo)) 2223 { 2224 return -1; 2225 } 2226 else 2227 { 2228 WorkspaceItem wi = (WorkspaceItem) subInfo.submission; 2229 int i = wi.getStageReached(); 2230 2231 if (i == -1) 2235 { 2236 i = INITIAL_QUESTIONS; 2237 } 2238 2239 return i; 2240 } 2241 } 2242 2243 2249 2289 private void readNames(HttpServletRequest request, Item item, 2290 String schema, String element, String qualifier, boolean repeated) 2291 { 2292 String dcname = MetadataField.formKey(schema,element,qualifier); 2293 2294 List firsts = new LinkedList (); 2296 List lasts = new LinkedList (); 2297 2298 if (repeated) 2299 { 2300 firsts = getRepeatedParameter(request, dcname + "_first"); 2301 lasts = getRepeatedParameter(request, dcname + "_last"); 2302 2303 String buttonPressed = UIUtil.getSubmitButton(request, ""); 2305 String removeButton = "submit_" + dcname + "_remove_"; 2306 2307 if (buttonPressed.startsWith(removeButton)) 2308 { 2309 int valToRemove = Integer.parseInt(buttonPressed 2310 .substring(removeButton.length())); 2311 2312 firsts.remove(valToRemove); 2313 lasts.remove(valToRemove); 2314 } 2315 } 2316 else 2317 { 2318 String lastName = request.getParameter(dcname + "_last"); 2320 String firstNames = request.getParameter(dcname + "_first"); 2321 2322 lasts.add(lastName); 2323 firsts.add(firstNames); 2324 } 2325 2326 item.clearMetadata(schema, element, qualifier, Item.ANY); 2328 2329 for (int i = 0; i < lasts.size(); i++) 2331 { 2332 String f = (String ) firsts.get(i); 2333 String l = (String ) lasts.get(i); 2334 2335 if ((l != null) && !((l.trim()).equals(""))) 2337 { 2338 if (f == null) 2340 { 2341 f = ""; 2342 } 2343 2344 int comma = l.indexOf(','); 2348 2349 if (comma >= 0) 2350 { 2351 f = f + l.substring(comma + 1); 2352 l = l.substring(0, comma); 2353 2354 while (f.startsWith(" ")) 2356 { 2357 f = f.substring(1); 2358 } 2359 } 2360 2361 item.addMetadata(schema, element, qualifier, null, new DCPersonName(l, f) 2363 .toString()); 2364 } 2365 } 2366 } 2367 2368 2400 private void readText(HttpServletRequest request, Item item, String schema, 2401 String element, String qualifier, boolean repeated, String lang) 2402 { 2403 String dcname = MetadataField.formKey(schema,element,qualifier); 2406 2407 List vals = new LinkedList (); 2409 2410 if (repeated) 2411 { 2412 vals = getRepeatedParameter(request, dcname); 2413 2414 String buttonPressed = UIUtil.getSubmitButton(request, ""); 2416 String removeButton = "submit_" + dcname + "_remove_"; 2417 2418 if (buttonPressed.startsWith(removeButton)) 2419 { 2420 int valToRemove = Integer.parseInt(buttonPressed 2421 .substring(removeButton.length())); 2422 2423 vals.remove(valToRemove); 2424 } 2425 } 2426 else 2427 { 2428 vals.add(request.getParameter(dcname).trim()); 2430 ; 2431 } 2432 2433 item.clearMetadata(schema, element, qualifier, Item.ANY); 2435 2436 for (int i = 0; i < vals.size(); i++) 2438 { 2439 String s = (String ) vals.get(i); 2441 2442 if ((s != null) && !s.equals("")) 2443 { 2444 item.addMetadata(schema, element, qualifier, lang, s); 2445 } 2446 } 2447 } 2448 2449 2470 private void readDate(HttpServletRequest request, Item item, 2471 String schema, String element, String qualifier) throws SQLException 2472 { 2473 String dcname = MetadataField.formKey(schema,element,qualifier); 2474 2475 int year = UIUtil.getIntParameter(request, dcname + "_year"); 2476 int month = UIUtil.getIntParameter(request, dcname + "_month"); 2477 int day = UIUtil.getIntParameter(request, dcname + "_day"); 2478 2479 DCDate d = new DCDate(); 2482 2483 d.setDateLocal(year, month, day, -1, -1, -1); 2484 2485 item.clearMetadata(schema, element, qualifier, Item.ANY); 2486 2487 if (year > 0) 2488 { 2489 item.addMetadata(schema, element, qualifier, null, d.toString()); 2491 } 2492 } 2493 2494 2528 private void readSeriesNumbers(HttpServletRequest request, Item item, 2529 String schema, String element, String qualifier, boolean repeated) 2530 { 2531 String dcname = MetadataField.formKey(schema,element,qualifier); 2532 2533 List series = new LinkedList (); 2535 List numbers = new LinkedList (); 2536 2537 if (repeated) 2538 { 2539 series = getRepeatedParameter(request, dcname + "_series"); 2540 numbers = getRepeatedParameter(request, dcname + "_number"); 2541 2542 String buttonPressed = UIUtil.getSubmitButton(request, ""); 2544 String removeButton = "submit_" + dcname + "_remove_"; 2545 2546 if (buttonPressed.startsWith(removeButton)) 2547 { 2548 int valToRemove = Integer.parseInt(buttonPressed 2549 .substring(removeButton.length())); 2550 2551 series.remove(valToRemove); 2552 numbers.remove(valToRemove); 2553 } 2554 } 2555 else 2556 { 2557 String s = request.getParameter(dcname + "_series"); 2559 String n = request.getParameter(dcname + "_number"); 2560 2561 if ((s != null) && !s.equals("")) 2563 { 2564 series.add(s); 2565 numbers.add(n); 2566 } 2567 } 2568 2569 item.clearMetadata(schema, element, qualifier, Item.ANY); 2571 2572 for (int i = 0; i < series.size(); i++) 2574 { 2575 String s = ((String ) series.get(i)).trim(); 2576 String n = ((String ) numbers.get(i)).trim(); 2577 2578 if (!s.equals("") || !n.equals("")) 2580 { 2581 item.addMetadata(schema, element, qualifier, null, new DCSeriesNumber(s, n) 2582 .toString()); 2583 } 2584 } 2585 } 2586 2587 2598 private List getRepeatedParameter(HttpServletRequest request, String param) 2599 { 2600 List vals = new LinkedList (); 2601 2602 int i = 0; 2603 boolean foundLast = false; 2604 2605 while (!foundLast) 2607 { 2608 String s = request.getParameter(param + "_" + i); 2609 2610 if (s != null) 2612 { 2613 vals.add(s.trim()); 2614 } 2615 else 2616 { 2617 foundLast = true; 2620 } 2621 2622 i++; 2623 } 2624 2625 return vals; 2626 } 2627} 2628 | Popular Tags |