agave-metadata/metadata-api/src/main/java/org/iplantc/service/metadata/resources/MetadataShareResource.java
/**
	 * This method represents the HTTP GET action. Gets Perms on specified iod.
	 */
This method represents the HTTP GET action. Gets Perms on specified iod.
This method represents the HTTP GET action . Gets Perms on specified iod .
@Override
	public Representation represent(Variant variant) {
		AgaveLogServiceClient.log(METADATA02.name(), MetaPemsList.name(), username, "", getRequest().getClientInfo().getUpstreamAddress());
		if (!ServiceUtils.isValid(uuid)) {
			getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
			return new IplantErrorRepresentation("No metadata id provided");
		}
		try {
			MetadataItem metadataItem = getRequestedMetadataItem();
			MetadataPermissionManager metadataItemPermissionManager = new MetadataPermissionManager(metadataItem, username);
			if (metadataItemPermissionManager.canRead(username)) {
				if (StringUtils.isBlank(sharedUsername)) {
					List<MetadataPermission> foundPermissions = metadataItem.getPermissions();
					StringBuilder jsonPems = new StringBuilder(new MetadataPermission(metadataItem.getOwner(), PermissionType.ALL).toJSON(uuid));
					if (foundPermissions.size() > 0) {
						for (MetadataPermission foundPermission : foundPermissions) {
							if (!StringUtils.equals(foundPermission.getUsername(), metadataItem.getOwner())) {
								jsonPems.append(",").append(foundPermission.toJSON(uuid));
							}
						}
					}
					return new IplantSuccessRepresentation("[" + jsonPems + "]");
				} else {
					MetadataPermission foundPermission;
					if (ServiceUtils.isAdmin(sharedUsername) || StringUtils.equals(metadataItem.getOwner(), sharedUsername)) {
						foundPermission = new MetadataPermission(sharedUsername, PermissionType.ALL);
					} else {
						foundPermission = metadataItemPermissionManager.getPermission(sharedUsername);
						if (PermissionType.NONE == foundPermission.getPermission()) {
							throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND,
									"No permissions found for user " + sharedUsername);
						}
					}
					return new IplantSuccessRepresentation(foundPermission.toJSON(uuid));
				}
			} else {
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN,
						"User does not have permission to view this resource.");
			}
		} catch (ResourceException e) {
			log.error("Unable to retrieve metadata permission", e);
			getResponse().setStatus(e.getStatus());
			return new IplantErrorRepresentation(e.getMessage());
		} catch (Throwable e) {
			log.error("Failed to retrieve metadata permission", e);
			getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
			return new IplantErrorRepresentation(e.getMessage());
		}
	}
@ Override public Representation represent ( Variant variant ) { AgaveLogServiceClient . log ( METADATA02 . name ( ) , MetaPemsList . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; if ( ! ServiceUtils . isValid ( uuid ) ) { getResponse ( ) . setStatus ( Status . CLIENT_ERROR_BAD_REQUEST ) ; return new IplantErrorRepresentation ( "No metadata id provided" ) ; } try { MetadataItem metadataItem = getRequestedMetadataItem ( ) ; MetadataPermissionManager metadataItemPermissionManager = new MetadataPermissionManager ( metadataItem , username ) ; if ( metadataItemPermissionManager . canRead ( username ) ) { if ( StringUtils . isBlank ( sharedUsername ) ) { List < MetadataPermission > foundPermissions = metadataItem . getPermissions ( ) ; StringBuilder jsonPems = new StringBuilder ( new MetadataPermission ( metadataItem . getOwner ( ) , PermissionType . ALL ) . toJSON ( uuid ) ) ; if ( foundPermissions . size ( ) > 0 ) { for ( MetadataPermission foundPermission : foundPermissions ) { if ( ! StringUtils . equals ( foundPermission . getUsername ( ) , metadataItem . getOwner ( ) ) ) { jsonPems . append ( "," ) . append ( foundPermission . toJSON ( uuid ) ) ; } } } return new IplantSuccessRepresentation ( "[" + jsonPems + "]" ) ; } else { MetadataPermission foundPermission ; if ( ServiceUtils . isAdmin ( sharedUsername ) || StringUtils . equals ( metadataItem . getOwner ( ) , sharedUsername ) ) { foundPermission = new MetadataPermission ( sharedUsername , PermissionType . ALL ) ; } else { foundPermission = metadataItemPermissionManager . getPermission ( sharedUsername ) ; if ( PermissionType . NONE == foundPermission . getPermission ( ) ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No permissions found for user " + sharedUsername ) ; } } return new IplantSuccessRepresentation ( foundPermission . toJSON ( uuid ) ) ; } } else { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have permission to view this resource." ) ; } } catch ( ResourceException e ) { log . error ( "Unable to retrieve metadata permission" , e ) ; getResponse ( ) . setStatus ( e . getStatus ( ) ) ; return new IplantErrorRepresentation ( e . getMessage ( ) ) ; } catch ( Throwable e ) { log . error ( "Failed to retrieve metadata permission" , e ) ; getResponse ( ) . setStatus ( Status . SERVER_ERROR_INTERNAL ) ; return new IplantErrorRepresentation ( e . getMessage ( ) ) ; } }
This method represents the HTTP GET action.
This method represents the HTTP GET action .
//get all permissions //get single permission