-
Notifications
You must be signed in to change notification settings - Fork 4
BUG/CITE-212: Adding search endpoint with collections #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 4 commits
31bad6e
0f070c3
1055f4d
cd7e94a
8debefb
a59e176
469c014
857052f
83d0b27
18855ca
c0681fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,10 @@ | |
|
|
||
| import edu.asu.diging.citesphere.core.search.service.SearchEngine; | ||
| import edu.asu.diging.citesphere.core.search.service.impl.ResultPage; | ||
| import edu.asu.diging.citesphere.core.service.ICitationCollectionManager; | ||
| import edu.asu.diging.citesphere.core.service.IGroupManager; | ||
| import edu.asu.diging.citesphere.model.bib.ICitation; | ||
| import edu.asu.diging.citesphere.model.bib.ICitationCollection; | ||
| import edu.asu.diging.citesphere.model.bib.ICitationGroup; | ||
| import edu.asu.diging.citesphere.user.IUser; | ||
| import edu.asu.diging.citesphere.web.BreadCrumb; | ||
|
|
@@ -37,6 +39,9 @@ public class SearchController { | |
|
|
||
| @Autowired | ||
| private IGroupManager groupManager; | ||
|
|
||
| @Autowired | ||
| private ICitationCollectionManager collectionManager; | ||
|
|
||
| @Value("${_zotero_page_size}") | ||
| private Integer zoteroPageSize; | ||
|
|
@@ -101,4 +106,78 @@ public String search(@PathVariable String zoteroGroupId, | |
| model.addAttribute("breadCrumbs", breadCrumbs); | ||
| return "auth/group/items"; | ||
| } | ||
|
|
||
| @RequestMapping(value = {"/auth/group/{zoteroGroupId}/collection/{collectionId}/search"}) | ||
| public String searchCollection(@PathVariable String zoteroGroupId, | ||
| @PathVariable(value="collectionId", required=false) String collectionId, | ||
| @RequestParam(value = "searchTerm", required = false) String searchTerm, Model model, | ||
| @RequestParam(defaultValue = "0", required = false, value = "page") String page, | ||
| @RequestParam(defaultValue = "title", required = false, value = "sort") String sort, | ||
| @RequestParam(required = false, value = "columns") String[] columns, Authentication authentication) { | ||
| IUser user = (IUser) authentication.getPrincipal(); | ||
| ICitationGroup group = groupManager.getGroup(user, zoteroGroupId); | ||
|
|
||
| if (group == null) { | ||
| logger.error("User " + user.getUsername() + " does not have access to group " + zoteroGroupId); | ||
| return "error/404"; | ||
|
||
| } | ||
|
|
||
| if (searchTerm == null || searchTerm.trim().isEmpty()) { | ||
| return "redirect:/auth/group/" + zoteroGroupId + "/collection/" + collectionId + "/items"; | ||
| } | ||
|
|
||
| Integer pageInt = 1; | ||
| try { | ||
| pageInt = new Integer(page); | ||
| } catch (NumberFormatException ex) { | ||
| logger.warn("Trying to access invalid page number: " + page); | ||
| } | ||
|
|
||
| pageInt = pageInt > 0 ? pageInt : 1; | ||
|
|
||
| ResultPage citations = engine.search(searchTerm, zoteroGroupId, collectionId, pageInt-1, 50); | ||
|
|
||
| model.addAttribute("searchTerm", searchTerm); | ||
| model.addAttribute("items", citations.getResults()); | ||
| model.addAttribute("totalPages", Math.max(1, citations.getTotalPages())); | ||
| model.addAttribute("total", citations.getTotalResults()); | ||
| model.addAttribute("currentPage", pageInt); | ||
| model.addAttribute("zoteroGroupId", zoteroGroupId); | ||
| model.addAttribute("collectionId", collectionId); | ||
| model.addAttribute("group", groupManager.getGroup(user, zoteroGroupId)); | ||
| model.addAttribute("sort", sort); | ||
|
|
||
| List<String> allowedColumns = Arrays.asList(availableColumns.split(",")); | ||
| List<String> shownColumns = new ArrayList<>(); | ||
| if (columns != null && columns.length > 0) { | ||
| for (String column : columns) { | ||
| if (allowedColumns.contains(column)) { | ||
| shownColumns.add(column); | ||
| } | ||
| } | ||
| } | ||
| model.addAttribute("columns", shownColumns); | ||
| model.addAttribute("availableColumns", allowedColumns); | ||
|
|
||
| List<BreadCrumb> breadCrumbs = new ArrayList<>(); | ||
| ICitationCollection collection = null; | ||
| if (collectionId != null) { | ||
| collection = collectionManager.getCollection(user, zoteroGroupId, collectionId); | ||
| if(collection != null) { | ||
| model.addAttribute("collectionName", collection.getName()); | ||
| } | ||
| } | ||
| while(collection != null) { | ||
| breadCrumbs.add(new BreadCrumb(collection.getName(), BreadCrumbType.COLLECTION, collection.getKey(), collection)); | ||
| if (collection.getParentCollectionKey() != null) { | ||
| collection = collectionManager.getCollection(user, zoteroGroupId, collection.getParentCollectionKey()); | ||
| } else { | ||
| collection = null; | ||
| } | ||
| } | ||
| breadCrumbs.add(new BreadCrumb(group.getName(), BreadCrumbType.GROUP, group.getGroupId() + "", group)); | ||
| Collections.reverse(breadCrumbs); | ||
| model.addAttribute("breadCrumbs", breadCrumbs); | ||
| return "auth/group/items"; | ||
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, looks like pretty much the same as the above method. I actually doubt you'll need two separate methods. |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this pretty much the same code as in the search method above? DRY