Search in sources :

Example 6 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class MetadataController method searchByMetadata.

@RequestMapping(value = "/search/", method = RequestMethod.POST)
@ResponseBody
public String searchByMetadata(@RequestParam(required = false) final String jsonMetadataSearch, @RequestParam("draw") final int draw, @RequestParam("start") final int start, @RequestParam("length") final int length) throws DataGridConnectionRefusedException {
    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 {
        if (jsonMetadataSearch != null) {
            currPage = (int) (Math.floor(start / length) + 1);
            this.jsonMetadataSearch = jsonMetadataSearch;
        }
        // Creating parser
        JsonNode jsonObject = mapper.readTree(this.jsonMetadataSearch);
        currSearch = new ArrayList<>();
        JsonNode attributes = jsonObject.get("attribute");
        JsonNode operators = jsonObject.get("operator");
        JsonNode values = jsonObject.get("value");
        JsonNode units = jsonObject.get("unit");
        for (int i = 0; i < attributes.size(); i++) {
            String attr = attributes.get(i).textValue();
            String val = values.get(i).textValue();
            String unit = units.get(i).textValue();
            String opt = operators.get(i).textValue();
            DataGridSearchOperatorEnum op = DataGridSearchOperatorEnum.valueOf(opt);
            DataGridMetadataSearch ms = new DataGridMetadataSearch(attr, val, unit, op);
            currSearch.add(ms);
        }
        DataGridPageContext pageContext = new DataGridPageContext();
        List<DataGridCollectionAndDataObject> dgCollDataObjs = metadataService.findByMetadata(currSearch, pageContext, currPage, length);
        jsonResponse.put("recordsTotal", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("recordsFiltered", String.valueOf(pageContext.getTotalNumberOfItems()));
        jsonResponse.put("data", dgCollDataObjs);
    } catch (DataGridConnectionRefusedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not search by metadata: ", e.getMessage());
    }
    try {
        jsonString = mapper.writeValueAsString(jsonResponse);
    } catch (JsonProcessingException e) {
        logger.error("Could not parse hashmap in metadata search to json: {}", e.getMessage());
    }
    return jsonString;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridSearchOperatorEnum(com.emc.metalnx.core.domain.entity.enums.DataGridSearchOperatorEnum) HashMap(java.util.HashMap) JsonNode(com.fasterxml.jackson.databind.JsonNode) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DataGridPageContext(com.emc.metalnx.core.domain.entity.DataGridPageContext) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) 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 7 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class PreviewPreparationController method getPreview.

/**
 * Responds the preview/ request
 *
 * @param model
 * @return the collection management template
 * @throws DataGridConnectionRefusedException
 * @throws JargonException
 * @throws DataGridException
 */
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getPreview(final Model model, @RequestParam("path") final String path, RedirectAttributes redirectAttributes) throws DataGridException {
    logger.info("prepareForPreview for {} ::" + path);
    String mimeType = null;
    boolean permission = previewService.getPermission(path);
    if (permission) {
        try {
            IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
            DataTypeResolutionService dataTypeResolutionService = dataTypeResolutionServiceFactory.instanceDataTypeResolutionService(irodsAccount);
            logger.info("dataTypeResolutionService created from factory:{}", dataTypeResolutionService);
            logger.info("doing quick check for mime type");
            mimeType = dataTypeResolutionService.quickMimeType(path);
            logger.info("mimetype:{}", mimeType);
            redirectAttributes.addAttribute("path", path);
            redirectAttributes.addAttribute("mimeType", mimeType);
            return "redirect:/preview/templateByMimeType";
        } catch (JargonException e) {
            logger.error("Could not retrieve data from path: {}", path, e);
            throw new DataGridException(e.getMessage());
        } catch (Exception e) {
            logger.error("general exception generating preview", e);
            throw new DataGridException(e.getLocalizedMessage());
        }
    } else {
        return "collections/preview :: noPermission";
    }
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) DataTypeResolutionService(org.irods.jargon.extensions.datatyper.DataTypeResolutionService) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class ServerServiceImpl method getAllNonResourceServers.

@Override
public List<DataGridServer> getAllNonResourceServers(List<DataGridServer> servers, HashMap<String, DataGridServer> serverMapInCache, List<DataGridResource> dataGridResources) throws DataGridConnectionRefusedException {
    logger.info("Getting the list of all non-resource servers from the Grid using Resource cache");
    List<DataGridServer> nonResourceServers = new ArrayList<DataGridServer>();
    for (DataGridServer server : servers) {
        if (server.getHostname().compareToIgnoreCase("localhost") == 0) {
            continue;
        }
        ObjectMapper mapper = new ObjectMapper();
        String mounts = null;
        try {
            String serverInfo = getServerInfo(server.getHostname());
            JsonNode json = mapper.readTree(serverInfo);
            mounts = json.get("mounts").toString();
        } catch (JsonProcessingException e) {
            logger.error("Could not parse server information", e.getMessage());
        } catch (IOException e) {
            logger.error("Could not parse server information", e.getMessage());
        }
        if (mounts != null && !mounts.isEmpty()) {
            HashMap<String, String> hashMap = ServerUtil.getNFSMountMap(mounts);
            List<DataGridResource> resources = null;
            try {
                logger.info("Getting resources of a server {}", server.getHostname());
                resources = resourceService.getResourcesOfAServer(server.getHostname(), dataGridResources);
            } catch (DataGridConnectionRefusedException e) {
                // any
                if (serverMapInCache != null) {
                    resources = serverMapInCache.get(server.getHostname()).getResources();
                } else {
                    resources = new ArrayList<DataGridResource>();
                }
            }
            for (DataGridResource resource : resources) {
                if (hashMap.containsKey(resource.getPath())) {
                    String host = hashMap.get(resource.getPath());
                    DataGridServer newServer = new DataGridServer();
                    try {
                        host = reverseDnsLookup.compareTo("true") == 0 ? machineInfoService.getHostName(host) : host;
                        newServer.setHostname(host);
                        newServer.setIp(machineInfoService.getAddress(host));
                    } catch (UnknownHostException e) {
                        logger.error("Could not resolve IP address for " + host);
                    }
                    if (!nonResourceServers.contains(newServer)) {
                        nonResourceServers.add(newServer);
                    }
                }
            }
        }
    }
    return nonResourceServers.isEmpty() ? null : nonResourceServers;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnknownHostException(java.net.UnknownHostException) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) DataGridServer(com.emc.metalnx.core.domain.entity.DataGridServer) DataGridResource(com.emc.metalnx.core.domain.entity.DataGridResource) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 9 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException 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;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) UnsupportedDataGridFeatureException(com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) ConnectException(java.net.ConnectException)

Example 10 with DataGridConnectionRefusedException

use of com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException in project metalnx-web by irods-contrib.

the class PermissionsServiceImpl method canLoggedUserModifyPermissionOnPath.

@Override
public boolean canLoggedUserModifyPermissionOnPath(String path) throws DataGridConnectionRefusedException {
    String userName = irodsServices.getCurrentUser();
    final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    try {
        int resultingPermission;
        final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(path);
        if (irodsFileSystemAO.isDirectory(fileObj)) {
            resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, userName);
        } else {
            resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, userName);
        }
        return resultingPermission > FilePermissionEnum.WRITE.getPermissionNumericValue();
    } catch (final Exception e) {
        logger.error("Could not get permissions for current user: {}", e.getMessage());
    }
    return false;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) JargonException(org.irods.jargon.core.exception.JargonException) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException)

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