mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-16 21:33:21 +00:00
Module Server : fin de l'implémentation du support des query; Suppression des queryLogin et queryConnect
This commit is contained in:
parent
a11b85eccd
commit
80ba949505
1
Documentation/.~lock.Interactions_serveur-clients.ods#
Normal file
1
Documentation/.~lock.Interactions_serveur-clients.ods#
Normal file
@ -0,0 +1 @@
|
||||
,Notmoo-PC/Guillaume,Notmoo-PC,26.07.2017 21:36,file:///C:/Users/Guillaume/AppData/Roaming/LibreOffice/4;
|
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
package com.pqt.core.entities.query;
|
||||
|
||||
public class ConnectQuery extends SimpleQuery {
|
||||
|
||||
private String serverAddress;
|
||||
|
||||
public ConnectQuery(String serverAddress) {
|
||||
super(QueryType.CONNECT);
|
||||
this.serverAddress = serverAddress;
|
||||
}
|
||||
|
||||
public String getServerAddress() {
|
||||
return serverAddress;
|
||||
}
|
||||
|
||||
public void setServerAddress(String serverAddress) {
|
||||
this.serverAddress = serverAddress;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.pqt.core.entities.query;
|
||||
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
|
||||
public class LogQuery extends SimpleQuery {
|
||||
|
||||
private Account account;
|
||||
|
||||
private boolean newDesiredState;
|
||||
|
||||
public LogQuery(Account account, boolean newDesiredState) {
|
||||
super(QueryType.LOG);
|
||||
this.account = account;
|
||||
this.newDesiredState = newDesiredState;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void setAccount(Account account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public boolean isNewDesiredState() {
|
||||
return newDesiredState;
|
||||
}
|
||||
|
||||
public void setNewDesiredState(boolean newDesiredState) {
|
||||
this.newDesiredState = newDesiredState;
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package com.pqt.server;
|
||||
|
||||
public class Server {
|
||||
public static void main(String[] args){
|
||||
|
||||
}
|
||||
}
|
@ -2,11 +2,14 @@ package com.pqt.server.controller;
|
||||
|
||||
import com.pqt.core.communication.GSonMessageToolFactory;
|
||||
import com.pqt.core.communication.IMessageToolFactory;
|
||||
import com.pqt.core.entities.members.Client;
|
||||
import com.pqt.core.entities.messages.Message;
|
||||
import com.pqt.core.entities.messages.MessageType;
|
||||
import com.pqt.core.entities.product.LightweightProduct;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.core.entities.sale.Sale;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.server.exception.ServerQueryException;
|
||||
import com.pqt.server.module.account.AccountService;
|
||||
import com.pqt.server.module.client.ClientService;
|
||||
@ -16,8 +19,10 @@ import com.pqt.server.module.statistics.StatisticsService;
|
||||
import com.pqt.server.module.stock.StockService;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
//TODO ajouter des messages d'erreur spécifiques pour les NullPointerException si le param du message vaut null
|
||||
public class SimpleMessageHandler implements IMessageHandler {
|
||||
|
||||
private final String header_ref_query = "Detail_refus";
|
||||
@ -55,7 +60,7 @@ public class SimpleMessageHandler implements IMessageHandler {
|
||||
long saleId = saleService.submitSale(messageToolFactory.getObjectParser(Sale.class).parse(message.getField("sale")));
|
||||
fields.put("saleId", Long.toString(saleId));
|
||||
return new Message(MessageType.ACK_SALE, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
}catch(ServerQueryException e){
|
||||
}catch(ServerQueryException | NullPointerException e){
|
||||
fields.put(header_ref_query, e.toString());
|
||||
return new Message(MessageType.REFUSED_QUERY, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
}
|
||||
@ -64,7 +69,7 @@ public class SimpleMessageHandler implements IMessageHandler {
|
||||
try{
|
||||
saleService.submitSaleRevert(messageToolFactory.getObjectParser(Long.class).parse(message.getField("saleId")));
|
||||
return new Message(MessageType.ACK_REVERT_SALE, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, null);
|
||||
}catch(ServerQueryException e){
|
||||
}catch(ServerQueryException | NullPointerException e){
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
fields.put(header_err_query, e.toString());
|
||||
return new Message(MessageType.ERROR_QUERY, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
@ -84,16 +89,15 @@ public class SimpleMessageHandler implements IMessageHandler {
|
||||
return new Message(MessageType.MSG_STAT, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
});
|
||||
queryHandlers.put(MessageType.QUERY_UPDATE, (message)->{
|
||||
//TODO Supporter les query update
|
||||
return null;
|
||||
});
|
||||
queryHandlers.put(MessageType.QUERY_CONNECT, (message)->{
|
||||
//TODO Supporter les query client
|
||||
return null;
|
||||
});
|
||||
queryHandlers.put(MessageType.QUERY_LOGIN, (message)->{
|
||||
//TODO Supporter les query account
|
||||
return null;
|
||||
try{
|
||||
List<ProductUpdate> updates = messageToolFactory.getListParser(ProductUpdate.class).parse(message.getField("updates"));
|
||||
stockService.applyUpdateList(updates);
|
||||
return new Message(MessageType.ACK_UPDATE, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, null);
|
||||
}catch (ServerQueryException | NullPointerException e){
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
fields.put(header_err_query, e.toString());
|
||||
return new Message(MessageType.ERROR_QUERY, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -102,10 +106,6 @@ public class SimpleMessageHandler implements IMessageHandler {
|
||||
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
|
||||
if(!checkClient(message)){
|
||||
fields.put(header_ref_query, "client non enregistré sur le serveur");
|
||||
return new Message(MessageType.REFUSED_QUERY, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
}
|
||||
if(!isAccountRegistered(message)){
|
||||
fields.put(header_ref_query, "Compte utilisateur inconnu");
|
||||
return new Message(MessageType.REFUSED_QUERY, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
|
||||
@ -127,11 +127,6 @@ public class SimpleMessageHandler implements IMessageHandler {
|
||||
Message execute(Message request);
|
||||
}
|
||||
|
||||
private boolean checkClient(Message message){
|
||||
//TODO faire ça
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isAccountRegistered(Message message){
|
||||
//TODO faire ça
|
||||
return false;
|
||||
|
@ -20,4 +20,7 @@ public class AccountService {
|
||||
return dao.setAccountConnected(acc, connected);
|
||||
}
|
||||
|
||||
public boolean isAccountRegistered(Account acc){
|
||||
return dao.isAccountRegistered(acc);
|
||||
}
|
||||
}
|
||||
|
@ -10,4 +10,5 @@ public interface IAccountDao {
|
||||
|
||||
boolean setAccountConnected(Account acc, boolean connected);
|
||||
|
||||
boolean isAccountRegistered(Account acc);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.pqt.server.module.stock;
|
||||
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.server.exception.ServerQueryException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,15 +24,29 @@ public class StockService {
|
||||
return dao.getProduct(id);
|
||||
}
|
||||
|
||||
public void addProduct(Product product) {
|
||||
public void applyUpdateList(List<ProductUpdate> updates) throws ServerQueryException{
|
||||
for(ProductUpdate upd : updates){
|
||||
if(upd.getOldVersion()==null){
|
||||
addProduct(upd.getNewVersion());
|
||||
}else if(upd.getNewVersion()==null){
|
||||
removeProduct(upd.getOldVersion().getId());
|
||||
}else if(upd.getOldVersion()!=null && upd.getNewVersion()!=null){
|
||||
modifyProduct(upd.getOldVersion().getId(), upd.getNewVersion());
|
||||
}else{
|
||||
//TODO écrit le throw d'une ServerQueryException
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addProduct(Product product) {
|
||||
dao.addProduct(product);
|
||||
}
|
||||
|
||||
public void removeProduct(long id) {
|
||||
private void removeProduct(long id) {
|
||||
dao.removeProduct(id);
|
||||
}
|
||||
|
||||
public void modifyProduct(long id, Product product) {
|
||||
private void modifyProduct(long id, Product product) {
|
||||
dao.modifyProduct(id, product);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user