Commit 92ef8d7e authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

437: Show result highlight in item view (OPENED)

Task-Url: #437
parent 51c9dab2
Pipeline #25488 passed with stage
in 41 seconds
...@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -20,6 +20,7 @@ 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.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -51,7 +52,7 @@ import eu.dariah.de.search.service.DatamodelService; ...@@ -51,7 +52,7 @@ import eu.dariah.de.search.service.DatamodelService;
@RequestMapping("/item/{type}/{itemId}") @RequestMapping("/item/{type}/{itemId}")
public class ItemController extends BaseController { public class ItemController extends BaseController {
private static final String ITEM_404_VIEW = "item/404"; private static final String ITEM_404_VIEW = "item/404";
@Autowired private CollectionService collectionService; @Autowired private CollectionService collectionService;
@Autowired private DatamodelService datamodelService; @Autowired private DatamodelService datamodelService;
@Autowired private ItemService itemService; @Autowired private ItemService itemService;
...@@ -69,11 +70,6 @@ public class ItemController extends BaseController { ...@@ -69,11 +70,6 @@ public class ItemController extends BaseController {
@GetMapping(value = "/") @GetMapping(value = "/")
public String getItem(@PathVariable String type, @PathVariable String itemId, Model model, Locale locale, HttpServletResponse response) throws IOException { public String getItem(@PathVariable String type, @PathVariable String itemId, Model model, Locale locale, HttpServletResponse response) throws IOException {
return this.postItem(type, itemId, null, model, locale, response);
}
@PostMapping(value = "/")
public String postItem(@PathVariable String type, @PathVariable String itemId, @RequestParam(required= false, name="query") String jsonQuery, Model model, Locale locale, HttpServletResponse response) throws IOException {
model.addAttribute("itemId", itemId); model.addAttribute("itemId", itemId);
if (itemId==null || type==null) { if (itemId==null || type==null) {
return ITEM_404_VIEW; return ITEM_404_VIEW;
...@@ -84,14 +80,15 @@ public class ItemController extends BaseController { ...@@ -84,14 +80,15 @@ public class ItemController extends BaseController {
} }
Query query = null; Query query = null;
if (jsonQuery!=null && !jsonQuery.isBlank()) { if (model.asMap().containsKey("jsonQuery") && model.asMap().get("jsonQuery")!=null) {
try { try {
query = queryExecutionService.deserializeQuery(jsonQuery); query = queryExecutionService.deserializeQuery(String.class.cast(model.asMap().get("jsonQuery")));
} catch (QueryExecutionException e) { } catch (QueryExecutionException e) {
logger.error("Failed to deserialize query", e); logger.error("Failed to deserialize query", e);
} }
} }
JsonNode itemSource = null; JsonNode itemSource = null;
ResultElement item = null; ResultElement item = null;
if (query!=null) { if (query!=null) {
...@@ -156,6 +153,14 @@ public class ItemController extends BaseController { ...@@ -156,6 +153,14 @@ public class ItemController extends BaseController {
return "item/view"; return "item/view";
} }
@PostMapping(value = "/")
public String postItem(@PathVariable String type, @PathVariable String itemId, @RequestParam(required= false, name="query") String jsonQuery, Model model, Locale locale, RedirectAttributes attributes, HttpServletResponse response) throws IOException {
if (jsonQuery!=null) {
attributes.addFlashAttribute("jsonQuery", jsonQuery);
}
return String.format("redirect:/item/%s/%s/", type, itemId);
}
private void findReferencingParents(List<ResultElement> rootedParents, ResultElement item, ResultElementRelationTypes relationType) { private void findReferencingParents(List<ResultElement> rootedParents, ResultElement item, ResultElementRelationTypes relationType) {
rootedParents.add(0, item); rootedParents.add(0, item);
......
...@@ -38,19 +38,8 @@ public class SimpleSearchController extends BaseSimpleSearchController { ...@@ -38,19 +38,8 @@ public class SimpleSearchController extends BaseSimpleSearchController {
return new ModelAndView("redirect:/search/simple/"); return new ModelAndView("redirect:/search/simple/");
} }
@SuppressWarnings("unchecked")
@GetMapping(value="/") @GetMapping(value="/")
public ModelAndView getViewAndQuery(@RequestParam(required=false, name="q") String expression, @RequestParam(required=false, name="sourceId") List<String> sourceIds, RedirectAttributes attributes, Model model, HttpServletRequest request, Locale locale) { public ModelAndView getViewAndQuery(@RequestParam(required=false, name="q") String expression, @RequestParam(required=false, name="sourceId") List<String> sourceIds, RedirectAttributes attributes, Model model, HttpServletRequest request, Locale locale) {
if (this.isNeedsRedirect(expression, sourceIds, attributes)) {
return new ModelAndView("redirect:/search/simple/");
}
if (model.asMap().containsKey("redirectExpression") && model.asMap().get("redirectExpression")!=null) {
expression = (String)model.asMap().get("redirectExpression");
}
if (model.asMap().containsKey("redirectSourceIds") && model.asMap().get("redirectSourceIds")!=null) {
sourceIds = (List<String>)model.asMap().get("redirectSourceIds");
}
List<String> notifications = new ArrayList<>(); List<String> notifications = new ArrayList<>();
List<Collection> collections = collectionService.getAll(); List<Collection> collections = collectionService.getAll();
...@@ -59,7 +48,6 @@ public class SimpleSearchController extends BaseSimpleSearchController { ...@@ -59,7 +48,6 @@ public class SimpleSearchController extends BaseSimpleSearchController {
model.addAttribute("availableFilters", filterService.getAllAvailableFilters()); model.addAttribute("availableFilters", filterService.getAllAvailableFilters());
model.addAttribute("searchNotifications", notifications); model.addAttribute("searchNotifications", notifications);
return super.getViewAndQuery(expression, sourceIds, model, locale); return super.getViewAndQuery(expression, sourceIds, model, locale);
} }
......
...@@ -5,7 +5,6 @@ import java.util.Locale; ...@@ -5,7 +5,6 @@ import java.util.Locale;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import eu.dariah.de.search.query.SimpleQueryImpl; import eu.dariah.de.search.query.SimpleQueryImpl;
...@@ -24,17 +23,4 @@ public abstract class BaseSimpleSearchController extends BaseSearchController { ...@@ -24,17 +23,4 @@ public abstract class BaseSimpleSearchController extends BaseSearchController {
return new ModelAndView("search/simple", model.asMap()); return new ModelAndView("search/simple", model.asMap());
} }
protected boolean isNeedsRedirect(String expression, List<String> sourceIds, RedirectAttributes attributes) {
if (expression!=null || (sourceIds!=null && !sourceIds.isEmpty())) {
if (expression!=null) {
attributes.addFlashAttribute("redirectExpression", expression);
}
if (sourceIds!=null && !sourceIds.isEmpty()) {
attributes.addFlashAttribute("redirectSourceIds", sourceIds);
}
return true;
}
return false;
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment