agave-jobs/jobs-api/src/main/java/org/iplantc/service/jobs/resources/JobPermissionsResource.java
/**
	 * This method represents the HTTP GET action. Without specifying a job
	 * handle, there is no job information to retrieve, so we bind this action
	 * to simply serving a static HTML form for job submission.
	 */
This method represents the HTTP GET action. Without specifying a job
handle, there is no job information to retrieve, so we bind this action
to simply serving a static HTML form for job submission.
This method represents the HTTP GET action . Without specifying a job handle there is no job information to retrieve so we bind this action to simply serving a static HTML form for job submission .
@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 job = JobDao.getByUuid(sJobId, true);
				if (job == null) {
					String msg = "No job found with job id " + sJobId + ".";
					log.error(msg);
					getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
					return new IplantErrorRepresentation(msg);
				} else if (!job.isVisible()) {
					String msg = "Job with uuid " + sJobId + " is not visible.";
					log.error(msg);
					getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
					return new IplantErrorRepresentation(msg);
				}
				JobPermissionManager pm = new JobPermissionManager(job, username);
				if (pm.canRead(username)) {
					List<JobPermission> permissions = JobPermissionDao.getByJobId(job.getId());
					String jPems = "";
					if (StringUtils.isEmpty(sharedUsername)) {
						jPems = new JobPermission(job, job.getOwner(), PermissionType.ALL).toJSON(job);
						for (int i = offset; i < Math.min((limit + offset), permissions.size()); i++) {
							jPems += "," + permissions.get(i).toJSON(job);
						}
						jPems = "[" + jPems + "]";
					} else {
						boolean found = false;
						if (StringUtils.equals(sharedUsername, job.getOwner())) {
							jPems = new JobPermission(job, job.getOwner(), PermissionType.ALL).toJSON(job);
						} else {
							for (int i = offset; i < Math.min((limit + offset), permissions.size()); i++) {
								JobPermission pem = permissions.get(i);
								if (pem.getUsername().equalsIgnoreCase(sharedUsername)) {
									found = true;
									jPems = pem.toJSON(job);
									break;
								}
							}
							if (!found) {
								throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
										"No permissions found for user " + sharedUsername);
							}
						}
					}
					return new IplantSuccessRepresentation(jPems);
				} else {
					throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
							"User does not have permission to view this resource");
				}
			} 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 { try { if ( ! ServiceUtils . isValid ( sJobId ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "Job id cannot be empty" ) ; } try { Job job = JobDao . getByUuid ( sJobId , true ) ; if ( job == null ) { String msg = "No job found with job id " + sJobId + "." ; log . error ( msg ) ; getResponse ( ) . setStatus ( Status . CLIENT_ERROR_NOT_FOUND ) ; return new IplantErrorRepresentation ( msg ) ; } else if ( ! job . isVisible ( ) ) { String msg = "Job with uuid " + sJobId + " is not visible." ; log . error ( msg ) ; getResponse ( ) . setStatus ( Status . CLIENT_ERROR_NOT_FOUND ) ; return new IplantErrorRepresentation ( msg ) ; } JobPermissionManager pm = new JobPermissionManager ( job , username ) ; if ( pm . canRead ( username ) ) { List < JobPermission > permissions = JobPermissionDao . getByJobId ( job . getId ( ) ) ; String jPems = "" ; if ( StringUtils . isEmpty ( sharedUsername ) ) { jPems = new JobPermission ( job , job . getOwner ( ) , PermissionType . ALL ) . toJSON ( job ) ; for ( int i = offset ; i < Math . min ( ( limit + offset ) , permissions . size ( ) ) ; i ++ ) { jPems += "," + permissions . get ( i ) . toJSON ( job ) ; } jPems = "[" + jPems + "]" ; } else { boolean found = false ; if ( StringUtils . equals ( sharedUsername , job . getOwner ( ) ) ) { jPems = new JobPermission ( job , job . getOwner ( ) , PermissionType . ALL ) . toJSON ( job ) ; } else { for ( int i = offset ; i < Math . min ( ( limit + offset ) , permissions . size ( ) ) ; i ++ ) { JobPermission pem = permissions . get ( i ) ; if ( pem . getUsername ( ) . equalsIgnoreCase ( sharedUsername ) ) { found = true ; jPems = pem . toJSON ( job ) ; break ; } } if ( ! found ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No permissions found for user " + sharedUsername ) ; } } } return new IplantSuccessRepresentation ( jPems ) ; } else { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have permission to view this resource" ) ; } } 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 .
// can't set a stopped job back to running. Bad request