mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-11-24 18:14:16 +00:00
[CLIENT] #17 : Ajout du support des modifs de compte (ajout/modif/suppr) dans le code métier
This commit is contained in:
parent
117ad57579
commit
cdeb16f15d
@ -2,6 +2,7 @@ package com.pqt.client.gui.modules.account_screen;
|
||||
|
||||
import com.pqt.client.gui.modules.account_screen.listeners.IAccountScreenModelListener;
|
||||
import com.pqt.client.module.account.AccountService;
|
||||
import com.pqt.client.module.account.listeners.AccountUpdateBuilder;
|
||||
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountLevel;
|
||||
@ -40,15 +41,15 @@ class AccountScreenModel {
|
||||
}
|
||||
|
||||
void modifyAccount(Account oldVal, Account newVal) {
|
||||
//accountService.submitAccountUpdate(oldVal, newVal);
|
||||
accountService.submitAccountUpdate(new AccountUpdateBuilder().modifyAccount(oldVal,newVal));
|
||||
}
|
||||
|
||||
void addAccount(Account newVal) {
|
||||
//accountService.submitAccountUpdate(null, newVal);
|
||||
accountService.submitAccountUpdate(new AccountUpdateBuilder().addAccount(newVal));
|
||||
}
|
||||
|
||||
void removeAccount(Account oldVal) {
|
||||
//accountService.submitAccountUpdate(oldVal, null);
|
||||
accountService.submitAccountUpdate(new AccountUpdateBuilder().removeAccount(oldVal));
|
||||
}
|
||||
|
||||
Collection<Account> getAccountCollection() {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.pqt.client.module.account;
|
||||
|
||||
import com.pqt.client.module.account.listeners.AccountListenerAdapter;
|
||||
import com.pqt.client.module.account.listeners.AccountUpdateBuilder;
|
||||
import com.pqt.client.module.query.QueryExecutor;
|
||||
import com.pqt.client.module.query.query_callback.ICollectionItemMessageCallback;
|
||||
import com.pqt.client.module.query.query_callback.INoItemMessageCallback;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.client.module.account.listeners.IAccountListener;
|
||||
|
||||
@ -12,7 +12,6 @@ import javax.swing.event.EventListenerList;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
//TODO écrire javadoc
|
||||
@ -155,4 +154,24 @@ public class AccountService {
|
||||
//Nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
public void submitAccountUpdate(AccountUpdateBuilder builder) {
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.pqt.client.module.account.listeners;
|
||||
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountUpdate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class AccountUpdateBuilder {
|
||||
|
||||
private Set<Account> toAdd, toRemove;
|
||||
private Map<Account, Account> toModify;
|
||||
|
||||
public AccountUpdateBuilder() {
|
||||
toAdd = new HashSet<>();
|
||||
toRemove = new HashSet<>();
|
||||
toModify = new HashMap<>();
|
||||
}
|
||||
|
||||
public AccountUpdateBuilder addAccount(Account account) {
|
||||
if(!toAdd.contains(account)){
|
||||
toAdd.add(account);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountUpdateBuilder removeAccount(Account account) {
|
||||
if(!toRemove.contains(account)){
|
||||
toRemove.add(account);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountUpdateBuilder modifyAccount(Account oldVersion, Account newVersion) {
|
||||
toModify.put(oldVersion, newVersion);
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<AccountUpdate> build() {
|
||||
List<AccountUpdate> reply = new ArrayList<>();
|
||||
for(Account account : toAdd){
|
||||
reply.add(new AccountUpdate(null, account));
|
||||
}
|
||||
for(Account account : toRemove){
|
||||
reply.add(new AccountUpdate(account, null));
|
||||
}
|
||||
for(Account account : toModify.keySet()){
|
||||
reply.add(new AccountUpdate(account, toModify.get(account)));
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
@ -13,8 +13,8 @@ import com.pqt.core.entities.messages.MessageType;
|
||||
import com.pqt.core.entities.product.Product;
|
||||
import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.core.entities.sale.LightweightSale;
|
||||
import com.pqt.core.entities.sale.Sale;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountUpdate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -47,6 +47,10 @@ public class QueryExecutor {
|
||||
sendMessage(messageFactory.newStockUpdateMessage(updates), callback, MessageType.ACK_STOCK_UPDATE);
|
||||
}
|
||||
|
||||
public void executeAccountUpdateQuery(List<AccountUpdate> updates, INoItemMessageCallback callback) {
|
||||
sendMessage(messageFactory.newAccountUpdateMessage(updates), callback, MessageType.ACK_ACCOUNT_UPDATE);
|
||||
}
|
||||
|
||||
public void executeConnectAccountQuery(Account account, boolean desiredState, INoItemMessageCallback callback){
|
||||
sendMessage(messageFactory.newConnectAccountMessage(account,desiredState), callback, MessageType.ACK_CONNECT_ACCOUNT);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import com.pqt.core.entities.product.ProductUpdate;
|
||||
import com.pqt.core.entities.sale.LightweightSale;
|
||||
import com.pqt.core.entities.sale.Sale;
|
||||
import com.pqt.core.entities.user_account.Account;
|
||||
import com.pqt.core.entities.user_account.AccountUpdate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -48,6 +49,12 @@ class QueryMessageFactory {
|
||||
return newSimpleMessage(MessageType.QUERY_STOCK_UPDATE, fields);
|
||||
}
|
||||
|
||||
Message newAccountUpdateMessage(List<AccountUpdate> updates) {
|
||||
Map<String, String> fields = new HashMap<>();
|
||||
fields.put("updates", messageToolFactory.getListFormatter(AccountUpdate.class).format(updates));
|
||||
return newSimpleMessage(MessageType.QUERY_ACCOUNT_UPDATE, fields);
|
||||
}
|
||||
|
||||
Message newAccountListMessage(){
|
||||
return newSimpleMessage(MessageType.QUERY_ACCOUNT_LIST);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user