You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
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 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();
|
|
}
|
|
}
|