Compare commits
10 Commits
53cda5688f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
772c5d8452 | ||
|
|
d38a67e4f6 | ||
|
|
501467b7d7 | ||
|
|
addedcab4d | ||
|
|
5b1619f34e | ||
|
|
b841c81599 | ||
|
|
ca88a009a0 | ||
|
|
9e3b3cdf58 | ||
|
|
48136c1b7d | ||
|
|
160e5d2740 |
@@ -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 }}
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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 "";
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package entities;
|
package entities;
|
||||||
|
|
||||||
import utils.SendNotificationStrategy;
|
import notificationSendingStrategies.SendNotificationStrategy;
|
||||||
|
|
||||||
public class SmsNotification extends Notification {
|
public class SmsNotification extends Notification {
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils;
|
package notificationSendingStrategies;
|
||||||
|
|
||||||
public class DifferedSendNotificationStrategy implements SendNotificationStrategy {
|
public class DifferedSendNotificationStrategy implements SendNotificationStrategy {
|
||||||
private int delay;
|
private int delay;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils;
|
package notificationSendingStrategies;
|
||||||
|
|
||||||
public class FastSendNotificationStrategy implements SendNotificationStrategy {
|
public class FastSendNotificationStrategy implements SendNotificationStrategy {
|
||||||
@Override
|
@Override
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils;
|
package notificationSendingStrategies;
|
||||||
|
|
||||||
public class SecureSendNotificationStrategy implements SendNotificationStrategy {
|
public class SecureSendNotificationStrategy implements SendNotificationStrategy {
|
||||||
private int key;
|
private int key;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package utils;
|
package notificationSendingStrategies;
|
||||||
|
|
||||||
public interface SendNotificationStrategy {
|
public interface SendNotificationStrategy {
|
||||||
String makeContent(String message);
|
String makeContent(String message);
|
||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user