@Test public void testFindEntities() throws Exception { SqlWorkspace sqlWorkspace = (SqlWorkspace) sqlWorkspaceRepository.add("test", testUser); sqlWorkspaceRepository.updateEntityOnWorkspace(sqlWorkspace, "123", true, new GraphPosition(0, 0), testUser); sqlWorkspaceRepository.updateEntityOnWorkspace(sqlWorkspace, "345", true, new GraphPosition(1, 0), testUser); sqlWorkspaceRepository.updateEntityOnWorkspace(sqlWorkspace, "678", true, new GraphPosition(2, 0), testUser); sqlWorkspaceRepository.updateEntityOnWorkspace(sqlWorkspace, "910", true, new GraphPosition(3, 0), testUser); List<WorkspaceEntity> workspaceEntities = sqlWorkspaceRepository.findEntities(sqlWorkspace, testUser); assertTrue(workspaceEntities.size() == 4); }
@Override public List<WorkspaceEntity> findEntities(Workspace workspace, User user) { if (!hasReadPermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } Session session = sessionManager.getSession(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.get(SqlWorkspace.class, workspace.getWorkspaceId()); List<WorkspaceEntity> workspaceEntities; List<SqlWorkspaceVertex> sqlWorkspaceVertices = sqlWorkspace.getSqlWorkspaceVertices(); workspaceEntities = toList(new ConvertingIterable<SqlWorkspaceVertex, WorkspaceEntity>(sqlWorkspaceVertices) { @Override protected WorkspaceEntity convert(SqlWorkspaceVertex sqlWorkspaceVertex) { String vertexId = sqlWorkspaceVertex.getVertexId(); Integer graphPositionX = sqlWorkspaceVertex.getGraphPositionX(); Integer graphPositionY = sqlWorkspaceVertex.getGraphPositionY(); boolean visible = sqlWorkspaceVertex.isVisible(); return new WorkspaceEntity(vertexId, visible, graphPositionX, graphPositionY, null); } }); return workspaceEntities; }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public List<WorkspaceEntity> findEntities(Workspace workspace, User user) { if (!hasReadPermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } Session session = sessionManager.getSession(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.get(SqlWorkspace.class, workspace.getWorkspaceId()); List<WorkspaceEntity> workspaceEntities; List<SqlWorkspaceVertex> sqlWorkspaceVertices = sqlWorkspace.getSqlWorkspaceVertices(); workspaceEntities = toList(new ConvertingIterable<SqlWorkspaceVertex, WorkspaceEntity>(sqlWorkspaceVertices) { @Override protected WorkspaceEntity convert(SqlWorkspaceVertex sqlWorkspaceVertex) { String vertexId = sqlWorkspaceVertex.getVertexId(); Integer graphPositionX = sqlWorkspaceVertex.getGraphPositionX(); Integer graphPositionY = sqlWorkspaceVertex.getGraphPositionY(); boolean visible = sqlWorkspaceVertex.isVisible(); return new WorkspaceEntity(vertexId, visible, graphPositionX, graphPositionY, null); } }); return workspaceEntities; } }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public List<WorkspaceEntity> findEntities(Workspace workspace, User user) { if (!hasReadPermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } Session session = sessionManager.getSession(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.get(SqlWorkspace.class, workspace.getWorkspaceId()); List<WorkspaceEntity> workspaceEntities; List<SqlWorkspaceVertex> sqlWorkspaceVertices = sqlWorkspace.getSqlWorkspaceVertices(); workspaceEntities = toList(new ConvertingIterable<SqlWorkspaceVertex, WorkspaceEntity>(sqlWorkspaceVertices) { @Override protected WorkspaceEntity convert(SqlWorkspaceVertex sqlWorkspaceVertex) { String vertexId = sqlWorkspaceVertex.getVertexId(); Integer graphPositionX = sqlWorkspaceVertex.getGraphPositionX(); Integer graphPositionY = sqlWorkspaceVertex.getGraphPositionY(); boolean visible = sqlWorkspaceVertex.isVisible(); return new WorkspaceEntity(vertexId, visible, graphPositionX, graphPositionY, null); } }); return workspaceEntities; } @Inject  SqlWorkspaceRepository(final SqlUserRepository userRepository, final HibernateSessionManager sessionManager,
                                  final Graph graph); }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public List<WorkspaceEntity> findEntities(Workspace workspace, User user) { if (!hasReadPermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } Session session = sessionManager.getSession(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.get(SqlWorkspace.class, workspace.getWorkspaceId()); List<WorkspaceEntity> workspaceEntities; List<SqlWorkspaceVertex> sqlWorkspaceVertices = sqlWorkspace.getSqlWorkspaceVertices(); workspaceEntities = toList(new ConvertingIterable<SqlWorkspaceVertex, WorkspaceEntity>(sqlWorkspaceVertices) { @Override protected WorkspaceEntity convert(SqlWorkspaceVertex sqlWorkspaceVertex) { String vertexId = sqlWorkspaceVertex.getVertexId(); Integer graphPositionX = sqlWorkspaceVertex.getGraphPositionX(); Integer graphPositionY = sqlWorkspaceVertex.getGraphPositionY(); boolean visible = sqlWorkspaceVertex.isVisible(); return new WorkspaceEntity(vertexId, visible, graphPositionX, graphPositionY, null); } }); return workspaceEntities; } @Inject  SqlWorkspaceRepository(final SqlUserRepository userRepository, final HibernateSessionManager sessionManager,
                                  final Graph graph); @Override void delete(Workspace workspace, User user); @Override Workspace findById(String workspaceId, boolean includeHidden, User user); @Override Workspace add(String workspaceId, String title, User user); @Override Iterable<Workspace> findAllForUser(User user); @Override void setTitle(Workspace workspace, String title, User user); @Override List<WorkspaceUser> findUsersWithAccess(String workspaceId, User user); @Override List<WorkspaceEntity> findEntities(Workspace workspace, User user); @Override void softDeleteEntitiesFromWorkspace(Workspace workspace, List<String> entityIdsToDelete, User authUser); @Override void updateEntitiesOnWorkspace(Workspace workspace, Iterable<Update> updates, User user); @Override void deleteUserFromWorkspace(Workspace workspace, String userId, User user); @Override void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user); @Override ClientApiWorkspaceDiff getDiff(Workspace workspace, User user, Locale locale, String timeZone); @Override boolean hasCommentPermissions(String workspaceId, User user); @Override boolean hasWritePermissions(String workspaceId, User user); @Override boolean hasReadPermissions(String workspaceId, User user); }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public List<WorkspaceEntity> findEntities(Workspace workspace, User user) { if (!hasReadPermissions(workspace.getWorkspaceId(), user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspace.getWorkspaceId(), user, workspace.getWorkspaceId()); } Session session = sessionManager.getSession(); SqlWorkspace sqlWorkspace = (SqlWorkspace) session.get(SqlWorkspace.class, workspace.getWorkspaceId()); List<WorkspaceEntity> workspaceEntities; List<SqlWorkspaceVertex> sqlWorkspaceVertices = sqlWorkspace.getSqlWorkspaceVertices(); workspaceEntities = toList(new ConvertingIterable<SqlWorkspaceVertex, WorkspaceEntity>(sqlWorkspaceVertices) { @Override protected WorkspaceEntity convert(SqlWorkspaceVertex sqlWorkspaceVertex) { String vertexId = sqlWorkspaceVertex.getVertexId(); Integer graphPositionX = sqlWorkspaceVertex.getGraphPositionX(); Integer graphPositionY = sqlWorkspaceVertex.getGraphPositionY(); boolean visible = sqlWorkspaceVertex.isVisible(); return new WorkspaceEntity(vertexId, visible, graphPositionX, graphPositionY, null); } }); return workspaceEntities; } @Inject  SqlWorkspaceRepository(final SqlUserRepository userRepository, final HibernateSessionManager sessionManager,
                                  final Graph graph); @Override void delete(Workspace workspace, User user); @Override Workspace findById(String workspaceId, boolean includeHidden, User user); @Override Workspace add(String workspaceId, String title, User user); @Override Iterable<Workspace> findAllForUser(User user); @Override void setTitle(Workspace workspace, String title, User user); @Override List<WorkspaceUser> findUsersWithAccess(String workspaceId, User user); @Override List<WorkspaceEntity> findEntities(Workspace workspace, User user); @Override void softDeleteEntitiesFromWorkspace(Workspace workspace, List<String> entityIdsToDelete, User authUser); @Override void updateEntitiesOnWorkspace(Workspace workspace, Iterable<Update> updates, User user); @Override void deleteUserFromWorkspace(Workspace workspace, String userId, User user); @Override void updateUserOnWorkspace(Workspace workspace, String userId, WorkspaceAccess workspaceAccess, User user); @Override ClientApiWorkspaceDiff getDiff(Workspace workspace, User user, Locale locale, String timeZone); @Override boolean hasCommentPermissions(String workspaceId, User user); @Override boolean hasWritePermissions(String workspaceId, User user); @Override boolean hasReadPermissions(String workspaceId, User user);  }