agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/JobHistoryResource.java
/**
	 * Returns a collection of JobEvent objects representing the history
	 * of events for this job.
	 */
Returns a collection of JobEvent objects representing the history
of events for this job.
Returns a collection of JobEvent objects representing the history of events for this job .
@Override
	public Representation represent(Variant variant) throws ResourceException
	{
		try {
			AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.JOBS02.name(),
					AgaveLogServiceClient.ActivityKeys.JobsGetHistory.name(),
					getAuthenticatedUsername(), "", getRequest().getClientInfo().getUpstreamAddress());
			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) {
					String msg = "No job found with job id " + sJobId + ".";
					log.error(msg);
					throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, msg);
				} else if (!job.isVisible()) {
					String msg = "Job with uuid " + sJobId + " is not visible.";
					log.error(msg);
					throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, msg);
				} else if (new JobPermissionManager(job, getAuthenticatedUsername()).canRead(getAuthenticatedUsername())) {
					ObjectMapper mapper = new ObjectMapper();
					ArrayNode history = mapper.createArrayNode();
					Map<SearchTerm, Object> queryParameters = getQueryParameters();
					List<JobEvent> events = null;
					if (queryParameters.isEmpty()) {
						events = JobEventDao.getByJobId(job.getId(), limit, offset, getSortOrder(AgaveResourceResultOrdering.ASC), getSortOrderSearchTerm());
					} else {
						events = JobEventDao.findMatching(job.getId(), queryParameters, offset, limit, getSortOrder(AgaveResourceResultOrdering.ASC), getSortOrderSearchTerm());
					}
					for (JobEvent event : events) {
						ObjectNode jsonEvent = mapper.createObjectNode();
						if (event.getTransferTask() != null) {
                .put("href", TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_TRANSFER_SERVICE) + event.getTransferTask().getUuid());
							ObjectNode jsonTransferTask = mapper.createObjectNode();
							try {
								TransferSummary summary = TransferTaskDao.getTransferSummary(event.getTransferTask());
								jsonTransferTask
										.put("uuid", event.getTransferTask().getUuid())
										.put("source", event.getTransferTask().getSource())
										.put("totalActiveTransfers", summary.getTotalActiveTransfers())
										.put("totalFiles", summary.getTotalTransfers())
										.put("totalBytesTransferred", summary.getTotalTransferredBytes().longValue())
										.put("totalBytes", summary.getTotalBytes().longValue())
										.put("averageRate", summary.getAverageTransferRate());
								jsonEvent.set("progress", jsonTransferTask);
							} catch (TransferException e) {
								jsonEvent.put("progress", (String) null);
							}
						}
						jsonEvent
								.put("status", event.getStatus())
								.put("created", new DateTime(event.getCreated()).toString())
								.put("createdBy", event.getCreatedBy())
								.put("description", event.getDescription());
						history.add(jsonEvent);
					}
					return new IplantSuccessRepresentation(history.toString());
				} else {
					getResponse().setStatus(Status.CLIENT_ERROR_FORBIDDEN);
					return new IplantErrorRepresentation(
							"User does not have permission to view this job history");
				}
			} catch (ResourceException e) {
				throw e;
			} 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 { AgaveLogServiceClient . log ( AgaveLogServiceClient . ServiceKeys . JOBS02 . name ( ) , AgaveLogServiceClient . ActivityKeys . JobsGetHistory . name ( ) , getAuthenticatedUsername ( ) , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; 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 ) { String msg = "No job found with job id " + sJobId + "." ; log . error ( msg ) ; throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , msg ) ; } else if ( ! job . isVisible ( ) ) { String msg = "Job with uuid " + sJobId + " is not visible." ; log . error ( msg ) ; throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , msg ) ; } else if ( new JobPermissionManager ( job , getAuthenticatedUsername ( ) ) . canRead ( getAuthenticatedUsername ( ) ) ) { ObjectMapper mapper = new ObjectMapper ( ) ; ArrayNode history = mapper . createArrayNode ( ) ; Map < SearchTerm , Object > queryParameters = getQueryParameters ( ) ; List < JobEvent > events = null ; if ( queryParameters . isEmpty ( ) ) { events = JobEventDao . getByJobId ( job . getId ( ) , limit , offset , getSortOrder ( AgaveResourceResultOrdering . ASC ) , getSortOrderSearchTerm ( ) ) ; } else { events = JobEventDao . findMatching ( job . getId ( ) , queryParameters , offset , limit , getSortOrder ( AgaveResourceResultOrdering . ASC ) , getSortOrderSearchTerm ( ) ) ; } for ( JobEvent event : events ) { ObjectNode jsonEvent = mapper . createObjectNode ( ) ; if ( event . getTransferTask ( ) != null ) { ObjectNode jsonTransferTask = mapper . createObjectNode ( ) ; try { TransferSummary summary = TransferTaskDao . getTransferSummary ( event . getTransferTask ( ) ) ; jsonTransferTask . put ( "uuid" , event . getTransferTask ( ) . getUuid ( ) ) . put ( "source" , event . getTransferTask ( ) . getSource ( ) ) . put ( "totalActiveTransfers" , summary . getTotalActiveTransfers ( ) ) . put ( "totalFiles" , summary . getTotalTransfers ( ) ) . put ( "totalBytesTransferred" , summary . getTotalTransferredBytes ( ) . longValue ( ) ) . put ( "totalBytes" , summary . getTotalBytes ( ) . longValue ( ) ) . put ( "averageRate" , summary . getAverageTransferRate ( ) ) ; jsonEvent . set ( "progress" , jsonTransferTask ) ; } catch ( TransferException e ) { jsonEvent . put ( "progress" , ( String ) null ) ; } } jsonEvent . put ( "status" , event . getStatus ( ) ) . put ( "created" , new DateTime ( event . getCreated ( ) ) . toString ( ) ) . put ( "createdBy" , event . getCreatedBy ( ) ) . put ( "description" , event . getDescription ( ) ) ; history . add ( jsonEvent ) ; } return new IplantSuccessRepresentation ( history . toString ( ) ) ; } else { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_FORBIDDEN ) ; return new IplantErrorRepresentation ( "User does not have permission to view this job history" ) ; } } catch ( ResourceException e ) { throw e ; } 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 ) { } } }
Returns a collection of JobEvent objects representing the history
 of events for this job.
Returns a collection of JobEvent objects representing the history of events for this job .
//            		ObjectNode jsonLinks = mapper.createObjectNode(); //            		jsonLinks.putObject("self") //                        .put("href", TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_JOB_SERVICE) + job.getUuid() + "/events/" + event.getUUid()); //            		jsonLinks.putObject("job") //            		    .put("href", TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_JOB_SERVICE) + job.getUuid()); //             //    				    ObjectNode jsonLinks = mapper.createObjectNode(); //    				    jsonLinks.putObject("transferTask") //                            .put("href", TenancyHelper.resolveURLToCurrentTenant(Settings.IPLANT_TRANSFER_SERVICE) + event.getTransferTask().getUuid()); //             //					    .put("_links", jsonLinks); // can't set a stopped job back to running. Bad request