package com.vst.webapp.action;
import com.vst.util.FileHelper;
import com.vst.webapp.util.FTPUtil;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
public class UpdateFormController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse httpServletResponse) throws Exception {
ModelAndView mav = new ModelAndView("updateForm");
if (request.getParameter("update") != null) {
Properties properties = new Properties();
properties.load(new FileInputStream(FileHelper.getCurrentPath(request) + "WEB-INF/classes/ApplicationResources.properties"));
FTPUtil ftpUtil = new FTPUtil(
properties.getProperty("update.ftpAddress"),
properties.getProperty("update.ftpUser"),
properties.getProperty("update.ftpPassword"));
ftpUtil.setIgnoreFiles(properties.getProperty("update.ignoreFiles"));
ftpUtil.setLogFile(properties.getProperty("update.logFile"));
ftpUtil.copyFromFTP(
properties.getProperty("update.ftpFolder"),
FileHelper.getCurrentPath(request));
mav.addObject("message", "Updated!");
File batRestartFile = new File(FileHelper.getCurrentPath(request) + "restart_tomcat.bat");
try {
new ProcessBuilder(batRestartFile.getAbsolutePath()).start();
}
catch (IOException e) {
e.printStackTrace();
}
}
return mav;
}
}