Beispiel #1
0
 /**
  * Checks whether:
  *
  * <ul>
  *   <li>a job list name is specified in the given UWS URL <i>(<u>note:</u> by default, the
  *       existence of the jobs list is not checked)</i>,
  *   <li>the UWS URL does not make a reference to a job (so: no job ID),
  *   <li>the HTTP method is HTTP-POST.
  * </ul>
  *
  * @see uws.service.actions.UWSAction#match(UWSUrl, JobOwner, HttpServletRequest)
  */
 @Override
 public boolean match(UWSUrl urlInterpreter, JobOwner user, HttpServletRequest request)
     throws UWSException {
   return (urlInterpreter.hasJobList()
       && !urlInterpreter.hasJob()
       && request.getMethod().equalsIgnoreCase("post"));
 }
Beispiel #2
0
  /**
   * Gets the specified jobs list <i>(throw an error if not found)</i>, creates a new job, adds it
   * to the jobs list and makes a redirection to the summary of this new job.
   *
   * @see #getJobsList(UWSUrl)
   * @see uws.service.UWSFactory#createJob(HttpServletRequest, JobOwner)
   * @see JobList#addNewJob(UWSJob)
   * @see UWSService#redirect(String, HttpServletRequest, JobOwner, String, HttpServletResponse)
   * @see uws.service.actions.UWSAction#apply(UWSUrl, JobOwner, HttpServletRequest,
   *     HttpServletResponse)
   */
  @Override
  public boolean apply(
      UWSUrl urlInterpreter,
      JobOwner user,
      HttpServletRequest request,
      HttpServletResponse response)
      throws UWSException, IOException {
    // Get the jobs list:
    JobList jobsList = getJobsList(urlInterpreter);

    // Forbids the job creation if the user has not the WRITE permission for the specified jobs
    // list:
    if (user != null && !user.hasWritePermission(jobsList))
      throw new UWSException(
          UWSException.PERMISSION_DENIED,
          UWSExceptionFactory.writePermissionDenied(user, true, jobsList.getName()));

    // Create the job:
    UWSJob newJob;
    try {
      newJob = uws.getFactory().createJob(request, user);
    } catch (UWSException ue) {
      getLogger()
          .logUWS(LogLevel.ERROR, urlInterpreter, "ADD_JOB", "Can not create a new job!", ue);
      throw ue;
    }

    // Add it to the jobs list:
    if (jobsList.addNewJob(newJob) != null) {

      // Make a redirection to the added job:
      uws.redirect(
          urlInterpreter.jobSummary(jobsList.getName(), newJob.getJobId()).getRequestURL(),
          request,
          user,
          getName(),
          response);

      return true;
    } else
      throw new UWSException(
          UWSException.INTERNAL_SERVER_ERROR,
          "Unable to add the new job to the jobs list for an unknown reason. (ID of the new job = \""
              + newJob.getJobId()
              + "\" ; ID already used = "
              + (jobsList.getJob(newJob.getJobId()) != null)
              + ")");
  }