From 0ceb0d72cda5467e884e85d16a60ab6c95170a70 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Thu, 10 Aug 2017 09:25:55 +0200 Subject: [PATCH] Module Core : ajout clss config serveur, update enum MessageType & AccountLevel --- .../core/entities/messages/MessageType.java | 21 +++++--- .../entities/server_config/ConfigFields.java | 12 +++++ .../entities/server_config/ServerConfig.java | 53 +++++++++++++++++++ .../entities/user_account/AccountLevel.java | 15 +++++- 4 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 Workspace/core/src/main/java/com/pqt/core/entities/server_config/ConfigFields.java create mode 100644 Workspace/core/src/main/java/com/pqt/core/entities/server_config/ServerConfig.java diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/messages/MessageType.java b/Workspace/core/src/main/java/com/pqt/core/entities/messages/MessageType.java index 0455c219..14d4a887 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/messages/MessageType.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/messages/MessageType.java @@ -4,24 +4,33 @@ public enum MessageType { ERROR_QUERY, REFUSED_QUERY, - QUERY_CONNECT, - ACK_CONNECT, - QUERY_SALE, ACK_SALE, QUERY_REVERT_SALE, ACK_REVERT_SALE, + QUERY_LAST_SALES_LIST, + MSG_LAST_SALES_LIST, + QUERY_STAT, MSG_STAT, QUERY_STOCK, MSG_STOCK, - QUERY_LOGIN, - ACK_LOGIN, + QUERY_ACCOUNT_LIST, + MSG_ACCOUNT_LIST, + + QUERY_CONNECT_ACCOUNT, + ACK_CONNECT_ACCOUNT, QUERY_UPDATE, - ACK_UPDATE + ACK_UPDATE, + + QUERY_PING, + ACK_PING, + + QUERY_CONFIG_LIST, + MSG_CONFIG_LIST } diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ConfigFields.java b/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ConfigFields.java new file mode 100644 index 00000000..a17de0cb --- /dev/null +++ b/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ConfigFields.java @@ -0,0 +1,12 @@ +package com.pqt.core.entities.server_config; + +public enum ConfigFields { + ALLOW_SALE_COMMIT, + ALLOW_SALE_REVERT, + + ALLOW_STOCK_VIEW, + ALLOW_STOCK_UPDATE, + + ALLOW_ACCOUNT_CONNECT, + ALLOW_ACCOUNT_MODIFICATION +} diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ServerConfig.java b/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ServerConfig.java new file mode 100644 index 00000000..1111a8df --- /dev/null +++ b/Workspace/core/src/main/java/com/pqt/core/entities/server_config/ServerConfig.java @@ -0,0 +1,53 @@ +package com.pqt.core.entities.server_config; + +import java.util.Arrays; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Map; + +public class ServerConfig { + + private Map fields; + + public ServerConfig() { + } + + public ServerConfig(Map fields) { + this.fields = fields; + } + + public ServerConfig(ConfigFields... configFields) { + fields = new HashMap<>(); + Arrays.stream(configFields).forEach(field->fields.put(field, true)); + + EnumSet.allOf(ConfigFields.class).stream().filter(field->!fields.containsKey(field)).forEach(field->fields.put(field, false)); + } + + public Map getFields() { + return fields; + } + + public void setFields(Map fields) { + this.fields = fields; + } + + public boolean isSupported(ConfigFields field){ + return fields.containsKey(field) && fields.get(field); + } + + public void switchFieldValue(ConfigFields field){ + if(fields.containsKey(field)){ + fields.replace(field, !fields.get(field)); + }else{ + fields.put(field, true); + } + } + + public boolean add(ConfigFields field, boolean value){ + if(!fields.containsKey(field)){ + fields.put(field, value); + return true; + } + return false; + } +} diff --git a/Workspace/core/src/main/java/com/pqt/core/entities/user_account/AccountLevel.java b/Workspace/core/src/main/java/com/pqt/core/entities/user_account/AccountLevel.java index dd068a72..8875aecd 100644 --- a/Workspace/core/src/main/java/com/pqt/core/entities/user_account/AccountLevel.java +++ b/Workspace/core/src/main/java/com/pqt/core/entities/user_account/AccountLevel.java @@ -1,8 +1,21 @@ package com.pqt.core.entities.user_account; +import java.util.Arrays; +import java.util.Comparator; +import java.util.stream.Collector; +import java.util.stream.Collectors; + /** * Created by Notmoo on 18/07/2017. */ public enum AccountLevel { - GUEST, STAFF, WAITER, MASTER + LOWEST, GUEST, STAFF, WAITER, MASTER; + + public static AccountLevel getLowest(){ + return Arrays.stream(AccountLevel.values()).sorted(Comparator.naturalOrder()).findFirst().orElse(null); + } + + public static AccountLevel getHighest(){ + return Arrays.stream(AccountLevel.values()).sorted(Comparator.reverseOrder()).findFirst().orElse(null); + } }