Skip to content

Commit

Permalink
Add search gui, node labels, and status filtering (#194)
Browse files Browse the repository at this point in the history
* Search form and results page in webapp

- Initial search results page, needs tests.
- Removed original search form and replaced with one that uses GET. All filters/searches use GET so that the URL can be bookmarked
- Includes filters for status, date, and agent

* Add node labels, add support for status filter on all data views

- use search index to create meaningful node labels
- refactored graph model to support new labels
- add label to top of resource summary page
- add ability to filter by status on all views (incomplete) - this is to resolve a problem where you can only see active statements on Resource Summary, but in future could be used to toggle agent filters and other things on Resource view.

* GUI changes to support status filter

back end was already configured, this adds a checkbox to toggle status
on and off, and shows messages/tooltips to prompt people to show
inactive.

* Added more webapp search gui tests, improved  existing tests

Added basic tests for new search and label functionality.
For existing tests, shifted them to depend on mocks rather than embedded solr, where possible.
Rearranged and improved TestUtils.
  • Loading branch information
karenhanson authored and emetsger committed Jan 12, 2018
1 parent f1c7cd1 commit b5c871c
Show file tree
Hide file tree
Showing 57 changed files with 4,098 additions and 902 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import info.rmapproject.core.model.request.RMapSearchParams;
import info.rmapproject.core.model.request.RMapSearchParamsFactory;
import info.rmapproject.core.model.request.RMapStatusFilter;
import info.rmapproject.core.model.request.ResultBatch;
import info.rmapproject.webapp.domain.Graph;
import info.rmapproject.webapp.domain.PageStatus;
Expand All @@ -58,12 +61,16 @@ public class AgentDisplayController {
/** Service for managing RMap data display. */
private DataDisplayService dataDisplayService;

/**used to get instances of RMapSearchParams which passes search properties to rmap**/
private RMapSearchParamsFactory paramsFactory;

/** term for standard view, used in VIEWMODE. */
private static final String STANDARD_VIEW = "standard";

@Autowired
public AgentDisplayController(DataDisplayService dataDisplayService) {
public AgentDisplayController(DataDisplayService dataDisplayService, RMapSearchParamsFactory paramsFactory) {
this.dataDisplayService = dataDisplayService;
this.paramsFactory = paramsFactory;
}

/**
Expand Down Expand Up @@ -213,15 +220,22 @@ public String agentGraphData(@PathVariable(value="uri") String agentUri,
*/
@RequestMapping(value="/agents/{uri}/discos", method = RequestMethod.GET)
public String agentRelatedDiSCOs(@PathVariable(value="uri") String agentUri, Model model,
@RequestParam(value="offset", required=false) Integer offset) throws Exception {
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status) throws Exception {
LOG.info("Agent requested: {}", agentUri);
if (offset==null){
offset=0;
}
try {
agentUri = URLDecoder.decode(agentUri, "UTF-8");

ResultBatch<URI> agentDiSCOs = dataDisplayService.getAgentDiSCOs(agentUri, offset);
RMapStatusFilter statusFilter = RMapStatusFilter.getStatusFromTerm(status);
statusFilter = (statusFilter==null) ? RMapStatusFilter.ACTIVE : statusFilter;
RMapSearchParams params = paramsFactory.newInstance();
params.setStatusCode(statusFilter);
params.setOffset(offset);

ResultBatch<URI> agentDiSCOs = dataDisplayService.getAgentDiSCOs(agentUri, params);
PageStatus pageStatus = dataDisplayService.getPageStatus(agentDiSCOs, PaginatorType.AGENT_DISCOS);
model.addAttribute("PAGINATOR", pageStatus);
model.addAttribute("AGENT_DISCOS", agentDiSCOs.getResultList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import info.rmapproject.webapp.domain.SearchForm;

/**
* Handles display of the home and contact pages.
*
Expand All @@ -47,11 +45,6 @@ public class HomeController {
*/
@RequestMapping(value={"/", "/home"}, method = RequestMethod.GET)
public String home(Locale locale, Model model) {
if (!model.containsAttribute("search")){
//otherwise initiate search form.
SearchForm search = new SearchForm();
model.addAttribute("search", search);
}
return "home";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package info.rmapproject.webapp.controllers;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
Expand All @@ -38,13 +37,16 @@
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import info.rmapproject.core.exception.RMapObjectNotFoundException;
import info.rmapproject.core.model.RMapTriple;
import info.rmapproject.core.model.request.RMapSearchParams;
import info.rmapproject.core.model.request.RMapSearchParamsFactory;
import info.rmapproject.core.model.request.RMapStatusFilter;
import info.rmapproject.core.model.request.ResultBatch;
import info.rmapproject.webapp.domain.Graph;
import info.rmapproject.webapp.domain.PageStatus;
import info.rmapproject.webapp.domain.PaginatorType;
import info.rmapproject.webapp.domain.ResourceDescription;
import info.rmapproject.webapp.domain.SearchForm;
import info.rmapproject.webapp.exception.ErrorCode;
import info.rmapproject.webapp.exception.RMapWebException;
import info.rmapproject.webapp.service.DataDisplayService;
Expand All @@ -58,16 +60,25 @@
@SessionAttributes({"user","account"})
public class ResourceDisplayController {

/** Service for managing RMap data display. */
@Autowired
private DataDisplayService dataDisplayService;

/** The log. */
private static final Logger LOG = LoggerFactory.getLogger(ResourceDisplayController.class);

/** term for standard view, used in VIEWMODE. */
private static final String STANDARD_VIEW = "standard";

/** Service for managing RMap data display. */
private DataDisplayService dataDisplayService;

/**used to get instances of RMapSearchParams which passes search properties to rmap**/
private RMapSearchParamsFactory paramsFactory;

@Autowired
public ResourceDisplayController(DataDisplayService dataDisplayService, RMapSearchParamsFactory paramsFactory) {
this.dataDisplayService = dataDisplayService;
this.paramsFactory = paramsFactory;
}


/**
* GET details of a resource.
*
Expand All @@ -84,42 +95,32 @@ public class ResourceDisplayController {
@RequestMapping(value="/resources/{uri}", method = RequestMethod.GET)
public String resource(@PathVariable(value="uri") String sResourceUri,
@RequestParam(value="resview", required=false) Integer resview,
@RequestParam(value="status", required=false) String status,
Model model, RedirectAttributes redirectAttributes) throws Exception {

LOG.info("Resource requested {}", sResourceUri);

if (resview == null) {resview = 0;}
sResourceUri = URLDecoder.decode(sResourceUri, "UTF-8");

try {
if (resview==0) {
String rmapType = dataDisplayService.getRMapTypeDisplayName(new URI(sResourceUri));
LOG.debug("rmapType identified as {}", rmapType);
if (rmapType.length()>0){
String redirectPath = "redirect:/" + rmapType.toLowerCase() + "s/" + URLEncoder.encode(sResourceUri, "UTF-8");
LOG.debug("Redirecting resource path to {}", redirectPath);
return redirectPath;
}
}

//do this to trigger not found error
dataDisplayService.getResourceBatch(sResourceUri, 0, PaginatorType.RESOURCE_GRAPH);

List<URI> resourceTypes = dataDisplayService.getResourceRDFTypes(new URI(sResourceUri));

model.addAttribute("RESOURCEURI", sResourceUri);
model.addAttribute("RESOURCE_TYPES", resourceTypes);
model.addAttribute("PAGEPATH", "resources");

} catch (URISyntaxException|IllegalArgumentException ex){
LOG.warn("{}. Submitted value: {}.", ex.getMessage(), sResourceUri);
SearchForm search = new SearchForm();
search.setSearch(sResourceUri);
redirectAttributes.addFlashAttribute("search", search);
redirectAttributes.addFlashAttribute("notice", "<strong>" + sResourceUri + "</strong> is not a valid URI. Currently only URI searches are supported.");
return "redirect:/search";

if (resview==0) {
String rmapType = dataDisplayService.getRMapTypeDisplayName(new URI(sResourceUri));
LOG.debug("rmapType identified as {}", rmapType);
if (rmapType.length()>0){
String redirectPath = "redirect:/" + rmapType.toLowerCase() + "s/" + URLEncoder.encode(sResourceUri, "UTF-8");
LOG.debug("Redirecting resource path to {}", redirectPath);
return redirectPath;
}
}
RMapSearchParams params = generateSearchParams(status, 0);

List<URI> resourceTypes = dataDisplayService.getResourceRDFTypes(new URI(sResourceUri),params);

model.addAttribute("RESOURCEURI", sResourceUri);
model.addAttribute("RESOURCELABEL", dataDisplayService.getResourceLabel(sResourceUri,params));
model.addAttribute("RESOURCE_TYPES", resourceTypes);
model.addAttribute("PAGEPATH", "resources");

return "resources";
}

Expand Down Expand Up @@ -176,8 +177,6 @@ public String resourceVisualView(@PathVariable(value="uri") String reqUri,
return "redirect:/" + rmapType.toLowerCase() + "s/" + reqUri + "/visual";
}
}
//do this to trigger not found error
dataDisplayService.getResourceBatch(reqUri, 0, PaginatorType.RESOURCE_GRAPH);

model.addAttribute("RESOURCEURI", reqUri);

Expand All @@ -199,6 +198,8 @@ public String resourceVisualView(@PathVariable(value="uri") String reqUri,
@RequestMapping(value="/resources/{uri}/widget", method = RequestMethod.GET)
public String resourceWidgetView(@PathVariable(value="uri") String reqUri,
@RequestParam(value="resview", required=false) Integer resview,
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status,
Model model) throws Exception {
LOG.info("Resource requested {}", reqUri);

Expand All @@ -214,10 +215,15 @@ public String resourceWidgetView(@PathVariable(value="uri") String reqUri,
}
}

ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, 0, PaginatorType.RESOURCE_GRAPH);
Graph resourceGraph = dataDisplayService.getResourceGraph(triplebatch);

model.addAttribute("RESOURCEURI", decodedUri);
model.addAttribute("status", status);

RMapSearchParams params = generateSearchParams(status, offset);
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, params, PaginatorType.RESOURCE_GRAPH);
if (triplebatch==null || triplebatch.size()==0) {
return "resourcenotfoundembedded";
}
Graph resourceGraph = dataDisplayService.getResourceGraph(triplebatch,params);
model.addAttribute("GRAPH", resourceGraph);

return "resourcewidget";
Expand All @@ -235,22 +241,25 @@ public String resourceWidgetView(@PathVariable(value="uri") String reqUri,
*/
@RequestMapping(value="/resources/{uri}/tabledata", method = RequestMethod.GET)
public String resourceTableView(@PathVariable(value="uri") String reqUri,
@RequestParam(value="offset", required=false) String sOffset,
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status,
Model model) throws Exception {
LOG.info("Resource requested {}", reqUri);
String decodedUri = URLDecoder.decode(reqUri, "UTF-8");
Integer offset;
try {
offset = Integer.parseInt(sOffset);
} catch (NumberFormatException e){
offset = 0;
}
try {
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, offset, PaginatorType.RESOURCE_TABLE);
ResourceDescription rd = dataDisplayService.getResourceTableData(decodedUri, triplebatch);

model.addAttribute("RESOURCEURI", decodedUri);
model.addAttribute("status", status);

RMapSearchParams params = generateSearchParams(status, offset);
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, params, PaginatorType.RESOURCE_TABLE);
if (triplebatch==null || triplebatch.size()==0) {
return "resourcenotfoundembedded";
}
params.setOffset(0); //
ResourceDescription rd = dataDisplayService.getResourceTableData(decodedUri, triplebatch, params, true);
PageStatus pageStatus = dataDisplayService.getPageStatus(triplebatch, PaginatorType.RESOURCE_TABLE);

model.addAttribute("RESOURCEURI", decodedUri);
model.addAttribute("TABLEDATA", rd);
model.addAttribute("PAGINATOR", pageStatus);
} catch (Exception e){
Expand All @@ -272,28 +281,30 @@ public String resourceTableView(@PathVariable(value="uri") String reqUri,
*/
@RequestMapping(value="/resources/{uri}/graphdata", method = RequestMethod.GET)
public String resourceGraphData(@PathVariable(value="uri") String reqUri,
@RequestParam(value="offset", required=false) String sOffset,
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status,
@RequestParam(value="view", required=false) String view,
Model model) throws Exception {
LOG.info("Resource requested {}", reqUri);
if (view==null || view.length()==0){
view = STANDARD_VIEW;
}
String decodedUri = URLDecoder.decode(reqUri, "UTF-8");
Integer offset;
try {
offset = Integer.parseInt(sOffset);
} catch (NumberFormatException e){
offset = 0;
}
try {
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, offset, PaginatorType.RESOURCE_GRAPH);
Graph resourceGraph = dataDisplayService.getResourceGraph(triplebatch);
PageStatus pageStatus = dataDisplayService.getPageStatus(triplebatch, PaginatorType.RESOURCE_GRAPH);
model.addAttribute("RESOURCEURI", decodedUri);
model.addAttribute("status", status);
RMapSearchParams params = generateSearchParams(status,offset);

ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceBatch(decodedUri, params, PaginatorType.RESOURCE_GRAPH);
if (triplebatch==null || triplebatch.size()==0) {
return "resourcenotfoundembedded";
}

Graph resourceGraph = dataDisplayService.getResourceGraph(triplebatch, params);
PageStatus pageStatus = dataDisplayService.getPageStatus(triplebatch, PaginatorType.RESOURCE_GRAPH);
model.addAttribute("GRAPH", resourceGraph);
model.addAttribute("PAGINATOR", pageStatus);
model.addAttribute("VIEWMODE", view);
model.addAttribute("VIEWMODE", view);
} catch (Exception e){
throw new RMapWebException(e,ErrorCode.ER_PROBLEM_LOADING_RESOURCEGRAPH);
}
Expand All @@ -311,18 +322,16 @@ public String resourceGraphData(@PathVariable(value="uri") String reqUri,
*/
@RequestMapping(value="/resources/{uri}/discos", method = RequestMethod.GET)
public String resourceRelatedDiscos(@PathVariable(value="uri") String reqUri,
@RequestParam(value="offset", required=false) String sOffset,
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status,
Model model) throws Exception {
LOG.info("Resource requested {}", reqUri);
try {
String decodedUri = URLDecoder.decode(reqUri, "UTF-8");
Integer offset;
try {
offset = Integer.parseInt(sOffset);
} catch (NumberFormatException e){
offset = 0;
}
ResultBatch<URI> resourceDiscos = dataDisplayService.getResourceRelatedDiSCOs(decodedUri, offset);

RMapSearchParams params = generateSearchParams(status, offset);

ResultBatch<URI> resourceDiscos = dataDisplayService.getResourceRelatedDiSCOs(decodedUri, params);
PageStatus resDiscoPageStatus = dataDisplayService.getPageStatus(resourceDiscos, PaginatorType.RESOURCE_DISCOS);

model.addAttribute("RESOURCEURI", decodedUri);
Expand All @@ -336,8 +345,7 @@ public String resourceRelatedDiscos(@PathVariable(value="uri") String reqUri,

return "resourcediscos";
}



/**
* Retrieves information about the node to be formatted in a popup
*
Expand All @@ -352,6 +360,7 @@ public String resourceRelatedDiscos(@PathVariable(value="uri") String reqUri,
@RequestMapping(value="/resources/{resource}/nodeinfo", method = RequestMethod.GET)
public String resourceLiterals(@PathVariable(value="resource") String resourceUri,
@RequestParam(value="offset", required=false) Integer offset,
@RequestParam(value="status", required=false) String status,
@RequestParam(value="view", required=false) String view, Model model,
@RequestParam(value="referer", required=false) String referer) throws Exception {
if (offset==null){offset=0;}
Expand All @@ -360,9 +369,10 @@ public String resourceLiterals(@PathVariable(value="resource") String resourceUr
}
try {
resourceUri = URLDecoder.decode(resourceUri, "UTF-8");

ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceLiterals(resourceUri, offset);
ResourceDescription resourceDescription = dataDisplayService.getResourceTableData(resourceUri, triplebatch);

RMapSearchParams params = generateSearchParams(status,offset);
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceLiterals(resourceUri, params);
ResourceDescription resourceDescription = dataDisplayService.getResourceTableData(resourceUri, triplebatch, params, true);
PageStatus pageStatus = dataDisplayService.getPageStatus(triplebatch, PaginatorType.NODE_INFO);
String rmapType = dataDisplayService.getRMapTypeDisplayName(new URI(resourceUri));

Expand Down Expand Up @@ -405,9 +415,11 @@ public String resourceLiteralsInContext(@PathVariable(value="resource") String r
try {
resourceUri = URLDecoder.decode(resourceUri, "UTF-8");
contextUri = URLDecoder.decode(contextUri, "UTF-8");

RMapSearchParams params = generateSearchParams(RMapStatusFilter.ALL, offset);

ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceLiteralsInContext(resourceUri, contextUri, offset);
ResourceDescription resourceDescription = dataDisplayService.getResourceTableData(resourceUri, triplebatch, contextUri);
ResultBatch<RMapTriple> triplebatch = dataDisplayService.getResourceLiteralsInContext(resourceUri, contextUri, params);
ResourceDescription resourceDescription = dataDisplayService.getResourceTableDataInContext(resourceUri, triplebatch, contextUri, false);
PageStatus pageStatus = dataDisplayService.getPageStatus(triplebatch, PaginatorType.NODE_INFO);
String rmapType = dataDisplayService.getRMapTypeDisplayName(new URI(resourceUri));

Expand All @@ -423,7 +435,21 @@ public String resourceLiteralsInContext(@PathVariable(value="resource") String r
}

return "nodeinfo";
}
}

private RMapSearchParams generateSearchParams(String status, Integer offset) {
RMapStatusFilter statusFilter = RMapStatusFilter.getStatusFromTerm(status);
return generateSearchParams(statusFilter,offset);
}

private RMapSearchParams generateSearchParams(RMapStatusFilter statusFilter, Integer offset) {
RMapSearchParams params = paramsFactory.newInstance();
statusFilter = (statusFilter==null) ? RMapStatusFilter.ACTIVE : statusFilter;
offset = (offset==null) ? 0 : offset;
params.setStatusCode(statusFilter);
params.setOffset(offset);
return params;
}


}
Loading

0 comments on commit b5c871c

Please sign in to comment.