use of org.irods.jargon.core.exception.JargonException 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 org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionController method indexViaUrl.
/**
* Responds the collections/ request
*
* @param model
* @return the collection management template
* @throws JargonException
* @throws DataGridException
*/
@RequestMapping(method = RequestMethod.GET)
public String indexViaUrl(final Model model, final HttpServletRequest request, @RequestParam("path") final Optional<String> path, @ModelAttribute("requestHeader") String requestHeader) {
logger.info("indexViaUrl()");
String myPath = path.orElse("");
logger.info("dp Header requestHeader is :: " + requestHeader);
try {
if (myPath.isEmpty()) {
model.addAttribute("topnavHeader", headerService.getheader("collections"));
logger.info("no path, go to home dir");
myPath = cs.getHomeDirectyForCurrentUser();
} else {
logger.info("path provided...go to:{}", path);
// TODO: do I need to worry about decoding, versus configure
myPath = URLDecoder.decode(myPath);
// in filter? - MCC
// see
// https://stackoverflow.com/questions/25944964/where-and-how-to-decode-pathvariable
}
logger.info("myPath:{}" + myPath);
DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
String uiMode = (String) request.getSession().getAttribute("uiMode");
sourcePaths = MiscIRODSUtils.breakIRODSPathIntoComponents(myPath);
CollectionAndPath collectionAndPath = MiscIRODSUtils.separateCollectionAndPathFromGivenAbsolutePath(myPath);
this.parentPath = collectionAndPath.getCollectionParent();
this.currentPath = myPath;
if (uiMode == null || uiMode.isEmpty()) {
boolean isUserAdmin = loggedUser != null && loggedUser.isAdmin();
uiMode = isUserAdmin ? UI_ADMIN_MODE : UI_USER_MODE;
}
if (cs.isDataObject(myPath)) {
logger.info("redirect to info page");
StringBuilder sb = new StringBuilder();
sb.append("redirect:/collectionInfo?path=");
sb.append(URLEncoder.encode(myPath));
return sb.toString();
}
logger.info("is collection...continue to collection management");
if (uiMode.equals(UI_USER_MODE)) {
model.addAttribute("homePath", cs.getHomeDirectyForCurrentUser());
model.addAttribute("publicPath", cs.getHomeDirectyForPublic());
}
model.addAttribute("uiMode", uiMode);
model.addAttribute("currentPath", currentPath);
model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
model.addAttribute("parentPath", parentPath);
model.addAttribute("resources", resourceService.findAll());
model.addAttribute("overwriteFileOption", loggedUser != null && loggedUser.isForceFileOverwriting());
} catch (JargonException | DataGridException e) {
logger.error("error establishing collection location", e);
model.addAttribute("unexpectedError", true);
}
logger.info("displaying collections/collectionManagement");
return "collections/collectionManagement";
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class FilePropertiesController method search.
@RequestMapping(value = "/search")
@ResponseBody
public String search(@RequestParam(value = "jsonFilePropertySearch", required = false) final String jsonFilePropertySearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException, JargonException {
if (jsonFilePropertySearch != null) {
currentPage = (int) (Math.floor(start / length) + 1);
this.jsonFilePropertySearch = jsonFilePropertySearch;
}
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(0));
jsonResponse.put("recordsFiltered", String.valueOf(0));
jsonResponse.put("data", new ArrayList<String>());
String jsonString = "";
try {
JsonNode jsonNode = mapper.readTree(this.jsonFilePropertySearch);
currentFilePropertySearch = new ArrayList<>();
JsonNode attributes = jsonNode.get("attribute");
JsonNode operators = jsonNode.get("operator");
JsonNode values = jsonNode.get("value");
for (int i = 0; i < attributes.size(); i++) {
DataGridFilePropertySearch ms = new DataGridFilePropertySearch(FilePropertyField.valueOf(attributes.get(i).textValue()), DataGridSearchOperatorEnum.valueOf(operators.get(i).textValue()), values.get(i).textValue());
currentFilePropertySearch.add(ms);
}
DataGridPageContext pageContext = new DataGridPageContext();
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = filePropertyService.findByFileProperties(currentFilePropertySearch, pageContext, currentPage, length);
jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
jsonResponse.put("data", dataGridCollectionAndDataObjects);
} catch (DataGridConnectionRefusedException e) {
logger.error("data grid error in search", e);
throw e;
} catch (JargonException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw e;
} catch (ParseException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
} catch (JsonProcessingException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
} catch (IOException e) {
logger.error("Could not search by metadata: ", e.getMessage());
throw new JargonException(e);
}
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse hashmap in file properties search to json: {}", e.getMessage());
throw new JargonException(e);
}
return jsonString;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class CollectionInfoController method extractFilePath.
private String extractFilePath(HttpServletRequest request) throws JargonException {
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
try {
path = URLDecoder.decode(path, this.getIrodsServices().getIrodsAccessObjectFactory().getJargonProperties().getEncoding());
} catch (UnsupportedEncodingException | JargonException e) {
logger.error("unable to decode path", e);
throw new JargonException(e);
}
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE);
AntPathMatcher apm = new AntPathMatcher();
return apm.extractPathWithinPattern(bestMatchPattern, path);
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class BrowseController method getPaginatedJSONObjs.
/*
* *************************************************************************
* ******************************** UTILS **********************************
* *************************************************************************
*/
/**
* Finds all collections and data objects existing under a certain path
*
* @param request
* contains all parameters in a map, we can use it to get all
* parameters passed in request
* @return json with collections and data objects
* @throws DataGridConnectionRefusedException
* @throws JargonException
*/
@RequestMapping(value = "getPaginatedJSONObjs/")
@ResponseBody
public String getPaginatedJSONObjs(final HttpServletRequest request) throws DataGridConnectionRefusedException, JargonException {
logger.info("getPaginatedJSONObjs()");
List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects;
int draw = Integer.parseInt(request.getParameter("draw"));
int start = Integer.parseInt(request.getParameter("start"));
int length = Integer.parseInt(request.getParameter("length"));
String searchString = request.getParameter("search[value]");
int orderColumn = Integer.parseInt(request.getParameter("order[0][column]"));
String orderDir = request.getParameter("order[0][dir]");
boolean deployRule = request.getParameter("rulesdeployment") != null;
// Pagination context to get the sequence number for the listed items
DataGridPageContext pageContext = new DataGridPageContext();
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(1));
jsonResponse.put("recordsFiltered", String.valueOf(0));
jsonResponse.put("data", new ArrayList<String>());
String jsonString = "";
try {
logger.info("using path of:{}", currentPath);
String path = currentPath;
if (deployRule) {
path = ruleDeploymentService.getRuleCachePath();
}
Math.floor(start / length);
logger.info("getting subcollections under path:{}", path);
// TODO: temporary add
dataGridCollectionAndDataObjects = cs.getSubCollectionsAndDataObjectsUnderPath(path);
// paging service
logger.debug("dataGridCollectionAndDataObjects:{}", dataGridCollectionAndDataObjects);
/*
* cs.getSubCollectionsAndDataObjectsUnderPathThatMatchSearchTextPaginated(
* path, searchString, startPage.intValue(), length, orderColumn, orderDir,
* pageContext);
*/
totalObjsForCurrentSearch = pageContext.getTotalNumberOfItems();
totalObjsForCurrentPath = pageContext.getTotalNumberOfItems();
jsonResponse.put("recordsTotal", String.valueOf(totalObjsForCurrentPath));
jsonResponse.put("recordsFiltered", String.valueOf(totalObjsForCurrentSearch));
jsonResponse.put("data", dataGridCollectionAndDataObjects);
} catch (DataGridConnectionRefusedException e) {
logger.error("connection refused", e);
throw e;
} catch (Exception e) {
logger.error("Could not get collections/data objs under path {}: {}", currentPath, e.getMessage());
throw new JargonException("exception getting paginated objects", e);
}
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (JsonProcessingException e) {
logger.error("Could not parse hashmap in collections to json: {}", e.getMessage());
throw new JargonException("exception in json parsing", e);
}
return jsonString;
}
Aggregations