1, 添加gdms.Mode以方便后期调试

2,修改Operation的option属性的类型再次改为Map<String, Object>
3,完成operation的抽象定义
4,梳理operation和AP的关系
5,其他
hechu
zhai_lw 6 years ago
parent 42612fdfef
commit a0ddf99418

@ -1,27 +0,0 @@
package core.operation;
import java.util.Map;
public interface Executable {
default void execute(String options){
}
default void execute(Map<String, String> options) throws Exception {
checkSelf();
beforeRun(options);
run(options);
afterRun(options);
}
void checkSelf ()throws Exception;
void beforeRun(Map<String, String> options);
void run(Map<String, String> options);
void afterRun(Map<String, String> options);
}

@ -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<String, Object> options;
private Map<String, Object> 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<String, String> 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<String, String> options) {
//todo
public void execute(User subject){
this.subject = subject;
}
}

@ -1,13 +1,7 @@
package core.operation;
import java.io.File;
import java.util.Map;
public class UploadFileOperation extends Operation {
Map<String, Object> options;
@Override
public void run(Map<String, String> options) {
//todo
}
}

@ -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<String, String> options){
static String stringOptionsFormat(String options){
return options.replaceAll(" {2,}", " ") ;
}
static Map<String, Object> string2MapOptions(String sOptions){
sOptions = stringOptionsFormat(sOptions);
Map<String, Object> options = new HashMap<>();
String[] sOpts = sOptions.split(" ");
for(int i=0;i<sOpts.length;i++){
options.put(sOpts[i],sOpts[++i]);
}
return options;
}
}

@ -0,0 +1,4 @@
package core.process;
public class APSet {
}

@ -3,23 +3,25 @@ package core.process;
import core.operation.Operation;
import core.user.User;
import java.util.Map;
public class AtomProcess extends Process {
private User subject;
private String permission;
private Operation operation;
private Map<String, Object> option;
private String info;
private String processOptions;
public AtomProcess(String subjectName, String operationName, Map<String, Object> 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);
}
}

@ -8,10 +8,4 @@ public class CompoundProcess extends Process {
super(info);
}
@Override
public void execute() throws Exception {
for(Process process:processes){
process.execute();
}
}
}

@ -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;
}

@ -7,7 +7,4 @@ public class ProcessManagement {
public void setProcessesByJson(File file){
//todo
}
public void execute() throws Exception {
processes.execute();
}
}

@ -0,0 +1,4 @@
package core.user;
public class Administrator {
}

@ -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<String> 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();

@ -0,0 +1,6 @@
package gdms;
public interface Mode {
public static int strict = 1;
public static int debug = 1;
}

@ -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<String,Object> test = core.operation.utils.util.string2MapOptions(sTest);
System.out.println(test);
}
}

Loading…
Cancel
Save