Browse Source

ParseController modificado y OrganController eliminado

Mario Martínez Hernández 2 weeks ago
parent
commit
e34285ee62

+ 26 - 0
src/main/java/es/uv/saic/feign/ParseClient.java

@@ -0,0 +1,26 @@
+package es.uv.saic.feign;
+
+import java.io.IOException;
+import java.sql.SQLException;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+import jakarta.servlet.http.HttpServletResponse;
+
+@FeignClient(value = "parse-controller", url = "${saic.url.domain}")
+public interface ParseClient {
+
+    @PostMapping("/admin/parse/do")
+	public void doParse(HttpServletResponse response, @RequestParam String database, 
+        @RequestParam String table, @RequestParam Integer year) throws IOException, SQLException, ClassNotFoundException;	
+
+    @PostMapping("/admin/parse/action")
+	public void doAction(HttpServletResponse response, @RequestParam String action) 
+        throws IOException, SQLException, ClassNotFoundException;
+
+    @PostMapping("/admin/parse/delete")
+	public void doDelete(HttpServletResponse response, @RequestParam String action, @RequestParam Integer year) 
+        throws IOException, SQLException, ClassNotFoundException;
+}

+ 0 - 66
src/main/java/es/uv/saic/web/DownloadController.java

@@ -8,7 +8,6 @@ import java.nio.file.Path;
 import java.util.Optional;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.FileSystemResource;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -23,7 +22,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import es.uv.saic.dto.PdfDTO;
 import es.uv.saic.feign.DocumentClient;
 import fr.opensagres.xdocreport.core.XDocReportException;
-import jakarta.servlet.http.HttpServletResponse;
 
 @Controller
 public class DownloadController {
@@ -66,21 +64,6 @@ public class DownloadController {
 	}
 
 	/*
-	 * Download the latest report for a given process and degree
-	 * @param model
-	 * @param idTitulacio The ID of the degree
-	 * @param nomProces The name of the process
-	 * @param response HttpServletResponse
-	 * @return A FileSystemResource representing the report to download
-	 */
-	@GetMapping(value="/download/report/{t}/{p}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
-	@ResponseBody 
-	public FileSystemResource downloadReport(Model model, @PathVariable("t") Integer idTitulacio, @PathVariable("p") String nomProces) throws IOException, XDocReportException {
-		return dc.downloadReport(idTitulacio, nomProces).getBody();
-	}
-
-
-	/*
 	 * Download a populated template for a given task instance
 	 * @param model
 	 * @param idTascai The ID of the task instance
@@ -94,55 +77,6 @@ public class DownloadController {
 	}
 
 	/*
-	 * Test endpoint to generate a populated template for a given task (id of task)
-	 * @param model
-	 * @param idTitulacio The ID of the degree
-	 * @param idCentre The ID of the center
-	 * @param idTascap The ID of the task
-	 * @param idProces The ID of the process
-	 * @param response HttpServletResponse
-	 * @return A byte array representing the populated template
-	 */
-	@GetMapping(value="/test/template/{titulacio}/{centre}/{idProces}/{idTascap}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
-	@ResponseBody
-	public byte[] testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
-			@PathVariable("idTascap") Integer idTascap, @PathVariable("idProces") Integer idProces) 
-					throws IOException, XDocReportException {
-		return dc.testTemplate(idTitulacio, idCentre, idProces, idTascap);
-	}
-
-	/*
-	 * Test endpoint to generate a populated template for a given degree and evidence (Type of task)
-	 * @param model
-	 * @param idTitulacio The ID of the degree
-	 * @param idCentre The ID of the center
-	 * @param evidencia The name of the evidence
-	 * @param curs The academic year
-	 * @param tipusTasca The type of task
-	 * @param response HttpServletResponse
-	 * @return A byte array representing the populated template
-	 */
-	@GetMapping(value="/test/template2/{titulacio}/{centre}/{evidencia}/{curs}/{tipusTasca}", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
-	@ResponseBody
-	public byte[] testTemplate(Model model, @PathVariable("titulacio") Integer idTitulacio, @PathVariable("centre") Integer idCentre,
-			@PathVariable("evidencia") String evidencia, @PathVariable("curs") Integer curs, @PathVariable("tipusTasca") Integer tipusTasca) throws IOException, XDocReportException {
-		return dc.testTemplate(idTitulacio, idCentre, evidencia, curs, tipusTasca);
-	}
-	
-	/*
-	 * Generate a PDF from the content of a task instance (unused)
-	 * @param model
-	 * @param idTascai The ID of the task instance
-	 * @param response HttpServletResponse
-	 * @return A byte array representing the generated PDF
-	 */
-	@GetMapping(value="/pdf/download/{idTascai}")
-	@ResponseBody
-	public byte[] downloadTemplatePdf(Model model, @PathVariable("idTascai") BigInteger idTascai) throws IOException, InterruptedException {
-		return dc.downloadTemplatePdf(idTascai);
-	}
-
-	/*
 	 * Generate a PDF preview from provided content
 	 * @param model
 	 * @param content The content to convert to PDF

+ 0 - 108
src/main/java/es/uv/saic/web/OrganController.java

@@ -1,108 +0,0 @@
-package es.uv.saic.web;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RestController;
-
-import es.uv.saic.domain.IndicadorEnquesta;
-import es.uv.saic.domain.Organ;
-import es.uv.saic.dto.OrganDTO;
-import es.uv.saic.dto.OrganTransferDTO;
-import es.uv.saic.service.IndicadorEnquestaService;
-import es.uv.saic.service.OrganService;
-
-@RestController
-public class OrganController {
-    
-    @Autowired
-    private OrganService os;
-
-    @Autowired
-    private IndicadorEnquestaService ies;
-
-    /*
-     * Endpoint for getTitulacions
-     */
-    @GetMapping("/getTitulacionsWithCentre")
-    public List<OrganDTO> getTitulacionsWithCentre() {
-        return os.findAllTitulacionsWithCentre();
-    }
-
-    /*
-     * Endopint for findByRuct
-     */
-    @GetMapping("/getAllIndsByRuct/{ruct}/{curs}")
-    public List<IndicadorEnquesta> getAllIndsByRuct(@PathVariable Integer ruct, @PathVariable Integer curs) {
-        Organ o = os.findByRuct(ruct); 
-        return ies.getAllInds(o, curs);
-    }
-
-    @GetMapping("/getOrgByRuct/{ruct}")
-    public OrganDTO getOrgByRuct(@PathVariable Integer ruct) {
-        return os.findByRuctDTO(ruct);
-    }
-
-    /*
-     * Endpoint para findById
-     */
-    @GetMapping("/findById/{tlugar}/{idTitulacio}")
-    public ResponseEntity<?> findById(@PathVariable String tlugar,  @PathVariable Integer idTitulacio) {
-        try {
-            Organ organ = os.findByID(tlugar, idTitulacio);
-            OrganTransferDTO organTransferDTO = new OrganTransferDTO(organ);
-
-            return ResponseEntity.ok(organTransferDTO);
-        } catch(Exception e) {
-            return ResponseEntity.badRequest().body("Error al obtener el organo" +
-                " por tlugar y titulación: " + e.getMessage());
-        }
-    }
-
-    /*
-     * Endpoint para getTitulacionsByTypeCentre
-     */
-    @GetMapping("/getTitulacionsByTypeCentre/{lugar}/{ambit}")
-    public ResponseEntity<?> getTitulacionsByTypeCentre(@PathVariable Integer lugar, @PathVariable Integer ambit) {
-        try {
-            List<Organ> organList = os.getTitulacionsByTypeCentre(lugar, ambit);
-            List<OrganTransferDTO> organDTOList = new ArrayList<>();
-            
-            for(Organ org: organList) {
-                organDTOList.add(new OrganTransferDTO(org));
-            }
-
-            return ResponseEntity.ok(organDTOList);
-        } catch(Exception e) {
-            return ResponseEntity.badRequest().body("Error al obtener los organos" +
-                " por lugar y ambit: " + e.getMessage());
-        }
-    }
-
-    @GetMapping("/existsOrg/{tlugar}/{idTitulacio}")
-    public boolean existsOrg(@PathVariable String tlugar,  @PathVariable Integer idTitulacio) {
-        return os.exists(tlugar, idTitulacio);
-    }
-
-    @GetMapping("/getTitulacionsByCentreTambit/{centre}/{tambit}")
-    public ResponseEntity<?> getTitulacionsByCentreTambit(@PathVariable Integer lugar, @PathVariable String tambit) {
-        try {
-            List<Organ> organList = os.findActiveTitulacionsByCentreTambit(lugar, tambit);
-            List<OrganTransferDTO> organDTOList = new ArrayList<>();
-
-            for(Organ org: organList) {
-                organDTOList.add(new OrganTransferDTO(org));
-            }
-
-            return ResponseEntity.ok(organDTOList);
-        } catch(Exception e) {
-            return ResponseEntity.badRequest().body("Error al obtener los organos" +
-                " por lugar y ambit: " + e.getMessage());
-        }
-    }
-}

+ 6 - 58
src/main/java/es/uv/saic/web/ParseController.java

@@ -12,48 +12,22 @@ import org.springframework.security.access.annotation.Secured;
 import org.springframework.security.core.Authentication;
 import org.springframework.stereotype.Controller;
 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.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
 public class ParseController {
 
 	@Autowired
-	private ParserService ps;
-	@Autowired
-	private IndicadorEnquestaService ies;
+	private ParseClient pc;
+
 	@Value("${saic.parser.surveys.path}")
 	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
 	 * @param model
 	 * @param auth Authentication
@@ -66,11 +40,7 @@ public class ParseController {
 	@Secured({"ROLE_ADMIN"})
 	public void doParse(Model model, Authentication auth, HttpServletResponse response, @RequestParam String database, 
 			@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"})
 	public void doAction(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action) 
 			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"})
 	public void doDelete(Model model, Authentication auth, HttpServletResponse response, @RequestParam String action, @RequestParam Integer year) 
 			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);
 	}
 		
 }