1
|
package eu.dnetlib.enabling.inspector;
|
2
|
|
3
|
import java.util.Collections;
|
4
|
import java.util.List;
|
5
|
import java.util.stream.Collectors;
|
6
|
import javax.annotation.PostConstruct;
|
7
|
import javax.servlet.http.HttpServletRequest;
|
8
|
|
9
|
import org.springframework.beans.factory.annotation.Autowired;
|
10
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
11
|
|
12
|
|
13
|
|
14
|
/**
|
15
|
* Common stuff for the inspector controllers.
|
16
|
*
|
17
|
* @author marko
|
18
|
*
|
19
|
*/
|
20
|
public abstract class AbstractInspectorController { // NOPMD
|
21
|
/**
|
22
|
* entry point groups
|
23
|
*/
|
24
|
@Autowired
|
25
|
List<EntryPointDescriptorGroup> entryPointsGroups;
|
26
|
|
27
|
/**
|
28
|
* sort entry point groups according to the group name.
|
29
|
*/
|
30
|
@PostConstruct
|
31
|
public void sortEntryPointGroups() {
|
32
|
Collections.sort(entryPointsGroups, (o1, o2) -> o1.getName().compareTo(o2.getName()));
|
33
|
}
|
34
|
|
35
|
/**
|
36
|
* common base url for all inspector pages.
|
37
|
*
|
38
|
* @param request
|
39
|
* http request
|
40
|
* @return base url
|
41
|
*/
|
42
|
@ModelAttribute("baseUrl")
|
43
|
public String baseUrl(final HttpServletRequest request) {
|
44
|
return request.getContextPath() + "/mvc/inspector";
|
45
|
}
|
46
|
|
47
|
@ModelAttribute("entryPointGroups")
|
48
|
public List<EntryPointDescriptorGroup> entryPointGroups() {
|
49
|
return entryPointsGroups;
|
50
|
}
|
51
|
/**
|
52
|
* Obtain a list of entry points, ordered by groups.
|
53
|
*
|
54
|
* @return
|
55
|
*/
|
56
|
@ModelAttribute("entryPoints")
|
57
|
public <R> List<EntryPointDescriptorModel> entryPoints(final HttpServletRequest request) {
|
58
|
final String currentRelativeUrl = request.getPathInfo().replaceAll("/inspector/(.*\\.do).*", "$1");
|
59
|
|
60
|
return entryPointGroups().stream()
|
61
|
.flatMap(
|
62
|
group -> group.getDescriptors().stream()
|
63
|
.map(it ->
|
64
|
generateEntryPointDescriptorModel(it, currentRelativeUrl)))
|
65
|
.collect(Collectors.toList());
|
66
|
}
|
67
|
|
68
|
private EntryPointDescriptorModel generateEntryPointDescriptorModel(final EntryPointDescriptor it, final String currentRelativeUrl) {
|
69
|
return new EntryPointDescriptorModel(it.getName(), it.getRelativeUrl(), currentRelativeUrl.equals(it.getRelativeUrl()),
|
70
|
it.isHiddenAsDefault());
|
71
|
}
|
72
|
|
73
|
|
74
|
|
75
|
}
|