use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class MetadataServiceImpl method populateVisibilityForCurrentUser.
/**
* Sets whether or not a user can check an object resulting from a metadata
* search
*
* @param objectList
* list of data objects/collections
* @throws DataGridConnectionRefusedException
*/
@Override
public void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
if (objectList == null || objectList.isEmpty()) {
return;
}
final String currentUser = irodsServices.getCurrentUser();
final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
for (final DataGridCollectionAndDataObject obj : objectList) {
try {
int resultingPermission;
final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(obj.getPath());
if (obj.isCollection()) {
resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, currentUser);
} else {
resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, currentUser);
}
// By default, the visibility of a user over an object is set to false
obj.setVisibleToCurrentUser(resultingPermission != FilePermissionEnum.NONE.getPermissionNumericValue());
} catch (final Exception e) {
logger.error("Could not get permissions for current user: {}", e.getMessage());
}
}
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class MetadataServiceImpl method findByMetadata.
@Override
public List<DataGridCollectionAndDataObject> findByMetadata(List<DataGridMetadataSearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException {
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = new ArrayList<>();
List<DataGridCollectionAndDataObject> dataGridObjects;
List<DataGridCollectionAndDataObject> dataGridCollections;
int totalCollections;
int totalDataObjects;
int startIndex = (pageNum - 1) * pageSize;
int endIndex = (pageNum * pageSize) - 1;
int endIndexForDataObjs;
int endIndexForCollections;
try {
String zone = irodsServices.getCurrentUserZone();
totalCollections = specQueryService.countCollectionsMatchingMetadata(searchList, zone);
totalDataObjects = specQueryService.countDataObjectsMatchingMetadata(searchList, zone);
pageContext.setStartItemNumber(startIndex + 1);
pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
if (endIndex + 1 <= totalCollections) {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(resultSetColls);
endIndexForCollections = dataGridCollections.size();
dataGridCollectionAndDataObjects.addAll(dataGridCollections);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForCollections - 1);
} else if (startIndex + 1 > totalCollections) {
// looking for data objects
SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByMetadata(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
} else {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(resultSetColls);
endIndexForDataObjs = pageSize - (totalCollections % pageSize);
// looking for data objects
SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByMetadata(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
dataGridCollectionAndDataObjects.addAll(dataGridCollections);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
}
} catch (DataGridConnectionRefusedException e) {
throw e;
} catch (Exception e) {
logger.error("Could not find data objects by metadata. ", e.getMessage());
}
populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
return dataGridCollectionAndDataObjects;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class UserServiceImpl method deleteUserByUsername.
@Override
public boolean deleteUserByUsername(String username) throws DataGridConnectionRefusedException {
UserAO userAO = irodsServices.getUserAO();
try {
DataGridUser user = findByUsername(username).get(0);
String userHomeFolder = String.format("/%s/home/%s", configService.getIrodsZone(), username);
// Removing user
userAO.deleteUser(username);
userDao.deleteByUsername(username);
// Removing favorites and user bookmarks before removing user
userBookmarkService.removeBookmarkBasedOnUser(user);
userBookmarkService.removeBookmarkBasedOnPath(userHomeFolder);
favoritesService.removeFavoriteBasedOnUser(user);
favoritesService.removeFavoriteBasedOnPath(userHomeFolder);
return true;
} catch (Exception e) {
logger.error("Could not delete user with username [" + username + "]");
}
return false;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class UserServiceImpl method updateGroupList.
@Override
public boolean updateGroupList(DataGridUser user, List<DataGridGroup> groups) throws DataGridConnectionRefusedException {
UserGroupAO groupAO = irodsServices.getGroupAO();
try {
// List current groups for user
List<UserGroup> groupsFromIrods = groupAO.findUserGroupsForUser(user.getUsername());
// Building set with iRODS IDs already on this group
HashMap<Long, UserGroup> idsFromIrods = new HashMap<Long, UserGroup>();
for (UserGroup groupFromIrods : groupsFromIrods) {
idsFromIrods.put(Long.valueOf(groupFromIrods.getUserGroupId()), groupFromIrods);
}
// Building set with iRODS IDs coming from UI
HashMap<Long, DataGridGroup> idsFromUi = new HashMap<Long, DataGridGroup>();
for (DataGridGroup groupFromUi : groups) {
idsFromUi.put(groupFromUi.getDataGridId(), groupFromUi);
}
// Resolving differences from UI to iRODS
Set<Long> keysFromUi = idsFromUi.keySet();
Set<Long> keysFromIrods = idsFromIrods.keySet();
// Committing changes to iRODS
for (Long dataGridId : keysFromUi) {
if (!keysFromIrods.contains(dataGridId)) {
groupService.attachUserToGroup(user, idsFromUi.get(dataGridId));
}
}
for (Long dataGridId : keysFromIrods) {
if (!keysFromUi.contains(dataGridId)) {
DataGridGroup group = new DataGridGroup();
group.setGroupname(idsFromIrods.get(dataGridId).getUserGroupName());
if (group.getGroupname().compareTo("public") != 0) {
groupService.removeUserFromGroup(user, group);
}
}
}
return true;
} catch (Exception e) {
logger.info("Could not update [" + user.getUsername() + "] group list: ", e);
}
return false;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class BrowseController method getFileInfo.
/**
* Gets checksum, total number of replicas and where each replica lives in the
* data grid for a specific data object
*
* @param model
* @param path
* path to the data object to get checksum and replica information
* @return the template that shows the data object information
* @throws DataGridException
* @throws FileNotFoundException
*/
@RequestMapping(value = "/info/", method = RequestMethod.POST)
public String getFileInfo(final Model model, final String path) throws DataGridException, FileNotFoundException {
logger.info("CollectionController getInfoFile() starts :: " + path);
DataGridCollectionAndDataObject dataGridObj = null;
Map<DataGridCollectionAndDataObject, DataGridResource> replicasMap = null;
try {
dataGridObj = cs.findByName(path);
if (dataGridObj != null && !dataGridObj.isCollection()) {
replicasMap = cs.listReplicasByResource(path);
dataGridObj.setChecksum(cs.getChecksum(path));
dataGridObj.setNumberOfReplicas(cs.getTotalNumberOfReplsForDataObject(path));
dataGridObj.setReplicaNumber(String.valueOf(cs.getReplicationNumber(path)));
permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, loggedUserUtils.getLoggedDataGridUser());
}
} catch (DataGridConnectionRefusedException e) {
logger.error("Could not connect to the data grid", e);
throw e;
} catch (DataGridException e) {
logger.error("Could not get file info for {}", path, e);
throw e;
} catch (FileNotFoundException e) {
logger.error("file does not exist for:{}", path, e);
throw e;
}
model.addAttribute("collectionAndDataObject", dataGridObj);
model.addAttribute("currentCollection", dataGridObj);
model.addAttribute("replicasMap", replicasMap);
model.addAttribute("infoFlag", true);
logger.info("CollectionController getInfoFile() ends !!");
return "collections/info :: infoView";
// return "collections/info";
}
Aggregations