Search in sources :

Example 6 with DataGridException

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

the class TemplateController method importXMLFile.

@RequestMapping(value = "/import/", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public String importXMLFile(final Model model, final HttpServletRequest request, final RedirectAttributes redirect) {
    String responseString = "ok";
    if (request instanceof MultipartHttpServletRequest) {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<MultipartFile> multipartFiles = multipartRequest.getFiles("file");
        String prefix = multipartRequest.getParameter("prefix");
        String suffix = multipartRequest.getParameter("suffix");
        try {
            String username = loggedUserUtils.getLoggedDataGridUser().getUsername();
            boolean result = templateService.importXmlMetadataTemplate(multipartFiles.get(0).getInputStream(), username, prefix, suffix);
            if (!result) {
                responseString = "partial";
            }
        } catch (JAXBException | IOException | DataGridException e) {
            logger.error("Could not import metadata templates", e);
            responseString = "error";
        }
    }
    return responseString;
}
Also used : MultipartFile(org.springframework.web.multipart.MultipartFile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException 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 DataGridException

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

the class GroupServiceImpl method updateOwnership.

@Override
public boolean updateOwnership(DataGridGroup group, Map<String, Boolean> addCollectionsToOwn, Map<String, Boolean> removeCollectionsToOwn) throws DataGridConnectionRefusedException {
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    try {
        for (String path : addCollectionsToOwn.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.setAccessPermissionOwnAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToOwn.get(path));
            } else {
                dataObjectAO.setAccessPermissionWriteInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        for (String path : removeCollectionsToOwn.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToOwn.get(path));
            } else {
                dataObjectAO.removeAccessPermissionsForUserInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        return true;
    } catch (JargonException | DataGridException e) {
        logger.error("Could not set ownership:", e);
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 9 with DataGridException

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

the class GroupServiceImpl method updateReadPermissions.

@Override
public boolean updateReadPermissions(DataGridGroup group, Map<String, Boolean> addCollectionsToRead, Map<String, Boolean> removeCollectionsToRead) throws DataGridConnectionRefusedException {
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
    try {
        for (String path : addCollectionsToRead.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.setAccessPermissionReadAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), addCollectionsToRead.get(path));
            } else {
                dataObjectAO.setAccessPermissionReadInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        for (String path : removeCollectionsToRead.keySet()) {
            if (collectionService.isCollection(path)) {
                collectionAO.removeAccessPermissionForUserAsAdmin(group.getAdditionalInfo(), path, group.getGroupname(), removeCollectionsToRead.get(path));
            } else {
                dataObjectAO.setAccessPermissionReadInAdminMode(group.getAdditionalInfo(), path, group.getGroupname());
            }
        }
        return true;
    } catch (JargonException | DataGridException e) {
        logger.error("Could not set read permission:", e);
    }
    return false;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) JargonException(org.irods.jargon.core.exception.JargonException) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 10 with DataGridException

use of com.emc.metalnx.core.domain.exceptions.DataGridException 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";
}
Also used : DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) CollectionAndPath(org.irods.jargon.core.utils.CollectionAndPath) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)19 JargonException (org.irods.jargon.core.exception.JargonException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)5 CollectionAO (org.irods.jargon.core.pub.CollectionAO)4 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)4 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)3 IOException (java.io.IOException)3 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)3 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)3 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)3 DataGridUser (com.emc.metalnx.core.domain.entity.DataGridUser)2 InputStream (java.io.InputStream)2 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)2 Stream2StreamAO (org.irods.jargon.core.pub.Stream2StreamAO)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)1 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)1