예제 #1
0
  /**
   * Process input from get file type page
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by UI-related code! (if STATUS_COMPLETE or
   *     0 is returned, no errors occurred!)
   */
  protected int processSaveFileFormat(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    if (subInfo.getBitstream() != null) {
      // Did the user select a format?
      int typeID = Util.getIntParameter(request, "format");

      BitstreamFormat format = BitstreamFormat.find(context, typeID);

      if (format != null) {
        subInfo.getBitstream().setFormat(format);
      } else {
        String userDesc = request.getParameter("format_description");

        subInfo.getBitstream().setUserFormatDescription(userDesc);
      }

      // update database
      subInfo.getBitstream().update();
    } else {
      return STATUS_INTEGRITY_ERROR;
    }

    return STATUS_COMPLETE;
  }
예제 #2
0
  protected Group checkGroup(Context context, HttpServletRequest request)
      throws ServletException, IOException, SQLException, AuthorizeException {

    // Find out if there's a group parameter
    int groupID = Util.getIntParameter(request, "group_id");
    Group group = null;

    if (groupID >= 0) {
      group = Group.find(context, groupID);
    }

    return group;
  } // end checkGroup
  protected void doDSGet(Context context, HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // dispense with simple service document requests
    String scope = request.getParameter("scope");
    if (scope != null && "".equals(scope)) {
      scope = null;
    }
    String path = request.getPathInfo();
    if (path != null && path.endsWith("description.xml")) {
      String svcDescrip = OpenSearch.getDescription(scope);
      response.setContentType(OpenSearch.getContentType("opensearchdescription"));
      response.setContentLength(svcDescrip.length());
      response.getWriter().write(svcDescrip);
      return;
    }

    // get enough request parameters to decide on action to take
    String format = request.getParameter("format");
    if (format == null || "".equals(format)) {
      // default to atom
      format = "atom";
    }

    // do some sanity checking
    if (!OpenSearch.getFormats().contains(format)) {
      response.sendError(HttpServletResponse.SC_BAD_REQUEST);
      return;
    }

    // then the rest - we are processing the query
    String query = request.getParameter("query");
    int start = Util.getIntParameter(request, "start");
    int rpp = Util.getIntParameter(request, "rpp");
    int sort = Util.getIntParameter(request, "sort_by");
    String order = request.getParameter("order");
    String sortOrder =
        (order == null || order.length() == 0 || order.toLowerCase().startsWith("asc"))
            ? SortOption.ASCENDING
            : SortOption.DESCENDING;

    QueryArgs qArgs = new QueryArgs();
    // can't start earlier than 0 in the results!
    if (start < 0) {
      start = 0;
    }
    qArgs.setStart(start);

    if (rpp > 0) {
      qArgs.setPageSize(rpp);
    }
    qArgs.setSortOrder(sortOrder);

    if (sort > 0) {
      try {
        qArgs.setSortOption(SortOption.getSortOption(sort));
      } catch (Exception e) {
        // invalid sort id - do nothing
      }
    }
    qArgs.setSortOrder(sortOrder);

    // Ensure the query is non-null
    if (query == null) {
      query = "";
    }

    // If there is a scope parameter, attempt to dereference it
    // failure will only result in its being ignored
    DSpaceObject container = (scope != null) ? HandleManager.resolveToObject(context, scope) : null;

    // Build log information
    String logInfo = "";

    // get the start of the query results page
    qArgs.setQuery(query);

    // Perform the search
    QueryResults qResults = null;
    if (container == null) {
      qResults = DSQuery.doQuery(context, qArgs);
    } else if (container instanceof Collection) {
      logInfo = "collection_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Collection) container);
    } else if (container instanceof Community) {
      logInfo = "community_id=" + container.getID() + ",";
      qResults = DSQuery.doQuery(context, qArgs, (Community) container);
    }

    // now instantiate the results
    DSpaceObject[] results = new DSpaceObject[qResults.getHitHandles().size()];
    for (int i = 0; i < qResults.getHitHandles().size(); i++) {
      String myHandle = (String) qResults.getHitHandles().get(i);
      DSpaceObject dso = HandleManager.resolveToObject(context, myHandle);
      if (dso == null) {
        throw new SQLException("Query \"" + query + "\" returned unresolvable handle: " + myHandle);
      }
      results[i] = dso;
    }

    // Log
    log.info(
        LogManager.getHeader(
            context,
            "search",
            logInfo + "query=\"" + query + "\",results=(" + results.length + ")"));

    // format and return results
    Map<String, String> labelMap = getLabels(request);
    Document resultsDoc =
        OpenSearch.getResultsDoc(format, query, qResults, container, results, labelMap);
    try {
      Transformer xf = TransformerFactory.newInstance().newTransformer();
      response.setContentType(OpenSearch.getContentType(format));
      xf.transform(new DOMSource(resultsDoc), new StreamResult(response.getWriter()));
    } catch (TransformerException e) {
      log.error(e);
      throw new ServletException(e.toString());
    }
  }
예제 #4
0
  /**
   * Do any processing of the information input by the user, and/or perform step processing (if no
   * user interaction required)
   *
   * <p>It is this method's job to save any data to the underlying database, as necessary, and
   * return error messages (if any) which can then be processed by the appropriate user interface
   * (JSP-UI or XML-UI)
   *
   * <p>NOTE: If this step is a non-interactive step (i.e. requires no UI), then it should perform
   * *all* of its processing in this method!
   *
   * @param context current DSpace context
   * @param request current servlet request object
   * @param response current servlet response object
   * @param subInfo submission info object
   * @return Status or error flag which will be processed by doPostProcessing() below! (if
   *     STATUS_COMPLETE or 0 is returned, no errors occurred!)
   */
  public int doProcessing(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      SubmissionInfo subInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // get button user pressed
    String buttonPressed = Util.getSubmitButton(request, NEXT_BUTTON);

    // get reference to item
    Item item = subInfo.getSubmissionItem().getItem();

    // -----------------------------------
    // Step #0: Upload new files (if any)
    // -----------------------------------
    String contentType = request.getContentType();

    // if multipart form, then we are uploading a file
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") != -1)) {
      // This is a multipart request, so it's a file upload
      // (return any status messages or errors reported)
      int status = processUploadFile(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // if user pressed jump-to button in process bar,
    // return success (so that jump will occur)
    if (buttonPressed.startsWith(PROGRESS_BAR_PREFIX)) {
      // check if a file is required to be uploaded
      if (fileRequired && !item.hasUploadedFiles()) {
        return STATUS_NO_FILES_ERROR;
      } else {
        return STATUS_COMPLETE;
      }
    }

    // ---------------------------------------------
    // Step #1: Check if this was just a request to
    // edit file information.
    // (or canceled editing information)
    // ---------------------------------------------
    // check if we're already editing a specific bitstream
    if (request.getParameter("bitstream_id") != null) {
      if (buttonPressed.equals(CANCEL_EDIT_BUTTON)) {
        // canceled an edit bitstream request
        subInfo.setBitstream(null);

        // this flag will just return us to the normal upload screen
        return STATUS_EDIT_COMPLETE;
      } else {
        // load info for bitstream we are editing
        Bitstream b =
            Bitstream.find(context, Integer.parseInt(request.getParameter("bitstream_id")));

        // save bitstream to submission info
        subInfo.setBitstream(b);
      }
    } else if (buttonPressed.startsWith("submit_edit_")) {
      // get ID of bitstream that was requested for editing
      String bitstreamID = buttonPressed.substring("submit_edit_".length());

      Bitstream b = Bitstream.find(context, Integer.parseInt(bitstreamID));

      // save bitstream to submission info
      subInfo.setBitstream(b);

      // return appropriate status flag to say we are now editing the
      // bitstream
      return STATUS_EDIT_BITSTREAM;
    }

    // ---------------------------------------------
    // Step #2: Process any remove file request(s)
    // ---------------------------------------------
    // Remove-selected requests come from Manakin
    if (buttonPressed.equalsIgnoreCase("submit_remove_selected")) {
      // this is a remove multiple request!

      if (request.getParameter("remove") != null) {
        // get all files to be removed
        String[] removeIDs = request.getParameterValues("remove");

        // remove each file in the list
        for (int i = 0; i < removeIDs.length; i++) {
          int id = Integer.parseInt(removeIDs[i]);

          int status = processRemoveFile(context, item, id);

          // if error occurred, return immediately
          if (status != STATUS_COMPLETE) {
            return status;
          }
        }

        // remove current bitstream from Submission Info
        subInfo.setBitstream(null);
      }
    } else if (buttonPressed.startsWith("submit_remove_")) {
      // A single file "remove" button must have been pressed

      int id = Integer.parseInt(buttonPressed.substring(14));
      int status = processRemoveFile(context, item, id);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }

      // remove current bitstream from Submission Info
      subInfo.setBitstream(null);
    }

    // -------------------------------------------------
    // Step #3: Check for a change in file description
    // -------------------------------------------------
    String fileDescription = request.getParameter("description");

    if (fileDescription != null && fileDescription.length() > 0) {
      // save this file description
      int status = processSaveFileDescription(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // ------------------------------------------
    // Step #4: Check for a file format change
    // (if user had to manually specify format)
    // ------------------------------------------
    int formatTypeID = Util.getIntParameter(request, "format");
    String formatDesc = request.getParameter("format_description");

    // if a format id or description was found, then save this format!
    if (formatTypeID >= 0 || (formatDesc != null && formatDesc.length() > 0)) {
      // save this specified format
      int status = processSaveFileFormat(context, request, response, subInfo);

      // if error occurred, return immediately
      if (status != STATUS_COMPLETE) {
        return status;
      }
    }

    // ---------------------------------------------------
    // Step #5: Check if primary bitstream has changed
    // -------------------------------------------------
    if (request.getParameter("primary_bitstream_id") != null) {
      Bundle[] bundles = item.getBundles("ORIGINAL");
      if (bundles.length > 0) {
        bundles[0].setPrimaryBitstreamID(
            Integer.valueOf(request.getParameter("primary_bitstream_id")).intValue());
        bundles[0].update();
      }
    }

    // ---------------------------------------------------
    // Step #6: Determine if there is an error because no
    // files have been uploaded.
    // ---------------------------------------------------
    // check if a file is required to be uploaded
    if (fileRequired && !item.hasUploadedFiles()) {
      return STATUS_NO_FILES_ERROR;
    }

    // commit all changes to database
    context.commit();

    return STATUS_COMPLETE;
  }