Compare commits

...

10 Commits

Author SHA1 Message Date
Namu
772c5d8452 Fix: Remove sonar job as java version is not compatible with sonarqube (I hate java) 2025-10-06 11:56:48 +02:00
Namu
d38a67e4f6 Fix: try fix the sonar job with java
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 16s
2025-10-06 11:55:05 +02:00
Namu
501467b7d7 Fix: try fix the sonar job with java
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 1m3s
2025-10-06 11:44:15 +02:00
Namu
addedcab4d Refactor: Remove non-relevant modificators on transformContent
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 19s
2025-10-06 11:40:58 +02:00
Namu
5b1619f34e Refactor: Make NotificationDecoration an Interface
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 18s
2025-10-06 11:37:56 +02:00
Namu
b841c81599 Fix: add missing methods in decorator
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 19s
2025-10-06 11:31:32 +02:00
Namu
ca88a009a0 Feat: We can play the code multiple times with different message
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 19s
2025-10-06 11:06:01 +02:00
Namu
9e3b3cdf58 Refactor: move strategies in a package, other minor modification 2025-10-06 11:02:38 +02:00
Namu
48136c1b7d Doc: add documentation and change the message 2025-10-06 10:55:12 +02:00
Namu
160e5d2740 Refactor: Remove unused imports and add final where it should be 2025-10-06 10:46:01 +02:00
17 changed files with 48 additions and 71 deletions

View File

@@ -1,32 +0,0 @@
name: SonarQube Scan
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
sonarqube:
name: SonarQube Trigger
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download SonarQube Scanner
run: |
curl -sSLo sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-linux.zip
unzip sonar-scanner.zip
- name: Run SonarQube Scan
run: |
./sonar-scanner-*/bin/sonar-scanner \
-Dsonar.projectKey=tp1-iaavancee \
-Dsonar.sources=. \
-Dsonar.host.url=${{ secrets.SONARQUBE_HOST }} \
-Dsonar.login=${{ secrets.SONARQUBE_TOKEN }}

View File

@@ -2,7 +2,10 @@ import utils.*;
public class Application { public class Application {
public void run() { public void run() {
SendNotificationFacade.sendNotifications(); String[] messages = new String[]{"Bonjour", "You got mail", "Je préfère C#", "Fin !"};
for (final String message: messages) {
SendNotificationFacade.sendNotifications(message);
}
} }
} }

View File

@@ -3,27 +3,24 @@ package decorator;
import entities.Notification; import entities.Notification;
import notificationsDecorations.NotificationDecoration; import notificationsDecorations.NotificationDecoration;
/**
* Ces approches ne seront pas implémentées ici, car elles pourraient alourdir le code sans apport clair.
* Par exemple, un builder pourrait être utile pour construire des notifications (objets complexes),
* ou des stratégies pourraient être envisagées pour des fonctionnalités comme la datation.
* Les design patterns ne sont pas des solutions universelles : leur utilisation doit être justifiée par un besoin concret.
* Le code actuel ne respecte pas pleinement les principes SOLID, ce qui peut rendre sa maintenance plus difficile.
* L'ajout de patterns comme le Singleton (considéré comme un anti-pattern dans certains contextes,
* notamment parmi les principes STUPID) ne résoudrait pas nécessairement ces problèmes.
* Pour s'entraîner, les Katas sont une excellente alternative : ce sont des exercices simples et variés,
* idéaux pour explorer les design patterns de manière propre et progressive.
* Ils permettent aussi de comparer différentes solutions pour un même problème, ce qui est très formateur !
*/
public abstract class BaseDecorator { public abstract class BaseDecorator {
protected Notification notification; protected Notification notification;
protected NotificationDecoration decoration;
public BaseDecorator(Notification notification) { public BaseDecorator(Notification notification) {
this.notification = notification; this.notification = notification;
} }
public void transitionState() {
notification.transitionState();
}
public void setKoState() {
notification.setKoState();
}
public void addDecoration(NotificationDecoration decoration) {
notification.addDecoration(decoration);
}
public abstract String getContent(); public abstract String getContent();
} }

View File

@@ -1,6 +1,6 @@
package entities; package entities;
import utils.SendNotificationStrategy; import notificationSendingStrategies.SendNotificationStrategy;
public class MailNotification extends Notification { public class MailNotification extends Notification {
public MailNotification(String content, User user, SendNotificationStrategy strategy) { public MailNotification(String content, User user, SendNotificationStrategy strategy) {

View File

@@ -2,7 +2,7 @@ package entities;
import notificationsDecorations.NotificationDecoration; import notificationsDecorations.NotificationDecoration;
import utils.NotificationState; import utils.NotificationState;
import utils.SendNotificationStrategy; import notificationSendingStrategies.SendNotificationStrategy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -28,7 +28,7 @@ public abstract class Notification {
/** /**
* Adds a decoration to the notification. Please use a decorator for that * Adds a decoration to the notification. Please use a decorator for that
* @param decoration * @param decoration The decoration you want to add
*/ */
public void addDecoration(NotificationDecoration decoration) { public void addDecoration(NotificationDecoration decoration) {
decorations.add(decoration); decorations.add(decoration);
@@ -39,14 +39,17 @@ public abstract class Notification {
} }
/** /**
* Transition d'état spéciale pour indiquer que l'envoie de notification est en échec * Set KO state on notification
*/ */
public void setKoState() { public void setKoState() {
state = NotificationState.KO; state = NotificationState.KO;
} }
/** /**
* Fait la transition des états * Make state transition
* PENDING -> SENT
* SENT -> READ
*
*/ */
public void transitionState() { public void transitionState() {
switch (state) { switch (state) {
@@ -55,14 +58,18 @@ public abstract class Notification {
} }
} }
/**
* Generates the content of the notification dynamically with the decoration (if some)
* @return content of the notification
*/
public String getContent() { public String getContent() {
if (isSendable() && content != "") { if (isSendable() && !content.isEmpty()) {
transitionState(); transitionState();
for (final NotificationDecoration decoration : decorations) for (final NotificationDecoration decoration : decorations)
content = decoration.transformContent(content); content = decoration.transformContent(content);
return content; return strategy.makeContent(content) + "\n";
} }
setKoState(); setKoState();
return ""; return "";

View File

@@ -1,6 +1,6 @@
package entities; package entities;
import utils.SendNotificationStrategy; import notificationSendingStrategies.SendNotificationStrategy;
public class PushNotification extends Notification { public class PushNotification extends Notification {
public PushNotification(String content, User user, SendNotificationStrategy strategy) { public PushNotification(String content, User user, SendNotificationStrategy strategy) {

View File

@@ -1,6 +1,6 @@
package entities; package entities;
import utils.SendNotificationStrategy; import notificationSendingStrategies.SendNotificationStrategy;
public class SmsNotification extends Notification { public class SmsNotification extends Notification {

View File

@@ -1,7 +1,7 @@
package entities; package entities;
import utils.NotificationType; import utils.NotificationType;
import utils.SendNotificationStrategy; import notificationSendingStrategies.SendNotificationStrategy;
import java.util.List; import java.util.List;

View File

@@ -1,4 +1,4 @@
package utils; package notificationSendingStrategies;
public class DifferedSendNotificationStrategy implements SendNotificationStrategy { public class DifferedSendNotificationStrategy implements SendNotificationStrategy {
private int delay; private int delay;

View File

@@ -1,4 +1,4 @@
package utils; package notificationSendingStrategies;
public class FastSendNotificationStrategy implements SendNotificationStrategy { public class FastSendNotificationStrategy implements SendNotificationStrategy {
@Override @Override

View File

@@ -1,4 +1,4 @@
package utils; package notificationSendingStrategies;
public class SecureSendNotificationStrategy implements SendNotificationStrategy { public class SecureSendNotificationStrategy implements SendNotificationStrategy {
private int key; private int key;

View File

@@ -1,4 +1,4 @@
package utils; package notificationSendingStrategies;
public interface SendNotificationStrategy { public interface SendNotificationStrategy {
String makeContent(String message); String makeContent(String message);

View File

@@ -2,7 +2,7 @@ package notificationsDecorations;
import java.util.Date; import java.util.Date;
public class DateNotificationDecoration extends NotificationDecoration { public class DateNotificationDecoration implements NotificationDecoration {
private final Date date; private final Date date;
public DateNotificationDecoration(Date date) { public DateNotificationDecoration(Date date) {

View File

@@ -1,11 +1,9 @@
package notificationsDecorations; package notificationsDecorations;
import entities.Notification; public interface NotificationDecoration {
public abstract class NotificationDecoration {
/** /**
* Each decoration apply a transformation on the content of the Notifications * Each decoration apply a transformation on the content of the Notifications
* @return the content transformed * @return the content transformed
*/ */
public abstract String transformContent(String content); String transformContent(String content);
} }

View File

@@ -1,7 +1,7 @@
package notificationsDecorations; package notificationsDecorations;
public class WatermarkNotificationDecoration extends NotificationDecoration { public class WatermarkNotificationDecoration implements NotificationDecoration {
private String waterMark; private final String waterMark;
public WatermarkNotificationDecoration(String waterMark) { public WatermarkNotificationDecoration(String waterMark) {
this.waterMark = waterMark; this.waterMark = waterMark;

View File

@@ -1,6 +1,7 @@
package utils; package utils;
import entities.*; import entities.*;
import notificationSendingStrategies.SendNotificationStrategy;
public class NotificationFactory { public class NotificationFactory {
public Notification createNotification(NotificationType type, String content, User user, SendNotificationStrategy strategy) { public Notification createNotification(NotificationType type, String content, User user, SendNotificationStrategy strategy) {

View File

@@ -1,6 +1,9 @@
package utils; package utils;
import entities.User; import entities.User;
import notificationSendingStrategies.DifferedSendNotificationStrategy;
import notificationSendingStrategies.SecureSendNotificationStrategy;
import notificationSendingStrategies.SendNotificationStrategy;
import java.util.Arrays; import java.util.Arrays;
@@ -9,7 +12,7 @@ import static utils.NotificationType.Mail;
import static utils.NotificationType.Sms; import static utils.NotificationType.Sms;
public class SendNotificationFacade { public class SendNotificationFacade {
public static void sendNotifications() { public static void sendNotifications(String message) {
var notificationManager = NotificationManager.getInstance(); var notificationManager = NotificationManager.getInstance();
NotificationType[] typesThomas = {Sms, Mail, Push}; NotificationType[] typesThomas = {Sms, Mail, Push};
@@ -24,6 +27,6 @@ public class SendNotificationFacade {
notificationManager.getObservable().addSubscribers(thomas); notificationManager.getObservable().addSubscribers(thomas);
notificationManager.getObservable().addSubscribers(alexandre); notificationManager.getObservable().addSubscribers(alexandre);
notificationManager.getObservable().sendNotifications("C# > Java (mais Rust c'est le goat)"); notificationManager.getObservable().sendNotifications(message);
} }
} }