use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class CollectionServiceImplTest method testGetSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated.
@Test
public void testGetSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated() throws Exception {
CollectionServiceImpl collectionService = new CollectionServiceImpl();
IRODSServices irodsService = Mockito.mock(IRODSServices.class);
AdminServices adminServices = Mockito.mock(AdminServices.class);
IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory().getEnvironmentalInfoAO(irodsAccount);
CollectionAndDataObjectListAndSearchAO listAndSearchAO = irodsFileSystem.getIRODSAccessObjectFactory().getCollectionAndDataObjectListAndSearchAO(irodsAccount);
SpecificQueryAO specificQueryAO = irodsFileSystem.getIRODSAccessObjectFactory().getSpecificQueryAO(irodsAccount);
Mockito.when(irodsService.getEnvironmentalInfoAO()).thenReturn(environmentalInfoAO);
Mockito.when(irodsService.getCollectionAndDataObjectListAndSearchAO()).thenReturn(listAndSearchAO);
Mockito.when(adminServices.getSpecificQueryAO()).thenReturn(specificQueryAO);
collectionService.setIrodsServices(irodsService);
collectionService.setAdminServices(adminServices);
List<DataGridCollectionAndDataObject> actual = collectionService.searchCollectionAndDataObjectsByName("textSearch");
Assert.assertTrue("no recs returned", actual.size() > 1);
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class FilePropertyServiceImpl method findByFileProperties.
@Override
public List<DataGridCollectionAndDataObject> findByFileProperties(List<DataGridFilePropertySearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException, JargonException {
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = null;
List<DataGridCollectionAndDataObject> dataGridObjects = null;
List<DataGridCollectionAndDataObject> dataGridCollections = null;
int totalCollections = 0;
int totalDataObjects = 0;
int startIndex = (pageNum - 1) * pageSize;
int endIndex = (pageNum * pageSize) - 1;
int endIndexForDataObjs;
int endIndexForCollections;
try {
String zone = irodsServices.getCurrentUserZone();
totalCollections = specQueryService.countCollectionsMatchingFileProperties(searchList, zone);
totalDataObjects = specQueryService.countDataObjectsMatchingFileProperties(searchList, zone);
pageContext.setStartItemNumber(startIndex + 1);
pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
dataGridCollectionAndDataObjects = new ArrayList<DataGridCollectionAndDataObject>();
if (endIndex + 1 <= totalCollections) {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(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.searchByFileProperties(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
} else {
// looking for collections
SpecificQueryResultSet resultSetColls = specQueryService.searchByFileProperties(searchList, zone, true, pageContext, startIndex, pageSize);
dataGridCollections = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetColls);
endIndexForDataObjs = pageSize - (totalCollections % pageSize);
// looking for data objects
SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByFileProperties(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
dataGridObjects = DataGridUtils.mapPropertiesResultSetToDataGridObjects(resultSetDataObjs);
endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
dataGridCollectionAndDataObjects.addAll(dataGridCollections);
dataGridCollectionAndDataObjects.addAll(dataGridObjects);
pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
}
} catch (JargonException | UnsupportedDataGridFeatureException e) {
logger.error("Could not find data objects by metadata. ", e);
if (e.getCause() instanceof ConnectException) {
throw new DataGridConnectionRefusedException();
}
}
this.populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
return dataGridCollectionAndDataObjects;
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class FilePropertyServiceImpl method populateVisibilityForCurrentUser.
private void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
CollectionAO collectionAO = irodsServices.getCollectionAO();
DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
String currentUser = getLoggedDataGridUser().getUsername();
for (DataGridCollectionAndDataObject obj : objectList) {
List<UserFilePermission> permissions = null;
try {
if (obj.isCollection()) {
permissions = collectionAO.listPermissionsForCollection(obj.getPath());
} else {
permissions = dataObjectAO.listPermissionsForDataObject(obj.getPath());
}
} catch (JargonException e) {
logger.error("Could not get permission list for object {}", obj.getPath(), e);
}
obj.setVisibleToCurrentUser(false);
if (permissions != null) {
for (UserFilePermission permission : permissions) {
if (permission.getUserName().compareTo(currentUser) == 0) {
obj.setVisibleToCurrentUser(true);
break;
}
}
}
}
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class PermissionsController method getPermissionDetails.
/**
* Gives permission details related to a collection or file that is passed as a
* parameter
*
* @param model
* @param path
* @return
* @throws DataGridConnectionRefusedException
* @throws JargonException
* @throws FileNotFoundException
*/
@RequestMapping(value = "/getPermissionDetails/", method = RequestMethod.POST)
public String getPermissionDetails(final Model model, @RequestParam("path") final String path) throws DataGridConnectionRefusedException {
logger.debug("Getting permission info for {}", path);
DataGridCollectionAndDataObject obj = null;
List<DataGridFilePermission> permissions;
List<DataGridGroupPermission> groupPermissions;
List<DataGridUserPermission> userPermissions;
List<DataGridGroupBookmark> bookmarks;
List<DataGridUserBookmark> userBookmarks;
Set<String> groupsWithBookmarks;
Set<String> usersWithBookmarks;
boolean userCanModify = false;
boolean isCollection = false;
try {
loggedUser = luu.getLoggedDataGridUser();
permissions = ps.getPathPermissionDetails(path);
groupPermissions = ps.getGroupsWithPermissions(permissions);
userPermissions = ps.getUsersWithPermissions(permissions);
bookmarks = gBMS.findBookmarksOnPath(path);
userBookmarks = uBMS.findBookmarksOnPath(path);
userCanModify = loggedUser.isAdmin() || ps.canLoggedUserModifyPermissionOnPath(path);
groupsWithBookmarks = new HashSet<>();
for (DataGridGroupBookmark bookmark : bookmarks) {
groupsWithBookmarks.add(bookmark.getGroup().getGroupname());
}
usersWithBookmarks = new HashSet<>();
for (DataGridUserBookmark userBookmark : userBookmarks) {
usersWithBookmarks.add(userBookmark.getUser().getUsername());
}
obj = cs.findByName(path);
ps.resolveMostPermissiveAccessForUser(obj, loggedUser);
} catch (Exception e) {
logger.error("Could not get permission details {}: {}", path, e.getMessage());
groupPermissions = new ArrayList<>();
userPermissions = new ArrayList<>();
groupsWithBookmarks = new HashSet<>();
usersWithBookmarks = new HashSet<>();
}
model.addAttribute("usersWithBookmarks", usersWithBookmarks);
model.addAttribute("groupsWithBookmark", groupsWithBookmarks);
model.addAttribute("groupPermissions", groupPermissions);
model.addAttribute("userPermissions", userPermissions);
model.addAttribute("userCanModify", userCanModify);
model.addAttribute("permissions", PERMISSIONS);
model.addAttribute("permissionsWithoutNone", PERMISSIONS_WITHOUT_NONE);
model.addAttribute("collectionAndDataObject", obj);
model.addAttribute("isCollection", isCollection);
model.addAttribute("permissionOnCurrentPath", cs.getPermissionsForPath(path));
model.addAttribute("permissionFlag", true);
System.out.println("permissionOnCurrentPath =======" + cs.getPermissionsForPath(path));
System.out.println("------Permission Conroller - /getPermissionDetail/ ends------");
return "permissions/permissionDetails :: permissionDetails";
}
use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.
the class FileOperationsController method showModifyForm.
/**
* Displays the modify user form with all fields set to the selected collection
*
* @param model
* MVC model
* @return collectionForm with fields set
* @throws DataGridException
* if item cannot be modified
* @throws JargonException
*/
@RequestMapping(value = "modify/", method = RequestMethod.GET)
public String showModifyForm(final Model model, @RequestParam("path") final String path) throws DataGridException, JargonException {
String currentPath = browseController.getCurrentPath();
String parentPath = browseController.getParentPath();
String formType = "editDataObjectForm";
CollectionOrDataObjectForm targetForm = new CollectionOrDataObjectForm();
DataGridCollectionAndDataObject dataGridCollectionAndDataObject = collectionService.findByName(path);
logger.info("Modify form for {}", path);
targetForm.setCollectionName(dataGridCollectionAndDataObject.getName());
targetForm.setPath(dataGridCollectionAndDataObject.getPath());
targetForm.setParentPath(currentPath);
if (dataGridCollectionAndDataObject.isCollection()) {
formType = "editCollectionForm";
targetForm.setCollection(true);
logger.info("Setting inheritance for {}", path);
targetForm.setInheritOption(collectionService.getInheritanceOptionForCollection(targetForm.getPath()));
}
model.addAttribute("currentPath", currentPath);
model.addAttribute("parentPath", parentPath);
model.addAttribute("collection", targetForm);
model.addAttribute("requestMapping", "/browse/modify/action/");
return String.format("collections/%s", formType);
}
Aggregations