Skip to content

Commit

Permalink
Bugfix for Sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
r-monti committed Jan 19, 2024
1 parent ba76836 commit eca1f6c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/main/java/controller/ExerciseEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ private int evaluateCrossword(String[][] execution, String[][] solution) {
}
}
}
return (int)((right /total)*100);
if(total != 0){
return (int)((right /total)*100);
}

return 0;
}

private int evaluateAudio(int exerciseId, int userId, Date d) throws IOException, ExecutionException, InterruptedException {
Expand Down
31 changes: 28 additions & 3 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ public Exercise getExerciseByPk(int userID, int exerciseID, Date insertDate) {

public List<SlimmerExercise> retrieveNotDoneExercises(int patientId) {
List<SlimmerExercise> exercises = new ArrayList<>();
PreparedStatement stmt = null;
try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
String query = "SELECT e.ID_exercise, e.ID_user, eg.ExerciseName, e.InsertionDate, eg.ExerciseDescription, e.Feedback, eg.Difficulty, eg.Target, eg.Type, e.Evaluation FROM exercise e" +
" JOIN exercise_glossary eg ON e.ID_exercise = eg.ID_exercise" +
" WHERE e.CompletionDate IS NULL AND e.ID_user = ? ORDER BY InsertionDate";

PreparedStatement stmt = connection.prepareStatement(query);
stmt = connection.prepareStatement(query);
stmt.setInt(1, patientId);
ResultSet rs = stmt.executeQuery();

Expand All @@ -121,19 +122,27 @@ public List<SlimmerExercise> retrieveNotDoneExercises(int patientId) {
}
} catch(SQLException e) {
logger.error("Error query", e);
} finally {
try {
if (stmt != null) stmt.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
logger.error("Error finally", e);
}
}
return exercises;
}

public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
List<SlimmerExercise> exercises = new ArrayList<>();
PreparedStatement stmt = null;
try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
String query = "SELECT e.ID_exercise, e.ID_user, eg.ExerciseName, e.InsertionDate, eg.ExerciseDescription, e.Feedback, eg.Difficulty, eg.Target, eg.Type, e.Evaluation FROM exercise e" +
" JOIN exercise_glossary eg ON e.ID_exercise = eg.ID_exercise" +
" WHERE e.CompletionDate IS NOT NULL AND e.ID_user = ?";

PreparedStatement stmt = connection.prepareStatement(query);
stmt = connection.prepareStatement(query);
stmt.setInt(1, patientId);
ResultSet rs = stmt.executeQuery();

Expand All @@ -154,6 +163,13 @@ public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
}
} catch(SQLException e) {
logger.error("Error query", e);
} finally {
try {
if (stmt != null) stmt.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
logger.error("Error finally", e);
}
}
return exercises;
}
Expand Down Expand Up @@ -412,13 +428,14 @@ public boolean AddExerciseRecommendation(int idExercise, int idPatient) {

public List<SlimmerExercise> getExerciseToApprove(int therapistId){
List<SlimmerExercise> exercises = new ArrayList<>();
PreparedStatement stmt = null;
try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
String query = "SELECT e.ID_exercise, e.ID_user, eg.ExerciseName, e.InsertionDate, eg.ExerciseDescription, e.Feedback, eg.Difficulty, eg.Target, eg.Type, e.Evaluation " +
"FROM exercise e JOIN exercise_glossary eg ON e.ID_exercise = eg.ID_exercise JOIN user u ON e.ID_user = u.ID " +
"WHERE e.CompletionDate IS NULL AND u.ID_Therapist = ? AND e.Recommended = 0";

PreparedStatement stmt = connection.prepareStatement(query);
stmt = connection.prepareStatement(query);
stmt.setInt(1, therapistId);
ResultSet rs = stmt.executeQuery();

Expand All @@ -439,6 +456,14 @@ public List<SlimmerExercise> getExerciseToApprove(int therapistId){
}
} catch(SQLException e) {
logger.error("Error query", e);
} finally {
try {
if (stmt != null) stmt.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
// Handle the exception (e.g., log or throw)
logger.error("Error finally", e);
}
}
return exercises;
}
Expand Down

0 comments on commit eca1f6c

Please sign in to comment.