Skip to content

Commit

Permalink
Merge branch 'development' into 66-insert-exercise-images
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/model/service/exercise/SpeechRecognition.java
  • Loading branch information
r-monti committed Jan 20, 2024
2 parents e0d08fc + c496063 commit fb85dec
Show file tree
Hide file tree
Showing 125 changed files with 4,181 additions and 2,657 deletions.
63 changes: 38 additions & 25 deletions .github/workflows/github-actions.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
name: GitHub Actions Test
on: [push]
name: SonarCloud
on:
push:
branches:
- development
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'adopt'
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots clean compile
- name: Test with Maven
run: mvn --batch-mode --update-snapshots test
- name: SonarCloud Scan
uses: SonarSource/[email protected]
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build:
name: Build and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=panuozzo77_TalkAId
#mvn sonar:sonar -Pcoverage -Dsonar.qualitygate.wait=false
46 changes: 42 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<junit.version>5.10.0</junit.version>
<sonar.organization>panuozzo77</sonar.organization>
<sonar.organization>pastore99</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>

Expand All @@ -38,6 +38,19 @@
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.11</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
</dependency>



<dependency>
<groupId>mysql</groupId>
Expand Down Expand Up @@ -140,6 +153,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 +269,8 @@
<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>
</configuration>
</plugin>
</plugins>
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/Main.java

This file was deleted.

31 changes: 24 additions & 7 deletions src/main/java/controller/AddRemovePatientCondition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller;

import model.service.condition.ConditionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
Expand All @@ -11,13 +13,20 @@

@WebServlet("/AddRemovePatientCondition")
public class AddRemovePatientCondition extends HttpServlet {

private static final Logger logger = LoggerFactory.getLogger(AddRemovePatientCondition.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
String referer = request.getHeader("Referer");
ConditionManager conditionService= new ConditionManager();
int idPatient = 0;
int idCondition = 0;
try{
idPatient = Integer.parseInt(request.getParameter("idPatient"));
idCondition = Integer.parseInt(request.getParameter("idCondition"));
}catch(NumberFormatException e){
logger.error("Error parsing idPatient and idCondition", e);
}

int idPatient = Integer.parseInt(request.getParameter("idPatient"));
int idCondition = Integer.parseInt(request.getParameter("idCondition"));

String operation= request.getParameter("operation");
if (operation.equals("Rimuovi")) //REMOVE
Expand All @@ -26,12 +35,20 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
}
if (operation.equals("Aggiungi")) //ADD
{
int severity= Integer.parseInt(request.getParameter("severity"));
int severity = 0;
try{
severity= Integer.parseInt(request.getParameter("severity"));
}catch(NumberFormatException e){
logger.error("Error parsing severity", e);
}

conditionService.AddConditionPatient(idCondition,idPatient,severity);
}

response.sendRedirect(referer);
try{
response.sendRedirect(referer);
} catch(IOException e){
logger.error("Error redirecting", e);
}

}

}
13 changes: 10 additions & 3 deletions src/main/java/controller/ChangePassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import model.service.login.Authenticator;
import model.service.user.UserData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand All @@ -11,14 +13,19 @@
import java.io.IOException;

@WebServlet("/ChangePassword")
public class ChangePassword extends HttpServlet
{
public class ChangePassword extends HttpServlet {
private static final Logger logger = LoggerFactory.getLogger(ChangePassword.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String password = request.getParameter("password");
String password_control = password.replaceAll("\\s", "");
int id = (int) request.getSession().getAttribute("id");
new Authenticator().resetPassword( new UserData().getUser(id).getEmail(), password_control);
response.getWriter().write("true");
try {
response.getWriter().write("true");
}catch(IOException e){
logger.error("Error writing response", e);
}
}
}
16 changes: 12 additions & 4 deletions src/main/java/controller/ChangeUserInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller;

import model.service.user.UserRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand All @@ -11,21 +13,27 @@
import java.io.IOException;

@WebServlet("/changeDate")
public class ChangeUserInfo extends HttpServlet
{
public class ChangeUserInfo extends HttpServlet {
private static final Logger logger = LoggerFactory.getLogger(ChangeUserInfo.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
int userId = (int) session.getAttribute("id");
UserRegistry userRegistry = new UserRegistry();
String risultato = "";
String risultato;
if (updatePersonalInfo(request, userId, userRegistry)) {
risultato = "Dati personali aggiornati con successo;";
} else {
risultato = "Dati personali non aggiornati, email gia' utilizzata";
}
response.sendRedirect("JSP/userInfoChange.jsp?risultato=" + risultato);
try {
response.sendRedirect("JSP/userArea.jsp?errorMessage=" + risultato);
}catch(IOException e){
logger.error("Error redirecting", e);
}
}


private boolean updatePersonalInfo(HttpServletRequest request, int userId, UserRegistry userRegistry) {
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/controller/CheckCurrentPassword.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import model.service.login.Authenticator;
import model.service.user.UserData;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand All @@ -11,14 +13,19 @@
import java.io.IOException;

@WebServlet("/ControllPassword")
public class CheckCurrentPassword extends HttpServlet
{
public class CheckCurrentPassword extends HttpServlet {
private static final Logger logger = LoggerFactory.getLogger(CheckCurrentPassword.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String password = request.getParameter("password");
Authenticator authenticator = new Authenticator();
int id = (int) request.getSession().getAttribute("id");
String email = new UserData().getUser(id).getEmail();
String password = request.getParameter("password");
Authenticator authenticator = new Authenticator();
int id = (int) request.getSession().getAttribute("id");
String email = new UserData().getUser(id).getEmail();
try {
response.getWriter().write(String.valueOf(authenticator.authenticate(email, password) > 0)); //true se deve abilitare, false altrimenti
}catch(IOException e){
logger.error("Error writing response", e);
}
}
}
14 changes: 9 additions & 5 deletions src/main/java/controller/CountMessages.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package controller;

import model.service.message.MessageManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
Expand All @@ -11,17 +13,19 @@

@WebServlet("/CountMessages")
public class CountMessages extends HttpServlet {

private static final Logger logger = LoggerFactory.getLogger(CountMessages.class);
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
int recipientId = (int) session.getAttribute("id");
MessageManager messageManager = new MessageManager();
int receivedMessageCount = messageManager.countReceivedMessages(recipientId);

response.setContentType("text/plain"); // Output is a plain text integer
response.getWriter().println(receivedMessageCount);
try{
response.getWriter().println(receivedMessageCount);
}catch(IOException e){
logger.error("Error writing response", e);
}
}

}
Loading

0 comments on commit fb85dec

Please sign in to comment.