Merge remote-tracking branch 'remotes/origin/hechu1'

# Conflicts:
#	.idea/dataSources/356b1cbb-8e8d-401f-bdfc-b3e917bc8301.xml
#	src/core/operation/Select.json
#	src/core/process/Process.java
1,基本完成Operation
2,调整AccountManagement
3,其余
zgl
zhai_lw 6 years ago
parent 9f31df0a89
commit 36fb645981

@ -19,15 +19,15 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Tomcat 8.5" level="application_server_libraries" />
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://E:/tomcat8/apache-tomcat-8.5.37/lib/tomcat-jdbc.jar!/" />
<root url="jar://C:/Program Files/Apache Software Foundation/Tomcat 8.5/lib/tomcat-jdbc.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" scope="PROVIDED" name="Tomcat 8.5.37" level="application_server_libraries" />
</component>
</module>

@ -15,6 +15,6 @@ public class Delete extends Operation {
for(String table:DBManagement.graduationDesignTables){
DBManagement.delete(table,map);
}
return options;
return this.getOptions();
}
}

@ -1,12 +1,27 @@
package core.operation;
import core.user.User;
import dao.DBManagement;
import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class DownloadFile extends Operation{
@Override
public Map<String, Object> execute(User subject) throws Exception {
String table = (String) this.getOptions().get("file_type");
Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
String field = core.operation.utils.Utils.getFileField(table);
List<String> ls = new ArrayList<>();
ls.add(field);
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
rs.next();
String filePath = rs.getString(0);
File file = new File(filePath);
this.getOptions().put("file",file);
return this.getOptions();
}
}

@ -1,6 +1,9 @@
{
"options":{
"file_type":"String",
"limits":"Map<String,String>"
},
"return":{}
"return":{
"file":"File"
}
}

@ -1,6 +1,7 @@
package core.operation;
import core.operation.utils.Utils;
import core.user.User;
import error.GExcptFormat;
import gdms.Mode;
@ -9,8 +10,8 @@ import java.util.Map;
public abstract class Operation {
protected Map<String, Object> options;
protected User subject;
private Map<String, Object> options;
private User subject;
Operation(){
super();
}
@ -26,7 +27,7 @@ public abstract class Operation {
return options;
}
public void setOptions(String options) throws GExcptFormat {
this.options = core.operation.utils.util.string2MapOptions(options);
this.options = Utils.string2MapOptions(options);
}
public void addOptions(String key, Object value){
if ( Mode.strict == 1){

@ -1,13 +1,38 @@
package core.operation;
import core.user.User;
import dao.DBManagement;
import error.GExcptSQL;
import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class UploadFileOperation extends Operation {
@Override
public Map<String, Object> execute(User subject) throws GExcptSQL {
public Map<String, Object> execute(User subject) throws Exception {
File file = (File) this.getOptions().get("file");
String table = (String) this.getOptions().get("file_type");
Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
String field = core.operation.utils.Utils.getFileField(table);
String filePath = core.operation.utils.Utils.getFilePathName(table,file.getName());
Map<String,String> vMap = new HashMap<>();
vMap.put(field,filePath);
file.renameTo(new File(filePath));
//todo
List<String> ls = new ArrayList<>();
ls.add(field);
ResultSet rs = DBManagement.select(ls,table,limits,0,1);
rs.next();
String lastFilePath = rs.getString(0);
new File(lastFilePath).delete();
DBManagement.update(table,vMap,limits);
return this.getOptions();
}
}

@ -1,6 +1,8 @@
{
"options":{
"file": "File"
"file": "File",
"file_type": "String",
"limits":"Map<String,String>"
},
"return":{}
}

@ -0,0 +1,5 @@
{
"公告文件": "announcement",
"开题报告":"graduation_design_reply",
"毕业设计定稿":"graduation_design_finished_product"
}

@ -0,0 +1,53 @@
package core.operation.utils;
import error.GExcptFormat;
import gdms.Configuration;
import gdms.Mode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public interface Utils {
Map<String,String> fileTableField = new HashMap<>() {
{
put("announcement","annex_url");
put("graduation_design_finished_product","graduation_design_url");
put("graduation_design_opening_report","report_url");
}};
static String stringOptionsFormat(String options){
return options.replaceAll(" {2,}", " ") ;
}
static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
sOptions = stringOptionsFormat(sOptions);
Map<String, Object> options = new HashMap<>();
String[] sOpts = sOptions.split(" ");
for(int i=0;i<sOpts.length;i++){
if(Mode.strict==1){
if(sOpts[i].indexOf(0)=='-')
throw new GExcptFormat("options format error");
}
options.put(sOpts[i].substring(1),sOpts[++i]);
}
return options;
}
static String getFileField(String table){
return fileTableField.get(table);
}
static String getFilePath(String table){
return Configuration.filePath+table+"/";
}
static String getFileName(String fileName){
SimpleDateFormat simpleDateFormat;
simpleDateFormat = new SimpleDateFormat("yyMMddHHmmssSSS");
Date date = new Date();
String str = simpleDateFormat.format(date);
str+=(int)(Math.random()*100000);
str+= utils.Utils.getFileType(fileName);
return str;
}
static String getFilePathName(String table, String fileName){
return getFilePath(table)+getFileName(fileName);
}
}

@ -1,26 +0,0 @@
package core.operation.utils;
import error.GExcptFormat;
import gdms.Mode;
import java.util.HashMap;
import java.util.Map;
public interface util {
static String stringOptionsFormat(String options){
return options.replaceAll(" {2,}", " ") ;
}
static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
sOptions = stringOptionsFormat(sOptions);
Map<String, Object> options = new HashMap<>();
String[] sOpts = sOptions.split(" ");
for(int i=0;i<sOpts.length;i++){
if(Mode.strict==1){
if(sOpts[i].indexOf(0)=='-')
throw new GExcptFormat("options format error");
}
options.put(sOpts[i].substring(1),sOpts[++i]);
}
return options;
}
}

@ -1,6 +1,7 @@
package core.user.utils;
import core.user.User;
import core.utils.GetObjectByName;
import dao.DBManagement;
import error.GExcptAccount;
import error.GExcptSQL;
@ -18,7 +19,7 @@ import java.util.Map;
import static dao.DBManagement.userTables;
public interface AccountManagement {
static User login(String id, String password) throws GExcptSQL, GExcptAccount, SQLException {
static User login(String id, String password) throws Exception {
ResultSet rs = null;
String userType = null;
for(String userTable:userTables){
@ -40,22 +41,17 @@ public interface AccountManagement {
throw new GExcptAccount("id "+id+"don't exists");
}
rs.next();
try {
if(!rs.getString(2).equals(password))
throw new GExcptAccount("password wrong");
Map<String, String> vMap = new HashMap<>();
ResultSetMetaData rsm = rs.getMetaData();
rs.next();
for(int i=0;i<rsm.getColumnCount();i++){
vMap.put(rsm.getCatalogName(i),rs.getString(i));
}
return createUser(userType,vMap);
} catch (SQLException e) {
e.printStackTrace();
if(!rs.getString(2).equals(password))
throw new GExcptAccount("password wrong");
Map<String, String> vMap = new HashMap<>();
ResultSetMetaData rsm = rs.getMetaData();
rs.next();
for(int i=0;i<rsm.getColumnCount();i++){
vMap.put(rsm.getCatalogName(i),rs.getString(i));
}
return null;
return createUser(userType,vMap);
}
static User register(String userType, Map<String, String> vMap) throws GExcptSQL {
static User register(String userType, Map<String, String> vMap) throws Exception {
DBManagement.insert(userType,vMap);
return createUser(userType, vMap);
}
@ -65,16 +61,8 @@ public interface AccountManagement {
static void destroy(User user){
//todo
}
static User getUser(String userType){
try {
return (User) Class.forName("core.user."+ Utils.toUpperFirstChar(userType)).getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
static User createUser(String userType, Map<String, String> vMap) {
User user = getUser(userType);
static User createUser(String userType, Map<String, String> vMap) throws Exception {
User user = GetObjectByName.getUserByName(userType);
user.setAttr(vMap);
return user;
}

@ -1,12 +1,15 @@
package core.utils;
import core.operation.Operation;
import core.user.User;
public interface GetObjectByName {
String userClassPath = "core.user";
String operationClassPath = "core.operation";
static Object getUserByName(String name) throws Exception {
return Class.forName(userClassPath+"."+name).getDeclaredConstructor().newInstance();
static User getUserByName(String name) throws Exception {
return (User)Class.forName(userClassPath+"."+name).getDeclaredConstructor().newInstance();
}
static Object getOperationByName(String name) throws Exception{
return Class.forName(operationClassPath+"."+name).getDeclaredConstructor().newInstance();
static Operation getOperationByName(String name) throws Exception{
return (Operation)Class.forName(operationClassPath+"."+name).getDeclaredConstructor().newInstance();
}
}

@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map;
import error.GExcptSQL;
import gdms.Configuration;
import org.apache.tomcat.jdbc.pool.DataSource;
import org.apache.tomcat.jdbc.pool.PoolProperties;
@ -27,12 +28,9 @@ public class DBManagement {
"graduation_design_reply",
"graduation_design_reply_opinion_record_score"
};
public static String driverClassName="org.mariadb.jdbc.Driver";
static final String driverClassName="org.mariadb.jdbc.Driver";
static final String url="jdbc:mariadb://localhost:3306/gdms";
static final String username="gdms";
static final String password="GDMS";
public static DataSource dataSource = new DataSource();
@ -40,10 +38,10 @@ public class DBManagement {
public static void init(){
PoolProperties poolProperties = new PoolProperties();
poolProperties.setUrl(url);
poolProperties.setDriverClassName(driverClassName);
poolProperties.setUsername(username);
poolProperties.setPassword(password);
poolProperties.setUrl(Configuration.dbUrl);
poolProperties.setDriverClassName(DBManagement.driverClassName);
poolProperties.setUsername(Configuration.dbUsername);
poolProperties.setPassword(Configuration.dbPassword);
dataSource.setPoolProperties(poolProperties);
try {
Class.forName(driverClassName);
@ -55,7 +53,7 @@ public class DBManagement {
public static Connection getConnection(){
if(!ifInit) return null;
try {
return DriverManager.getConnection(url,username,password);
return DriverManager.getConnection(Configuration.dbUrl,Configuration.dbUsername,Configuration.dbPassword);
} catch (SQLException e) {
e.printStackTrace();
}

@ -0,0 +1,10 @@
package gdms;
public interface Configuration {
//file
String filePath = "/";
//database
String dbUrl="jdbc:mariadb://localhost:3306/gdms";
String dbUsername="gdms";
String dbPassword="GDMS";
}

@ -1,5 +1,6 @@
package gdms;
import core.operation.utils.Utils;
import dao.Select;
import java.util.ArrayList;
@ -17,5 +18,6 @@ public class test {
map.put("c","d");
Select sql = new Select(list,"zx",map,1,2);
System.out.println(sql.getSQL());
System.out.println(Utils.getFilePathName("a","b"));
}
}

@ -28,8 +28,10 @@ public class login extends HttpServlet {
gExcptSQL.printStackTrace();
} catch (GExcptAccount gExcptAccount) {
gExcptAccount.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
request.getSession().setAttribute("User",user);
request.getSession().setAttribute("User",user);
request.getRequestDispatcher("/home.jsp").forward(request,response);
}

@ -27,4 +27,11 @@ public interface Utils {
static String cutTail(String s,int i){
return s.substring(0,s.length()-i);
}
static String getFileType(String fileName){
if(fileName.contains(".")){
return fileName.substring(fileName.lastIndexOf('.'));
}else{
return "";
}
}
}

Loading…
Cancel
Save