agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/JobsResource.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.
	 */
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
	{
		AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.JOBS02.name(),
				AgaveLogServiceClient.ActivityKeys.JobsList.name(),
				getAuthenticatedUsername(), "", getRequest().getClientInfo().getUpstreamAddress());
		try
		{
			Map<SearchTerm, Object> queryParameters = getQueryParameters();
			if (queryParameters.isEmpty()) {
				List<Job> jobs = JobDao.getByUsername(getAuthenticatedUsername(), offset, limit, getSortOrder(AgaveResourceResultOrdering.DESC), getSortOrderSearchTerm());
				if (hasJsonPathFilters()) {
					ObjectMapper mapper = new ObjectMapper();
					ArrayNode json = mapper.createArrayNode();
					for(Job job: jobs)
					{
						json.add(mapper.readTree(job.toJSON()));
					}
					return new IplantSuccessRepresentation(json.toString());
				}
				else {
					JSONWriter writer = new JSONStringer();
					writer.array();
					for(Job job: jobs)
					{
						writer.object()
							.key("id").value(job.getUuid())
							.key("name").value(job.getName())
							.key("owner").value(job.getOwner())
							.key("executionSystem").value(job.getSystem())
							.key("appId").value(job.getSoftwareName())
							.key("created").value(new DateTime(job.getCreated()).toString())
							.key("status").value(job.getStatus())
							.key("startTime").value(job.getStartTime() == null ? null : new DateTime(job.getStartTime()).toString())
							.key("endTime").value(job.getEndTime() == null ? null : new DateTime(job.getEndTime()).toString())
							.key("_links").object()
					        	.key("self").object()
					        		.key("href").value(TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_JOB_SERVICE) + job.getUuid())
						        .endObject()
						        .key("archiveData").object()
				        			.key("href").value(TenancyHelper.resolveURLToCurrentTenant(job.getArchiveUrl()))
						        .endObject()
					       .endObject()
				        .endObject();
					}
					writer.endArray();
					return new IplantSuccessRepresentation(writer.toString());
				}
			} 
			else {
				List<JobDTO> jobs = JobDao.findMatching(getAuthenticatedUsername(), queryParameters, offset, limit, getSortOrder(AgaveResourceResultOrdering.DESC), getSortOrderSearchTerm());
				ObjectMapper mapper = new ObjectMapper();
				if (hasJsonPathFilters()) {
					return new IplantSuccessRepresentation(mapper.writeValueAsString(jobs));
				}
				else {
					JSONWriter writer = new JSONStringer();
					writer.array();
					for(JobDTO job: jobs)
					{
						writer.object()
							.key("id").value(job.getUuid())
							.key("name").value(job.getName())
							.key("owner").value(job.getOwner())
							.key("executionSystem").value(job.getExecution_system())
							.key("appId").value(job.getSoftware_name())
							.key("created").value(new DateTime(job.getCreated()).toString())
							.key("status").value(job.getStatus())
							.key("startTime").value(job.getStart_time() == null ? null : new DateTime(job.getStart_time()).toString())
							.key("endTime").value(job.getEnd_time() == null ? null : new DateTime(job.getEnd_time()).toString())
							.key("_links").object()
					        	.key("self").object()
					        		.key("href").value(TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_JOB_SERVICE) + job.getUuid())
						        .endObject()
						        .key("archiveData").object()
				        			.key("href").value(TenancyHelper.resolveURLToCurrentTenant(job.getArchiveUrl()))
						        .endObject()
					       .endObject()
				        .endObject();
					}
					writer.endArray();
					return new IplantSuccessRepresentation(writer.toString());
				}
			}	
		}
		catch (HibernateException e) {
				log.error("Failed to fetch job listings from db.", e);
				getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
						return new IplantErrorRepresentation("Unable to fetch job records.");
		}
		catch (Exception e)
		{
			log.error("Failed to fetch job listings from db.", 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 { AgaveLogServiceClient . log ( AgaveLogServiceClient . ServiceKeys . JOBS02 . name ( ) , AgaveLogServiceClient . ActivityKeys . JobsList . name ( ) , getAuthenticatedUsername ( ) , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; try { Map < SearchTerm , Object > queryParameters = getQueryParameters ( ) ; if ( queryParameters . isEmpty ( ) ) { List < Job > jobs = JobDao . getByUsername ( getAuthenticatedUsername ( ) , offset , limit , getSortOrder ( AgaveResourceResultOrdering . DESC ) , getSortOrderSearchTerm ( ) ) ; if ( hasJsonPathFilters ( ) ) { ObjectMapper mapper = new ObjectMapper ( ) ; ArrayNode json = mapper . createArrayNode ( ) ; for ( Job job : jobs ) { json . add ( mapper . readTree ( job . toJSON ( ) ) ) ; } return new IplantSuccessRepresentation ( json . toString ( ) ) ; } else { JSONWriter writer = new JSONStringer ( ) ; writer . array ( ) ; for ( Job job : jobs ) { writer . object ( ) . key ( "id" ) . value ( job . getUuid ( ) ) . key ( "name" ) . value ( job . getName ( ) ) . key ( "owner" ) . value ( job . getOwner ( ) ) . key ( "executionSystem" ) . value ( job . getSystem ( ) ) . key ( "appId" ) . value ( job . getSoftwareName ( ) ) . key ( "created" ) . value ( new DateTime ( job . getCreated ( ) ) . toString ( ) ) . key ( "status" ) . value ( job . getStatus ( ) ) . key ( "startTime" ) . value ( job . getStartTime ( ) == null ? null : new DateTime ( job . getStartTime ( ) ) . toString ( ) ) . key ( "endTime" ) . value ( job . getEndTime ( ) == null ? null : new DateTime ( job . getEndTime ( ) ) . toString ( ) ) . key ( "_links" ) . object ( ) . key ( "self" ) . object ( ) . key ( "href" ) . value ( TenancyHelper . resolveURLToCurrentTenant ( Settings . IPLANT_JOB_SERVICE ) + job . getUuid ( ) ) . endObject ( ) . key ( "archiveData" ) . object ( ) . key ( "href" ) . value ( TenancyHelper . resolveURLToCurrentTenant ( job . getArchiveUrl ( ) ) ) . endObject ( ) . endObject ( ) . endObject ( ) ; } writer . endArray ( ) ; return new IplantSuccessRepresentation ( writer . toString ( ) ) ; } } else { List < JobDTO > jobs = JobDao . findMatching ( getAuthenticatedUsername ( ) , queryParameters , offset , limit , getSortOrder ( AgaveResourceResultOrdering . DESC ) , getSortOrderSearchTerm ( ) ) ; ObjectMapper mapper = new ObjectMapper ( ) ; if ( hasJsonPathFilters ( ) ) { return new IplantSuccessRepresentation ( mapper . writeValueAsString ( jobs ) ) ; } else { JSONWriter writer = new JSONStringer ( ) ; writer . array ( ) ; for ( JobDTO job : jobs ) { writer . object ( ) . key ( "id" ) . value ( job . getUuid ( ) ) . key ( "name" ) . value ( job . getName ( ) ) . key ( "owner" ) . value ( job . getOwner ( ) ) . key ( "executionSystem" ) . value ( job . getExecution_system ( ) ) . key ( "appId" ) . value ( job . getSoftware_name ( ) ) . key ( "created" ) . value ( new DateTime ( job . getCreated ( ) ) . toString ( ) ) . key ( "status" ) . value ( job . getStatus ( ) ) . key ( "startTime" ) . value ( job . getStart_time ( ) == null ? null : new DateTime ( job . getStart_time ( ) ) . toString ( ) ) . key ( "endTime" ) . value ( job . getEnd_time ( ) == null ? null : new DateTime ( job . getEnd_time ( ) ) . toString ( ) ) . key ( "_links" ) . object ( ) . key ( "self" ) . object ( ) . key ( "href" ) . value ( TenancyHelper . resolveURLToCurrentTenant ( Settings . IPLANT_JOB_SERVICE ) + job . getUuid ( ) ) . endObject ( ) . key ( "archiveData" ) . object ( ) . key ( "href" ) . value ( TenancyHelper . resolveURLToCurrentTenant ( job . getArchiveUrl ( ) ) ) . endObject ( ) . endObject ( ) . endObject ( ) ; } writer . endArray ( ) ; return new IplantSuccessRepresentation ( writer . toString ( ) ) ; } } } catch ( HibernateException e ) { log . error ( "Failed to fetch job listings from db." , e ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; return new IplantErrorRepresentation ( "Unable to fetch job records." ) ; } catch ( Exception e ) { log . error ( "Failed to fetch job listings from db." , 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 .
//				Job job = jobs.get(i); //					return new IplantSuccessRepresentation(mapper.valueToTree(jobs)); //				Job job = jobs.get(i);