Search in sources :

Example 11 with CollectionAO

use of org.irods.jargon.core.pub.CollectionAO 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 12 with CollectionAO

use of org.irods.jargon.core.pub.CollectionAO 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 13 with CollectionAO

use of org.irods.jargon.core.pub.CollectionAO 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 14 with CollectionAO

use of org.irods.jargon.core.pub.CollectionAO 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 15 with CollectionAO

use of org.irods.jargon.core.pub.CollectionAO in project metalnx-web by irods-contrib.

the class CollectionServiceImpl method modifyCollectionAndDataObject.

@Override
public boolean modifyCollectionAndDataObject(String previousPath, String newPath, boolean inheritOption) throws DataGridConnectionRefusedException {
    logger.info("modifyCollectionAndDataObject()");
    IRODSFileSystemAO irodsFileSystemAO = irodsServices.getIRODSFileSystemAO();
    IRODSFileFactory irodsFileFactory = irodsServices.getIRODSFileFactory();
    CollectionAO collectionAO = irodsServices.getCollectionAO();
    logger.debug("Modify Collection/DataObject {} to {}", previousPath, newPath);
    try {
        logger.debug("Locating {} in iRODS", previousPath);
        IRODSFile previousFile = irodsFileFactory.instanceIRODSFile(previousPath);
        logger.info("Creating new IRODSFile instance for {}", newPath);
        IRODSFile newFile = irodsFileFactory.instanceIRODSFile(newPath);
        boolean isDirectory = irodsFileSystemAO.isDirectory(previousFile);
        if (previousPath.compareTo(newPath) != 0) {
            // checking if the path given is a collection
            if (isDirectory) {
                logger.debug("{} is a collection", previousPath);
                irodsFileSystemAO.renameDirectory(previousFile, newFile);
            } else // the path given is a data object
            {
                logger.debug("{} is a data object", previousPath);
                irodsFileSystemAO.renameFile(previousFile, newFile);
            }
        }
        // Updating inheritance option on the collection, if needed
        String zoneName = irodsFileSystemAO.getIRODSServerProperties().getRodsZone();
        if (isDirectory) {
            boolean isInheritanceSetForNewCollection = collectionAO.isCollectionSetForPermissionInheritance(newPath);
            if (inheritOption != isInheritanceSetForNewCollection) {
                // enable inheritance for this collection
                if (inheritOption) {
                    logger.debug("Setting inheritance option on {}", newPath);
                    collectionAO.setAccessPermissionInherit(zoneName, newPath, false);
                } else // disable inheritance for this collection
                {
                    logger.debug("Removing inheritance setting on {}", newPath);
                    collectionAO.setAccessPermissionToNotInherit(zoneName, newPath, false);
                }
            }
        }
        return true;
    } catch (JargonException e) {
        logger.error("Could not edit Collection/DataObject {} to {}: ", previousPath, newPath, e);
    }
    return false;
}
Also used : IRODSFileFactory(org.irods.jargon.core.pub.io.IRODSFileFactory) CollectionAO(org.irods.jargon.core.pub.CollectionAO) JargonException(org.irods.jargon.core.exception.JargonException) IRODSFileSystemAO(org.irods.jargon.core.pub.IRODSFileSystemAO) IRODSFile(org.irods.jargon.core.pub.io.IRODSFile)

Aggregations

CollectionAO (org.irods.jargon.core.pub.CollectionAO)22 JargonException (org.irods.jargon.core.exception.JargonException)20 DataObjectAO (org.irods.jargon.core.pub.DataObjectAO)14 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)7 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)7 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)7 CollectionAndDataObjectListAndSearchAO (org.irods.jargon.core.pub.CollectionAndDataObjectListAndSearchAO)5 DataObject (org.irods.jargon.core.pub.domain.DataObject)5 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)4 HashSet (java.util.HashSet)3 AvuData (org.irods.jargon.core.pub.domain.AvuData)3 FileNotFoundException (org.irods.jargon.core.exception.FileNotFoundException)2 FilePermissionEnum (org.irods.jargon.core.protovalues.FilePermissionEnum)2 IRODSFileSystemAO (org.irods.jargon.core.pub.IRODSFileSystemAO)2 DataGridMetadata (com.emc.metalnx.core.domain.entity.DataGridMetadata)1 IconObject (com.emc.metalnx.core.domain.entity.IconObject)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)1 DataTransferOperations (org.irods.jargon.core.pub.DataTransferOperations)1