use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class GroupBookmarkController method listGroupsByQueryPaginatedModel.
@RequestMapping(value = "/groupsBookmarksPaginated")
@ResponseBody
public String listGroupsByQueryPaginatedModel(final HttpServletRequest request) throws DataGridConnectionRefusedException {
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 onlyCollections = Boolean.parseBoolean(request.getParameter("onlyCollections"));
String currentUser = irodsServices.getCurrentUser();
String currentZone = irodsServices.getCurrentUserZone();
String[] orderBy = { "Dggb.name", "Dggb.path", "Dgg.groupname", "Dggb.createTs" };
List<DataGridGroupBookmark> groupBookmarks = null;
ObjectMapper mapper = new ObjectMapper();
Map<String, Object> jsonResponse = new HashMap<String, Object>();
String jsonString = "";
try {
groupBookmarks = groupBookmarkService.getGroupsBookmarksPaginated(currentUser, currentZone, start, length, searchString, orderBy[orderColumn], orderDir, onlyCollections);
if ("".equals(searchString)) {
totalGroupBookmarks = groupBookmarkService.countTotalGroupBookmarks(currentUser, currentZone);
totalGroupBookmarksFiltered = totalGroupBookmarks;
} else {
totalGroupBookmarksFiltered = groupBookmarks.size();
}
} catch (JargonException e) {
logger.error("Could not get groups bookmarks for {}", currentUser);
groupBookmarks = new ArrayList<DataGridGroupBookmark>();
}
jsonResponse.put("draw", String.valueOf(draw));
jsonResponse.put("recordsTotal", String.valueOf(totalGroupBookmarks));
jsonResponse.put("recordsFiltered", String.valueOf(totalGroupBookmarksFiltered));
jsonResponse.put("data", groupBookmarks);
try {
jsonString = mapper.writeValueAsString(jsonResponse);
} catch (Exception e) {
logger.error("Could not parse hashmap in favorites to json", e.getMessage());
}
return jsonString;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException 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.exceptions.DataGridConnectionRefusedException 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 com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException 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;
}
use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.
the class BrowseController method addCollection.
/**
* Performs the action of actually creating a collection in iRODS
*
* @param model
* @param collection
* @return if the creation of collection was successful, it returns the
* collection management template, and returns the add collection
* template, otherwise.
* @throws DataGridConnectionRefusedException
*/
@RequestMapping(value = "add/action", method = RequestMethod.POST)
public String addCollection(final Model model, @ModelAttribute final CollectionOrDataObjectForm collection, final RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
logger.info("addCollection()");
logger.info("collection:{}", collection);
logger.info("redirectAttributes:{}", redirectAttributes);
DataGridCollectionAndDataObject newCollection = new DataGridCollectionAndDataObject(currentPath + '/' + collection.getCollectionName(), collection.getCollectionName(), currentPath, true);
logger.info("newCollection:{}", newCollection);
newCollection.setParentPath(currentPath);
newCollection.setCreatedAt(new Date());
newCollection.setModifiedAt(newCollection.getCreatedAt());
newCollection.setInheritanceOption(collection.getInheritOption());
boolean creationSucessful;
try {
creationSucessful = cs.createCollection(newCollection);
logger.info("creationSuccessful?:{}", creationSucessful);
if (creationSucessful) {
redirectAttributes.addFlashAttribute("collectionAddedSuccessfully", collection.getCollectionName());
}
} catch (DataGridConnectionRefusedException e) {
throw e;
} catch (DataGridException e) {
logger.error("Could not create collection/data object (lack of permission): ", e.getMessage());
redirectAttributes.addFlashAttribute("missingPermissionError", true);
}
return "redirect:/collections?path=" + URLEncoder.encode(currentPath);
}
Aggregations