Revision 47835
Added by Claudio Atzori over 7 years ago
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/deploy.info | ||
---|---|---|
1 |
{"type_source": "SVN", "goal": "package -U -T 4C source:jar", "url": "http://svn-public.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-resultset-inspector/trunk/", "deploy_repository": "dnet45-snapshots", "version": "4", "mail": "sandro.labruzzo@isti.cnr.it,michele.artini@isti.cnr.it, claudio.atzori@isti.cnr.it, alessia.bardi@isti.cnr.it", "deploy_repository_url": "http://maven.research-infrastructures.eu/nexus/content/repositories/dnet45-snapshots", "name": "cnr-resultset-inspector"} |
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/src/main/java/eu/dnetlib/resultset/inspector/ResultsetInspector.java | ||
---|---|---|
1 |
package eu.dnetlib.resultset.inspector; |
|
2 |
|
|
3 |
import static eu.dnetlib.miscutils.collections.MappedCollection.listMap; |
|
4 |
|
|
5 |
import java.util.List; |
|
6 |
|
|
7 |
import javax.annotation.Resource; |
|
8 |
|
|
9 |
import org.apache.commons.logging.Log; |
|
10 |
import org.apache.commons.logging.LogFactory; |
|
11 |
import org.springframework.stereotype.Controller; |
|
12 |
import org.springframework.ui.Model; |
|
13 |
import org.springframework.ui.ModelMap; |
|
14 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
15 |
import org.springframework.web.bind.annotation.RequestParam; |
|
16 |
|
|
17 |
import com.google.common.collect.Iterators; |
|
18 |
import com.google.common.collect.Ordering; |
|
19 |
|
|
20 |
import eu.dnetlib.enabling.inspector.AbstractInspectorController; |
|
21 |
import eu.dnetlib.enabling.resultset.LocalResultSetImpl; |
|
22 |
import eu.dnetlib.enabling.resultset.MappedResultSet; |
|
23 |
import eu.dnetlib.enabling.resultset.ResultSet; |
|
24 |
import eu.dnetlib.enabling.resultset.ResultSetListener; |
|
25 |
import eu.dnetlib.enabling.resultset.ResultSetRegistryImpl; |
|
26 |
import eu.dnetlib.enabling.resultset.client.IterableResultSetClient; |
|
27 |
import eu.dnetlib.enabling.resultset.client.ResultSetClientFactory; |
|
28 |
import eu.dnetlib.miscutils.cache.Cache; |
|
29 |
import eu.dnetlib.miscutils.cache.CacheElement; |
|
30 |
import eu.dnetlib.miscutils.functional.UnaryFunction; |
|
31 |
import eu.dnetlib.miscutils.functional.string.EscapeHtml; |
|
32 |
import eu.dnetlib.miscutils.functional.xml.ApplyXslt; |
|
33 |
import eu.dnetlib.miscutils.functional.xml.IndentXmlString; |
|
34 |
|
|
35 |
@Controller |
|
36 |
public class ResultsetInspector extends AbstractInspectorController { |
|
37 |
|
|
38 |
private static final Log log = LogFactory.getLog(ResultsetInspector.class); // NOPMD by marko on 11/24/08 5:02 PM |
|
39 |
|
|
40 |
@Resource |
|
41 |
private ResultSetRegistryImpl registry; |
|
42 |
|
|
43 |
class ResultsetDescription { |
|
44 |
|
|
45 |
private String id; |
|
46 |
private String type; |
|
47 |
private String handler; |
|
48 |
private boolean open; |
|
49 |
private int size; |
|
50 |
|
|
51 |
public ResultsetDescription(final String id, final String type, final String handler, final boolean open, final int size) { |
|
52 |
super(); |
|
53 |
this.id = id; |
|
54 |
this.type = type; |
|
55 |
this.handler = handler; |
|
56 |
this.open = open; |
|
57 |
this.size = size; |
|
58 |
} |
|
59 |
|
|
60 |
public String getId() { |
|
61 |
return id; |
|
62 |
} |
|
63 |
|
|
64 |
public void setId(final String id) { |
|
65 |
this.id = id; |
|
66 |
} |
|
67 |
|
|
68 |
public String getHandler() { |
|
69 |
return handler; |
|
70 |
} |
|
71 |
|
|
72 |
public void setHandler(final String handler) { |
|
73 |
this.handler = handler; |
|
74 |
} |
|
75 |
|
|
76 |
public boolean isOpen() { |
|
77 |
return open; |
|
78 |
} |
|
79 |
|
|
80 |
public void setOpen(final boolean open) { |
|
81 |
this.open = open; |
|
82 |
} |
|
83 |
|
|
84 |
public String getType() { |
|
85 |
return type; |
|
86 |
} |
|
87 |
|
|
88 |
public void setType(final String type) { |
|
89 |
this.type = type; |
|
90 |
} |
|
91 |
|
|
92 |
public int getSize() { |
|
93 |
return size; |
|
94 |
} |
|
95 |
|
|
96 |
public void setSize(final int size) { |
|
97 |
this.size = size; |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* resultset client. |
|
103 |
*/ |
|
104 |
@Resource(name = "resultSetClientFactory") |
|
105 |
private ResultSetClientFactory resultSetClientFactory; |
|
106 |
|
|
107 |
/** |
|
108 |
* Default max elements in RS to display |
|
109 |
*/ |
|
110 |
private final Integer defaultMax = 100; |
|
111 |
|
|
112 |
/** |
|
113 |
* build a resultset and show its content. |
|
114 |
* |
|
115 |
* @param model |
|
116 |
* mvc model |
|
117 |
* @param query |
|
118 |
* query (optional) |
|
119 |
* @param epr |
|
120 |
* epr (optional) |
|
121 |
* @throws Exception |
|
122 |
*/ |
|
123 |
@RequestMapping("/inspector/rs.do") |
|
124 |
public void resultset(final ModelMap model, |
|
125 |
@RequestParam(value = "epr", required = false) final String epr, |
|
126 |
@RequestParam(value = "max", required = false) final Integer max) { |
|
127 |
|
|
128 |
if (epr != null) { |
|
129 |
|
|
130 |
log.info("building resultset from query or EPR"); |
|
131 |
try { |
|
132 |
IterableResultSetClient client = resultSetClientFactory.getClient(epr.trim()); |
|
133 |
model.addAttribute("message", "resultset elements listed below:"); |
|
134 |
model.addAttribute("iter", Iterators.limit(client.iterator(), max != null ? max : defaultMax)); |
|
135 |
} catch (Exception e) { |
|
136 |
model.addAttribute("message", "failed: " + e.getMessage()); |
|
137 |
model.addAttribute("iter", ""); |
|
138 |
} |
|
139 |
} |
|
140 |
model.addAttribute("epr", epr); |
|
141 |
model.addAttribute("max", max != null ? max : defaultMax); |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* Renders a sorded list of local resultset instances taken from the resultset registry eh cache. |
|
146 |
* |
|
147 |
* @param model |
|
148 |
*/ |
|
149 |
@RequestMapping(value = "/inspector/resultsets.do") |
|
150 |
public void resultsets(final Model model) { |
|
151 |
final Cache<String, ResultSet> cache = registry.getCache(); |
|
152 |
|
|
153 |
final List<ResultsetDescription> descriptors = listMap(cache.keySet(), new UnaryFunction<ResultsetDescription, String>() { |
|
154 |
|
|
155 |
@Override |
|
156 |
public ResultsetDescription evaluate(final String arg) { |
|
157 |
final ResultSet rs = cache.get(arg); |
|
158 |
if (rs == null) return new ResultsetDescription("expired", null, null, true, 0); |
|
159 |
String handler = ""; |
|
160 |
if (rs instanceof LocalResultSetImpl) { |
|
161 |
|
|
162 |
final ResultSetListener listener = ((LocalResultSetImpl) rs).getListener(); |
|
163 |
|
|
164 |
handler = listener.getClass().getName(); |
|
165 |
if (listener instanceof MappedResultSet) { |
|
166 |
final MappedResultSet mappedResultSet = (MappedResultSet) listener; |
|
167 |
final UnaryFunction<String, String> mapper = mappedResultSet.getMapper(); |
|
168 |
handler += "(" + mapper.getClass().getName() + ")"; |
|
169 |
if (mapper instanceof ApplyXslt) { |
|
170 |
handler += ": " + ((ApplyXslt) mapper).getXsltName(); |
|
171 |
} |
|
172 |
} |
|
173 |
} |
|
174 |
int number = -1; |
|
175 |
try { |
|
176 |
number = rs.getNumberOfResults(); |
|
177 |
} catch (Throwable e) { |
|
178 |
// really, who cares |
|
179 |
log.debug("cannot get number of results", e); |
|
180 |
} |
|
181 |
return new ResultsetDescription(arg, rs.getClass().getSimpleName(), handler, rs.isOpen(), number); |
|
182 |
} |
|
183 |
}); |
|
184 |
|
|
185 |
final Ordering<ResultsetDescription> byCreationTime = new Ordering<ResultsetDescription>() { |
|
186 |
|
|
187 |
@Override |
|
188 |
public int compare(final ResultsetDescription left, final ResultsetDescription right) { |
|
189 |
final CacheElement<ResultSet> rightElement = cache.getElement(right.getId()); |
|
190 |
final CacheElement<ResultSet> leftElement = cache.getElement(left.getId()); |
|
191 |
|
|
192 |
if ((leftElement == null) && (rightElement == null)) return 0; |
|
193 |
if ((rightElement == null) && (leftElement != null)) return -1; |
|
194 |
if ((leftElement == null) && (rightElement != null)) return 1; |
|
195 |
|
|
196 |
return (int) (rightElement.getCreationTime() - leftElement.getCreationTime()); |
|
197 |
} |
|
198 |
}; |
|
199 |
|
|
200 |
model.addAttribute("resultsets", byCreationTime.nullsLast().sortedCopy(descriptors)); |
|
201 |
} |
|
202 |
|
|
203 |
@RequestMapping(value = "/inspector/resultset.do") |
|
204 |
public void resultset(final Model model, |
|
205 |
@RequestParam("id") final String id, |
|
206 |
@RequestParam(value = "from", required = false) final Integer from, |
|
207 |
@RequestParam(value = "to", required = false) final Integer to) { |
|
208 |
|
|
209 |
model.addAttribute("id", id); |
|
210 |
model.addAttribute("from", from); |
|
211 |
model.addAttribute("to", to); |
|
212 |
|
|
213 |
if ((from != null) && (to != null)) { |
|
214 |
fetchPage(model, id, from, to); |
|
215 |
} |
|
216 |
} |
|
217 |
|
|
218 |
private void fetchPage(final Model model, final String rsId, final Integer from, final Integer to) { |
|
219 |
final ResultSet rs = registry.getResultSetById(rsId); |
|
220 |
|
|
221 |
final List<String> res = rs.getResults(from, to); |
|
222 |
model.addAttribute("res", listMap(listMap(res, new IndentXmlString()), new EscapeHtml())); |
|
223 |
} |
|
224 |
} |
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/src/main/resources/eu/dnetlib/enabling/views/inspector/resultset.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
<h2> |
|
3 |
Details for Resultset $id$ |
|
4 |
</h2> |
|
5 |
|
|
6 |
<form> |
|
7 |
<label for="from">From</label> <input type="text" name="from" id="from" value="$from$"/> |
|
8 |
<label for="to">To</label> <input type="text" name="to" id="to" value="$to$"/> |
|
9 |
|
|
10 |
<input type="hidden" name="id" value="$id$"/> |
|
11 |
|
|
12 |
<p> <input type="submit" value="show page"/> </p> |
|
13 |
|
|
14 |
<p> Positions starts from 1 and "to" is inclusive. </p> |
|
15 |
</form> |
|
16 |
|
|
17 |
<ul> |
|
18 |
$res:{<li><pre>$it$</pre></li>}$ |
|
19 |
</ul> |
|
20 |
|
|
21 |
})$ |
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/src/main/resources/eu/dnetlib/enabling/views/inspector/resultsets.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
<h2> |
|
3 |
List of resultsets registered on this container |
|
4 |
</h2> |
|
5 |
|
|
6 |
<table> |
|
7 |
<tr> |
|
8 |
<td>ID</td> |
|
9 |
<td>Open?</td> |
|
10 |
<td>Size</td> |
|
11 |
<td>Type</td> |
|
12 |
<td>Handler</td> |
|
13 |
</tr> |
|
14 |
$resultsets:{ |
|
15 |
<tr> |
|
16 |
<td><a href="resultset.do?id=$it.id$">$it.id$</a></td> |
|
17 |
<td>$it.open$</td> |
|
18 |
<td>$it.size$</td> |
|
19 |
<td>$it.type$</td> |
|
20 |
<td>$it.handler$</td> |
|
21 |
</tr> |
|
22 |
}$ |
|
23 |
</table> |
|
24 |
})$ |
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/src/main/resources/eu/dnetlib/enabling/views/inspector/rs.st | ||
---|---|---|
1 |
$inspector/master(it={ |
|
2 |
|
|
3 |
<h2>resultset inspector</h2> |
|
4 |
|
|
5 |
<style type="text/css"> |
|
6 |
#results { |
|
7 |
width: 100%; |
|
8 |
} |
|
9 |
|
|
10 |
#results td:first-child { |
|
11 |
width: 2em; |
|
12 |
} |
|
13 |
|
|
14 |
#results td { |
|
15 |
border: 1px solid #cecece; |
|
16 |
} |
|
17 |
</style> |
|
18 |
|
|
19 |
<br>Paste an EPR here:<br/> |
|
20 |
<form "method="POST"> |
|
21 |
<textarea name="epr" rows="10" cols="120">$epr$</textarea> |
|
22 |
<br/> |
|
23 |
max elements: <input type="text" value="$max$" name="max"/> |
|
24 |
<input type="submit" value="submit"/> |
|
25 |
</form> |
|
26 |
|
|
27 |
<p>$message$</p> |
|
28 |
|
|
29 |
<ol> |
|
30 |
$iter:{ |
|
31 |
<tr> |
|
32 |
<li><textarea readonly="yes" rows="3" cols="115">$it$</textarea></li> |
|
33 |
</tr> |
|
34 |
}$ |
|
35 |
</ol> |
|
36 |
|
|
37 |
})$ |
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/src/main/resources/eu/dnetlib/resultset/inspector/webContext-resultset-inspector.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<beans xmlns="http://www.springframework.org/schema/beans" |
|
3 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" |
|
4 |
xmlns:util="http://www.springframework.org/schema/util" |
|
5 |
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd |
|
6 |
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> |
|
7 |
|
|
8 |
<bean id="resultsetInspectorGroup" |
|
9 |
class="eu.dnetlib.enabling.inspector.StaticEntryPointDescriptorGroup" |
|
10 |
p:name="resultset"> |
|
11 |
<property name="descriptors"> |
|
12 |
<list> |
|
13 |
<bean class="eu.dnetlib.enabling.inspector.StaticEntryPointDescriptor" |
|
14 |
p:name="resultsets" p:relativeUrl="resultsets.do" p:hiddenAsDefault="true" /> |
|
15 |
<bean class="eu.dnetlib.enabling.inspector.StaticEntryPointDescriptor" |
|
16 |
p:name="rs" p:relativeUrl="rs.do" p:hiddenAsDefault="true" /> |
|
17 |
</list> |
|
18 |
</property> |
|
19 |
</bean> |
|
20 |
|
|
21 |
</beans> |
|
22 |
|
modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<parent> |
|
4 |
<groupId>eu.dnetlib</groupId> |
|
5 |
<artifactId>dnet45-parent</artifactId> |
|
6 |
<version>1.0.0</version> |
|
7 |
</parent> |
|
8 |
<modelVersion>4.0.0</modelVersion> |
|
9 |
<groupId>eu.dnetlib</groupId> |
|
10 |
<artifactId>cnr-resultset-inspector</artifactId> |
|
11 |
<packaging>jar</packaging> |
|
12 |
<version>2.0.1</version> |
|
13 |
<scm> |
|
14 |
<developerConnection>scm:svn:https://svn.driver.research-infrastructures.eu/driver/dnet45/modules/cnr-resultset-inspector/tags/cnr-resultset-inspector-2.0.1</developerConnection> |
|
15 |
</scm> |
|
16 |
<dependencies> |
|
17 |
<dependency> |
|
18 |
<groupId>junit</groupId> |
|
19 |
<artifactId>junit</artifactId> |
|
20 |
<version>${junit.version}</version> |
|
21 |
<scope>test</scope> |
|
22 |
</dependency> |
|
23 |
<dependency> |
|
24 |
<groupId>eu.dnetlib</groupId> |
|
25 |
<artifactId>cnr-resultset-service</artifactId> |
|
26 |
<version>[2.0.0,3.0.0)</version> |
|
27 |
</dependency> |
|
28 |
<dependency> |
|
29 |
<groupId>eu.dnetlib</groupId> |
|
30 |
<artifactId>cnr-resultset-client</artifactId> |
|
31 |
<version>[2.0.0,3.0.0)</version> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>eu.dnetlib</groupId> |
|
35 |
<artifactId>cnr-inspector</artifactId> |
|
36 |
<version>[1.0.0,2.0.0)</version> |
|
37 |
</dependency> |
|
38 |
</dependencies> |
|
39 |
</project> |
Also available in: Unified diff
[maven-release-plugin] copy for tag cnr-resultset-inspector-2.0.1