Skip to content
Snippets Groups Projects
Unverified Commit e3bdf7db authored by BARBIER Marc's avatar BARBIER Marc
Browse files

centralized getCurrentItem

parent 3a6dc14e
No related branches found
No related tags found
No related merge requests found
package be.uantwerpen.mime_webapp.controller;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import be.uantwerpen.mime_webapp.dao.ProjectRepository;
import be.uantwerpen.mime_webapp.model.FileItem;
import be.uantwerpen.mime_webapp.model.MySession;
@RestController
public abstract class AbstractController {
@Autowired
ProjectRepository repository;
protected FileItem getCurrentItem(HttpServletRequest request, Optional<String> id){
FileItem currentInput = null;
if(id.isPresent()) {
currentInput = repository.findItemById(id.get().trim());
if(currentInput != null) return currentInput;
}
MySession session = (MySession) request.getSession().getAttribute("mySession");
return repository.findItemById(session.getCurrentItem());
}
}
...@@ -19,7 +19,7 @@ import be.uantwerpen.mime_webapp.model.MySession; ...@@ -19,7 +19,7 @@ import be.uantwerpen.mime_webapp.model.MySession;
import be.uantwerpen.mime_webapp.model.Project; import be.uantwerpen.mime_webapp.model.Project;
@RestController @RestController
public class DataManagementController { public class DataManagementController extends AbstractController{
@RequestMapping("/") @RequestMapping("/")
public String index() { public String index() {
......
...@@ -7,9 +7,7 @@ import java.util.Map; ...@@ -7,9 +7,7 @@ import java.util.Map;
import java.util.Optional; import java.util.Optional;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -20,15 +18,12 @@ import be.uantwerpen.ldataminining.preprocessing.ArffStatistics; ...@@ -20,15 +18,12 @@ import be.uantwerpen.ldataminining.preprocessing.ArffStatistics;
import be.uantwerpen.ldataminining.preprocessing.ArffUtils; import be.uantwerpen.ldataminining.preprocessing.ArffUtils;
import be.uantwerpen.ldataminining.preprocessing.FindNullPattern; import be.uantwerpen.ldataminining.preprocessing.FindNullPattern;
import be.uantwerpen.ldataminining.utils.CollectionUtils; import be.uantwerpen.ldataminining.utils.CollectionUtils;
import be.uantwerpen.mime_webapp.dao.ProjectRepository;
import be.uantwerpen.mime_webapp.model.FileItem; import be.uantwerpen.mime_webapp.model.FileItem;
import be.uantwerpen.mime_webapp.model.MySession;
@RestController @RestController
public class FileItemMetadataController { public class FileItemMetadataController extends AbstractController {
@Autowired
ProjectRepository repository;
/** /**
* returns name/type for all attributes * returns name/type for all attributes
...@@ -39,13 +34,7 @@ public class FileItemMetadataController { ...@@ -39,13 +34,7 @@ public class FileItemMetadataController {
@RequestMapping(value="/rest/metadata/attributes", method=RequestMethod.GET) @RequestMapping(value="/rest/metadata/attributes", method=RequestMethod.GET)
public @ResponseBody List<Map<String,String>> getSchema(@RequestParam("id") Optional<String> id, HttpServletRequest request) public @ResponseBody List<Map<String,String>> getSchema(@RequestParam("id") Optional<String> id, HttpServletRequest request)
{ {
FileItem item = null; FileItem item = getCurrentItem(request, id);
if(id.isPresent()) {
item = repository.findItemById(id.get().trim());
}
if(item == null) {
item = getCurrentItem(request.getSession());
}
if(item == null) if(item == null)
return new ArrayList<>(); return new ArrayList<>();
...@@ -68,16 +57,10 @@ public class FileItemMetadataController { ...@@ -68,16 +57,10 @@ public class FileItemMetadataController {
} }
} }
@RequestMapping(value="/rest/metadata/attribute-and-statistics", method=RequestMethod.GET) @GetMapping(value="/rest/metadata/attribute-and-statistics")
public @ResponseBody List<Map<String,String>> getAttributeStatistics(@RequestParam("id") Optional<String> id, HttpServletRequest request) public @ResponseBody List<Map<String,String>> getAttributeStatistics(@RequestParam("id") Optional<String> id, HttpServletRequest request)
{ {
FileItem currentItem = null; FileItem currentItem = getCurrentItem(request, id);
if(id.isPresent()) {
currentItem = repository.findItemById(id.get().trim());
}
if(currentItem == null) {
currentItem = getCurrentItem(request.getSession());
}
if(currentItem == null) { if(currentItem == null) {
return null; return null;
...@@ -96,9 +79,9 @@ public class FileItemMetadataController { ...@@ -96,9 +79,9 @@ public class FileItemMetadataController {
@RequestMapping(value="/rest/metadata/nullpatterns", method=RequestMethod.GET) @RequestMapping(value="/rest/metadata/nullpatterns", method=RequestMethod.GET)
public @ResponseBody List<List<String>> getNullPatterns(HttpServletRequest request) public @ResponseBody List<List<String>> getNullPatterns(@RequestParam("id") Optional<String> id, HttpServletRequest request)
{ {
FileItem item = getCurrentItem(request.getSession()); FileItem item = getCurrentItem(request, id);
if(item == null) if(item == null)
return null; return null;
if(!item.isArff()) { if(!item.isArff()) {
...@@ -114,23 +97,13 @@ public class FileItemMetadataController { ...@@ -114,23 +97,13 @@ public class FileItemMetadataController {
} }
@RequestMapping(value="/rest/metadata/fileitem", method=RequestMethod.GET) @RequestMapping(value="/rest/metadata/fileitem", method=RequestMethod.GET)
public @ResponseBody FileItem getFileItem(HttpServletRequest request) public @ResponseBody FileItem getFileItem(@RequestParam("id") Optional<String> id, HttpServletRequest request)
{ {
FileItem item = getCurrentItem(request.getSession()); FileItem item = getCurrentItem(request, id);
if(item == null) if(item == null)
return null; return null;
else else
return item; return item;
} }
private FileItem getCurrentItem(HttpSession httpSession){
MySession session = (MySession) httpSession.getAttribute("mySession");
if(session == null)
return null;
String id = session.getCurrentItem();
return repository.findItemById(id);
}
} }
...@@ -4,7 +4,6 @@ import java.io.BufferedOutputStream; ...@@ -4,7 +4,6 @@ import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -16,16 +15,11 @@ import be.uantwerpen.ldataminining.preprocessing.ArffUtils; ...@@ -16,16 +15,11 @@ import be.uantwerpen.ldataminining.preprocessing.ArffUtils;
import be.uantwerpen.ldataminining.preprocessing.CSVUtils; import be.uantwerpen.ldataminining.preprocessing.CSVUtils;
import be.uantwerpen.ldataminining.utils.IOUtils; import be.uantwerpen.ldataminining.utils.IOUtils;
import be.uantwerpen.mime_webapp.Settings; import be.uantwerpen.mime_webapp.Settings;
import be.uantwerpen.mime_webapp.dao.ProjectRepository;
import be.uantwerpen.mime_webapp.model.FileItem; import be.uantwerpen.mime_webapp.model.FileItem;
import be.uantwerpen.mime_webapp.model.Project; import be.uantwerpen.mime_webapp.model.Project;
@Controller @Controller
public class FileItemUploadController { public class FileItemUploadController extends AbstractController{
@Autowired
private ProjectRepository repository;
@RequestMapping(value="/rest/upload", method=RequestMethod.GET) @RequestMapping(value="/rest/upload", method=RequestMethod.GET)
public @ResponseBody String provideUploadInfo() { public @ResponseBody String provideUploadInfo() {
return "You can upload a file by posting to this same URL."; return "You can upload a file by posting to this same URL.";
......
...@@ -17,7 +17,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -17,7 +17,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
...@@ -43,7 +42,6 @@ import be.uantwerpen.ldataminining.utils.Timer; ...@@ -43,7 +42,6 @@ import be.uantwerpen.ldataminining.utils.Timer;
import be.uantwerpen.ldataminining.utils.Triple; import be.uantwerpen.ldataminining.utils.Triple;
import be.uantwerpen.ldataminining.utils.Utils; import be.uantwerpen.ldataminining.utils.Utils;
import be.uantwerpen.mime_webapp.Settings; import be.uantwerpen.mime_webapp.Settings;
import be.uantwerpen.mime_webapp.dao.ProjectRepository;
import be.uantwerpen.mime_webapp.model.AnomalyScores; import be.uantwerpen.mime_webapp.model.AnomalyScores;
import be.uantwerpen.mime_webapp.model.FileItem; import be.uantwerpen.mime_webapp.model.FileItem;
import be.uantwerpen.mime_webapp.model.MySession; import be.uantwerpen.mime_webapp.model.MySession;
...@@ -51,11 +49,7 @@ import be.uantwerpen.mime_webapp.model.PatternSet; ...@@ -51,11 +49,7 @@ import be.uantwerpen.mime_webapp.model.PatternSet;
import be.uantwerpen.mime_webapp.model.Project; import be.uantwerpen.mime_webapp.model.Project;
@RestController @RestController
public class PatternMiningController { public class PatternMiningController extends AbstractController{
@Autowired
ProjectRepository repository;
MakePatternOccurrences makePatternOccurrences = new MakePatternOccurrences(); MakePatternOccurrences makePatternOccurrences = new MakePatternOccurrences();
MakePatternOccurrencesSpan makePatternOccurrencesSpan = new MakePatternOccurrencesSpan(); MakePatternOccurrencesSpan makePatternOccurrencesSpan = new MakePatternOccurrencesSpan();
RunPBADEmbeddingOnly runPBADEmbeddingOnly = new RunPBADEmbeddingOnly(); RunPBADEmbeddingOnly runPBADEmbeddingOnly = new RunPBADEmbeddingOnly();
...@@ -744,16 +738,4 @@ public class PatternMiningController { ...@@ -744,16 +738,4 @@ public class PatternMiningController {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private FileItem getCurrentItem(HttpServletRequest request, Optional<String> id){
FileItem currentInput = null;
if(id.isPresent()) {
currentInput = repository.findItemById(id.get().trim());
if(currentInput != null) return currentInput;
}
MySession session = (MySession) request.getSession().getAttribute("mySession");
return repository.findItemById(session.getCurrentItem());
}
} }
...@@ -25,7 +25,6 @@ import javax.servlet.http.HttpSession; ...@@ -25,7 +25,6 @@ import javax.servlet.http.HttpSession;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference; import org.codehaus.jackson.type.TypeReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -55,16 +54,12 @@ import be.uantwerpen.ldataminining.utils.IOUtils; ...@@ -55,16 +54,12 @@ import be.uantwerpen.ldataminining.utils.IOUtils;
import be.uantwerpen.ldataminining.utils.MathUtils; import be.uantwerpen.ldataminining.utils.MathUtils;
import be.uantwerpen.ldataminining.utils.Triple; import be.uantwerpen.ldataminining.utils.Triple;
import be.uantwerpen.ldataminining.utils.Utils; import be.uantwerpen.ldataminining.utils.Utils;
import be.uantwerpen.mime_webapp.dao.ProjectRepository;
import be.uantwerpen.mime_webapp.model.FileItem; import be.uantwerpen.mime_webapp.model.FileItem;
import be.uantwerpen.mime_webapp.model.MySession; import be.uantwerpen.mime_webapp.model.MySession;
import be.uantwerpen.mime_webapp.model.Project; import be.uantwerpen.mime_webapp.model.Project;
@RestController @RestController
public class TransformController { public class TransformController extends AbstractController{
@Autowired
ProjectRepository repository;
@RequestMapping(value="/rest/transform/convert-to-arff", method=RequestMethod.POST) @RequestMapping(value="/rest/transform/convert-to-arff", method=RequestMethod.POST)
public @ResponseBody void convertToArff( public @ResponseBody void convertToArff(
...@@ -1249,15 +1244,4 @@ public class TransformController { ...@@ -1249,15 +1244,4 @@ public class TransformController {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
private FileItem getCurrentItem(HttpServletRequest request, Optional<String> id){
FileItem currentInput = null;
if(id.isPresent()) {
currentInput = repository.findItemById(id.get().trim());
if(currentInput != null) return currentInput;
}
MySession session = (MySession) request.getSession().getAttribute("mySession");
return repository.findItemById(session.getCurrentItem());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment