Project

General

Profile

« Previous | Next » 

Revision 28403

partial implementation using profile

View differences:

modules/dnet-modular-lightui-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/lightui/IndexClient.java
12 12
import org.apache.commons.logging.LogFactory;
13 13
import org.dom4j.Document;
14 14
import org.dom4j.DocumentException;
15
import org.dom4j.DocumentHelper;
16
import org.dom4j.Element;
15 17
import org.dom4j.Node;
16 18
import org.dom4j.io.SAXReader;
17 19
import org.springframework.beans.factory.annotation.Required;
......
42 44
	private ServiceResolver serviceResolver;
43 45
	
44 46
	private static final Log log = LogFactory.getLog(IndexClient.class);
45
	
47
		
46 48
	public List<BrowseFieldResult> browse(final String query, final IndexConfiguration idx, final List<ValueWithLabel> fields, int max) throws IndexServiceException, DocumentException, ResultSetException {
47 49
		
48 50
		final Map<String, String> labels = Maps.newHashMap();
......
67 69
			int to  = Math.min(max, total);
68 70
		
69 71
			final SAXReader reader = new SAXReader();
70
		
72
			
71 73
			for (String s : rs.getResult(rsId, 1, to, "WAITING")) {
72 74
				final Document doc = reader.read(new StringReader(s));
73
	
75
					
74 76
				for (Object o : doc.selectNodes("//groupresult")) {
75 77
					final Node node = (Node) o;
76 78
					final String field = node.valueOf("@field");
77 79
					final String value = node.valueOf("./value");
78 80
					final int size = Integer.parseInt(node.valueOf("./count"));
79
	
81
					
80 82
					boolean notFound = true;
81 83
					for (int i = 0; (i < list.size()) && notFound; i++) {
82 84
						final BrowseFieldResult elem = list.get(i);
......
96 98

  
97 99
		return list;
98 100
	}	
101
	
102
	public String browse(final String query, final IndexConfiguration idx, final List<ValueWithLabel> fields, final int max, final Resource xslt) throws IndexServiceException, DocumentException, ResultSetException {
103
		
104
		final Map<String, String> labels = Maps.newHashMap();
105
		for (ValueWithLabel v : fields) {
106
			labels.put(v.getValue(), v.getLabel());
107
		}
108
		
109
		final String q = generateBrowseQuery(query, fields);
110
			
111
		log.info("executing browse query: " + q);
112
		
113
		final W3CEndpointReference epr = indexLocator.getService().browse(idx.getId(), q, idx.getFormat(), idx.getLayout(), idx.getInterpretation());
114
		
115
		final ResultSetService rs = serviceResolver.getService(ResultSetService.class, epr);
116
		final String rsId = serviceResolver.getResourceIdentifier(epr);
117
		final int total = rs.getNumberOfElements(rsId);
99 118

  
119
		if (total > 0) {
120

  
121
			int to  = Math.min(max, total);
122
		
123
			final SAXReader reader = new SAXReader();
124
			final Element docRoot = DocumentHelper.createElement("browse");
125
			final Document docRes = DocumentHelper.createDocument(docRoot);
126
			//final Set<String> founds = Sets.newHashSet();
127
			
128
			for (String s : rs.getResult(rsId, 1, to, "WAITING")) {
129
				final Document doc = reader.read(new StringReader(s));
130
					
131
				for (Object o : doc.selectNodes("//groupresult")) {
132
					final Node node = (Node) o;
133
					final String field = node.valueOf("@field");
134
					final String value = node.valueOf("./value");
135
					final int size = Integer.parseInt(node.valueOf("./count"));
136
					
137
					Element f = (Element) docRoot.selectSingleNode("./field[@name='"+ field +"']");
138
					if (f == null) {
139
						f = docRoot.addElement("field");
140
						f.addAttribute("name", field);
141
						//founds.add(field);
142
					}
143
					
144
					final Element v = f.addElement("value");
145
					v.addAttribute("name", value.replaceAll("\"", "%22").replaceAll("'", "%27"));
146
					v.addAttribute("size", "" + size);
147
				}
148
			}
149
			
150
			System.out.println("******************************");
151
			System.out.println(docRes.asXML());
152
			System.out.println("******************************");
153
			
154
			return  (new ApplyXslt(xslt)).evaluate(docRes.asXML());
155
		}
156

  
157
		return "";
158
	}	
159
	
160
	
161

  
100 162
	public SearchResult search(final String query, final IndexConfiguration idx, final int page, final int pageSize, final Resource xslt) throws IndexServiceException, DocumentException, ResultSetException {
101 163

  
102 164
		log.info("executing query: " + query);
modules/dnet-modular-lightui-ui/trunk/src/main/java/eu/dnetlib/functionality/modular/ui/lightui/LightUiInternalController.java
6 6
import org.apache.commons.lang.math.NumberUtils;
7 7
import org.dom4j.Document;
8 8
import org.dom4j.DocumentException;
9
import org.dom4j.Element;
9 10
import org.dom4j.Node;
10
import org.dom4j.Element;
11 11
import org.dom4j.io.SAXReader;
12 12
import org.springframework.core.io.ClassPathResource;
13 13
import org.springframework.core.io.Resource;
......
18 18

  
19 19
import com.google.common.collect.Lists;
20 20

  
21
import eu.dnetlib.functionality.modular.ui.lightui.objects.BrowseFieldResult;
22 21
import eu.dnetlib.functionality.modular.ui.lightui.objects.IndexConfiguration;
23 22
import eu.dnetlib.functionality.modular.ui.lightui.objects.SearchResult;
24 23
import eu.dnetlib.functionality.modular.ui.lightui.objects.ValueWithLabel;
......
37 36
	private static final String lightuiId = "eagle"; 
38 37

  
39 38
	@RequestMapping("/ui/lightui_browse")
40
	public @ResponseBody List<BrowseFieldResult> browse(@RequestParam(value="query", required=true) final String query) throws Exception {
39
	public @ResponseBody String browse(@RequestParam(value="query", required=true) final String query) throws Exception {
41 40
		final Node browseNode = getConfigurationNode(lightuiId, "//BROWSE");
42 41
		final int max = NumberUtils.toInt(browseNode.valueOf("@max"), DEFAULT_MAX_BROWSE_VALUES);
42
		final Resource xslt = new ClassPathResource(browseNode.valueOf("./FORMATTER/@xslt"));
43 43
		
44 44
		final List<ValueWithLabel> fields = Lists.newArrayList();
45
		
46 45
		for (Object o : browseNode.selectNodes(".//BROWSE_FIELD")) {
47 46
			final String id = ((Element) o).valueOf("@id");
48 47
			final String label = ((Element) o).valueOf("@label");
49 48
			fields.add(new ValueWithLabel(label, id));
50 49
		}
51 50
		
52
		return indexClient.browse(query, calculateIndexConfiguration(lightuiId, browseNode), fields, max);
51
		return indexClient.browse(query, calculateIndexConfiguration(lightuiId, browseNode), fields, max, xslt);
53 52
	}
54 53
	
55 54
	@RequestMapping("/ui/lightui_search")
modules/dnet-modular-lightui-ui/trunk/src/main/resources/eu/dnetlib/functionality/modular/ui/xslt/default_browse.xslt
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<xsl:stylesheet version="2.0" 
4
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
5
	xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
6

  
7
	<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" omit-xml-declaration="yes"/>
8

  
9
	<xsl:template match="/">
10
		<xsl:for-each select="//field">
11
			<xsl:variable name="field" select="@name"></xsl:variable>
12
			
13
			<div class="panel panel-default">
14
				<div class="panel-heading"><xsl:value-of select="$field" /></div>
15
				
16
				<xsl:choose>
17
					<xsl:when test="count(./value) &gt; 5">
18
						<table class="table" ng-hide="browse_{$field}_showAll">
19
							<xsl:for-each select="./value">
20
								<xsl:if test="position() &lt;= 5">
21
									<tr ng-hide="browse_{$field}_showAll">
22
										<th><a href="javascript:void(0)" ng-click="updateQueryWithValue('{$field}', '{@name}')"><xsl:value-of select="@name" /></a></th>
23
										<td class="text-right"><xsl:value-of select="@size" /></td>
24
									</tr>
25
								</xsl:if>
26
							</xsl:for-each>
27
							<tr>
28
								<td colspan="2" class="text-right">
29
									<a href="javascript:void(0)" ng-click="browse_{$field}_showAll = true">more</a>
30
								</td>
31
							</tr>
32
						</table>
33
						<table class="table" ng-show="browse_{$field}_showAll">
34
							<xsl:for-each select="./value">
35
								<tr>
36
									<th><a href="javascript:void(0)" ng-click="updateQueryWithValue('{$field}', '{@name}')"><xsl:value-of select="@name" /></a></th>
37
									<td class="text-right"><xsl:value-of select="@size" /></td>
38
								</tr>
39
							</xsl:for-each>
40
							<tr>
41
								<td colspan="2" class="text-right">
42
									<a href="javascript:void(0)" ng-click="browse_{$field}_showAll = false">less</a>
43
								</td>
44
							</tr>
45
						</table>
46
					</xsl:when>
47
					<xsl:otherwise>
48
						<table class="table">
49
							<xsl:for-each select="./value">
50
								<tr>
51
									<th><a href="javascript:void(0)" ng-click="updateQueryWithValue('{$field}', '{@name}')"><xsl:value-of select="@name" /></a></th>
52
									<td class="text-right"><xsl:value-of select="@size" /></td>
53
								</tr>
54
							</xsl:for-each>
55
						</table>
56
					</xsl:otherwise>
57
				</xsl:choose>
58
			</div>
59
		</xsl:for-each>
60
	
61
	</xsl:template>
62
</xsl:stylesheet>
modules/dnet-modular-lightui-ui/trunk/src/main/resources/eu/dnetlib/web/resources/html/lightUiResults.html
1 1
<div class="row" ng-show="query && !documentHTML">
2 2
	<div class="col-md-4 col-lg-2">
3
		<div class="panel panel-default" ng-repeat="b in browseResults">
4
			<div class="panel-heading">{{b.label}}</div>
5
			<table class="table">
6
				<tr ng-repeat="v in b.values" ng-show="b.showAll || ($index < 4) ">
7
					<th><a href="javascript:void(0)" ng-click="updateQueryWithValue(b.field, v.value)">{{v.value}}</a></th>
8
					<td class="text-right">{{v.size}}</td>
9
				</tr>
10
				<tr ng-show="b.values.length > 4">
11
					<td colspan="2" class="text-right" ng-hide="b.showAll">
12
						<a href="javascript:void(0)" ng-click="b.showAll = true">more</a>
13
					</td>
14
					<td colspan="2" class="text-right" ng-show="b.showAll">
15
						<a href="javascript:void(0)" ng-click="b.showAll = false">less</a>
16
					</td>
17
				</tr>
18
			</table>
19
		</div>
3
		<div ng-bind-html="to_trusted(browseResultsHtml)" compile-template></div>
20 4
	</div>
21 5
	<div class="col-md-8 col-lg-10">
22 6
		<div>
modules/dnet-modular-lightui-ui/trunk/src/main/resources/eu/dnetlib/web/resources/js/dnet_lightui_controllers.js
43 43
		common_init($scope, $http, $sce, $location);
44 44

  
45 45
		$scope.query = $routeParams.query;
46
		$scope.browseResults = [];
46
		$scope.browseResultsHtml = "";
47 47
		$scope.searchResults = {};
48 48
		
49 49
		$scope.browse = function() {
......
56 56
		            'query' : $scope.query,
57 57
		    })).success(function(data) {
58 58
		            $scope.hideSpinner();
59
		            $scope.browseResults = data;
59
		            $scope.browseResultsHtml = data;
60 60
		    }).error(function() {
61 61
		            $scope.showError('Something really bad must have happened to our fellow hamster..');
62 62
		            $scope.hideSpinner();

Also available in: Unified diff