first commit
Some checks failed
SonarQube Scan / SonarQube Trigger (push) Failing after 20s

This commit is contained in:
Namu
2025-09-23 13:14:23 +02:00
commit 3479d5dcee
22 changed files with 367 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
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 }}

29
.gitignore vendored Normal file
View File

@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

31
src/Application.java Normal file
View File

@@ -0,0 +1,31 @@
import entities.User;
import utils.*;
import java.util.Arrays;
import static utils.NotificationType.*;
public class Application {
private final NotificationManager notificationManager;
public Application(NotificationManager notificationManager) {
this.notificationManager = notificationManager;
}
public void run() {
NotificationType[] typesThomas = {Sms, Mail, Push};
NotificationType[] typesAlexandre = {Sms, Mail};
SendNotificationStrategy secured = new SecureSendNotificationStrategy(123);
DifferedSendNotificationStrategy differed = new DifferedSendNotificationStrategy(300);
var thomas = new User(0, "Thomas", Arrays.asList(typesThomas), secured);
var alexandre = new User(1, "Alexandre", Arrays.asList(typesAlexandre), differed);
notificationManager.getObservable().addSubscribers(thomas);
notificationManager.getObservable().addSubscribers(alexandre);
notificationManager.getObservable().sendNotifications("C# > Java (mais Rust c'est le goat)");
}
}

8
src/Main.java Normal file
View File

@@ -0,0 +1,8 @@
import utils.NotificationManager;
void main(String[] args) {
final var notificationManager = NotificationManager.getInstance();
final var app = new Application(notificationManager);
app.run();
}

View File

@@ -0,0 +1,16 @@
package entities;
import utils.SendNotificationStrategy;
public class MailNotification extends Notification {
public MailNotification(String content, User user, SendNotificationStrategy strategy) {
super(content, user, strategy);
}
@Override
public void send() {
if (isSendable())
strategy.send(user.id() + " Mail: " + user.name() + " " + content);
}
}

View File

@@ -0,0 +1,24 @@
package entities;
import utils.NotificationState;
import utils.SendNotificationStrategy;
public abstract class Notification {
protected String content;
protected User user;
protected NotificationState state;
protected SendNotificationStrategy strategy;
public Notification(String content, User user, SendNotificationStrategy strategy) {
this.content = content;
this.user = user;
this.state = NotificationState.PENDING;
this.strategy = strategy;
}
protected boolean isSendable() {
return this.state != NotificationState.SENT && this.state != NotificationState.READ;
}
public abstract void send();
}

View File

@@ -0,0 +1,15 @@
package entities;
import utils.SendNotificationStrategy;
public class PushNotification extends Notification {
public PushNotification(String content, User user, SendNotificationStrategy strategy) {
super(content, user, strategy);
}
@Override
public void send() {
if (isSendable())
strategy.send(user.id() + " Push: " + user.name() + " " + content);
}
}

View File

@@ -0,0 +1,16 @@
package entities;
import utils.SendNotificationStrategy;
public class SmsNotification extends Notification {
public SmsNotification(String content, User user, SendNotificationStrategy strategy) {
super(content, user, strategy);
}
@Override
public void send() {
if (isSendable())
strategy.send(user.id() + " Sms: " + user.name() + " " + content);
}
}

9
src/entities/User.java Normal file
View File

@@ -0,0 +1,9 @@
package entities;
import utils.NotificationType;
import utils.SendNotificationStrategy;
import java.util.List;
public record User(int id, String name, List<NotificationType> notificationsTypes, SendNotificationStrategy chosenNotificationStrategy) {
}

View File

@@ -0,0 +1,21 @@
package utils;
public class DifferedSendNotificationStrategy implements SendNotificationStrategy {
private int delay;
public DifferedSendNotificationStrategy(int delay) {
this.delay = delay;
}
@Override
public NotificationState send(String message) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
System.err.println("Cannot wait for differed strategy");
return NotificationState.KO;
}
System.out.println(message);
return NotificationState.SENT;
}
}

View File

@@ -0,0 +1,9 @@
package utils;
public class FastSendNotificationStrategy implements SendNotificationStrategy {
@Override
public NotificationState send(String message) {
System.out.println(message);
return NotificationState.SENT;
}
}

View File

@@ -0,0 +1,5 @@
package utils;
public class NotificationFacade {
}

View File

@@ -0,0 +1,13 @@
package utils;
import entities.*;
public class NotificationFactory {
public Notification createNotification(NotificationType type, String content, User user, SendNotificationStrategy strategy) {
return switch (type) {
case Sms -> new SmsNotification(content, user, strategy);
case Mail -> new MailNotification(content, user, strategy);
case Push -> new PushNotification(content, user, strategy);
};
}
}

View File

@@ -0,0 +1,22 @@
package utils;
public class NotificationManager {
private static NotificationManager INSTANCE;
private final NotificationObservable observable;
private NotificationManager() {
this.observable = new NotificationObservable();
}
public static NotificationManager getInstance() {
if (INSTANCE == null) {
INSTANCE = new NotificationManager();
}
return INSTANCE;
}
public NotificationObservable getObservable() {
return this.observable;
}
}

View File

@@ -0,0 +1,29 @@
package utils;
import entities.User;
import java.util.ArrayList;
import java.util.List;
public class NotificationObservable {
private final List<User> subscribers;
public NotificationObservable() {
this.subscribers = new ArrayList<>();
}
public void addSubscribers(User subscriber) {
this.subscribers.add(subscriber);
}
public void sendNotifications(String content) {
var factory = new NotificationFactory();
for (final var subscriber : this.subscribers) {
for (final var notificationType : subscriber.notificationsTypes()) {
var notification = factory.createNotification(notificationType, content, subscriber, subscriber.chosenNotificationStrategy());
notification.send();
}
}
}
}

View File

@@ -0,0 +1,8 @@
package utils;
public enum NotificationState {
PENDING,
SENT,
KO,
READ,
}

View File

@@ -0,0 +1,7 @@
package utils;
public enum NotificationType {
Sms,
Mail,
Push
}

View File

@@ -0,0 +1,17 @@
package utils;
public class PriorityDecorator {
private boolean isPriority;
public PriorityDecorator(boolean isPriority) {
this.isPriority = isPriority;
}
public boolean isPriority() {
return isPriority;
}
public void setPriority(boolean priority) {
isPriority = priority;
}
}

View File

@@ -0,0 +1,17 @@
package utils;
public class ReceiptDecorator {
boolean received;
public ReceiptDecorator() {
this.received = false;
}
public boolean isReceived() {
return received;
}
public void setReceived(boolean received) {
this.received = received;
}
}

View File

@@ -0,0 +1,15 @@
package utils;
public class SecureSendNotificationStrategy implements SendNotificationStrategy {
private int key;
public SecureSendNotificationStrategy(int key) {
this.key = key;
}
@Override
public NotificationState send(String message) {
System.out.println(key+"Flcjsdjknesdlkgjsilkqzfjazio"+message+"kjhsdiuhisehifsdhfiuhsuidhuifhjsid");
return NotificationState.SENT;
}
}

View File

@@ -0,0 +1,5 @@
package utils;
public interface SendNotificationStrategy {
NotificationState send(String message);
}

View File

@@ -0,0 +1,19 @@
package utils;
import java.util.Date;
public class TimeStampDecorator {
private Date time;
public TimeStampDecorator(Date time) {
this.time = time;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
}