Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into 71-implementat…
Browse files Browse the repository at this point in the history
…ion-therapist-approves-ia-raccomandations

# Conflicts:
#	src/main/java/model/DAO/DAOExercise.java
#	src/main/java/model/entity/SlimmerExercise.java
  • Loading branch information
ms@Nicro authored and ms@Nicro committed Jan 17, 2024
2 parents 09f5535 + 459e3ca commit ebdad32
Show file tree
Hide file tree
Showing 34 changed files with 649 additions and 736 deletions.
32 changes: 29 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@
<version>2.0.0</version>
</dependency>

<!-- PowerMock -->
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4-rule</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-classloading-xstream</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -230,9 +256,9 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.12.1</version>
<configuration>
<source>21</source>
<target>21</target>
<compilerArgs>--enable-preview</compilerArgs>
<source>17</source>
<target>17</target>
<!-- <compilerArgs>-enable-preview</compilerArgs> -->
</configuration>
</plugin>
</plugins>
Expand Down
50 changes: 44 additions & 6 deletions src/main/java/model/DAO/DAOExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public List<SlimmerExercise> retrieveNotDoneExercises(int patientId) {
List<SlimmerExercise> exercises = new ArrayList<>();
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 FROM exercise e" +
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 = ?";
" WHERE e.CompletionDate IS NULL AND e.ID_user = ? ORDER BY InsertionDate ASC";

PreparedStatement stmt = connection.prepareStatement(query);
stmt.setInt(1, patientId);
Expand All @@ -110,7 +110,8 @@ public List<SlimmerExercise> retrieveNotDoneExercises(int patientId) {
rs.getDate("InsertionDate"),
rs.getInt("Difficulty"),
rs.getString("Target"),
rs.getString("Type")
rs.getString("Type"),
rs.getInt("Evaluation")
);
exercises.add(exercise);
}
Expand All @@ -124,9 +125,9 @@ public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
List<SlimmerExercise> exercises = new ArrayList<>();
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 FROM exercise e" +
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 = ?";
" WHERE e.CompletionDate IS NOT NULL AND e.ID_user = ?";

PreparedStatement stmt = connection.prepareStatement(query);
stmt.setInt(1, patientId);
Expand All @@ -142,7 +143,8 @@ public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
rs.getDate("InsertionDate"),
rs.getInt("Difficulty"),
rs.getString("Target"),
rs.getString("Type")
rs.getString("Type"),
rs.getInt("Evaluation")
);
exercises.add(exercise);
}
Expand Down Expand Up @@ -185,6 +187,42 @@ public List<Exercise> retrieveAllPatientExerciseDone(int userID) {
return exercises;
}

public List<Exercise> retrievePatientExerciseDone(int patientID) {
String query = "SELECT *\n" +
"FROM exercise\n" +
"WHERE ID_user = ? AND Evaluation IS NOT NULL\n" +
"ORDER BY InsertionDate;";
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
List<Exercise> exercises = new ArrayList<>();

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(query);
preparedStatement.setInt(1, patientID);

resultSet = preparedStatement.executeQuery();

while (resultSet.next()) {
Exercise exercise = extractExerciseFromResultSet(resultSet);
exercises.add(exercise);
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (resultSet != null) resultSet.close();
if (preparedStatement != null) preparedStatement.close();
DAOConnection.releaseConnection(connection);
} catch (SQLException e) {
e.printStackTrace();
}
}

return exercises;
}

public Blob getExerciseExecution(int userID, int exerciseID, Date insertDate) {
String query = "SELECT Execution FROM exercise WHERE ID_user = ? AND ID_exercise = ? AND InsertionDate = ?";
PreparedStatement preparedStatement = null;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/model/DAO/DAOLicense.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public String generateLicense(){
PreparedStatement preparedStatement = null;

try {
connection = connection.isClosed() ? DAOConnection.getConnection() : connection;
connection = connection == null || connection.isClosed() ? DAOConnection.getConnection() : connection;
preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, l.getSequence());
preparedStatement.setInt(2, 0);
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/model/entity/SlimmerExercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

public class SlimmerExercise {
private int id;

private String name;

private Date insertionDate;

private int evaluation;

private String description;

private int feedback;
Expand All @@ -19,7 +23,8 @@ public class SlimmerExercise {

private int userId;

public SlimmerExercise(int id, int userId, String name, String description, int feedback, Date insertionDate, int difficulty, String target, String type) {

public SlimmerExercise(int id, int userId, String name, String description, int feedback, Date insertionDate, int difficulty, String target, String type, int evaluation) {
this.id = id;
this.userId = userId;
this.name = name;
Expand All @@ -29,6 +34,7 @@ public SlimmerExercise(int id, int userId, String name, String description, int
this.difficulty = difficulty;
this.target = target;
this.type = type;
this.evaluation = evaluation;
}

public int getId() {
Expand Down Expand Up @@ -103,3 +109,12 @@ public void setUserId(int userId) {
this.userId = userId;
}
}

public int getEvaluation() {
return evaluation;
}

public void setEvaluation(int vote) {
this.evaluation = evaluation;
}
}
4 changes: 4 additions & 0 deletions src/main/java/model/service/exercise/ExerciseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public List<Exercise> retrieveAllPatientExerciseDone(int userID){
return daoE.retrieveAllPatientExerciseDone(userID);
}

public List<Exercise> retrievePatientExerciseDone(int patientID) {
return daoE.retrievePatientExerciseDone(patientID);
}

public List<SlimmerExercise> retrieveDoneExercises(int patientId) {
return daoE.retrieveDoneExercises(patientId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public interface ExerciseManagerInterface {
*/
public List<SlimmerExercise> retrieveDoneExercises(int patientId);

/**
* Recupera una lista di esercizi che un paziente ha già fatto.
*
* @param patientID L'ID del paziente.
* @return Una lista di oggetti Exercise che rappresentano gli esercizi fatti dal paziente.
*/
public List<Exercise> retrievePatientExerciseDone(int patientID);
/**
* Recupera una lista di esercizi che un paziente non ha ancora fatto.
*
Expand Down
35 changes: 21 additions & 14 deletions src/main/java/model/service/exercise/SpeechRecognition.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,15 @@ else if (speechRecognitionResult.getReason() == ResultReason.NoMatch){
}

public String generateFile(InputStream inputAudio) throws IOException {
//Crea temporaneamente il file creato dal DB
File tempFile = createTempFile(inputAudio);
String outputPath = getOutputPath(tempFile);
deleteExistingFile(outputPath);
executeCommand(tempFile, outputPath);

return outputPath;
}

File createTempFile(InputStream inputAudio) throws IOException {
File tempFile = File.createTempFile("tempAudio", ".opus");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
byte[] buffer = new byte[1024];
Expand All @@ -68,21 +76,25 @@ public String generateFile(InputStream inputAudio) throws IOException {
fos.write(buffer, 0, bytesRead);
}
}
//Ottieni il path dell'output basandoti sul file creato
return tempFile;
}

String getOutputPath(File tempFile) {
Path outputPath = Paths.get(tempFile.getPath()).getParent().resolve("outputJava.wav");
String path = outputPath.toString();
return outputPath.toString();
}

//Controlla che non esista già un file
void deleteExistingFile(String path) throws IOException {
try {
// Use the delete method from Files class to delete the file
Files.delete(Paths.get(path));
} catch (FileNotFoundException e){
System.err.println("File not found");
} catch (IOException e) {
System.err.println("Error deleting the file: " + e.getMessage());
}
}


int executeCommand(File tempFile, String path) throws IOException {
List<String> command = Arrays.asList(
"ffmpeg",
"-i", tempFile.getPath(),
Expand All @@ -92,24 +104,19 @@ public String generateFile(InputStream inputAudio) throws IOException {
path
);

int exitCode = -1;
try {
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = processBuilder.start();

BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
int exitCode = process.waitFor();
exitCode = process.waitFor();
if(exitCode != 0){
System.err.println("\nExited with error code : " + exitCode);
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}

return path;
return exitCode;
}

private Properties loadProps() {
Expand Down
29 changes: 19 additions & 10 deletions src/main/java/model/service/registration/Registration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model.service.registration;

import model.entity.License;
import model.entity.User;
import model.service.email.EmailManager;
import model.service.encryption.Encryption;
import model.service.license.LicenseActivation;
Expand All @@ -9,7 +10,20 @@

public class Registration implements RegistrationInterface {

LicenseActivation la;
UserData ud;
UserRegistry ur;
public Registration () {
la = new LicenseActivation();
ud = new UserData();
ur = new UserRegistry();
}

Registration (LicenseActivation la, UserData ud, UserRegistry ur) {
this.la = la;
this.ud = ud;
this.ur = ur;
}
@Override
public int registerNewUser(String licenseCode, String email, String password, String name, String surname) {
License license = validateLicense(licenseCode);
Expand All @@ -21,7 +35,6 @@ public int registerNewUser(String licenseCode, String email, String password, St
int theNewId = createNewUser(email, hashed, license);
if (theNewId >= 0) {
if (createUserPersonalInformation(theNewId, name, surname)) {
LicenseActivation la = new LicenseActivation();
la.activate(license, theNewId);
return 0; // no error
}
Expand All @@ -36,42 +49,38 @@ public int registerNewUser(String licenseCode, String email, String password, St
/**
* Validates license
*/
private License validateLicense(String licenseCode){
LicenseActivation la = new LicenseActivation();
License validateLicense(String licenseCode){
License license = la.getLicense(licenseCode);
return la.isActivable(license) ? license : null;
}

/**
* Checks if an email already exists or not.
*/
private boolean isEmailExists(String email){
UserData ud = new UserData();
boolean isEmailExists(String email){
return ud.checkIfEmailExists(email);
}

/**
* Encrypts user password
*/
private String encryptPassword(String password){
String encryptPassword(String password){
Encryption encryption = new Encryption();
return encryption.encryptPassword(password);
}

/**
* Creates a new user.
*/
private int createNewUser(String email, String hashed, License license){
UserData ud = new UserData();
int createNewUser(String email, String hashed, License license){
LicenseActivation la = new LicenseActivation();
return ud.createUser(email, hashed, la.isForTherapist(license));
}

/**
* Creates a user personal info.
*/
private boolean createUserPersonalInformation(int theNewId, String name, String surname){
UserRegistry ur = new UserRegistry();
boolean createUserPersonalInformation(int theNewId, String name, String surname){
return ur.firstAccess(theNewId, name, surname);
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/webapp/CSS/homepagepatient.css
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,23 @@
stroke-dashoffset: 80; /* 50% would be 220 (half the initial value specified above) */
}
}

.imagediv {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
flex-direction: row;
}

.tdown {
width: 5em;
padding-right: 3em;
margin: 0;
}
.tup {
width: 5em;
padding-left: 3em;
margin: 0;
}

Loading

0 comments on commit ebdad32

Please sign in to comment.