Search in sources :

Example 46 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class CollectionController method index.

/**
 * Legacy index method used in other controllers, eventually factor out TODO:
 * factor this out and make explicit via urls etc - mcc
 *
 * @param model
 * @param request
 * @return
 */
public String index(final Model model, final HttpServletRequest request) {
    logger.info("index()");
    try {
        sourcePaths.clear();
        if (!cs.isPathValid(currentPath)) {
            currentPath = cs.getHomeDirectyForCurrentUser();
            parentPath = currentPath;
        } else if (cs.isDataObject(currentPath)) {
            parentPath = currentPath.substring(0, currentPath.lastIndexOf("/") + 1);
        }
        DataGridUser loggedUser = loggedUserUtils.getLoggedDataGridUser();
        String uiMode = (String) request.getSession().getAttribute("uiMode");
        if (uiMode == null || uiMode.isEmpty()) {
            boolean isUserAdmin = loggedUser != null && loggedUser.isAdmin();
            uiMode = isUserAdmin ? UI_ADMIN_MODE : UI_USER_MODE;
        }
        if (uiMode.equals(UI_USER_MODE)) {
            model.addAttribute("homePath", cs.getHomeDirectyForCurrentUser());
            model.addAttribute("publicPath", cs.getHomeDirectyForPublic());
        }
        model.addAttribute("cameFromFilePropertiesSearch", cameFromFilePropertiesSearch);
        model.addAttribute("cameFromMetadataSearch", cameFromMetadataSearch);
        model.addAttribute("cameFromBookmarks", cameFromBookmarks);
        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());
        cameFromMetadataSearch = false;
        cameFromFilePropertiesSearch = false;
        cameFromBookmarks = false;
    } catch (DataGridException | JargonException e) {
        logger.error("Could not respond to request for collections: {}", e);
        model.addAttribute("unexpectedError", true);
    }
    logger.info("returning to 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)

Example 47 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class UserController method addUser.

/**
 * Controller method that executes action 'create user'
 *
 * @param user
 * @return the name of the template to render
 * @throws DataGridConnectionRefusedException
 */
@RequestMapping(value = "add/action/", method = RequestMethod.POST)
public String addUser(@ModelAttribute UserForm user, HttpServletRequest request, RedirectAttributes redirectAttributes) throws DataGridConnectionRefusedException {
    logger.info("addUser()");
    if (user == null) {
        throw new IllegalArgumentException("null user");
    }
    DataGridUser newUser = new DataGridUser();
    newUser.setAdditionalInfo(user.getAdditionalInfo());
    newUser.setUsername(user.getUsername());
    newUser.setFirstName(user.getFirstName());
    newUser.setLastName(user.getLastName());
    newUser.setEmail(user.getEmail());
    newUser.setUserType(user.getUserType());
    newUser.setOrganizationalRole(user.getOrganizationalRole() != null ? user.getOrganizationalRole() : "");
    newUser.setCompany(user.getCompany() != null ? user.getCompany() : "");
    newUser.setDepartment(user.getDepartment() != null ? user.getDepartment() : "");
    logger.info("adding user:{}", newUser);
    String selectedProfile = request.getParameter("selectedProfile");
    String[] groupList = groupsToBeAdded.toArray(new String[groupsToBeAdded.size()]);
    List<DataGridGroup> groups = new ArrayList<DataGridGroup>();
    if (groupList != null && groupList.length != 0) {
        groups = groupService.findByDataGridIdList(groupList);
    }
    boolean groupsUpdateSuccessful = false;
    boolean creationSucessful = false;
    try {
        logger.info("creating the user...");
        creationSucessful = userService.createUser(newUser, user.getPassword());
        logger.info("creation successful? {}", creationSucessful);
        // Updating the group list for the recently-created user
        if (creationSucessful) {
            // adding read, write and ownership permissions to a set of collections
            userService.updateReadPermissions(newUser, addReadPermissionsOnDirs, removeReadPermissionsOnDirs);
            userService.updateWritePermissions(newUser, addWritePermissionsOnDirs, removeWritePermissionsOnDirs);
            userService.updateOwnership(newUser, addOwnerOnDirs, removeOwnerOnDirs);
            cleanPermissionsSets();
            DataGridUser userForGroups = userService.findByUsernameAndAdditionalInfo(newUser.getUsername(), newUser.getAdditionalInfo());
            groupsUpdateSuccessful = userService.updateGroupList(userForGroups, groups);
            if (selectedProfile != null && selectedProfile != "") {
                UserProfile userProfile = userProfileService.findById(Long.valueOf(selectedProfile));
                userService.applyProfileToUser(userProfile, userForGroups);
                userForGroups.setUserProfile(userProfile);
            } else {
                user.setUserProfile(null);
            }
            // User bookmarks
            updateBookmarksList(newUser.getUsername(), newUser.getAdditionalInfo());
            userService.modifyUser(userForGroups);
            redirectAttributes.addFlashAttribute("userAddedSuccessfully", user.getUsername());
        }
    } catch (DuplicateDataException e) {
        redirectAttributes.addFlashAttribute("duplicateUser", ExceptionEnum.USERS_DATA_DUPLICATE_EXCEPTION.getCode());
        logger.error("Could not create user: ", e);
    } catch (JargonException e) {
        redirectAttributes.addFlashAttribute("error", ExceptionEnum.JARGON_EXCEPTION.getCode());
        logger.error("Could not create user: ", e);
    }
    return creationSucessful && groupsUpdateSuccessful ? "redirect:/users/" : "redirect:/users/add/";
}
Also used : DuplicateDataException(org.irods.jargon.core.exception.DuplicateDataException) UserProfile(com.emc.metalnx.core.domain.entity.UserProfile) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) DataGridGroup(com.emc.metalnx.core.domain.entity.DataGridGroup) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 48 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method findMetadataValuesByPath.

@Override
public List<DataGridMetadata> findMetadataValuesByPath(String path) throws DataGridConnectionRefusedException {
    List<MetaDataAndDomainData> metadataList;
    List<DataGridMetadata> dataGridMetadataList = new ArrayList<>();
    List<MetaDataAndDomainData> resultingList;
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    try {
        Object obj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(path);
        if (obj instanceof DataObject) {
            DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
            metadataList = dataObjectAO.findMetadataValuesForDataObject(path);
        } else {
            CollectionAO collectionAO = irodsServices.getCollectionAO();
            metadataList = collectionAO.findMetadataValuesForCollection(path);
        }
        // TODO2: Making sure all AVUs are unique. Jargon should do that.
        resultingList = new ArrayList<>();
        Set<Integer> setOfAlreadyListedAVUs = new HashSet<>();
        for (MetaDataAndDomainData avuForItem : metadataList) {
            int avuId = avuForItem.getAvuId();
            if (!setOfAlreadyListedAVUs.contains(avuId)) {
                resultingList.add(avuForItem);
                setOfAlreadyListedAVUs.add(avuId);
            }
        }
        for (MetaDataAndDomainData metadata : resultingList) {
            DataGridMetadata dataGridMetadata = new DataGridMetadata();
            dataGridMetadata.setAttribute(metadata.getAvuAttribute());
            dataGridMetadata.setValue(metadata.getAvuValue());
            dataGridMetadata.setUnit(metadata.getAvuUnit());
            dataGridMetadataList.add(dataGridMetadata);
        }
        Collections.sort(dataGridMetadataList);
    } catch (JargonQueryException e) {
        logger.error("Error getting metadata info from collection: " + e.toString());
    } catch (JargonException e) {
        logger.error("Error getting metadata info from dataobject: " + e.toString());
    }
    return dataGridMetadataList;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) ArrayList(java.util.ArrayList) MetaDataAndDomainData(org.irods.jargon.core.query.MetaDataAndDomainData) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) JargonQueryException(org.irods.jargon.core.query.JargonQueryException) DataGridMetadata(com.emc.metalnx.core.domain.entity.DataGridMetadata) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO) HashSet(java.util.HashSet)

Example 49 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method delMetadataFromPath.

@Override
public boolean delMetadataFromPath(String path, String attribute, String value, String unit) throws DataGridConnectionRefusedException {
    CollectionAndDataObjectListAndSearchAO collectionAndDataObjectListAndSearchAO = irodsServices.getCollectionAndDataObjectListAndSearchAO();
    try {
        AvuData avuData = new AvuData(attribute, value, unit);
        Object obj = collectionAndDataObjectListAndSearchAO.getFullObjectForType(path);
        if (obj instanceof DataObject) {
            DataObjectAO dataObjectAO = irodsServices.getDataObjectAO();
            dataObjectAO.deleteAVUMetadata(path, avuData);
        } else {
            CollectionAO collectionAO = irodsServices.getCollectionAO();
            collectionAO.deleteAVUMetadata(path, avuData);
        }
    } catch (JargonException e) {
        logger.error("Error trying to delete metadata: " + e.toString());
        return false;
    }
    return true;
}
Also used : CollectionAndDataObjectListAndSearchAO(org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) AvuData(org.irods.jargon.core.pub.domain.AvuData) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) DataObject(org.irods.jargon.core.pub.domain.DataObject) DataObjectAO(org.irods.jargon.core.pub.DataObjectAO)

Example 50 with JargonException

use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.

the class PreviewServiceImpl method filePreview.

@Override
public boolean filePreview(String path, String mimeType, HttpServletResponse response) {
    logger.info("getting file preview  for {} ::" + path + " and mimetype :: " + mimeType);
    boolean isCopySuccessFul = true;
    IRODSFileInputStream irodsFileInputStream = null;
    IRODSFile irodsFile = null;
    try {
        IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
        irodsFile = irodsFileFactory.instanceIRODSFile(path);
        irodsFileInputStream = irodsFileFactory.instanceIRODSFileInputStream(irodsFile);
        response.setContentType(mimeType);
        FileCopyUtils.copy(irodsFileInputStream, response.getOutputStream());
    } catch (IOException | JargonException | DataGridConnectionRefusedException e) {
        e.printStackTrace();
        isCopySuccessFul = false;
    } finally {
        try {
            if (irodsFileInputStream != null)
                irodsFileInputStream.close();
            if (irodsFile != null)
                irodsFile.close();
        } catch (Exception e) {
            logger.error("Could not close stream(s): ", e.getMessage());
        }
    }
    return isCopySuccessFul;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) IRODSFileInputStream(org.irods.jargon.core.pub.io.IRODSFileInputStream) JargonException(org.irods.jargon.core.exception.JargonException) IOException(java.io.IOException) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IOException(java.io.IOException) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException)

Aggregations

JargonException (org.irods.jargon.core.exception.JargonException)86 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)20 CollectionAO (org.irods.jargon.core.pub.CollectionAO)20 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)18 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)18 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)17 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)15 ArrayList (java.util.ArrayList)12 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)12 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)11 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)10 SpecificQueryDefinition (org.irods.jargon.core.pub.domain.SpecificQueryDefinition)10 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)9 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)8 SpecificQueryProvider (com.emc.metalnx.services.irods.utils.SpecificQueryProvider)8 ClientHints (org.irods.jargon.core.pub.domain.ClientHints)8 DataObject (org.irods.jargon.core.pub.domain.DataObject)8 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)8 SpecificQuery (org.irods.jargon.core.query.SpecificQuery)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8