Skip to content

Commit

Permalink
Merge branch 'niehs-development' of gitlab.niehs.nih.gov:conwaymc/met…
Browse files Browse the repository at this point in the history
…alnx-web into niehs-development
  • Loading branch information
Hetal Patel committed Jan 19, 2018
2 parents 31bfa59 + 0196724 commit 681f4cb
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 251 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ This change requires the addition of this property to metalnx.properties,and for
this property should be in settings.xml. See the CONFIGURATION.md and DEVELOPER-README.md for details. The sample
metalnx.properties in /etc/irods-ext in this repo shows a sample configuration.

#### NIEHS 500 Error on empty trash

Incorporated new TrashOperationsAO code from https://github.com/DICE-UNC/jargon/issues/280

This replaces the rule call, and now functions normally for logged in users. There remains a few issues with empty trash as rodsadmin but
that will be addressed at the Jargon or iRODS level.

#### NIEHS identified misc theming issues

* #22 fix search text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,128 +16,185 @@

package com.emc.metalnx.services.interfaces;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.irods.jargon.core.exception.JargonException;

import com.emc.metalnx.core.domain.entity.DataGridUser;
import com.emc.metalnx.core.domain.exceptions.DataGridChecksumException;
import com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException;
import com.emc.metalnx.core.domain.exceptions.DataGridException;
import com.emc.metalnx.core.domain.exceptions.DataGridReplicateException;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public interface FileOperationService {

/**
* Copy a file or collection between two locations in the data grid.
*
* @param sourcePath origin path
* @param dstPath destination path
* @param copyWithMetadata flag that says whether or not we are copying the file along with its metadata tags
* @return True, if file or collection was moved. False, otherwise.
* @throws DataGridConnectionRefusedException if Metalnx cannot connect to the data grid
*/
boolean copy(String sourcePath, String dstPath, boolean copyWithMetadata) throws DataGridConnectionRefusedException;

/**
* Copy a set of files or collections between two locations in the data grid.
*
* @param sourcePaths list of paths to be copied
* @param dstPath path where the files/collections will be copied
* @param copyWithMetadata flag that says whether or not we are copying the file along with its metadata tags
* @return True, if all files or collections were moved. False, otherwise.
* @throws DataGridConnectionRefusedException if Metalnx cannot connect to the data grid
*/
boolean copy(List<String> sourcePaths, String dstPath, boolean copyWithMetadata) throws DataGridConnectionRefusedException;

/**
* Delete a file or collection in iRODS
*
* @param path path to the collection or data object to be deleted
* @param force delete collection/data object with force flag set
* @throws DataGridConnectionRefusedException if Metalnx cannot connect to the data grid
*/
boolean deleteItem(String path, boolean force) throws DataGridConnectionRefusedException;

/**
* Delete a collection in iRODS
*
* @param collectionPath path to the collection to be deleted
* @param forceFlag when set to true, force delete an object (-f). When set to false, delete object no with force
* @throws DataGridException if an error occurred during deletion
*/
boolean deleteCollection(String collectionPath, boolean forceFlag) throws DataGridException;

/**
* Delete a data object in iRODS
*
* @param dataObjectPath path to the data object that will de removed
* @param forceFlag when set to true, force delete an object (-f). When set to false, delete object no with force
* @throws DataGridException if an error occurred during deletion
*/
boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException;

/**
* Delete a replica of a data object
*
* @param path path to the parent of the data object to be deleted
* @param replicaNumber number of the replica that is going to be deleted
* @param inAdminMode run the command as admin (-M option)
* @return true if the operation was successful and false otherwise
* @throws DataGridConnectionRefusedException if Metalnx cannot connect to the data grid
*/
boolean deleteReplica(String path, String fileName, int replicaNumber, boolean inAdminMode) throws DataGridConnectionRefusedException;

/**
* Download a file or collection from the data grid.
*
* @param path file to download
* @param httpResponse response to an http request
* @param removeTempCollection flag when set to true tells Metalnx to remove temporary collections and tar files
* created for downloading. When set to false, just puts the file into the HTTP response
* @return True, if file or collection was downloaded. False, otherwise.
* @throws DataGridException if an error happen in the data grid
* @throws IOException cannot create the tar ball file
*/
boolean download(String path, HttpServletResponse httpResponse, boolean removeTempCollection) throws DataGridException, IOException;

/**
* Removes all items existing in the trash folder of a given user.
*
* @param user user who will get the trash cleaned
* @param currentPath path from which the trash path will be extracted
* @return True, if all trash items were removed. False, otherwise.
* @throws DataGridConnectionRefusedException if Metalnx cannot connect to the data grid
*/
boolean emptyTrash(DataGridUser user, String currentPath) throws DataGridConnectionRefusedException;

/**
* Move a file or collection between two locations in the data grid.
*
* @param sourcePath origin path
* @param targetPath destination path where the file will be moved to
* @return True, if file or collection was moved. False, otherwise.
* @throws DataGridException if an error occurred during the move operation
*/
boolean move(String sourcePath, String targetPath) throws DataGridException;

/**
* Replicates a file into another resource.
*
* @param path path to the file to be replicated
* @param targetResource resource where the replica will be stored
* @param inAdminMode replicate object in admin mode (-M option)
* @throws DataGridReplicateException is thrown if replication fails
* @throws DataGridConnectionRefusedException is thrown if Metalnx cannot connect to the data grid
*/
void replicateDataObject(String path, String targetResource, boolean inAdminMode) throws DataGridConnectionRefusedException, DataGridReplicateException;

/**
* Computes checksum for a given path.
* @param path path to the file in the grid
* @param filename name of the file to compute checksum
* @throws DataGridChecksumException is thrown if checksum cannot be calculated
* @throws DataGridConnectionRefusedException is thrown when Metalnx cannot connect to the data grid
*/
void computeChecksum(String path, String filename) throws DataGridChecksumException, DataGridConnectionRefusedException;
/**
* Copy a file or collection between two locations in the data grid.
*
* @param sourcePath
* origin path
* @param dstPath
* destination path
* @param copyWithMetadata
* flag that says whether or not we are copying the file along with
* its metadata tags
* @return True, if file or collection was moved. False, otherwise.
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the data grid
*/
boolean copy(String sourcePath, String dstPath, boolean copyWithMetadata) throws DataGridConnectionRefusedException;

/**
* Copy a set of files or collections between two locations in the data grid.
*
* @param sourcePaths
* list of paths to be copied
* @param dstPath
* path where the files/collections will be copied
* @param copyWithMetadata
* flag that says whether or not we are copying the file along with
* its metadata tags
* @return True, if all files or collections were moved. False, otherwise.
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the data grid
*/
boolean copy(List<String> sourcePaths, String dstPath, boolean copyWithMetadata)
throws DataGridConnectionRefusedException;

/**
* Delete a file or collection in iRODS
*
* @param path
* path to the collection or data object to be deleted
* @param force
* delete collection/data object with force flag set
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the data grid
*/
boolean deleteItem(String path, boolean force) throws DataGridConnectionRefusedException;

/**
* Delete a collection in iRODS
*
* @param collectionPath
* path to the collection to be deleted
* @param forceFlag
* when set to true, force delete an object (-f). When set to false,
* delete object no with force
* @throws DataGridException
* if an error occurred during deletion
*/
boolean deleteCollection(String collectionPath, boolean forceFlag) throws DataGridException;

/**
* Delete a data object in iRODS
*
* @param dataObjectPath
* path to the data object that will de removed
* @param forceFlag
* when set to true, force delete an object (-f). When set to false,
* delete object no with force
* @throws DataGridException
* if an error occurred during deletion
*/
boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException;

/**
* Delete a replica of a data object
*
* @param path
* path to the parent of the data object to be deleted
* @param replicaNumber
* number of the replica that is going to be deleted
* @param inAdminMode
* run the command as admin (-M option)
* @return true if the operation was successful and false otherwise
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the data grid
*/
boolean deleteReplica(String path, String fileName, int replicaNumber, boolean inAdminMode)
throws DataGridConnectionRefusedException;

/**
* Download a file or collection from the data grid.
*
* @param path
* file to download
* @param httpResponse
* response to an http request
* @param removeTempCollection
* flag when set to true tells Metalnx to remove temporary
* collections and tar files created for downloading. When set to
* false, just puts the file into the HTTP response
* @return True, if file or collection was downloaded. False, otherwise.
* @throws DataGridException
* if an error happen in the data grid
* @throws IOException
* cannot create the tar ball file
*/
boolean download(String path, HttpServletResponse httpResponse, boolean removeTempCollection)
throws DataGridException, IOException;

/**
* Removes all items existing in the trash folder of a given user.
*
* @param user
* user who will get the trash cleaned
* @param currentPath
* path from which the trash path will be extracted
* @return True, if all trash items were removed. False, otherwise.
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the data grid
* @throws JargonException
*/
boolean emptyTrash(DataGridUser user, String currentPath)
throws DataGridConnectionRefusedException, JargonException;

/**
* Move a file or collection between two locations in the data grid.
*
* @param sourcePath
* origin path
* @param targetPath
* destination path where the file will be moved to
* @return True, if file or collection was moved. False, otherwise.
* @throws DataGridException
* if an error occurred during the move operation
*/
boolean move(String sourcePath, String targetPath) throws DataGridException;

/**
* Replicates a file into another resource.
*
* @param path
* path to the file to be replicated
* @param targetResource
* resource where the replica will be stored
* @param inAdminMode
* replicate object in admin mode (-M option)
* @throws DataGridReplicateException
* is thrown if replication fails
* @throws DataGridConnectionRefusedException
* is thrown if Metalnx cannot connect to the data grid
*/
void replicateDataObject(String path, String targetResource, boolean inAdminMode)
throws DataGridConnectionRefusedException, DataGridReplicateException;

/**
* Computes checksum for a given path.
*
* @param path
* path to the file in the grid
* @param filename
* name of the file to compute checksum
* @throws DataGridChecksumException
* is thrown if checksum cannot be calculated
* @throws DataGridConnectionRefusedException
* is thrown when Metalnx cannot connect to the data grid
*/
void computeChecksum(String path, String filename)
throws DataGridChecksumException, DataGridConnectionRefusedException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.emc.metalnx.services.interfaces;

import org.irods.jargon.core.exception.JargonException;
import org.irods.jargon.core.pub.BulkFileOperationsAO;
import org.irods.jargon.core.pub.CollectionAO;
import org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO;
Expand All @@ -29,6 +30,7 @@
import org.irods.jargon.core.pub.RuleProcessingAO;
import org.irods.jargon.core.pub.SpecificQueryAO;
import org.irods.jargon.core.pub.Stream2StreamAO;
import org.irods.jargon.core.pub.TrashOperationsAO;
import org.irods.jargon.core.pub.UserAO;
import org.irods.jargon.core.pub.UserGroupAO;
import org.irods.jargon.core.pub.ZoneAO;
Expand Down Expand Up @@ -221,4 +223,13 @@ CollectionAndDataObjectListAndSearchAO getCollectionAndDataObjectListAndSearchAO
* @return {@link IRODSAccessObjectFactory} reference
*/
IRODSAccessObjectFactory getIrodsAccessObjectFactory();

/**
* Obtain a reference to the {@link TrashOperationsAO}
*
* @return {@link TrashOperationsAO}
* @throws DataGridConnectionRefusedException
* @throws JargonException
*/
TrashOperationsAO getTrashOperationsAO() throws DataGridConnectionRefusedException, JargonException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.irods.jargon.core.pub.DataObjectAO;
import org.irods.jargon.core.pub.DataTransferOperations;
import org.irods.jargon.core.pub.IRODSFileSystemAO;
import org.irods.jargon.core.pub.TrashOperationsAO;
import org.irods.jargon.core.pub.io.IRODSFile;
import org.irods.jargon.core.pub.io.IRODSFileFactory;
import org.irods.jargon.core.pub.io.IRODSFileInputStream;
Expand Down Expand Up @@ -278,18 +279,36 @@ public boolean download(String path, HttpServletResponse response, boolean remov
}

@Override
public boolean emptyTrash(DataGridUser user, String collectionPath) throws DataGridConnectionRefusedException {
if (user == null || collectionPath == null || collectionPath.isEmpty())
public boolean emptyTrash(DataGridUser user, String collectionPath)
throws DataGridConnectionRefusedException, JargonException {

logger.info("emptyTrash()");
if (user == null || collectionPath == null || collectionPath.isEmpty()) {
return false;
}

logger.info("user:{}", user);
logger.info("collectionPath:{}", collectionPath);

boolean itemsDeleted = false;

try {
String resc = irodsServices.getDefaultStorageResource();
rs.execEmptyTrashRule(resc, collectionPath, user.isAdmin());

TrashOperationsAO trashOperationsAO = irodsServices.getTrashOperationsAO();

/*
* if (user.isAdmin()) { logger.info("delete as admin");
* trashOperationsAO.emptyAllTrashAsAdmin(irodsServices.getCurrentUserZone(),
* 0); // trashOperationsAO.emptyTrashAtPathAdminMode(collectionPath, "", //
* irodsServices.getCurrentUserZone(), 0); itemsDeleted = true; } else {
*/
logger.info("delete as user");
trashOperationsAO.emptyTrashAtPathForLoggedInUser(collectionPath, irodsServices.getCurrentUserZone(), 0);
itemsDeleted = true;
} catch (DataGridRuleException e) {
logger.info("Could not empty trash: ", e.getMessage());
/* } */
} catch (JargonException je) {
logger.error("jargon exception emptying trash", je);
throw je;
}

return itemsDeleted;
Expand Down
Loading

0 comments on commit 681f4cb

Please sign in to comment.