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 execute(User subject) throws Exception { File file = (File) this.getOptions().get("file"); String table = (String) this.getOptions().get("file_type"); Map limits = (Map) this.getOptions().get("limits"); String field = core.operation.utils.Utils.getFileField(table); String filePath = core.operation.utils.Utils.getFilePathName(table,file.getName()); Map vMap = new HashMap<>(); vMap.put(field,filePath); file.renameTo(new File(filePath)); //todo List 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(); } }