Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
<version>1.8.0</version>
</dependency>

<dependency>
<groupId>fr.recia.notifications</groupId>
<artifactId>event-rest-client-kafka</artifactId>
<version>1.0.14-java-11</version>
</dependency>



</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Copyright (C) 2023 GIP-RECIA, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.recia.mce.api.escomceapi.aop.notification;

import fr.recia.mce.api.escomceapi.aop.notification.configuration.NotificationAspectConfig;
import fr.recia.notifications.event_rest_client_kafka.HttpNotificationClient;
import fr.recia.notifications.model_kafka.model.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Locale;


@Component
@Aspect
@Slf4j
@Data

@nathancailbourdin nathancailbourdin Jul 8, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

est-ce que le @Data est nécéssaire car on expose pas de getter/setter ? à tester

public class NotificationAspect {
private final HttpNotificationClient notificationClient;
private final NotificationAspectConfig notificationAspectConfig;


private static final DateTimeFormatter DATE_TIME_FORMATTER =
DateTimeFormatter.ofPattern("dd/MM/yyyy 'à' HH:mm", Locale.FRENCH);

private String buildMessage(String template) {
return template + ZonedDateTime.now().format(DATE_TIME_FORMATTER);
}

@After("execution(* fr.recia.mce.api.escomceapi.ldap.repository.LdapUserDaoImp.updatePassword(..)) && args(uid, newHashedPassword)")
public void notifPasswordChange(String uid, String newHashedPassword) {
try {
final String title = notificationAspectConfig.getTitleMdp();
final String message = buildMessage(notificationAspectConfig.getMessageMdp());
final List<Channel> channel = List.of(Channel.WEB);
final String idLink = "";
final Priority priority = Priority.HIGH;
final TargetType targetType = TargetType.UID;
notificationClient.sendNotification(title, message, idLink, uid, channel, priority, targetType);
log.debug("Notification pour changement de mot de passe de {} a été mis à jour", uid);
} catch (Exception e) {
log.error("Erreur: la notification n'a pas pu être envoyée", e);
}
}

@After("execution(* fr.recia.mce.api.escomceapi.services.PersonneService.updateEmail(..)) && args(uid, ..)")
public void notifEmailChange(String uid) {
try {
final String title = notificationAspectConfig.getTitleMail();
final String message = buildMessage(notificationAspectConfig.getMessageMail());
final List<Channel> channel = List.of(Channel.WEB);
final String idLink = "";
final Priority priority = Priority.HIGH ;
final TargetType targetType = TargetType.UID;
notificationClient.sendNotification(title, message, idLink, uid, channel, priority, targetType);
log.info("Notification pour changement de mail {} a été envoyé", uid);
} catch (Exception e) {
log.error("Erreur: la notification n'a pas pu être envoyée", e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2023 GIP-RECIA, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package fr.recia.mce.api.escomceapi.aop.notification.configuration;

import fr.recia.notifications.event_rest_client_kafka.HttpNotificationClient;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faire avec un @ConfigurationProperties comme dans le reste du projet et enlever les @Value

@ConfigurationProperties(prefix = "notification-api")
public class NotificationAspectConfig {
private String url;
private String serviceName;
private String apiKey;
private String titleMdp;
private String messageMdp;
private String titleMail;
private String messageMail;

@Bean
public HttpNotificationClient notificationClient() {
return new HttpNotificationClient(url, serviceName, apiKey);
}
}
8 changes: 7 additions & 1 deletion src/main/resources/application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,11 @@ mail:
regexValideAddr: '[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z-]{2,4})'
regexsDomainesExclus: 'netocentre.fr touraine-eschool.fr chercan.fr colleges41.fr mon-e-college.loiret.fr e-college.indre.fr colleges-eureliens.fr'
verification:
base-url: http://localhost:8080/api/personne/mce/verify-email
frontend-url: http://localhost:5173/verification-email
expiry-hours: 1
expiry-hours: 24

notification-api:
url: "localhost:8079/event/emit"
service-name: "Service Name"
api-key: "MySecretApiKey"
Loading