use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class PreviewServiceImpl method filePreview.
@Override
public boolean filePreview(String path, String mimeType, HttpServletResponse response) {
logger.info("getting file preview for {} ::" + path + " and mimetype :: " + mimeType);
boolean isCopySuccessFul = true;
IRODSFileInputStream irodsFileInputStream = null;
IRODSFile irodsFile = null;
try {
IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
irodsFile = irodsFileFactory.instanceIRODSFile(path);
irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
response.setContentType(mimeType);
FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
} catch (IOException | JargonException | DataGridConnectionRefusedException e) {
e.printStackTrace();
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 com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class ResourceServiceImpl method getAllResourceServers.
@Override
public List<DataGridServer> getAllResourceServers(List<DataGridResource> resources) throws DataGridConnectionRefusedException {
logger.info("Getting all resource servers");
List<DataGridServer> servers = new ArrayList<>();
boolean isResourceWithEmptyHost = false;
for (DataGridResource resource : resources) {
logger.debug("Listing resource information: {}", resource);
if (resource.getContextString().contains("isi_host")) {
continue;
} else if (!resource.getHost().isEmpty()) {
DataGridServer server = new DataGridServer();
try {
server.setHostname(resource.getHost());
server.setIp(machineInfoService.getAddress(resource.getHost()));
server.setResources(getResourcesOfAServer(server.getHostname(), resources));
} catch (UnknownHostException e) {
logger.error("Could not retrieve IP address for [{}]", resource.getHost());
isResourceWithEmptyHost = true;
} catch (DataGridConnectionRefusedException e) {
logger.error("Could not get all resources of the server: ", resource.getHost());
server.setResources(null);
}
if (!isResourceWithEmptyHost && !servers.contains(server)) {
servers.add(server);
}
}
isResourceWithEmptyHost = false;
}
Collections.sort(servers);
return servers;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException 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 com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException 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 com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class GroupServiceImpl method updateMemberList.
@Override
public boolean updateMemberList(DataGridGroup group, List<DataGridUser> users) throws DataGridConnectionRefusedException {
try {
UserGroupAO groupAO = irodsServices.getGroupAO();
// Users that are currently on this group
List<User> usersFromIrods = groupAO.listUserGroupMembers(group.getGroupname());
// Building set with iRODS IDs already on this group
HashMap<Long, User> idsFromIrods = new HashMap<Long, User>();
for (User userFromIrods : usersFromIrods) {
idsFromIrods.put(Long.valueOf(userFromIrods.getId()), userFromIrods);
}
// Building set with iRODS IDs coming from UI
HashMap<Long, DataGridUser> idsFromUi = new HashMap<Long, DataGridUser>();
for (DataGridUser userFromUi : users) {
idsFromUi.put(userFromUi.getDataGridId(), userFromUi);
}
// Resolving differences from UI to iRODS
Set<Long> keysFromUi = idsFromUi.keySet();
Set<Long> keysFromIrods = idsFromIrods.keySet();
for (Long dataGridId : keysFromUi) {
if (!keysFromIrods.contains(dataGridId)) {
attachUserToGroup(idsFromUi.get(dataGridId), group);
}
}
for (Long dataGridId : keysFromIrods) {
if (!keysFromUi.contains(dataGridId)) {
DataGridUser user = new DataGridUser();
user.setUsername(idsFromIrods.get(dataGridId).getName());
removeUserFromGroup(user, group);
}
}
return true;
} catch (Exception e) {
logger.info("Could not update [" + group.getGroupname() + "]: ", e);
}
return false;
}
Aggregations