agave-files/files-api/src/main/java/org/iplantc/service/io/resources/FilePermissionResource.java
/**
	 * Processes the delete operation on a particular file or folder. 
	 * This will clear all permissions for that file or directory, but 
	 * the file or directory itself will remain unchanged. Only admin 
	 * and above can grant or change permissions.
	 */
Processes the delete operation on a particular file or folder.
This will clear all permissions for that file or directory, but
the file or directory itself will remain unchanged. Only admin
and above can grant or change permissions.
Processes the delete operation on a particular file or folder . This will clear all permissions for that file or directory but the file or directory itself will remain unchanged . Only admin and above can grant or change permissions .
@Delete
	public Representation remove() throws ResourceException 
	{
		AgaveLogServiceClient.log(AgaveLogServiceClient.ServiceKeys.FILES02.name(), 
				AgaveLogServiceClient.ActivityKeys.IOPemsDelete.name(), 
				username, "", getRequest().getClientInfo().getUpstreamAddress());
		try 
		{
			if (system == null) 
			{
	        	if (StringUtils.isEmpty(systemId)) {
	        		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
	        				"No default storage system found. Please register a system and set it as your default. ");
	        	} else {
	        		throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, 
	        				"No resource found for user with system id '" + systemId + "'");
	        	}
	        }
			else if (system.isPubliclyAvailable() && 
					system.getType().equals(RemoteSystemType.EXECUTION)) 
			{
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, 
						"User does not have access to view the requested resource. " + 
						"File access is restricted to administrators on public execution systems.");
			}
			try {
				this.remoteDataClient = system.getRemoteDataClient(internalUsername);
			} 
			catch(RemoteDataException e)
			{
				throw new ResourceException(Status.CLIENT_ERROR_PRECONDITION_FAILED, 
						e.getMessage(), e);
			} 
			catch (Exception e) {	
				throw new ResourceException(Status.CLIENT_ERROR_PRECONDITION_FAILED, 
						"Unable to establish a connection to the remote server. " + 
								e.getMessage(), e);
			}
			try 
			{
				String originalPath = getRequest().getOriginalRef().toUri().getPath();
				path = PathResolver.resolve(owner, originalPath);
				if (system.isPubliclyAvailable()) {
					owner = PathResolver.getOwner(originalPath);
				}
			} 
			catch (Exception e) 
			{
				throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST,
						"Invalid file path " + path);
			}
			LogicalFile logicalFile = null;
			try { 
            	logicalFile=LogicalFileDao.findBySystemAndPath(system, remoteDataClient.resolvePath(path)); 
            } catch(Exception e) {}
            PermissionManager pm = new PermissionManager(system, remoteDataClient, logicalFile, username);
			try 
			{
				if (!pm.canWrite(remoteDataClient.resolvePath(path))) {
					throw new PermissionException();
				}
                remoteDataClient.authenticate();
			} 
			catch (PermissionException e) {
				throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, 
						"User does not have access to change permissions on " + path);
			}
			catch (Exception e) {
				throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
						"Failed to authenticate to " + system.getId());
			}
			try 
			{
				if (!remoteDataClient.doesExist(path) && logicalFile == null)
				{
					throw new FileNotFoundException("File/folder does not exist");
				}
				String sRecursive = Request.getCurrent().getOriginalRef().getQueryAsForm().getFirstValue("recursive");
				boolean recursive = BooleanUtils.toBoolean(sRecursive);
				pm.clearPermissions(recursive);
				return new AgaveSuccessRepresentation();
			} 
			catch (PermissionException e) {
				throw new ResourceException(Status.SERVER_ERROR_INTERNAL, 
						"Failed to remove permissions.");
			}
			catch (FileNotFoundException e) {
				throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e);
			}
			catch (Exception e) {
				throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
						"Failed to retrieve information for " + path);
			}
        } 
		catch (ResourceException e) {
			throw e;
		}
		catch (Throwable e) {
			throw new ResourceException(Status.SERVER_ERROR_INTERNAL,
					"Failed to retrieve information for " + path);
		}
		finally {
        	try {remoteDataClient.disconnect();} catch (Exception e) {}
        }
	}
@ Delete public Representation remove ( ) throws ResourceException { AgaveLogServiceClient . log ( AgaveLogServiceClient . ServiceKeys . FILES02 . name ( ) , AgaveLogServiceClient . ActivityKeys . IOPemsDelete . name ( ) , username , "" , getRequest ( ) . getClientInfo ( ) . getUpstreamAddress ( ) ) ; try { if ( system == null ) { if ( StringUtils . isEmpty ( systemId ) ) { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No default storage system found. Please register a system and set it as your default. " ) ; } else { throw new ResourceException ( Status . CLIENT_ERROR_NOT_FOUND , "No resource found for user with system id '" + systemId + "'" ) ; } } else if ( system . isPubliclyAvailable ( ) && system . getType ( ) . equals ( RemoteSystemType . EXECUTION ) ) { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have access to view the requested resource. " + "File access is restricted to administrators on public execution systems." ) ; } try { this . remoteDataClient = system . getRemoteDataClient ( internalUsername ) ; } catch ( RemoteDataException e ) { throw new ResourceException ( Status . CLIENT_ERROR_PRECONDITION_FAILED , e . getMessage ( ) , e ) ; } catch ( Exception e ) { throw new ResourceException ( Status . CLIENT_ERROR_PRECONDITION_FAILED , "Unable to establish a connection to the remote server. " + e . getMessage ( ) , e ) ; } try { String originalPath = getRequest ( ) . getOriginalRef ( ) . toUri ( ) . getPath ( ) ; path = PathResolver . resolve ( owner , originalPath ) ; if ( system . isPubliclyAvailable ( ) ) { owner = PathResolver . getOwner ( originalPath ) ; } } catch ( Exception e ) { throw new ResourceException ( Status . CLIENT_ERROR_BAD_REQUEST , "Invalid file path " + path ) ; } LogicalFile logicalFile = null ; try { logicalFile = LogicalFileDao . findBySystemAndPath ( system , remoteDataClient . resolvePath ( path ) ) ; } catch ( Exception e ) { } PermissionManager pm = new PermissionManager ( system , remoteDataClient , logicalFile , username ) ; try { if ( ! pm . canWrite ( remoteDataClient . resolvePath ( path ) ) ) { throw new PermissionException ( ) ; } remoteDataClient . authenticate ( ) ; } catch ( PermissionException e ) { throw new ResourceException ( Status . CLIENT_ERROR_FORBIDDEN , "User does not have access to change permissions on " + path ) ; } catch ( Exception e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Failed to authenticate to " + system . getId ( ) ) ; } try { if ( ! remoteDataClient . doesExist ( path ) && logicalFile == null ) { throw new FileNotFoundException ( "File/folder does not exist" ) ; } String sRecursive = Request . getCurrent ( ) . getOriginalRef ( ) . getQueryAsForm ( ) . getFirstValue ( "recursive" ) ; boolean recursive = BooleanUtils . toBoolean ( sRecursive ) ; pm . clearPermissions ( recursive ) ; return new AgaveSuccessRepresentation ( ) ; } catch ( PermissionException e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Failed to remove permissions." ) ; } catch ( FileNotFoundException e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , e ) ; } catch ( Exception e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Failed to retrieve information for " + path ) ; } } catch ( ResourceException e ) { throw e ; } catch ( Throwable e ) { throw new ResourceException ( Status . SERVER_ERROR_INTERNAL , "Failed to retrieve information for " + path ) ; } finally { try { remoteDataClient . disconnect ( ) ; } catch ( Exception e ) { } } }
Processes the delete operation on a particular file or folder.
Processes the delete operation on a particular file or folder .
// make sure the resource they are looking for is available. // check for the file on disk //					if (logicalFile != null) { //						LogicalFileDao.deleteSubtreePath(logicalFile.getPath(), system.getId()); //					} //            	    // check for forced recursive operation in url query...this is the counterpart to  // making a POST { username: "*", permission: "" }