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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
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.ObjectMapper;
......@@ -51,7 +52,7 @@ import eu.dariah.de.search.service.DatamodelService;
@RequestMapping("/item/{type}/{itemId}")
public class ItemController extends BaseController {
private static final String ITEM_404_VIEW = "item/404";
@Autowired private CollectionService collectionService;
@Autowired private DatamodelService datamodelService;
@Autowired private ItemService itemService;
......@@ -69,11 +70,6 @@ public class ItemController extends BaseController {
@GetMapping(value = "/")
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);
if (itemId==null || type==null) {
return ITEM_404_VIEW;
......@@ -84,14 +80,15 @@ public class ItemController extends BaseController {
}
Query query = null;
if (jsonQuery!=null && !jsonQuery.isBlank()) {
if (model.asMap().containsKey("jsonQuery") && model.asMap().get("jsonQuery")!=null) {
try {
query = queryExecutionService.deserializeQuery(jsonQuery);
query = queryExecutionService.deserializeQuery(String.class.cast(model.asMap().get("jsonQuery")));
} catch (QueryExecutionException e) {
logger.error("Failed to deserialize query", e);
}
}
JsonNode itemSource = null;
ResultElement item = null;
if (query!=null) {
......@@ -156,6 +153,14 @@ public class ItemController extends BaseController {
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) {
rootedParents.add(0, item);
......
......@@ -38,19 +38,8 @@ public class SimpleSearchController extends BaseSimpleSearchController {
return new ModelAndView("redirect:/search/simple/");
}
@SuppressWarnings("unchecked")
@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) {
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<Collection> collections = collectionService.getAll();
......@@ -59,7 +48,6 @@ public class SimpleSearchController extends BaseSimpleSearchController {
model.addAttribute("availableFilters", filterService.getAllAvailableFilters());
model.addAttribute("searchNotifications", notifications);
return super.getViewAndQuery(expression, sourceIds, model, locale);
}
......
......@@ -5,7 +5,6 @@ import java.util.Locale;
import org.springframework.ui.Model;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import eu.dariah.de.search.query.SimpleQueryImpl;
......@@ -24,17 +23,4 @@ public abstract class BaseSimpleSearchController extends BaseSearchController {
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;
}
}
Markdown is supported
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