/** * 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) + ")"); }