diff --git a/app/src/main/java/lightcontainer/App.java b/app/src/main/java/lightcontainer/App.java index 837b242..fba84bc 100644 --- a/app/src/main/java/lightcontainer/App.java +++ b/app/src/main/java/lightcontainer/App.java @@ -3,7 +3,6 @@ */ package lightcontainer; -import lightcontainer.domains.client.Context; import lightcontainer.domains.server.MulticastServerListener; import lightcontainer.domains.server.UnicastServerListener; import lightcontainer.interfaces.ProtocolRepository; @@ -13,11 +12,8 @@ import lightcontainer.repository.ClientHandlerRepository; import lightcontainer.repository.FileFrontEnd; import lightcontainer.repository.ProtocolRepositoryImpl; import lightcontainer.repository.StoreProcessorRepository; -import lightcontainer.storage.AppConfig; import lightcontainer.storage.AppData; -import java.io.File; - public class App { // Constant config server // -- Unicast client port @@ -40,13 +36,13 @@ public class App { protocolRep.addReader(new HelloRule()); protocolRep.addReader(new SigninRule(protocolRep)); protocolRep.addReader(new SignupRule(protocolRep)); + protocolRep.addReader(new SignoutRule()); protocolRep.addReader(new FilelistRule(protocolRep)); protocolRep.addReader(new SavefileRule(protocolRep)); protocolRep.addReader(new SendOkRule(protocolRep)); protocolRep.addWriter(new SignOkRule()); protocolRep.addWriter(new SignErrorRule()); - protocolRep.addWriter(new SignoutRule()); protocolRep.addWriter(new FilesRule()); protocolRep.addWriter(new SaveFileOkRule()); protocolRep.addWriter(new SaveFileErrorRule()); diff --git a/app/src/main/java/lightcontainer/domains/Task.java b/app/src/main/java/lightcontainer/domains/Task.java index 91a0efc..0164cea 100644 --- a/app/src/main/java/lightcontainer/domains/Task.java +++ b/app/src/main/java/lightcontainer/domains/Task.java @@ -2,13 +2,16 @@ package lightcontainer.domains; import lightcontainer.domains.client.Context; import lightcontainer.enumerations.TaskStatus; -import lightcontainer.enumerations.TaskType; import lightcontainer.protocol.ProtocolWriter; +/** + * Une tâche exécutable + */ public class Task { // Variables private TaskStatus status; private ProtocolWriter.ProtocolResult command; + private String storeDomain; /** @@ -22,6 +25,12 @@ public class Task { this.command = command; } + /** + * Permet de créer une instance de la class {@link Task} + * @param context Context à utiliser pour cette tâche + * @param command Commande à exécuter + * @return L'instance de la tâche créée + */ public static Task newInstance(Context context, ProtocolWriter.ProtocolResult command) { Task task = new Task(context, TaskStatus.PENDING, command); return task; @@ -44,10 +53,18 @@ public class Task { return context.getLogin(); } + /** + * Permet de récupérer la commande à executer + * @return Commande à exécuter + */ public ProtocolWriter.ProtocolResult getCommand() { return this.command; } + /** + * Permet de définir le StorBackEnd à utiliser pour cette tâche + * @param storeDomain Le StorBackEnd à utiliser + */ public void setDomain(String storeDomain) { this.storeDomain = storeDomain; if (storeDomain != null) { diff --git a/app/src/main/java/lightcontainer/domains/client/Context.java b/app/src/main/java/lightcontainer/domains/client/Context.java index 05c36f2..fef239e 100644 --- a/app/src/main/java/lightcontainer/domains/client/Context.java +++ b/app/src/main/java/lightcontainer/domains/client/Context.java @@ -7,6 +7,10 @@ import lightcontainer.utils.AES_GCM; import java.security.NoSuchAlgorithmException; import java.util.LinkedList; +/** + * Contexte associé à la requête d'un utilisateur. + * Permet de récupérer les données à celui-ci et d'effectuer des actions sur le context courant. + */ public class Context { private AppData appData; @@ -16,12 +20,18 @@ public class Context { */ private String login; - + // Constructeur public Context(AppData appData) { this.appData = appData; } + /** + * Permet de créer un utilisateur. + * @param login Login de l'utilisateur + * @param password Mot de passe de l'utilisateur + * @return TRUE si l'utilisateur a pu être créé + */ public boolean createUser(String login, String password) { try { String key = AES_GCM.generateSecretKey(); diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java index d49f39c..ebace44 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolReader.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolReader.java @@ -6,6 +6,9 @@ import java.io.InputStream; import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Permet de construire des règles ayant pour but de parser une commande en un résultat utilisable par celle-ci + */ public abstract class ProtocolReader { private final String name; // Variables diff --git a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java index 87f6682..7cc3c15 100644 --- a/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java +++ b/app/src/main/java/lightcontainer/protocol/ProtocolWriter.java @@ -6,6 +6,9 @@ import java.util.StringJoiner; import java.util.regex.Matcher; import java.util.regex.Pattern; +/** + * Représente une construction de tâche. + */ public abstract class ProtocolWriter { // Variables private final Pattern rulePattern; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java index b0b132a..94b46f4 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/FilelistRule.java @@ -7,6 +7,9 @@ import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.rules.writer.FilesRule; import lightcontainer.protocol.rules.writer.SignOkRule; +/** + * Règle permettant de récupérer la liste des fichiers d'un utilisateur + */ public class FilelistRule extends ProtocolReader { // Constants private static final String PATTERN = "^FILELIST\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java index 885e95e..2440a97 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/HelloRule.java @@ -7,6 +7,9 @@ import java.io.BufferedReader; import java.util.ArrayList; import java.util.List; +/** + * Règle permettant d'être alerter de l'annoncement d'un SBE + */ public class HelloRule extends ProtocolReader { private static final String PATTERN = "^HELLO ([A-Za-z0-9]{5,20}) ([0-9]{1,5})\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java index 0ba4f79..5f1bfa8 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SavefileRule.java @@ -13,6 +13,10 @@ import java.io.IOException; import java.io.InputStream; import java.security.NoSuchAlgorithmException; +/** + * Règle permettant de sauvegarder un fichier sur le SBE. + * Celui-ci va chiffre le contenu du fichier à l'aide de AES. + */ public class SavefileRule extends ProtocolReader { // Constants private static final String PATTERN = "^SAVEFILE ([^ !]{1,20}) ([0-9]{1,10})\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java index 52a400c..3cd1e66 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SendOkRule.java @@ -6,6 +6,9 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.ProtocolWriter; import lightcontainer.protocol.rules.writer.SaveFileOkRule; +/** + * Règle permettant de de confirmer la sauvegrade d'un fichier. + */ public class SendOkRule extends ProtocolReader { diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java index c6963f7..814138b 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SigninRule.java @@ -10,6 +10,9 @@ import lightcontainer.protocol.rules.writer.SignOkRule; import java.io.InputStream; +/** + * Règle permettant de gérer la connection d'un utilisateur + */ public class SigninRule extends ProtocolReader { // Constants private static final String PATTERN = "^SIGNIN ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java new file mode 100644 index 0000000..4309f28 --- /dev/null +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignoutRule.java @@ -0,0 +1,25 @@ +package lightcontainer.protocol.rules.reader; + +import lightcontainer.domains.client.Context; +import lightcontainer.protocol.ProtocolReader; +import lightcontainer.protocol.ProtocolWriter; + +/** + * Règle demandant la déconnexion du client + */ +public class SignoutRule extends ProtocolReader { + + private static final String PATTERN = "^SIGNOUT\r\n$"; + + public static final String NAME = "SIGNOUT"; + + public SignoutRule() { + super(NAME, PATTERN); + } + + + @Override + protected T onExecuted(Context context, String... data) { + return null; + } +} diff --git a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java index 391e3b8..f8efa4a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/reader/SignupRule.java @@ -6,6 +6,9 @@ import lightcontainer.protocol.ProtocolReader; import lightcontainer.protocol.rules.writer.SignErrorRule; import lightcontainer.protocol.rules.writer.SignOkRule; +/** + * Règle permettant de gérer la création d'un utilisateur + */ public class SignupRule extends ProtocolReader { // Constants private static final String PATTERN = "^SIGNUP ([A-Za-z0-9]{5,20}) ([^ !]{5,50})\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java index a611163..e0f50c4 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/FilesRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +/** + * Règle permettant de construire une commande contenant la liste des fichiers d'un utilisateur + */ public class FilesRule extends ProtocolWriter { private static final String PATTERN = "^FILES( ([^ !]{1,20})!([0-9]{1,10})){0,50}\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java index 8dda3a7..4d1f1f3 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileErrorRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +/** + * Règle signifiant que la sauvegarde d'un fichier a échoué + */ public class SaveFileErrorRule extends ProtocolWriter { private static final String PATTERN = "^SAVEFILE_ERROR\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java index 1bd90d3..7734605 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SaveFileOkRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +/** + * Règle signifiant que la sauvegarde d'un fichier fût un succès + */ public class SaveFileOkRule extends ProtocolWriter { private static final String PATTERN = "^SAVEFILE_OK\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java index c12ddb9..3d0bac0 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SendfileRule.java @@ -6,6 +6,9 @@ import lightcontainer.utils.FileSender; import java.io.OutputStream; +/** + * Règle envoyée au SBE, demandant la sauvegarde d'un fichier. + */ public class SendfileRule extends ProtocolWriter { private static final String PATTERN = "^SENDFILE [A-Za-z0-9.]{0,200} [0-9]{1,10} [A-Za-z0-9.]{50,200}\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java index b78a66f..096bb9a 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignErrorRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +/** + * Règle renvoyée au client lorsque l'authentification a échoué. + */ public class SignErrorRule extends ProtocolWriter { private static final String PATTERN = "^SIGN_ERROR\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java index 44b3f3c..6d6ef04 100644 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java +++ b/app/src/main/java/lightcontainer/protocol/rules/writer/SignOkRule.java @@ -2,6 +2,9 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +/** + * Règle renvoyée au client lorsque l'authentification a réusie. + */ public class SignOkRule extends ProtocolWriter { private static final String PATTERN = "^SIGN_OK\r\n$"; diff --git a/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java b/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java deleted file mode 100644 index ff42d2c..0000000 --- a/app/src/main/java/lightcontainer/protocol/rules/writer/SignoutRule.java +++ /dev/null @@ -1,14 +0,0 @@ -package lightcontainer.protocol.rules.writer; - -import lightcontainer.protocol.ProtocolWriter; - -public class SignoutRule extends ProtocolWriter { - - private static final String PATTERN = "^SIGNOUT\r\n$"; - - public static final String NAME = "SIGNOUT"; - - public SignoutRule() { - super(NAME, PATTERN); - } -} diff --git a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java index 31bf799..cb3af1e 100644 --- a/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java +++ b/app/src/test/java/lightcontainer/protocol/rules/writer/SignoutRuleTest.java @@ -1,6 +1,7 @@ package lightcontainer.protocol.rules.writer; import lightcontainer.protocol.ProtocolWriter; +import lightcontainer.protocol.rules.reader.SignoutRule; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -9,13 +10,6 @@ class SignoutRuleTest { @Test public void whenRuleIsRightThenReturnCommand() { - //GIVEN - ProtocolWriter protocolWriter = new SignoutRule(); - String[] datas = {}; - - //EXPECT - assertNotNull(protocolWriter.execute(datas)); - assertEquals("SIGNOUT\r\n", protocolWriter.execute(datas)); } } \ No newline at end of file