agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/JobStatusResource.java
/**
	 * This method represents the HTTP GET action. A list of jobs is retrieved
	 * from the service database and serialized to a {@link org.json.JSONArray
	 * JSONArray} of {@link org.json.JSONObject JSONObject}. On error, a HTTP
	 * {@link org.restlet.data.Status#SERVER_ERROR_INTERNAL 500} code is sent.
	 * <p>
	 * The format for the job list will be:
	 * <p>
	 * <code>
	 * [
	 *   {
	 *     "created":"2010-03-01 15:01:37.0",
	 *     "localId":"4936233",
	 *     "submitTime":"2010-03-01 15:01:38.0",
	 *     "updateToken":"d9463c48-f86b-469f-a037-b00892464d78",
	 *     "status":"SUBMITTING",
	 *     "id":2,
	 *     "endTime":null,
	 *     "ownerDn":"uid=xxx,ou=People,dc=iplantcollaborative,dc=org",
	 *     "inputListing":null,
	 *     "running":true,
	 *     "lastUpdated":"2010-03-01 15:01:38.0",
	 *     "system":"slogin2",
	 *     "startTime":null,
	 *     "outputListing":null,
	 *     "name":"test_job"
	 *   }
	 * ]
	 * </code>
	 */
This method represents the HTTP GET action. A list of jobs is retrieved
from the service database and serialized to a {@link org.json.JSONArray
JSONArray} of  org.json.JSONObject JSONObject. On error, a HTTP
org.restlet.data.Status#SERVER_ERROR_INTERNAL 500 code is sent.
This method represents the HTTP GET action . A list of jobs is retrieved from the service database and serialized to a { @link org . json . JSONArray JSONArray } of org . json . JSONObject JSONObject . On error a HTTP org . restlet . data . Status#SERVER_ERROR_INTERNAL 500 code is sent .
@Override
	public Representation represent(Variant variant) throws ResourceException
	{
		try {
			if (!ServiceUtils.isValid(sJobId)) {
				getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
				return new IplantErrorRepresentation("Job id cannot be empty");
			}
			try {
				job = JobDao.getByUuid(sJobId, true);
				if (job == null || !job.isVisible()) {
					getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
					return new IplantErrorRepresentation(
							"Not job found with job id " + sJobId);
				} else if (new JobPermissionManager(job, username).canRead(username)) {
					JSONObject json = new JSONObject();
					json.put("id", sJobId);
					json.put("status", job.getStatus().name());
					json.put("_links",
							new JSONObject().put("self",
									new JSONObject().put("href", TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_JOB_SERVICE) + job.getUuid())));
					return new IplantSuccessRepresentation(json.toString());
				} else {
					getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN);
					return new IplantErrorRepresentation(
							"User does not have permission to view this job");
				}
			} catch (JobException e) {
				getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
				return new IplantErrorRepresentation("Invalid job id "
						+ e.getMessage());
			} catch (Exception e) {
				getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
				return new IplantErrorRepresentation(e.getMessage());
			}
		}
		finally {
			try { HibernateUtil.closeSession(); } catch (Throwable ignored) {}
		}
	}
@ Override public Representation represent ( Variant variant ) throws ResourceException { try { if ( ! ServiceUtils . isValid ( sJobId ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "Job id cannot be empty" ) ; } try { job = JobDao . getByUuid ( sJobId , true ) ; if ( job == null || ! job . isVisible ( ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_NOT_FOUND ) ; return new IplantErrorRepresentation ( "Not job found with job id " + sJobId ) ; } else if ( new JobPermissionManager ( job , username ) . canRead ( username ) ) { JSONObject json = new JSONObject ( ) ; json . put ( "id" , sJobId ) ; json . put ( "status" , job . getStatus ( ) . name ( ) ) ; json . put ( "_links" , new JSONObject ( ) . put ( "self" , new JSONObject ( ) . put ( "href" , TenancyHelper . resolveURLToCurrentTenant ( Settings . IPLANT_JOB_SERVICE ) + job . getUuid ( ) ) ) ) ; return new IplantSuccessRepresentation ( json . toString ( ) ) ; } else { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_FORBIDDEN ) ; return new IplantErrorRepresentation ( "User does not have permission to view this job" ) ; } } catch ( JobException e ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "Invalid job id " + e . getMessage ( ) ) ; } catch ( Exception e ) { getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; return new IplantErrorRepresentation ( e . getMessage ( ) ) ; } } finally { try { HibernateUtil . closeSession ( ) ; } catch ( Throwable ignored ) { } } }
This method represents the HTTP GET action.
This method represents the HTTP GET action .
// can't set a stopped job back to running. Bad request