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());
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations