Search in sources :

Example 1 with NoResourcePermissionException

use of io.lumeer.core.exception.NoResourcePermissionException in project engine by Lumeer.

the class ProjectFacade method getRawProjectContent.

public ProjectContent getRawProjectContent(final Project project) {
    if (!project.isPublic() && !permissionsChecker.canReadAllInWorkspace()) {
        throw new NoResourcePermissionException(project);
    }
    final ProjectContent content = new ProjectContent();
    content.setCollections(collectionDao.getAllCollections().stream().map(CollectionWithId::new).collect(Collectors.toList()));
    content.setViews(viewDao.getAllViews().stream().map(ViewWithId::new).collect(Collectors.toList()));
    content.setLinkTypes(linkTypeDao.getAllLinkTypes().stream().map(LinkTypeWithId::new).collect(Collectors.toList()));
    String userId = Utils.computeIfNotNull(authenticatedUser, AuthenticatedUser::getCurrentUserId);
    if (userId != null) {
        content.setFavoriteCollectionIds(favoriteItemDao.getFavoriteCollectionIds(userId, project.getId()));
        content.setFavoriteViewIds(favoriteItemDao.getFavoriteViewIds(userId, project.getId()));
    } else {
        content.setFavoriteCollectionIds(favoriteItemDao.getFavoriteCollectionIds(project.getId()));
        content.setFavoriteViewIds(favoriteItemDao.getFavoriteViewIds(project.getId()));
    }
    content.setSequences(sequenceDao.getAllSequences());
    content.setSelectionLists(selectionListDao.getAllLists(List.of(project.getId())));
    final List<LinkInstanceWithId> linkInstances = new ArrayList<>();
    final Map<String, List<DataDocument>> linksData = new HashMap<>();
    content.getLinkTypes().forEach(lt -> {
        linksData.put(lt.getId(), linkDataDao.getDataStream(lt.getId()).map(this::translateDataDocument).collect(Collectors.toList()));
        linkInstances.addAll(linkInstanceDao.getLinkInstancesByLinkType(lt.getId()).stream().map(LinkInstanceWithId::new).collect(Collectors.toList()));
    });
    content.setLinkInstances(linkInstances);
    content.setLinkData(linksData);
    final List<DocumentWithId> documents = new ArrayList<>();
    final Map<String, List<DataDocument>> documentsData = new HashMap<>();
    content.getCollections().forEach(c -> {
        documentsData.put(c.getId(), dataDao.getDataStream(c.getId()).map(this::translateDataDocument).collect(Collectors.toList()));
        documents.addAll(documentDao.getDocumentsByCollection(c.getId()).stream().map(DocumentWithId::new).collect(Collectors.toList()));
    });
    content.setDocuments(documents);
    content.setData(documentsData);
    content.setComments(resourceCommentDao.getAllComments().stream().map(ResourceCommentWrapper::new).collect(Collectors.toList()));
    if (permissionsChecker.hasRole(project, RoleType.TechConfig)) {
        content.setVariables(resourceVariableDao.getInProject(getOrganization().getId(), project.getId()).stream().filter(variable -> !variable.getSecure()).collect(Collectors.toList()));
    }
    content.setTemplateMeta(new ProjectMeta(project.getCode(), content.getCollections().size(), content.getLinkTypes().size(), content.getViews().size(), content.getDocuments().size()));
    return content;
}
Also used : LinkInstanceWithId(io.lumeer.api.model.templateParse.LinkInstanceWithId) DocumentWithId(io.lumeer.api.model.templateParse.DocumentWithId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProjectContent(io.lumeer.api.model.ProjectContent) LinkTypeWithId(io.lumeer.api.model.templateParse.LinkTypeWithId) ResourceCommentWrapper(io.lumeer.api.model.templateParse.ResourceCommentWrapper) ViewWithId(io.lumeer.api.model.templateParse.ViewWithId) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) CollectionWithId(io.lumeer.api.model.templateParse.CollectionWithId) NoResourcePermissionException(io.lumeer.core.exception.NoResourcePermissionException) List(java.util.List) ArrayList(java.util.ArrayList) ProjectMeta(io.lumeer.api.model.ProjectMeta)

Example 2 with NoResourcePermissionException

use of io.lumeer.core.exception.NoResourcePermissionException in project engine by Lumeer.

the class CollectionFacade method getCollection.

public Collection getCollection(String collectionId) {
    Collection collection = collectionDao.getCollectionById(collectionId);
    if (permissionsChecker.hasRoleInCollectionWithView(collection, RoleType.Read)) {
        return mapCollection(collection);
    }
    var userIdsInViews = resourceAdapter.getCollectionTransitiveReaders(getOrganization(), getProject(), collectionId);
    if (userIdsInViews.contains(getCurrentUserId())) {
        return mapCollection(collection);
    }
    throw new NoResourcePermissionException(collection);
}
Also used : NoResourcePermissionException(io.lumeer.core.exception.NoResourcePermissionException) Collection(io.lumeer.api.model.Collection)

Aggregations

NoResourcePermissionException (io.lumeer.core.exception.NoResourcePermissionException)2 Collection (io.lumeer.api.model.Collection)1 ProjectContent (io.lumeer.api.model.ProjectContent)1 ProjectMeta (io.lumeer.api.model.ProjectMeta)1 CollectionWithId (io.lumeer.api.model.templateParse.CollectionWithId)1 DocumentWithId (io.lumeer.api.model.templateParse.DocumentWithId)1 LinkInstanceWithId (io.lumeer.api.model.templateParse.LinkInstanceWithId)1 LinkTypeWithId (io.lumeer.api.model.templateParse.LinkTypeWithId)1 ResourceCommentWrapper (io.lumeer.api.model.templateParse.ResourceCommentWrapper)1 ViewWithId (io.lumeer.api.model.templateParse.ViewWithId)1 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1