Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dariah
search
Commits
92ef8d7e
Commit
92ef8d7e
authored
Jul 15, 2021
by
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
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
search-core/src/main/java/eu/dariah/de/search/controller/search/ItemController.java
View file @
92ef8d7e
...
...
@@ -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
);
...
...
search-core/src/main/java/eu/dariah/de/search/controller/search/SimpleSearchController.java
View file @
92ef8d7e
...
...
@@ -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
);
}
...
...
search-core/src/main/java/eu/dariah/de/search/controller/search/base/BaseSimpleSearchController.java
View file @
92ef8d7e
...
...
@@ -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
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment