Skip to content

Commit

Permalink
Remove unwanted unused methods
Browse files Browse the repository at this point in the history
These methods are not only unused but also either allow or are undesired
behaviour (loading groups by owner is bad because additional managers
now exist; gameboard stats are bad because there are too many gameboards
to load at once; etc).
  • Loading branch information
jsharkey13 committed Sep 27, 2024
1 parent 7d7e8ee commit e54999b
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 187 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,6 @@ public AssignmentDTO createAssignment(final AssignmentDTO newAssignment) throws
return newAssignment;
}

/**
* Assignments set by user.
*
* @param user
* - who set the assignments
* @return the assignments.
* @throws SegueDatabaseException
* - if we cannot complete a required database operation.
*/
public List<AssignmentDTO> getAllAssignmentsSetByUser(final RegisteredUserDTO user) throws SegueDatabaseException {
Objects.requireNonNull(user);
return this.assignmentPersistenceManager.getAssignmentsByOwner(user.getId());
}

/**
* Get all assignments for a list of groups.
*
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/uk/ac/cam/cl/dtg/isaac/api/managers/GameManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,24 +610,6 @@ public GameboardDTO saveNewGameboard(final GameboardDTO gameboardDTO, final Regi
return gameboardDTO;
}

/**
* @return useful for providing an indication of how many people are sharing boards.
* @throws SegueDatabaseException
* - if there is a problem updating the gameboard.
*/
public Map<String, Integer> getNumberOfConnectedUsersByGameboard()
throws SegueDatabaseException {
Map<String, List<String>> boardToUserIdMapping = this.gameboardPersistenceManager.getBoardToUserIdMapping();

Map<String, Integer> result = Maps.newTreeMap();

for (java.util.Map.Entry<String, List<String>> e : boardToUserIdMapping.entrySet()) {
result.put(e.getKey(), e.getValue().size());
}

return result;
}

/**
* Update the gameboards title.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,41 +503,6 @@ public void augmentGameboardItems(final List<GameboardDTO> gameboards) {
}
}

/**
* Utility method to get a map of gameboard id to list of users who are connected to it.
*
* @return map of gameboard id to list of users
* @throws SegueDatabaseException
* - if there is a database error.
*/
public Map<String, List<String>> getBoardToUserIdMapping() throws SegueDatabaseException {
Map<String, List<String>> results = Maps.newHashMap();

String query = "SELECT gameboard_id, user_id FROM user_gameboards;";
try (Connection conn = database.getDatabaseConnection();
PreparedStatement pst = conn.prepareStatement(query);
ResultSet sqlResults = pst.executeQuery();
) {
while (sqlResults.next()) {
String gameboardId = sqlResults.getString("gameboard_id");
String userId = sqlResults.getString("user_id");

if (results.containsKey(gameboardId)) {
results.get(gameboardId).add(userId);
} else {
List<String> users = Lists.newArrayList();
users.add(userId);
results.put(gameboardId, users);
}
}

} catch (SQLException e) {
throw new SegueDatabaseException("Unable to find assignment by id", e);
}

return results;
}

/**
* Utility function to create a gameboard item from a content DTO (Should be a question page).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ public interface IAssignmentPersistenceManager {
*/
List<AssignmentDTO> getAssignmentsByGroupId(Long groupId) throws SegueDatabaseException;

/**
* Retrieve all Assignments for a given group and set by a given user.
*
* @param assignmentOwnerId
* - to search for
* @param groupId
* - to search for
* @return assignments as a list
* @throws SegueDatabaseException
* - if there is an error when accessing the database.
*/
List<AssignmentDTO> getAssignmentsByOwnerIdAndGroupId(Long assignmentOwnerId, Long groupId)
throws SegueDatabaseException;

/**
* getAssignmentsByGameboardAndGroup.
*
Expand All @@ -71,17 +57,6 @@ List<AssignmentDTO> getAssignmentsByOwnerIdAndGroupId(Long assignmentOwnerId, Lo
List<AssignmentDTO> getAssignmentsByGameboardAndGroup(String gameboardId, Long groupId)
throws SegueDatabaseException;

/**
* getAssignmentsByOwner.
*
* @param ownerId
* - the user id who might have assigned the gameboard.
* @return list of assignments
* @throws SegueDatabaseException
* - if there is an error when accessing the database.
*/
List<AssignmentDTO> getAssignmentsByOwner(Long ownerId) throws SegueDatabaseException;

/**
* getAssignmentsByGroupList.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,33 +160,6 @@ public List<AssignmentDTO> getAssignmentsByGroupId(final Long groupId) throws Se
return this.getAssignmentsByGroupList(Collections.singletonList(groupId));
}

@Override
public List<AssignmentDTO> getAssignmentsByOwnerIdAndGroupId(final Long assignmentOwnerId, final Long groupId)
throws SegueDatabaseException {

String query = "SELECT * FROM assignments WHERE owner_user_id = ? AND group_id = ? ORDER BY creation_date";
try (Connection conn = database.getDatabaseConnection();
PreparedStatement pst = conn.prepareStatement(query);
) {
pst.setLong(1, assignmentOwnerId);
pst.setLong(2, groupId);

try (ResultSet results = pst.executeQuery()) {

List<AssignmentDTO> listOfResults = Lists.newArrayList();

while (results.next()) {
listOfResults.add(this.convertToAssignmentDTO(this.convertFromSQLToAssignmentDO(results)));
}

return listOfResults;
}
} catch (SQLException e) {
throw new SegueDatabaseException("Unable to find assignment by group", e);
}
}


@Override
public List<AssignmentDTO> getAssignmentsByGameboardAndGroup(final String gameboardId, final Long groupId)
throws SegueDatabaseException {
Expand All @@ -212,29 +185,6 @@ public List<AssignmentDTO> getAssignmentsByGameboardAndGroup(final String gamebo
}
}

@Override
public List<AssignmentDTO> getAssignmentsByOwner(final Long ownerId) throws SegueDatabaseException {
String query = "SELECT * FROM assignments WHERE owner_user_id = ? ORDER BY creation_date";
try (Connection conn = database.getDatabaseConnection();
PreparedStatement pst = conn.prepareStatement(query);
) {
pst.setLong(1, ownerId);

try (ResultSet results = pst.executeQuery()) {

List<AssignmentDTO> listOfResults = Lists.newArrayList();

while (results.next()) {
listOfResults.add(this.convertToAssignmentDTO(this.convertFromSQLToAssignmentDO(results)));
}

return listOfResults;
}
} catch (SQLException e) {
throw new SegueDatabaseException("Unable to find assignment by owner", e);
}
}

@Override
public List<AssignmentDTO> getAssignmentsByGroupList(Collection<Long> groupIds) throws SegueDatabaseException {
String query = "SELECT * FROM assignments WHERE group_id = ANY (?) ORDER BY creation_date";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,6 @@ private List<RegisteredUserDTO> orderUsersByName(final List<RegisteredUserDTO> u
.collect(Collectors.toList());
}

/**
* get all groups by owner.
*
* @param ownerUser
* - the owner of the groups to search for.
* @return List of groups or empty list.
* @throws SegueDatabaseException if there is a db error
*/
public List<UserGroupDTO> getGroupsByOwner(final RegisteredUserDTO ownerUser) throws SegueDatabaseException {
Objects.requireNonNull(ownerUser);
return convertGroupsToDTOs(groupDatabase.getGroupsByOwner(ownerUser.getId()));
}

/**
* getAllGroupsOwnedAndManagedByUser.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
*/
public interface IUserGroupPersistenceManager {

/**
* Get all groups by owner.
*
* @param ownerUserId
* the owner Id to find all groups for.
* @return List of groups belonging to owner user.
* @throws SegueDatabaseException
* - if we cannot contact the database.
*/
List<UserGroup> getGroupsByOwner(Long ownerUserId) throws SegueDatabaseException;

/**
* Get groups by owner.
*
Expand Down Expand Up @@ -236,16 +225,6 @@ public interface IUserGroupPersistenceManager {
*/
Map<Long, Set<Long>> getAdditionalManagerSetsByGroupIds(final Collection<Long> groupIds) throws SegueDatabaseException;

/**
* Get groups by additional manager id.
*
* @param additionalManagerId
* the additional Manager Id to find all groups for.
* @throws SegueDatabaseException
* - if we cannot contact the database.
*/
List<UserGroup> getGroupsByAdditionalManager(final Long additionalManagerId) throws SegueDatabaseException;

/**
* Get groups by additional manager id
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,6 @@ public void removeUserFromGroup(final Long userId, final Long groupId) throws Se
this.setUsersGroupMembershipStatus(userId, groupId, GroupMembershipStatus.DELETED);
}


@Override
public List<UserGroup> getGroupsByOwner(final Long ownerUserId) throws SegueDatabaseException {
return this.getGroupsByOwner(ownerUserId, null);
}

@Override
public List<UserGroup> getGroupsByOwner(final Long ownerUserId, @Nullable final Boolean archivedGroupsOnly) throws SegueDatabaseException {
String pstString = "SELECT * FROM groups WHERE owner_id = ?";
Expand All @@ -211,11 +205,6 @@ public List<UserGroup> getGroupsByOwner(final Long ownerUserId, @Nullable final

}

@Override
public List<UserGroup> getGroupsByAdditionalManager(final Long additionalManagerId) throws SegueDatabaseException {
return this.getGroupsByAdditionalManager(additionalManagerId, null);
}

@Override
public List<UserGroup> getGroupsByAdditionalManager(final Long additionalManagerId, @Nullable final Boolean archivedGroupsOnly) throws SegueDatabaseException {
String pstString = "SELECT * FROM groups WHERE id IN (SELECT group_id FROM group_additional_managers WHERE user_id = ?)";
Expand Down

0 comments on commit e54999b

Please sign in to comment.