use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method copyFileIntoHttpResponse.
/**
* Copies a buffered input stream from a file to a HTTP response for
* downloading.
*
* @param path
* path to the file in iRODS to be added to the HTTP response
* @param response
* HTTP response to let the user download the file
* @return True, if the file was successfully added to the HTTP response. False,
* otherwise.
* @throws DataGridConnectionRefusedException
* is Metalnx cannot connect to the data grid
*/
private boolean copyFileIntoHttpResponse(String path, HttpServletResponse response) throws DataGridConnectionRefusedException {
boolean isCopySuccessFul = true;
IRODSFileInputStream irodsFileInputStream = null;
IRODSFile irodsFile = null;
logger.debug("Trying to copy path stream {} to user", path);
try {
String fileName = path.substring(path.lastIndexOf("/") + 1, path.length());
logger.debug("The filename is [{}]", fileName);
logger.debug("Initiating iRodsFileFactory");
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
logger.debug("Getting iRodsFileFactory instance for {}", path);
irodsFile = irodsFileFactory.instanceIRODSFile(path);
logger.debug("Creating stream from {}", irodsFile);
irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
// set file mime type
response.setContentType(CONTENT_TYPE);
response.setHeader("Content-Disposition", String.format(HEADER_FORMAT, fileName));
response.setContentLength((int) irodsFile.length());
FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
} catch (IOException e) {
logger.error("Could not put the file in the Http response ", e);
isCopySuccessFul = false;
} catch (JargonException e) {
logger.error("Could not copy file in the Http response: ", e.getMessage());
isCopySuccessFul = false;
} finally {
try {
if (irodsFileInputStream != null)
irodsFileInputStream.close();
if (irodsFile != null)
irodsFile.close();
} catch (Exception e) {
logger.error("Could not close stream(s): ", e.getMessage());
}
}
return isCopySuccessFul;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class FileOperationServiceImpl method deleteDataObject.
@Override
public boolean deleteDataObject(String dataObjectPath, boolean forceFlag) throws DataGridException {
boolean dataObjDeleted = false;
try {
IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
IRODSFile fileToBeRemoved = irodsFileFactory.instanceIRODSFile(dataObjectPath);
if (forceFlag) {
irodsFileSystemAO.fileDeleteForce(fileToBeRemoved);
} else {
irodsFileSystemAO.fileDeleteNoForce(fileToBeRemoved);
}
dataObjDeleted = true;
} catch (JargonException e) {
logger.error("Could not delete data object: {}", e.getMessage());
}
return dataObjDeleted;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method deleteGroupByGroupname.
@Override
public boolean deleteGroupByGroupname(String groupname) throws DataGridConnectionRefusedException {
boolean groupDeleted = false;
UserGroupAO groupAO = irodsServices.getGroupAO();
try {
DataGridGroup group = groupDao.findByGroupnameAndZone(groupname, configService.getIrodsZone());
// remove group from the data grid
groupAO.removeUserGroup(groupname);
// Removing group bookmarks associated to this group
userBookmarkService.removeBookmarkBasedOnPath(String.format("/%s/home/%s", configService.getIrodsZone(), groupname));
groupBookmarkService.removeBookmarkBasedOnGroup(group);
// remove user from the Mlx database
groupDeleted = groupDao.deleteByGroupname(groupname);
} catch (JargonException e) {
logger.error("Could not execute removeUserGroup(String groupname)/" + "deleteByGroupname(groupname) on UserGroupAO/GroupDao class(es): ", e);
} catch (Exception e) {
logger.error("Could not execute delete group (dao)");
}
return groupDeleted;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method updateWritePermissions.
@Override
public boolean updateWritePermissions(DataGridGroup group, Map<String, Boolean> addCollectionsToWrite, Map<String, Boolean> removeCollectionsToWrite) throws DataGridConnectionRefusedException {
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
CollectionAO collectionAO = irodsServices.getCollectionAO();
try {
for (String path : addCollectionsToWrite.keySet()) {
if (collectionService.isCollection(path)) {
collectionAO.setAccessPermissionWriteAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToWrite.get(path));
} else {
dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
}
}
for (String path : removeCollectionsToWrite.keySet()) {
if (collectionService.isCollection(path)) {
collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToWrite.get(path));
} else {
dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
}
}
return true;
} catch (JargonException | DataGridException e) {
logger.error("Could not set read permission:", e);
}
return false;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method createGroup.
@Override
public boolean createGroup(DataGridGroup newGroup, List<DataGridUser> usersToBeAttached) throws DataGridConnectionRefusedException {
UserGroupAO groupAO = irodsServices.getGroupAO();
// Translating to iRODS model format
UserGroup irodsGroup = new UserGroup();
irodsGroup.setUserGroupName(newGroup.getGroupname());
irodsGroup.setZone(newGroup.getAdditionalInfo());
try {
irodsGroup.setUserGroupName(newGroup.getGroupname());
irodsGroup.setZone(newGroup.getAdditionalInfo());
// creating group in iRODS
groupAO.addUserGroup(irodsGroup);
// Recovering the recently created group to get the data grid id.
irodsGroup = groupAO.findByName(irodsGroup.getUserGroupName());
newGroup.setDataGridId(Long.parseLong(irodsGroup.getUserGroupId()));
// Persisting the new group into our database
groupDao.save(newGroup);
// attaching users to this group
updateMemberList(newGroup, usersToBeAttached);
return true;
} catch (DuplicateDataException e) {
logger.error("UserGroup " + newGroup.getGroupname() + " already exists: ", e);
} catch (JargonException e) {
logger.error("Could not execute createGroup() on UserGroupAO class: ", e);
}
return false;
}
Aggregations