@Test public void testFindById() throws Exception { SqlWorkspace workspace = (SqlWorkspace) sqlWorkspaceRepository.add("test workspace", testUser); SqlWorkspace workspace2 = (SqlWorkspace) sqlWorkspaceRepository.add("test workspace 2", testUser); SqlWorkspace testWorkspace = (SqlWorkspace) sqlWorkspaceRepository.findById(workspace.getWorkspaceId(), testUser); SqlWorkspace testWorkspace2 = (SqlWorkspace) sqlWorkspaceRepository.findById(workspace2.getWorkspaceId(), testUser); assertEquals(workspace.getWorkspaceCreator().getUserId(), testWorkspace.getWorkspaceCreator().getUserId()); assertEquals(workspace2.getWorkspaceCreator().getUserId(), testWorkspace2.getWorkspaceCreator().getUserId()); }
@Override public Workspace findById(String workspaceId, boolean includeHidden, User user) { Session session = sessionManager.getSession(); List workspaces = session.createCriteria(SqlWorkspace.class).add(Restrictions.eq("workspaceId", workspaceId)).list(); if (workspaces.size() == 0) { return null; } else if (workspaces.size() > 1) { throw new LumifyException("more than one workspace was returned"); } else { if (!hasReadPermissions(workspaceId, user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspaceId, user, workspaceId); } return (SqlWorkspace) workspaces.get(0); } }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public Workspace findById(String workspaceId, boolean includeHidden, User user) { Session session = sessionManager.getSession(); List workspaces = session.createCriteria(SqlWorkspace.class).add(Restrictions.eq("workspaceId", workspaceId)).list(); if (workspaces.size() == 0) { return null; } else if (workspaces.size() > 1) { throw new LumifyException("more than one workspace was returned"); } else { if (!hasReadPermissions(workspaceId, user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspaceId, user, workspaceId); } return (SqlWorkspace) workspaces.get(0); } } }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public Workspace findById(String workspaceId, boolean includeHidden, User user) { Session session = sessionManager.getSession(); List workspaces = session.createCriteria(SqlWorkspace.class).add(Restrictions.eq("workspaceId", workspaceId)).list(); if (workspaces.size() == 0) { return null; } else if (workspaces.size() > 1) { throw new LumifyException("more than one workspace was returned"); } else { if (!hasReadPermissions(workspaceId, user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspaceId, user, workspaceId); } return (SqlWorkspace) workspaces.get(0); } } @Inject  SqlWorkspaceRepository(final SqlUserRepository userRepository, final HibernateSessionManager sessionManager,
                                  final Graph graph); }
SqlWorkspaceRepository extends WorkspaceRepository { @Override public Workspace findById(String workspaceId, boolean includeHidden, User user) { Session session = sessionManager.getSession(); List workspaces = session.createCriteria(SqlWorkspace.class).add(Restrictions.eq("workspaceId", workspaceId)).list(); if (workspaces.size() == 0) { return null; } else if (workspaces.size() > 1) { throw new LumifyException("more than one workspace was returned"); } else { if (!hasReadPermissions(workspaceId, user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspaceId, user, workspaceId); } return (SqlWorkspace) workspaces.get(0); } } @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 Workspace findById(String workspaceId, boolean includeHidden, User user) { Session session = sessionManager.getSession(); List workspaces = session.createCriteria(SqlWorkspace.class).add(Restrictions.eq("workspaceId", workspaceId)).list(); if (workspaces.size() == 0) { return null; } else if (workspaces.size() > 1) { throw new LumifyException("more than one workspace was returned"); } else { if (!hasReadPermissions(workspaceId, user)) { throw new LumifyAccessDeniedException("user " + user.getUserId() + " does not have read access to workspace " + workspaceId, user, workspaceId); } return (SqlWorkspace) workspaces.get(0); } } @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);  }