|
@@ -12,48 +12,22 @@ import org.springframework.security.access.annotation.Secured;
|
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
|
|
-import es.uv.saic.service.IndicadorEnquestaService;
|
|
|
|
|
-import es.uv.saic.service.ParserService;
|
|
|
|
|
|
|
+import es.uv.saic.feign.ParseClient;
|
|
|
|
|
|
|
|
// Controller for the parsing options page for admin user
|
|
// Controller for the parsing options page for admin user
|
|
|
@Controller
|
|
@Controller
|
|
|
public class ParseController {
|
|
public class ParseController {
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private ParserService ps;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private IndicadorEnquestaService ies;
|
|
|
|
|
|
|
+ private ParseClient pc;
|
|
|
|
|
+
|
|
|
@Value("${saic.parser.surveys.path}")
|
|
@Value("${saic.parser.surveys.path}")
|
|
|
private String surveysPath;
|
|
private String surveysPath;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
- * Load the parsing options page data into the model
|
|
|
|
|
- * @param model
|
|
|
|
|
- * @param auth Authentication
|
|
|
|
|
- * @param err Optional error message
|
|
|
|
|
- * @param ok Optional success message
|
|
|
|
|
- * @return The name of the view to render
|
|
|
|
|
- */
|
|
|
|
|
- @GetMapping("/admin/parse")
|
|
|
|
|
- @Secured({"ROLE_ADMIN"})
|
|
|
|
|
- public String getParse(Model model, Authentication auth, @RequestParam(required=false, name="err") Optional<String> err,
|
|
|
|
|
- @RequestParam(required=false, name="ok") Optional<Integer> ok) throws IOException, SQLException, ClassNotFoundException {
|
|
|
|
|
-
|
|
|
|
|
- if(ok.isPresent()) {
|
|
|
|
|
- model.addAttribute("ok", ok.get());
|
|
|
|
|
- }
|
|
|
|
|
- else if(err.isPresent()) {
|
|
|
|
|
- model.addAttribute("err", true);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return "parseOptions";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /*
|
|
|
|
|
* Parse a given table from a given database for a given year
|
|
* Parse a given table from a given database for a given year
|
|
|
* @param model
|
|
* @param model
|
|
|
* @param auth Authentication
|
|
* @param auth Authentication
|
|
@@ -66,11 +40,7 @@ public class ParseController {
|
|
|
@Secured({"ROLE_ADMIN"})
|
|
@Secured({"ROLE_ADMIN"})
|
|
|
public void doParse(Model model, Authentication auth, HttpServletResponse response, @RequestParam String database,
|
|
public void doParse(Model model, Authentication auth, HttpServletResponse response, @RequestParam String database,
|
|
|
@RequestParam String table, @RequestParam Integer year) throws IOException, SQLException, ClassNotFoundException {
|
|
@RequestParam String table, @RequestParam Integer year) throws IOException, SQLException, ClassNotFoundException {
|
|
|
-
|
|
|
|
|
- System.out.println(database + " -> " + table + " -> " + year.toString());
|
|
|
|
|
- String r = this.ps.doParse(database, table, year.toString());
|
|
|
|
|
- response.sendRedirect("/admin/parse?ok="+r);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ pc.doParse(response, database, table, year);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -84,15 +54,7 @@ public class ParseController {
|
|
|
@Secured({"ROLE_ADMIN"})
|
|
@Secured({"ROLE_ADMIN"})
|
|
|
public void doAction(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action)
|
|
public void doAction(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action)
|
|
|
throws IOException, SQLException, ClassNotFoundException {
|
|
throws IOException, SQLException, ClassNotFoundException {
|
|
|
-
|
|
|
|
|
- System.out.println(action);
|
|
|
|
|
- String r = this.ps.doAction(action);
|
|
|
|
|
- if(r.equals("-1")) {
|
|
|
|
|
- response.sendRedirect("/admin/parse?err");
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- response.sendRedirect("/admin/parse?ok="+r);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ pc.doAction(response, action);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -107,21 +69,7 @@ public class ParseController {
|
|
|
@Secured({"ROLE_ADMIN"})
|
|
@Secured({"ROLE_ADMIN"})
|
|
|
public void doDelete(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action, @RequestParam Integer year)
|
|
public void doDelete(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action, @RequestParam Integer year)
|
|
|
throws IOException, SQLException, ClassNotFoundException {
|
|
throws IOException, SQLException, ClassNotFoundException {
|
|
|
-
|
|
|
|
|
- String r = "-1";
|
|
|
|
|
- if(year == 0) {
|
|
|
|
|
- r = Integer.toString(this.ies.deleteByEnquesta(action));
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- r = Integer.toString(this.ies.deleteByEnquestaCurs(action, year));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if(r.equals("-1")) {
|
|
|
|
|
- response.sendRedirect("/admin/parse?err");
|
|
|
|
|
- }
|
|
|
|
|
- else {
|
|
|
|
|
- response.sendRedirect("/admin/parse?ok="+r);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ pc.doDelete(response, action, year);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|