Search in sources :

Example 11 with DataGridConnectionRefusedException

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;
}
Also used : DataGridGroupBookmark(com.emc.metalnx.core.domain.entity.DataGridGroupBookmark) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with DataGridConnectionRefusedException

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";
}
Also used : DataGridGroupPermission(com.emc.metalnx.core.domain.entity.DataGridGroupPermission) DataGridUserPermission(com.emc.metalnx.core.domain.entity.DataGridUserPermission) DataGridGroupBookmark(com.emc.metalnx.core.domain.entity.DataGridGroupBookmark) ArrayList(java.util.ArrayList) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridUserBookmark(com.emc.metalnx.core.domain.entity.DataGridUserBookmark) DataGridFilePermission(com.emc.metalnx.core.domain.entity.DataGridFilePermission) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with DataGridConnectionRefusedException

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;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridFilePropertySearch(com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ParseException(java.text.ParseException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with DataGridConnectionRefusedException

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;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) HashMap(java.util.HashMap) JargonException(org.irods.jargon.core.exception.JargonException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) IconObject(com.emc.metalnx.core.domain.entity.IconObject) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with DataGridConnectionRefusedException

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);
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) Date(java.util.Date) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)24 JargonException (org.irods.jargon.core.exception.JargonException)17 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)10 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 IOException (java.io.IOException)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 ArrayList (java.util.ArrayList)6 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)5 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)4 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 ConnectException (java.net.ConnectException)3 UserGroupAO (org.irods.jargon.core.pub.UserGroupAO)3 DataGridGroup (com.emc.metalnx.core.domain.entity.DataGridGroup)2