diff --git a/src/core/operation/Executable.java b/src/core/operation/Executable.java deleted file mode 100644 index 53be8a4..0000000 --- a/src/core/operation/Executable.java +++ /dev/null @@ -1,27 +0,0 @@ -package core.operation; - - -import java.util.Map; - -public interface Executable { - default void execute(String options){ - - } - - default void execute(Map options) throws Exception { - checkSelf(); - beforeRun(options); - run(options); - afterRun(options); - } - - void checkSelf ()throws Exception; - - void beforeRun(Map options); - - void run(Map options); - - - - void afterRun(Map options); -} diff --git a/src/core/operation/Operation.java b/src/core/operation/Operation.java index 865fe06..5772175 100644 --- a/src/core/operation/Operation.java +++ b/src/core/operation/Operation.java @@ -2,12 +2,13 @@ package core.operation; import core.user.User; +import gdms.Mode; import java.util.Map; -public abstract class Operation implements Executable { +public abstract class Operation { - Map options; + private Map options; private User subject; Operation(){ super(); @@ -18,17 +19,26 @@ public abstract class Operation implements Executable { public void setSubject(User subject) { this.subject = subject; } - - @Override - public void checkSelf() throws Exception { - if(subject==null) throw new Exception("Operation's subject is Null"); + public void setOptions(String options) { + this.options = core.operation.utils.util.string2MapOptions(options); + } + public void setProcessOperations(String processOptions){ + setOptions(processOptions); } - @Override - public void beforeRun(Map options) { - core.operation.utils.util.checkOptions(core.utils.ConfigurationFileManagement.getConfigurationFile(this.getClass().getName()),options); + public void addUserOperations(String key, Object value){ + if ( Mode.strict == 1){ + if(!this.options.containsKey(key)) { + try { + throw new Exception("options repeat"); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + this.options.put(key,value); } - @Override - public void afterRun(Map options) { - //todo + public void execute(User subject){ + this.subject = subject; } + } diff --git a/src/core/operation/UploadFileOperation.java b/src/core/operation/UploadFileOperation.java index 4712db7..307b964 100644 --- a/src/core/operation/UploadFileOperation.java +++ b/src/core/operation/UploadFileOperation.java @@ -1,13 +1,7 @@ package core.operation; -import java.io.File; import java.util.Map; public class UploadFileOperation extends Operation { Map options; - @Override - public void run(Map options) { - //todo - } - } diff --git a/src/core/operation/utils/util.java b/src/core/operation/utils/util.java index ca0a5c6..031ce17 100644 --- a/src/core/operation/utils/util.java +++ b/src/core/operation/utils/util.java @@ -1,10 +1,19 @@ package core.operation.utils; -import java.io.File; +import java.util.HashMap; import java.util.Map; public interface util { - static void checkOptions(File jsonFile, Map options){ - + static String stringOptionsFormat(String options){ + return options.replaceAll(" {2,}", " ") ; + } + static Map string2MapOptions(String sOptions){ + sOptions = stringOptionsFormat(sOptions); + Map options = new HashMap<>(); + String[] sOpts = sOptions.split(" "); + for(int i=0;i option; + private String info; + private String processOptions; - public AtomProcess(String subjectName, String operationName, Map option, String info) throws Exception { + public AtomProcess(String permission, String operationName, String processOptions, String info) throws Exception { super(info); - this.subject = (User) core.utils.GetObjectByName.getUserByName(subjectName); + this.permission = permission; this.operation = (Operation) core.utils.GetObjectByName.getOperationByName(operationName); - this.option = option; - this.operation.setSubject(this.subject); + this.info = info; + this.processOptions = processOptions; + operation.setProcessOperations(processOptions); } - - public void execute() throws Exception { - this.operation.execute(this.option); + public void setUserOperations(String key,Object value){ + this.operation.addUserOperations(key,value); + } + public void execute(User subject){ + this.operation.execute(subject); } } diff --git a/src/core/process/CompoundProcess.java b/src/core/process/CompoundProcess.java index f874d6d..c4636be 100644 --- a/src/core/process/CompoundProcess.java +++ b/src/core/process/CompoundProcess.java @@ -8,10 +8,4 @@ public class CompoundProcess extends Process { super(info); } - @Override - public void execute() throws Exception { - for(Process process:processes){ - process.execute(); - } - } } diff --git a/src/core/process/Process.java b/src/core/process/Process.java index 3eeead6..564334d 100644 --- a/src/core/process/Process.java +++ b/src/core/process/Process.java @@ -1,11 +1,5 @@ package core.process; -import core.operation.Executable; -import core.operation.Operation; - -import java.io.File; -import java.util.List; - public abstract class Process { private String info; @@ -13,7 +7,6 @@ public abstract class Process { this.info=info; } - public abstract void execute()throws Exception; public String getInfo() { return info; } diff --git a/src/core/process/ProcessManagement.java b/src/core/process/ProcessManagement.java index 0408445..f7d1e1e 100644 --- a/src/core/process/ProcessManagement.java +++ b/src/core/process/ProcessManagement.java @@ -7,7 +7,4 @@ public class ProcessManagement { public void setProcessesByJson(File file){ //todo } - public void execute() throws Exception { - processes.execute(); - } } diff --git a/src/core/user/Administrator.java b/src/core/user/Administrator.java new file mode 100644 index 0000000..3901895 --- /dev/null +++ b/src/core/user/Administrator.java @@ -0,0 +1,4 @@ +package core.user; + +public class Administrator { +} diff --git a/src/core/user/User.java b/src/core/user/User.java index 2d15e9e..494f8fb 100644 --- a/src/core/user/User.java +++ b/src/core/user/User.java @@ -1,19 +1,33 @@ package core.user; +import core.process.APSet; import core.process.ProcessManagement; import core.user.userFun.AccountManageable; import core.user.userFun.ProcessConfigurable; import java.io.File; +import java.util.List; public abstract class User implements AccountManageable, ProcessConfigurable{ private String id; private String password; - private ProcessManagement processManagement; + private List permissions = null; + private APSet condition; + public void addPermission(String permission){ + if(!permissions.contains(permission)) + permissions.add(permission); + } + public void removePermission(String permission){ + permissions.remove(permission); + } + public boolean checkPermission(String permission){ + return permissions.contains(permission); + + } public User(){ super(); - processManagement = setProcessManagement(new File("")); + } public String getType(){ return this.getClass().getName(); diff --git a/src/gdms/Mode.java b/src/gdms/Mode.java new file mode 100644 index 0000000..4415ae0 --- /dev/null +++ b/src/gdms/Mode.java @@ -0,0 +1,6 @@ +package gdms; + +public interface Mode { + public static int strict = 1; + public static int debug = 1; +} diff --git a/src/gdms/test.java b/src/gdms/test.java index 3c21baa..48ec04b 100644 --- a/src/gdms/test.java +++ b/src/gdms/test.java @@ -3,9 +3,14 @@ import core.user.Student; import core.user.User; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; public class test { public static void main(String argc[]){ - System.out.println(new Student().getType()); + String sTest = "-a add -s set -d delete"; + Map test = core.operation.utils.util.string2MapOptions(sTest); + System.out.println(test); } }