Search in sources :

Example 1 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method populateVisibilityForCurrentUser.

/**
 * Sets whether or not a user can check an object resulting from a metadata
 * search
 *
 * @param objectList
 *            list of data objects/collections
 * @throws DataGridConnectionRefusedException
 */
@Override
public void populateVisibilityForCurrentUser(List<DataGridCollectionAndDataObject> objectList) throws DataGridConnectionRefusedException {
    if (objectList == null || objectList.isEmpty()) {
        return;
    }
    final String currentUser = irodsServices.getCurrentUser();
    final IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    final IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    for (final DataGridCollectionAndDataObject obj : objectList) {
        try {
            int resultingPermission;
            final IRODSFile fileObj = irodsFileFactory.instanceIRODSFile(obj.getPath());
            if (obj.isCollection()) {
                resultingPermission = irodsFileSystemAO.getDirectoryPermissionsForGivenUser(fileObj, currentUser);
            } else {
                resultingPermission = irodsFileSystemAO.getFilePermissionsForGivenUser(fileObj, currentUser);
            }
            // By default, the visibility of a user over an object is set to false
            obj.setVisibleToCurrentUser(resultingPermission != FilePermissionEnum.NONE.getPermissionNumericValue());
        } catch (final Exception e) {
            logger.error("Could not get permissions for current user: {}", e.getMessage());
        }
    }
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException)

Example 2 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class MetadataServiceImpl method findByMetadata.

@Override
public List<DataGridCollectionAndDataObject> findByMetadata(List<DataGridMetadataSearch> searchList, DataGridPageContext pageContext, int pageNum, int pageSize) throws DataGridConnectionRefusedException {
    List<DataGridCollectionAndDataObject> dataGridCollectionAndDataObjects = new ArrayList<>();
    List<DataGridCollectionAndDataObject> dataGridObjects;
    List<DataGridCollectionAndDataObject> dataGridCollections;
    int totalCollections;
    int totalDataObjects;
    int startIndex = (pageNum - 1) * pageSize;
    int endIndex = (pageNum * pageSize) - 1;
    int endIndexForDataObjs;
    int endIndexForCollections;
    try {
        String zone = irodsServices.getCurrentUserZone();
        totalCollections = specQueryService.countCollectionsMatchingMetadata(searchList, zone);
        totalDataObjects = specQueryService.countDataObjectsMatchingMetadata(searchList, zone);
        pageContext.setStartItemNumber(startIndex + 1);
        pageContext.setTotalNumberOfItems(totalCollections + totalDataObjects);
        if (endIndex + 1 <= totalCollections) {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(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.searchByMetadata(searchList, zone, false, pageContext, startIndex - totalCollections, pageSize);
            dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + dataGridObjects.size() - 1);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
        } else {
            // looking for collections
            SpecificQueryResultSet resultSetColls = specQueryService.searchByMetadata(searchList, zone, true, pageContext, startIndex, pageSize);
            dataGridCollections = DataGridUtils.mapMetadataResultSetToDataGridCollections(resultSetColls);
            endIndexForDataObjs = pageSize - (totalCollections % pageSize);
            // looking for data objects
            SpecificQueryResultSet resultSetDataObjs = specQueryService.searchByMetadata(searchList, zone, false, pageContext, 0, endIndexForDataObjs);
            dataGridObjects = DataGridUtils.mapMetadataResultSetToDataGridObjects(resultSetDataObjs);
            endIndexForDataObjs = endIndexForDataObjs > dataGridObjects.size() ? dataGridObjects.size() : endIndexForDataObjs;
            dataGridCollectionAndDataObjects.addAll(dataGridCollections);
            dataGridCollectionAndDataObjects.addAll(dataGridObjects);
            pageContext.setEndItemNumber(pageContext.getStartItemNumber() + endIndexForDataObjs + dataGridCollections.size() - 1);
        }
    } catch (DataGridConnectionRefusedException e) {
        throw e;
    } catch (Exception e) {
        logger.error("Could not find data objects by metadata. ", e.getMessage());
    }
    populateVisibilityForCurrentUser(dataGridCollectionAndDataObjects);
    return dataGridCollectionAndDataObjects;
}
Also used : DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) ArrayList(java.util.ArrayList) SpecificQueryResultSet(org.irods.jargon.core.query.SpecificQueryResultSet) DataGridConnectionRefusedException(com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException) JargonException(org.irods.jargon.core.exception.JargonException) JargonQueryException(org.irods.jargon.core.query.JargonQueryException)

Example 3 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method prepareFilesForDownload.

@Override
public String prepareFilesForDownload(List<String> sourcePaths) throws IOException, DataGridException, JargonException {
    logger.info("prepareFilesForDownload()");
    logger.info("Preparing files for download");
    if (sourcePaths == null || sourcePaths.isEmpty()) {
        return "";
    }
    Date currentDate = new Date();
    String tempCollectionName = "mlx_download_" + System.currentTimeMillis();
    String tempCollectionPath = getHomeDirectyForCurrentUser() + IRODS_PATH_SEPARATOR + tempCollectionName;
    String filePathToBeBundled = tempCollectionPath;
    String compressedFilePath = getHomeDirectyForCurrentUser() + IRODS_PATH_SEPARATOR + tempCollectionName + ".tar";
    String path = "";
    // through the HTTP response
    if (sourcePaths.size() == 1 && isDataObject(sourcePaths.get(0))) {
        path = sourcePaths.get(0);
    } else // if two or more files will be downloaded, then a compressed file needs
    // to be created in order to place all these files
    {
        // creating temporary collection for download
        DataGridCollectionAndDataObject tempCollection = new DataGridCollectionAndDataObject(tempCollectionPath, getHomeDirectyForCurrentUser(), true);
        tempCollection.setCreatedAt(currentDate);
        tempCollection.setModifiedAt(currentDate);
        tempCollection.setInheritanceOption(false);
        logger.debug("Creating temporary collection for download");
        boolean isTempCollectionCreated = createCollection(tempCollection);
        if (isTempCollectionCreated && !sourcePaths.isEmpty()) {
            logger.info("Copying files to be downloaded to the temporary collection");
            // copying all files and collections to be downloaded to the temporary
            // collection
            fileOperationService.copy(sourcePaths, tempCollectionPath, false);
            // creating the compressed file (tar) into the temporary collection
            logger.info("Compressing temporary collection");
            compressTempFolderIntoDataGrid(filePathToBeBundled, compressedFilePath, "");
            path = compressedFilePath;
        }
    }
    return path;
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) Date(java.util.Date)

Example 4 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method listWritePermissionsForPathAndGroupRecursive.

@Override
public Set<String> listWritePermissionsForPathAndGroupRecursive(String path, String groupName) throws DataGridConnectionRefusedException, JargonException {
    logger.info("listWritePermissionsForPathAndGroupRecursive()");
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    List<DataGridCollectionAndDataObject> children = getSubCollectionsAndDataObjectsUnderPath(path);
    Set<String> list = new HashSet<String>();
    for (DataGridCollectionAndDataObject child : children) {
        try {
            if (collectionAO.getPermissionForUserName(child.getPath(), groupName) != null) {
                list.add(child.getPath());
            } else {
                if (listWritePermissionsForPathAndGroupRecursive(child.getPath(), groupName).isEmpty()) {
                    list.add(child.getPath());
                }
            }
        } catch (JargonException e) {
            logger.error("Could not list write permissions for path " + path + "and group: " + groupName, e);
        }
    }
    return list;
}
Also used : CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) HashSet(java.util.HashSet)

Example 5 with DataGridCollectionAndDataObject

use of com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method mapListingEntryToDataGridCollectionAndDataObject.

@Override
public DataGridCollectionAndDataObject mapListingEntryToDataGridCollectionAndDataObject(CollectionAndDataObjectListingEntry entry) {
    logger.info("mapListingEntryToDataGridCollectionAndDataObject()");
    logger.debug("Mapping a CollectionAndDataObjectListingEntry into a " + "DataGridCollectionAndDataObject");
    String entryPath = "";
    String entryName = "";
    DataGridCollectionAndDataObject dgObj = null;
    if (entry.isCollection()) {
        entryPath = entry.getPathOrName();
    } else {
        entryPath = entry.getParentPath() + IRODS_PATH_SEPARATOR + entry.getPathOrName();
        if (entry.getParentPath().compareTo(IRODS_PATH_SEPARATOR) == 0) {
            entryPath = IRODS_PATH_SEPARATOR + entry.getPathOrName();
        }
    }
    entryName = entry.getNodeLabelDisplayValue();
    if (entryName == null || entryName.isEmpty()) {
        entryName = entryPath;
    }
    dgObj = new DataGridCollectionAndDataObject(entryPath, entryName, entry.getParentPath(), entry.isCollection());
    dgObj.setCreatedAt(entry.getCreatedAt());
    dgObj.setModifiedAt(entry.getModifiedAt());
    dgObj.setOwner(entry.getOwnerName());
    dgObj.setProxy(entry.getObjectType() == ObjectType.COLLECTION_HEURISTIC_STANDIN);
    return dgObj;
}
Also used : DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)

Aggregations

DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)55 JargonException (org.irods.jargon.core.exception.JargonException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Before (org.junit.Before)11 DataGridConnectionRefusedException (com.emc.metalnx.core.domain.exceptions.DataGridConnectionRefusedException)9 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)9 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)7 ArrayList (java.util.ArrayList)7 CollectionAndDataObjectListingEntry (org.irods.jargon.core.query.CollectionAndDataObjectListingEntry)7 DataGridPageContext (com.emc.metalnx.core.domain.entity.DataGridPageContext)6 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)5 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 JargonQueryException (org.irods.jargon.core.query.JargonQueryException)4 DataGridResource (com.emc.metalnx.core.domain.entity.DataGridResource)3 UnsupportedDataGridFeatureException (com.emc.metalnx.core.domain.exceptions.UnsupportedDataGridFeatureException)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3