mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-25 10:34:15 +00:00
[CLIENT] #6.A : Ajout de logs
This commit is contained in:
parent
d3b5e75896
commit
7f0dc93890
@ -4,9 +4,13 @@ import com.pqt.client.gui.FrameManager;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.stage.Stage;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class Main extends Application{
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args){
|
||||
launch(args);
|
||||
}
|
||||
@ -15,6 +19,7 @@ public class Main extends Application{
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
LOGGER.info("Instanciation de l'application JFX du client");
|
||||
fm = new FrameManager(primaryStage);
|
||||
|
||||
primaryStage.setOnCloseRequest(event-> Platform.exit());
|
||||
@ -24,6 +29,7 @@ public class Main extends Application{
|
||||
|
||||
@Override
|
||||
public void stop(){
|
||||
LOGGER.info("Fermeture de l'application JFX du client");
|
||||
if(fm!=null)
|
||||
fm.onCloseEvent();
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import com.pqt.client.module.query.query_callback.ICollectionItemMessageCallback
|
||||
import com.pqt.client.module.query.query_callback.INoItemMessageCallback;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
import java.util.ArrayList;
|
||||
@ -15,10 +17,10 @@ import java.util.Collection;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
//TODO écrire javadoc
|
||||
//TODO Issue #6 : add log lines
|
||||
//TODO Issue #17 : supporter la modif de comptes
|
||||
public class AccountService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(AccountService.class);
|
||||
|
||||
private QueryExecutor executor;
|
||||
private Account currentAccount;
|
||||
private boolean connected;
|
||||
@ -26,9 +28,11 @@ public class AccountService {
|
||||
private EventListenerList listenerList;
|
||||
|
||||
public AccountService(QueryExecutor executor){
|
||||
LOGGER.info("Initialisation du service 'Account'");
|
||||
this.executor = executor;
|
||||
listenerList = new EventListenerList();
|
||||
accounts = new ArrayList<>();
|
||||
LOGGER.info("Service 'Account' initialisé");
|
||||
}
|
||||
|
||||
public Account getCurrentAccount() {
|
||||
@ -65,30 +69,44 @@ public class AccountService {
|
||||
&& currentAccount.getUsername().equals(acc.getUsername())
|
||||
&& currentAccount.getPermissionLevel().equals(acc.getPermissionLevel())) {
|
||||
connected = state;
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusChangedEvent(connected));
|
||||
fireAccountStatusChangedEvent(connected);
|
||||
}else
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusNotChangedEvent(
|
||||
new IllegalStateException("Account service not in the right state")
|
||||
));
|
||||
fireAccountStatusNotChangedEvent(
|
||||
new IllegalStateException("Account service not in the right state")
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusNotChangedEvent(cause));
|
||||
fireAccountStatusNotChangedEvent(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusNotChangedEvent(cause));
|
||||
fireAccountStatusNotChangedEvent(cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void fireAccountStatusChangedEvent(boolean connected){
|
||||
LOGGER.info("Etat du compte courant changé à {}", connected);
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusChangedEvent(connected));
|
||||
}
|
||||
|
||||
private void fireAccountStatusNotChangedEvent(Throwable cause){
|
||||
LOGGER.info("Etat du compte courant inchangé : {}", cause);
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(l->l.onAccountStatusNotChangedEvent(cause));
|
||||
}
|
||||
|
||||
private void fireAccountListChangedEvent(){
|
||||
LOGGER.info("Liste des comptes utilisateurs changée");
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(IAccountListener::onAccountListChangedEvent);
|
||||
}
|
||||
|
||||
public void addListener(IAccountListener listener) {
|
||||
listenerList.add(IAccountListener.class, listener);
|
||||
}
|
||||
@ -116,13 +134,13 @@ public class AccountService {
|
||||
@Override
|
||||
public void ack(Collection<Account> obj) {
|
||||
accounts = obj;
|
||||
Arrays.stream(listenerList.getListeners(IAccountListener.class))
|
||||
.forEach(IAccountListener::onAccountListChangedEvent);
|
||||
fireAccountListChangedEvent();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Account'");
|
||||
if(connected) {
|
||||
try {
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
@ -130,13 +148,11 @@ public class AccountService {
|
||||
this.addListener(new AccountListenerAdapter() {
|
||||
@Override
|
||||
public void onAccountStatusChangedEvent(boolean status) {
|
||||
//TODO Issue #6 : ajouter des logs
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountStatusNotChangedEvent(Throwable cause) {
|
||||
//TODO Issue #6 : ajouter des logs
|
||||
cause.printStackTrace();
|
||||
latch.countDown();
|
||||
}
|
||||
@ -145,8 +161,7 @@ public class AccountService {
|
||||
}).start();
|
||||
latch.await(); // Wait for thread to call latch.countDown()
|
||||
} catch (InterruptedException e) {
|
||||
//TODO Issue #6 : ajouter des logs
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Interruption de la procédure de fermeture du service 'Account' : {}", e);
|
||||
}finally {
|
||||
listenerList = null;
|
||||
}
|
||||
@ -159,18 +174,15 @@ public class AccountService {
|
||||
executor.executeAccountUpdateQuery(builder.build(), new INoItemMessageCallback() {
|
||||
@Override
|
||||
public void ack() {
|
||||
//TODO Issue #6 : add log line
|
||||
refreshAccounts();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -3,21 +3,27 @@ package com.pqt.client.module.connection;
|
||||
import com.pqt.client.module.connection.listeners.IConnectionListener;
|
||||
import com.pqt.client.module.connection.senders.HttpTextSender;
|
||||
import com.pqt.client.module.connection.senders.ITextSender;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
public class ConnectionService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(ConnectionService.class);
|
||||
|
||||
private String serverUrl;
|
||||
private ExecutorService executor;
|
||||
private ITextSender textSender;
|
||||
|
||||
public ConnectionService(String serverUrl) {
|
||||
LOGGER.info("Initialisation du service 'Connection'");
|
||||
executor = new ThreadPoolExecutor(1, 1, 1000,
|
||||
TimeUnit.SECONDS, new LinkedBlockingQueue<>());
|
||||
this.serverUrl = serverUrl;
|
||||
this.textSender = new HttpTextSender();
|
||||
LOGGER.info("Service 'Connection' initialisé");
|
||||
}
|
||||
|
||||
public String getServerUrl() {
|
||||
@ -25,6 +31,7 @@ public class ConnectionService {
|
||||
}
|
||||
|
||||
public void setServerUrl(String url){
|
||||
LOGGER.info("L'url du serveur est : {}", url);
|
||||
this.serverUrl = url;
|
||||
}
|
||||
|
||||
@ -65,6 +72,7 @@ public class ConnectionService {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Connection'");
|
||||
stop(false);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.pqt.client.module.connection.senders;
|
||||
|
||||
import com.pqt.client.module.connection.listeners.IConnectionListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.ConnectException;
|
||||
@ -9,10 +11,13 @@ import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
public class HttpTextSender implements ITextSender{
|
||||
private static Logger LOGGER = LogManager.getLogger(HttpTextSender.class);
|
||||
|
||||
@Override
|
||||
public void send(String host, String text, IConnectionListener listener) {
|
||||
try {
|
||||
String trueURL = String.format("http://%s?%s", host, format(text));
|
||||
LOGGER.trace("Envoi de la requête HTTP : {}", trueURL);
|
||||
|
||||
HttpURLConnection con = (HttpURLConnection) new URL(trueURL).openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
@ -23,6 +28,7 @@ public class HttpTextSender implements ITextSender{
|
||||
|
||||
con.setDoOutput(true);
|
||||
con.connect();
|
||||
LOGGER.trace("Connexion du HTTPTextSender");
|
||||
listener.onConnectedEvent();
|
||||
|
||||
try(BufferedReader in = new BufferedReader(
|
||||
@ -32,28 +38,28 @@ public class HttpTextSender implements ITextSender{
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
content.append(inputLine);
|
||||
}
|
||||
|
||||
LOGGER.trace("réception de la réponse : {}", content.toString());
|
||||
listener.onMessageReceivedEvent(content.toString());
|
||||
}
|
||||
|
||||
con.disconnect();
|
||||
}catch (Exception e) {
|
||||
//TODO Issue #6 : ajouter un log ici
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Erreur durant l'envoi d'un message via HTTP vers le serveur : {}", e);
|
||||
listener.onConnexionError(e);
|
||||
}finally {
|
||||
LOGGER.trace("Déconnexion du HTTPTextSender");
|
||||
listener.onDisconnectedEvent();
|
||||
}
|
||||
}
|
||||
|
||||
// Méthode à modifier pour encoder le message suivant un algorithme spécifique
|
||||
private String format(String toFormat){
|
||||
String encodeTo = "UTF-8";
|
||||
try {
|
||||
String encodeTo = "UTF-8";
|
||||
return String.format("format=%s&message=%s", encodeTo, URLEncoder.encode(toFormat, encodeTo));
|
||||
}catch(UnsupportedEncodingException e){
|
||||
//TODO Issue #6 : ajouter un log ici
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Erreur d'encodage du texte à envoyer vers format {} : {}", encodeTo, e);
|
||||
LOGGER.error("Utilisation de la chaine non-formatée");
|
||||
}
|
||||
return String.format("message=%s", toFormat);
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ import com.pqt.client.module.query.query_callback.IMapItemMessageCallback;
|
||||
import com.pqt.client.module.query.query_callback.INoItemMessageCallback;
|
||||
import com.pqt.core.entities.server_config.ConfigFields;
|
||||
import com.pqt.core.entities.server_config.ServerConfig;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.swing.event.EventListenerList;
|
||||
import java.util.*;
|
||||
@ -18,16 +20,20 @@ import java.util.*;
|
||||
*/
|
||||
public class NetworkService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(NetworkService.class);
|
||||
|
||||
private final QueryExecutor queryExecutor;
|
||||
private final ConnectionService connectionService;
|
||||
private final EventListenerList listenerList;
|
||||
private final ServerConfigCache configCache;
|
||||
|
||||
public NetworkService(QueryExecutor queryExecutor, ConnectionService connectionService) {
|
||||
LOGGER.info("Initialisation du service 'Network'");
|
||||
this.queryExecutor = queryExecutor;
|
||||
this.connectionService = connectionService;
|
||||
listenerList = new EventListenerList();
|
||||
configCache = new ServerConfigCache();
|
||||
LOGGER.info("Service 'Network' initialisé");
|
||||
}
|
||||
|
||||
public void addListener(INetworkServiceListener l){
|
||||
@ -40,9 +46,11 @@ public class NetworkService {
|
||||
|
||||
public void sendPQTPing(String host, Integer port){
|
||||
checkData(host, port);
|
||||
LOGGER.trace("Envoi d'un ping");
|
||||
queryExecutor.executePingQuery(new INoItemMessageCallback() {
|
||||
@Override
|
||||
public void ack() {
|
||||
LOGGER.trace("Réponse au ping -> ACK");
|
||||
Arrays.stream(listenerList.getListeners(INetworkServiceListener.class))
|
||||
.forEach(l->l.onPQTPingSuccessEvent(host, port));
|
||||
sendConfigRequest(host, port);
|
||||
@ -50,12 +58,14 @@ public class NetworkService {
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
LOGGER.trace("Réponse au ping -> ERR");
|
||||
Arrays.stream(listenerList.getListeners(INetworkServiceListener.class))
|
||||
.forEach(l->l.onPQTPingFailureEvent(host, port, cause));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
LOGGER.trace("Réponse au ping -> REF");
|
||||
Arrays.stream(listenerList.getListeners(INetworkServiceListener.class))
|
||||
.forEach(l->l.onPQTPingFailureEvent(host, port, cause));
|
||||
}
|
||||
@ -79,20 +89,22 @@ public class NetworkService {
|
||||
}
|
||||
|
||||
private void sendConfigRequest(String host, Integer port){
|
||||
LOGGER.trace("Envoi d'une demande de configuration serveur");
|
||||
queryExecutor.executeConfigListQuery(new IMapItemMessageCallback<String, String>(){
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
//TODO Issue #6 : ajouter log erreur
|
||||
LOGGER.error("Erreur lors de la demande de configurations serveur : {}", cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
//TODO Issue #6 : ajouter log erreur
|
||||
LOGGER.error("Demande de configurations serveur refusée : {}", cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ack(Map<String, String> obj) {
|
||||
LOGGER.trace("Demande de configuration serveur acceptée");
|
||||
configCache.addServerConfig(host, port, convertToServerConfig(obj));
|
||||
Arrays.stream(listenerList.getListeners(INetworkServiceListener.class))
|
||||
.forEach(INetworkServiceListener::onNewServerConfigData);
|
||||
@ -141,6 +153,7 @@ public class NetworkService {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Network'");
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -15,20 +15,26 @@ import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.core.entities.sale.LightweightSale;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountUpdate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
public class QueryExecutor {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(QueryExecutor.class);
|
||||
|
||||
private IMessageToolFactory messageToolFactory;
|
||||
private ConnectionService connectionService;
|
||||
private QueryMessageFactory messageFactory;
|
||||
|
||||
public QueryExecutor(ConnectionService connectionService){
|
||||
LOGGER.info("Initialisation du QueryExecutor");
|
||||
messageToolFactory = new GSonMessageToolFactory();
|
||||
this.connectionService = connectionService;
|
||||
this.messageFactory = new QueryMessageFactory(messageToolFactory);
|
||||
LOGGER.info("QueryExecutor initialisé");
|
||||
}
|
||||
|
||||
public void setAccountService(AccountService accountService){
|
||||
@ -56,9 +62,11 @@ public class QueryExecutor {
|
||||
}
|
||||
|
||||
private void sendMessage(Message message, INoItemMessageCallback callback, MessageType responseType){
|
||||
LOGGER.debug("Envoi d'un message de type '{}' en mode no-item", message.getType().name());
|
||||
connectionService.sendText(messageToolFactory.getObjectFormatter(Message.class).format(message), new IConnectionListener() {
|
||||
@Override
|
||||
public void onMessageReceivedEvent(String msg) {
|
||||
LOGGER.trace("Réception d'une réponse : {}",msg);
|
||||
Message response = messageToolFactory.getObjectParser(Message.class).parse(msg);
|
||||
if(response.getType().equals(responseType))
|
||||
callback.ack();
|
||||
@ -68,21 +76,23 @@ public class QueryExecutor {
|
||||
|
||||
@Override
|
||||
public void onConnectedEvent() {
|
||||
|
||||
LOGGER.trace("Connexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnectedEvent() {
|
||||
|
||||
LOGGER.trace("Déconnexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeOutEvent() {
|
||||
LOGGER.trace("Timeout du server");
|
||||
callback.err(new MessageTimeoutException());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnexionError(Throwable e) {
|
||||
LOGGER.warn("Erreur durant l'envoi d'un message : {}", e);
|
||||
callback.err(e);
|
||||
}
|
||||
});
|
||||
@ -97,9 +107,11 @@ public class QueryExecutor {
|
||||
}
|
||||
|
||||
private <T> void sendMessage(Message message, ICollectionItemMessageCallback<T> callback, Class<T> clazz, MessageType responseType, String itemHeader){
|
||||
LOGGER.debug("Envoi d'un message de type '{}' en mode collection-item", message.getType().name());
|
||||
connectionService.sendText(messageToolFactory.getObjectFormatter(Message.class).format(message), new IConnectionListener() {
|
||||
@Override
|
||||
public void onMessageReceivedEvent(String msg) {
|
||||
LOGGER.trace("Réception d'une réponse : {}",msg);
|
||||
Message response = messageToolFactory.getObjectParser(Message.class).parse(msg);
|
||||
if(response.getType().equals(responseType)) {
|
||||
String item = response.getField(itemHeader);
|
||||
@ -114,21 +126,23 @@ public class QueryExecutor {
|
||||
|
||||
@Override
|
||||
public void onConnectedEvent() {
|
||||
|
||||
LOGGER.trace("Connexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnectedEvent() {
|
||||
|
||||
LOGGER.trace("Déconnexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeOutEvent() {
|
||||
LOGGER.trace("Timeout du server");
|
||||
callback.err(new MessageTimeoutException());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnexionError(Throwable e) {
|
||||
LOGGER.warn("Erreur durant l'envoi d'un message : {}", e);
|
||||
callback.err(e);
|
||||
}
|
||||
});
|
||||
@ -144,9 +158,11 @@ public class QueryExecutor {
|
||||
|
||||
//TODO à rendre générique pour toute Map<T, U> au lieu de Map<String, String>
|
||||
private void sendMessage(Message message, IMapItemMessageCallback<String, String> callback, MessageType responseType){
|
||||
LOGGER.debug("Envoi d'un message de type '{}' en mode map-item", message.getType().name());
|
||||
connectionService.sendText(messageToolFactory.getObjectFormatter(Message.class).format(message), new IConnectionListener() {
|
||||
@Override
|
||||
public void onMessageReceivedEvent(String msg) {
|
||||
LOGGER.trace("Réception d'une réponse : {}",msg);
|
||||
Message response = messageToolFactory.getObjectParser(Message.class).parse(msg);
|
||||
if(response.getType().equals(responseType)){
|
||||
callback.ack(response.getFields());
|
||||
@ -156,21 +172,23 @@ public class QueryExecutor {
|
||||
|
||||
@Override
|
||||
public void onConnectedEvent() {
|
||||
|
||||
LOGGER.trace("Connexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnectedEvent() {
|
||||
|
||||
LOGGER.trace("Déconnexion au serveur");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTimeOutEvent() {
|
||||
LOGGER.trace("Timeout du server");
|
||||
callback.err(new MessageTimeoutException());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnexionError(Throwable e) {
|
||||
LOGGER.warn("Erreur durant l'envoi d'un message : {}", e);
|
||||
callback.err(e);
|
||||
}
|
||||
});
|
||||
@ -204,6 +222,7 @@ public class QueryExecutor {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du QueryExecutor");
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -6,21 +6,26 @@ import com.pqt.client.module.sale.listeners.ISaleFirerer;
|
||||
import com.pqt.client.module.sale.listeners.ISaleListener;
|
||||
import com.pqt.client.module.sale.listeners.SimpleSaleFirerer;
|
||||
import com.pqt.core.entities.sale.SaleType;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
//TODO Issue #6 : add log lines
|
||||
public class SaleService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(SaleService.class);
|
||||
|
||||
private long saleId;
|
||||
private ISaleFirerer eventFirerer;
|
||||
private QueryExecutor executor;
|
||||
|
||||
public SaleService(QueryExecutor executor) {
|
||||
LOGGER.info("Initialisation du service 'Sale'");
|
||||
saleId = 0;
|
||||
eventFirerer = new SimpleSaleFirerer();
|
||||
this.executor = executor;
|
||||
LOGGER.info("Service 'Sale' initialisé");
|
||||
}
|
||||
|
||||
public SaleBuilder getNewSaleBuilder() {
|
||||
@ -34,19 +39,23 @@ public class SaleService {
|
||||
else
|
||||
saleId = 0;
|
||||
|
||||
LOGGER.debug("Soumission de la commande numéro {}", saleId);
|
||||
executor.executeSaleQuery(saleBuilder.buildLightweight(), new INoItemMessageCallback() {
|
||||
@Override
|
||||
public void ack() {
|
||||
LOGGER.debug("Commande {} acceptée", saleId);
|
||||
eventFirerer.fireSaleValidationSuccess(currentSaleId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
LOGGER.debug("Erreur durant la soumission de la commande {} : {}", saleId, cause.getMessage());
|
||||
eventFirerer.fireSaleValidationError(currentSaleId, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
LOGGER.debug("Commande {} refusée : {}", saleId, cause.getMessage());
|
||||
eventFirerer.fireSaleValidationRefused(currentSaleId, cause);
|
||||
}
|
||||
});
|
||||
@ -80,6 +89,7 @@ public class SaleService {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Sale'");
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -5,60 +5,65 @@ import com.pqt.client.module.query.query_callback.IMapItemMessageCallback;
|
||||
import com.pqt.client.module.stat.listeners.IStatFirerer;
|
||||
import com.pqt.client.module.stat.listeners.IStatListener;
|
||||
import com.pqt.client.module.stat.listeners.SimpleStatFirerer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
public class StatDao {
|
||||
|
||||
private Date lastRefreshTimestamp;
|
||||
private Map<String, String> stats;
|
||||
private IStatFirerer eventFirerer;
|
||||
private QueryExecutor executor;
|
||||
private static Logger LOGGER = LogManager.getLogger(StatDao.class);
|
||||
|
||||
public StatDao(QueryExecutor executor) {
|
||||
eventFirerer = new SimpleStatFirerer();
|
||||
stats = new HashMap<>();
|
||||
lastRefreshTimestamp = null;
|
||||
this.executor = executor;
|
||||
}
|
||||
private Date lastRefreshTimestamp;
|
||||
private Map<String, String> stats;
|
||||
private IStatFirerer eventFirerer;
|
||||
private QueryExecutor executor;
|
||||
|
||||
public synchronized Map<String, String> getStats() {
|
||||
return new HashMap<>(stats);
|
||||
}
|
||||
public StatDao(QueryExecutor executor) {
|
||||
eventFirerer = new SimpleStatFirerer();
|
||||
stats = new HashMap<>();
|
||||
lastRefreshTimestamp = null;
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
public void refreshStats() {
|
||||
executor.executeStatQuery(new IMapItemMessageCallback<String, String>() {
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
eventFirerer.fireGetStatError(cause);
|
||||
//TODO Issue #6 : add log line
|
||||
}
|
||||
public synchronized Map<String, String> getStats() {
|
||||
return new HashMap<>(stats);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
eventFirerer.fireGetStatRefused(cause);
|
||||
//TODO Issue #6 : add log line
|
||||
}
|
||||
public void refreshStats() {
|
||||
LOGGER.trace("Mise à jour des statistiques");
|
||||
executor.executeStatQuery(new IMapItemMessageCallback<String, String>() {
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
eventFirerer.fireGetStatError(cause);
|
||||
LOGGER.trace("Erreur de mise à jour des statistiques : {}", cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ack(Map<String, String> stats) {
|
||||
replaceStats(stats);
|
||||
eventFirerer.fireGetStatSuccess();
|
||||
//TODO Issue #6 : add log line
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
eventFirerer.fireGetStatRefused(cause);
|
||||
LOGGER.trace("Mise à jour des statistiques refusée : {}", cause);
|
||||
}
|
||||
|
||||
public Date getLastRefreshTimestamp(){
|
||||
return lastRefreshTimestamp;
|
||||
}
|
||||
@Override
|
||||
public void ack(Map<String, String> stats) {
|
||||
replaceStats(stats);
|
||||
eventFirerer.fireGetStatSuccess();
|
||||
LOGGER.trace("Mise à jour des statistiques finie");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void replaceStats(Map<String, String> stats) {
|
||||
this.stats = new HashMap<>(stats);
|
||||
this.lastRefreshTimestamp = new Date();
|
||||
eventFirerer.fireStatChangedEvent();
|
||||
}
|
||||
public Date getLastRefreshTimestamp(){
|
||||
return lastRefreshTimestamp;
|
||||
}
|
||||
|
||||
private synchronized void replaceStats(Map<String, String> stats) {
|
||||
this.stats = new HashMap<>(stats);
|
||||
this.lastRefreshTimestamp = new Date();
|
||||
eventFirerer.fireStatChangedEvent();
|
||||
}
|
||||
|
||||
public void removeListener(IStatListener listener) {
|
||||
eventFirerer.removeListener(listener);
|
||||
|
@ -2,17 +2,22 @@ package com.pqt.client.module.stat;
|
||||
|
||||
import com.pqt.client.module.query.QueryExecutor;
|
||||
import com.pqt.client.module.stat.listeners.IStatListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
//TODO Issue #6 : add log lines
|
||||
public class StatService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(StatService.class);
|
||||
|
||||
private StatDao dao;
|
||||
|
||||
public StatService(QueryExecutor executor) {
|
||||
LOGGER.info("Initialisation du service 'Stat'");
|
||||
dao = new StatDao(executor);
|
||||
LOGGER.info("Service 'Stat' initialisé");
|
||||
}
|
||||
|
||||
public Map<String,String> getStats() {
|
||||
@ -32,6 +37,7 @@ public class StatService {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Stat'");
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import com.pqt.client.module.stock.Listeners.IStockListener;
|
||||
import com.pqt.client.module.stock.Listeners.SimpleStockFirerer;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.product.ProductUpdate;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -17,6 +19,8 @@ import java.util.List;
|
||||
//TODO Issue #5 : écrire javadoc
|
||||
public class StockDao {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(StockDao.class);
|
||||
|
||||
private long updateId;
|
||||
private IStockFirerer eventFirerer;
|
||||
private Date lastRefreshTimestamp;
|
||||
@ -40,23 +44,24 @@ public class StockDao {
|
||||
}
|
||||
|
||||
public void refreshProductList() {
|
||||
LOGGER.trace("Demande de mise à jour du stock");
|
||||
executor.executeStockQuery(new ICollectionItemMessageCallback<Product>() {
|
||||
@Override
|
||||
public void ack(Collection<Product> obj) {
|
||||
replaceProductList(obj);
|
||||
eventFirerer.fireGetProductListSuccessEvent();
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Mise à jour du stock");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Demande de mise à jour du stock");
|
||||
eventFirerer.fireGetProductListErrorEvent(cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Demande de mise à jour du stock refusée : {}", cause);
|
||||
eventFirerer.fireGetProductListRefusedEvent(cause);
|
||||
}
|
||||
});
|
||||
@ -79,23 +84,24 @@ public class StockDao {
|
||||
updateId++;
|
||||
else
|
||||
updateId = 0;
|
||||
LOGGER.trace("Demande de modification du stock : modification numéro {}", updateId);
|
||||
executor.executeStockUpdateQuery(updates, new INoItemMessageCallback() {
|
||||
@Override
|
||||
public void ack() {
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Modification du stock numéro {} acceptée", updateId);
|
||||
refreshProductList();
|
||||
eventFirerer.fireProductListUpdateSuccessEvent(currentUpdateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void err(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Erreur durant la modification du stock numéro {} : {}", updateId, cause.getMessage());
|
||||
eventFirerer.fireProductListUpdateErrorEvent(currentUpdateId, cause);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ref(Throwable cause) {
|
||||
//TODO Issue #6 : add log line
|
||||
LOGGER.trace("Modification du stock numéro {} refusée : {}", updateId, cause.getMessage());
|
||||
eventFirerer.fireProductListUpdateRefusedEvent(currentUpdateId, cause);
|
||||
}
|
||||
});
|
||||
|
@ -3,17 +3,22 @@ package com.pqt.client.module.stock;
|
||||
import com.pqt.client.module.query.QueryExecutor;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.client.module.stock.Listeners.IStockListener;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
//TODO Issue #6 : Add log lines
|
||||
public class StockService {
|
||||
|
||||
private static Logger LOGGER = LogManager.getLogger(StockService.class);
|
||||
|
||||
private StockDao dao;
|
||||
|
||||
public StockService(QueryExecutor executor) {
|
||||
LOGGER.info("Initialisation du service 'Stock'");
|
||||
dao = new StockDao(executor);
|
||||
LOGGER.info("Service 'Stock' initialisé");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,6 +136,7 @@ public class StockService {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
LOGGER.info("Fermeture du service 'Stock'");
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user