agave-metadata/metadata-api/src/main/java/org/iplantc/service/metadata/resources/MetadataSchemaShareResource.java
/**
	 * This method represents the HTTP GET action. Gets Perms on specified id.
	 */
This method represents the HTTP GET action. Gets Perms on specified id.
This method represents the HTTP GET action . Gets Perms on specified id .
@Override
	public Representation represent(Variant variant)
	{
		AgaveLogServiceClient.log(METADATA02.name(), SchemaPemsList.name(), username, "", getRequest().getClientInfo().getUpstreamAddress());
		if (!ServiceUtils.isValid(schemaId))
		{
			getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
			return new IplantErrorRepresentation("No metadata schema id provided.");
		}
		try
		{
			MetadataSchemaPermissionManager pm = new MetadataSchemaPermissionManager(schemaId, owner);
			if (pm.canRead(username))
			{
				List<MetadataSchemaPermission> permissions = MetadataSchemaPermissionDao
						.getBySchemaId(schemaId);
				if (StringUtils.isEmpty(sharedUsername)) 
				{
					StringBuilder jPems = new StringBuilder(new MetadataSchemaPermission(schemaId, owner, PermissionType.ALL).toJSON());
					for (int i=offset; i< Math.min((limit+offset), permissions.size()); i++)
	    			{
						jPems.append(",").append(permissions.get(i).toJSON());
					}
					return new IplantSuccessRepresentation("[" + jPems + "]");
				} 
				else 
				{
					if (ServiceUtils.isAdmin(sharedUsername) || StringUtils.equals(owner, sharedUsername))
					{
						MetadataSchemaPermission pem = new MetadataSchemaPermission(schemaId, sharedUsername, PermissionType.ALL);
						return new IplantSuccessRepresentation(pem.toJSON());
					}
					else 
					{
						MetadataSchemaPermission pem = 
								MetadataSchemaPermissionDao.getByUsernameAndSchemaId(sharedUsername, schemaId);
						if (pem == null) {
							throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
									"No permissions found for user " + sharedUsername);
						}
						else {
							return new IplantSuccessRepresentation(pem.toJSON());
						}
					}
				}
			}
			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 ) { AgaveLogServiceClient . log ( METADATA02 . name ( ) , SchemaPemsList . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; if ( ! ServiceUtils . isValid ( schemaId ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "No metadata schema id provided." ) ; } try { MetadataSchemaPermissionManager pm = new MetadataSchemaPermissionManager ( schemaId , owner ) ; if ( pm . canRead ( username ) ) { List < MetadataSchemaPermission > permissions = MetadataSchemaPermissionDao . getBySchemaId ( schemaId ) ; if ( StringUtils . isEmpty ( sharedUsername ) ) { StringBuilder jPems = new StringBuilder ( new MetadataSchemaPermission ( schemaId , owner , PermissionType . ALL ) . toJSON ( ) ) ; for ( int i = offset ; i < Math . min ( ( limit + offset ) , permissions . size ( ) ) ; i ++ ) { jPems . append ( "," ) . append ( permissions . get ( i ) . toJSON ( ) ) ; } return new IplantSuccessRepresentation ( "[" + jPems + "]" ) ; } else { if ( ServiceUtils . isAdmin ( sharedUsername ) || StringUtils . equals ( owner , sharedUsername ) ) { MetadataSchemaPermission pem = new MetadataSchemaPermission ( schemaId , sharedUsername , PermissionType . ALL ) ; return new IplantSuccessRepresentation ( pem . toJSON ( ) ) ; } else { MetadataSchemaPermission pem = MetadataSchemaPermissionDao . getByUsernameAndSchemaId ( sharedUsername , schemaId ) ; if ( pem == null ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No permissions found for user " + sharedUsername ) ; } else { return new IplantSuccessRepresentation ( pem . toJSON ( ) ) ; } } } } 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 .
// Bad request