agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/OutputFileListingResource.java
/**
	 * This method represents the HTTP GET action. Using the job id from the
	 * URL, the output file information for the specified job are retrieved from
	 * the submit machine and sent to the user as a {@link org.json.JSONArray
	 * JSONArray} of {@link org.json.JSONObject JSONObjects}. If the job id is
	 * invalid for any reason, a HTTP
	 * {@link org.restlet.data.Status#CLIENT_ERROR_BAD_REQUEST 400} code is
	 * sent.
	 * <p>
	 * The format for the file listing is:
	 * <p>
	 * [{<br>
	 * &nbsp "directory":false,<br>
	 * &nbsp "readable":true,<br>
	 * &nbsp "writable":true,<br>
	 * &nbsp "owner":"xxx",<br>
	 * &nbsp "length":688,<br>
	 * &nbsp "lastModified":"Mon Mar 01 15:20:40 CST 2010",<br>
	 * &nbsp "path":"/xxx/1/geospiza.traits.fel",<br>
	 * &nbsp "url":"https://foundation.iplantc.org/io-v1/xxx/archive/job-1928719834asdf/geospiza.traits.fel"
	 * ,<br>
	 * &nbsp "name":"geospiza.traits.fel",<br>
	 * &nbsp "parent":"file:/home/0004/iplant/contrast/xxx/1/"<br>
	 * } }]<br>
	 */
This method represents the HTTP GET action. Using the job id from the
URL, the output file information for the specified job are retrieved from
the submit machine and sent to the user as a {@link org.json.JSONArray
JSONArray} of  org.json.JSONObject JSONObjects. If the job id is
invalid for any reason, a HTTP
org.restlet.data.Status#CLIENT_ERROR_BAD_REQUEST 400 code is
sent.
This method represents the HTTP GET action . Using the job id from the URL the output file information for the specified job are retrieved from the submit machine and sent to the user as a { @link org . json . JSONArray JSONArray } of org . json . JSONObject JSONObjects . If the job id is invalid for any reason a HTTP org . restlet . data . Status#CLIENT_ERROR_BAD_REQUEST 400 code is sent .
@Override
	public Representation represent(Variant variant) throws ResourceException
	{
		Job job;
		try
		{
			if (StringUtils.isEmpty(sJobId))
			{
				getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
				return new IplantErrorRepresentation("Job id cannot be empty");
			}
			job = JobDao.getByUuid(sJobId, true);
			if (job == null || !job.isVisible()) 
			{ 
				throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, 
						"Not job found with job id " + sJobId); 
			}
			JobPermissionManager pemManager = new JobPermissionManager(job, username);
			if (!pemManager.canRead(username)) { throw new ResourceException(
					Status.CLIENT_ERROR_UNAUTHORIZED,
					"User does not have permission to view this resource."); }
			DataLocator locator = new DataLocator(job);
			List<FileBean> listing = locator.listOutputDirectory(path);
			StringBuilder builder = new StringBuilder();
			for (int i=offset; i< Math.min((limit+offset), listing.size()); i++)
			{
				FileBean bean = listing.get(i);
				if (bean.getName().equals(".") || bean.getName().equals("..")) {
					continue;
				} else {
					builder.append(",");
					builder.append(bean.toJSON());
				}
			}
			if (builder.length() > 0)
				builder.deleteCharAt(0);
			return new IplantSuccessRepresentation("[" + builder
					+ "]");
		}
		catch (ResourceException e)
		{
			getResponse().setStatus(e.getStatus());
			return new IplantErrorRepresentation(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 { Job job ; try { if ( StringUtils . isEmpty ( sJobId ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "Job id cannot be empty" ) ; } job = JobDao . getByUuid ( sJobId , true ) ; if ( job == null || ! job . isVisible ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Not job found with job id " + sJobId ) ; } JobPermissionManager pemManager = new JobPermissionManager ( job , username ) ; if ( ! pemManager . canRead ( username ) ) { throw new ResourceException ( Status . CLIENT_ERROR_UNAUTHORIZED , "User does not have permission to view this resource." ) ; } DataLocator locator = new DataLocator ( job ) ; List < FileBean > listing = locator . listOutputDirectory ( path ) ; StringBuilder builder = new StringBuilder ( ) ; for ( int i = offset ; i < Math . min ( ( limit + offset ) , listing . size ( ) ) ; i ++ ) { FileBean bean = listing . get ( i ) ; if ( bean . getName ( ) . equals ( "." ) || bean . getName ( ) . equals ( ".." ) ) { continue ; } else { builder . append ( "," ) ; builder . append ( bean . toJSON ( ) ) ; } } if ( builder . length ( ) > 0 ) builder . deleteCharAt ( 0 ) ; return new IplantSuccessRepresentation ( "[" + builder + "]" ) ; } catch ( ResourceException e ) { getResponse ( ) . setStatus ( e . getStatus ( ) ) ; return new IplantErrorRepresentation ( 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 .