public List<PartData> retrieveOwnerEntries( String userId, String ownerEmail, ColumnField sort, boolean asc, int start, int limit) { List<Entry> entries; Account account = DAOFactory.getAccountDAO().getByEmail(userId); if (authorization.isAdmin(userId) || account.getEmail().equals(ownerEmail)) { entries = dao.retrieveOwnerEntries(ownerEmail, sort, asc, start, limit); } else { Set<Group> accountGroups = new HashSet<>(account.getGroups()); GroupController controller = new GroupController(); Group everybodyGroup = controller.createOrRetrievePublicGroup(); accountGroups.add(everybodyGroup); // retrieve entries for user that can be read by others entries = dao.retrieveUserEntries(account, ownerEmail, accountGroups, sort, asc, start, limit); } ArrayList<PartData> data = new ArrayList<>(); for (Entry entry : entries) { PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false); info.setViewCount(DAOFactory.getAuditDAO().getHistoryCount(entry)); data.add(info); } return data; }
public List<PartData> getEntriesSharedWithUser( String userId, ColumnField field, boolean asc, int start, int limit) { Account account = DAOFactory.getAccountDAO().getByEmail(userId); GroupController groupController = new GroupController(); Group publicGroup = groupController.createOrRetrievePublicGroup(); Set<Group> accountGroups = account.getGroups(); accountGroups.remove(publicGroup); List<Entry> entries = dao.sharedWithUserEntries(account, accountGroups, field, asc, start, limit); ArrayList<PartData> data = new ArrayList<>(); for (Entry entry : entries) { PartData info = ModelToInfoFactory.createTableViewData(userId, entry, false); info.setViewCount(DAOFactory.getAuditDAO().getHistoryCount(entry)); data.add(info); } return data; }