use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetAccessController method checkSharedDatasetsAccess.
private void checkSharedDatasetsAccess(Users user, Dataset dataset, ProjectsCollector collector, ShortLivedCache cache) {
if (cache.sharedWithProjectsCache.containsKey(dataset.getInodeId())) {
// cached
Set<Integer> projectIds = cache.sharedWithProjectsCache.get(dataset.getInodeId());
for (Integer projectId : projectIds) {
Pair<Project, String> projectAux = getProjectWithCache(user, projectId, cache);
if (projectAux != null && projectAux.getValue1() != null) {
collector.addAccessProject(projectAux.getValue0());
}
}
} else {
// not yet cached
List<DatasetSharedWith> dsSharedWith = dsSharedWithFacade.findByDataset(dataset);
Set<Integer> projectIds = new HashSet<>();
cache.sharedWithProjectsCache.put(dataset.getInodeId(), projectIds);
for (DatasetSharedWith ds : dsSharedWith) {
projectIds.add(ds.getProject().getId());
Pair<Project, String> projectAux = getProjectWithCache(user, ds.getProject(), cache);
if (projectAux != null && projectAux.getValue1() != null) {
collector.addAccessProject(projectAux.getValue0());
}
}
}
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetBuilder method datasetSharedWithItems.
// create dto from a list of DatasetSharedWith objects
private DatasetDTO datasetSharedWithItems(DatasetDTO dto, UriInfo uriInfo, ResourceRequest resourceRequest, Project accessProject, Users user, List<DatasetSharedWith> datasetSharedWithList, String parentPath, Users dirOwner) throws DatasetException, MetadataException, SchematizedTagException {
if (datasetSharedWithList != null && !datasetSharedWithList.isEmpty()) {
for (DatasetSharedWith datasetSharedWith : datasetSharedWithList) {
DatasetPath datasetPath = datasetHelper.getTopLevelDatasetPath(accessProject, datasetSharedWith);
dto.addItem(buildItems(uriInfo, resourceRequest, user, datasetPath, parentPath, dirOwner));
}
}
return dto;
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class ModelRegistryBuilder method build.
// Build collection
public ModelRegistryDTO build(UriInfo uriInfo, ResourceRequest resourceRequest, Users user, Project project) throws GenericException, ModelRegistryException, SchematizedTagException, MetadataException {
ModelRegistryDTO dto = new ModelRegistryDTO();
uri(dto, uriInfo, project);
expand(dto, resourceRequest);
Collection<Dataset> dsInProject = project.getDatasetCollection();
// Add all datasets shared with the project
dsInProject.addAll(project.getDatasetSharedWithCollection().stream().filter(DatasetSharedWith::getAccepted).map(DatasetSharedWith::getDataset).collect(Collectors.toList()));
Collection<Dataset> modelsDatasets = dsInProject.stream().filter(ds -> ds.getName().equals(Settings.HOPS_MODELS_DATASET)).collect(Collectors.toList());
dto.setCount((long) modelsDatasets.size());
for (Dataset ds : modelsDatasets) {
ModelRegistryDTO modelRegistryDTO = build(uriInfo, resourceRequest, user, project, ds.getProject());
if (modelRegistryDTO != null) {
dto.addItem(modelRegistryDTO);
}
}
return dto;
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class DatasetSharedWithFacade method findAllDatasetByProject.
public CollectionInfo findAllDatasetByProject(Integer offset, Integer limit, Set<? extends FilterBy> filter, Set<? extends SortBy> sort, Project project) {
String queryStr = buildQuery("SELECT d FROM DatasetSharedWith d ", filter, sort, "d.project = :project ");
String queryCountStr = buildQuery("SELECT COUNT(DISTINCT d.id) FROM DatasetSharedWith d ", filter, null, "d.project = :project ");
Query query = em.createQuery(queryStr, DatasetSharedWith.class).setParameter("project", project);
Query queryCount = em.createQuery(queryCountStr, DatasetSharedWith.class).setParameter("project", project);
setFilter(filter, query, project);
setFilter(filter, queryCount, project);
setOffsetAndLim(offset, limit, query);
return new CollectionInfo((Long) queryCount.getSingleResult(), query.getResultList());
}
use of io.hops.hopsworks.persistence.entity.dataset.DatasetSharedWith in project hopsworks by logicalclocks.
the class PathValidator method buildFullPath.
private void buildFullPath(Project project, String path, DsPath dsPath) throws DatasetException {
// Strip leading slashes.
while (path.startsWith("/")) {
path = path.substring(1);
}
String[] pathComponents = path.split(File.separator);
String dsName = pathComponents[0];
boolean shared = false;
String parentProjectPath = null;
if (pathComponents[0].contains(Settings.SHARED_FILE_SEPARATOR)) {
// we can split the string and get the project name
String[] shardDS = pathComponents[0].split(Settings.SHARED_FILE_SEPARATOR);
if (shardDS.length != 2) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
}
parentProjectPath = Utils.getProjectPath(shardDS[0]);
dsName = shardDS[1];
shared = true;
}
Dataset ds = datasetController.getByProjectAndDsName(project, parentProjectPath, dsName);
if (ds == null) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_NOT_FOUND, Level.FINE);
}
// If the dataset is shared, make sure that the user can access it
if (shared) {
DatasetSharedWith datasetSharedWith = datasetSharedWithFacade.findByProjectAndDataset(project, ds);
if (datasetSharedWith != null && !datasetSharedWith.getAccepted()) {
throw new DatasetException(RESTCodes.DatasetErrorCode.DATASET_PENDING, Level.FINE, "datasetId: " + ds.getId());
}
}
dsPath.setDs(ds);
String dsRelativePathStr = buildRelativePath(pathComponents, 1, pathComponents.length);
if (dsRelativePathStr.isEmpty()) {
dsPath.setFullPath(datasetController.getDatasetPath(ds));
} else {
Path dsRelativePath = new Path(dsRelativePathStr);
dsPath.setDsRelativePath(dsRelativePath);
Path fullPath = new Path(datasetController.getDatasetPath(ds), dsRelativePath);
dsPath.setFullPath(fullPath);
}
}
Aggregations