--- /dev/null
+package org.argeo.slc.web.mvc.result;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
+\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
+import org.argeo.slc.core.test.tree.TreeTestResultList;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultCollectionDao;\r
+import org.argeo.slc.web.mvc.AbstractServiceController;\r
+import org.springframework.web.servlet.ModelAndView;\r
+\r
+/** Lists results possibly filtering them. */\r
+public class ListResultsController extends AbstractServiceController {\r
+ private final TreeTestResultCollectionDao testResultCollectionDao;\r
+\r
+ public ListResultsController(\r
+ TreeTestResultCollectionDao testResultCollectionDao) {\r
+ this.testResultCollectionDao = testResultCollectionDao;\r
+ }\r
+\r
+ @Override\r
+ protected void handleServiceRequest(HttpServletRequest request,\r
+ HttpServletResponse response, ModelAndView modelAndView)\r
+ throws Exception {\r
+ String collectionId = request.getParameter("id");\r
+\r
+ Map<String, String[]> parameterMap = request.getParameterMap();\r
+\r
+ Map<String, String> attributes = new HashMap<String, String>();\r
+ for (String parameter : parameterMap.keySet()) {\r
+ if (parameter.startsWith("attr.")) {\r
+ String key = parameter.substring("attr.".length());\r
+ attributes.put(key, parameterMap.get(parameter)[0]);\r
+ }\r
+ }\r
+\r
+ List<TreeTestResult> resultAttributes = testResultCollectionDao\r
+ .listResults(collectionId, attributes);\r
+\r
+ modelAndView.addObject("resultList", new TreeTestResultList(\r
+ resultAttributes));\r
+ }\r
+}\r
<constructor-arg ref="testResultCollectionDao" />
</bean>
+ <bean name="/listResults.service"
+ class="org.argeo.slc.web.mvc.result.ListResultsController">
+ <constructor-arg ref="testResultCollectionDao" />
+ </bean>
+
<!--
<bean name="/resultList.service"
class="org.argeo.slc.web.mvc.result.ResultListController">
</field>
</class>
+ <class name="org.argeo.slc.core.test.tree.TreeTestResultList">
+ <map-to ns-uri="http://argeo.org/projects/slc/schemas"
+ ns-prefix="slc" />
+ <field name="list" collection="arraylist"
+ type="org.argeo.slc.core.test.tree.TreeTestResult">
+ <bind-xml auto-naming="deriveByClass" />
+ </field>
+ </class>
+
<!-- TESTS -->
<class name="org.argeo.slc.msg.test.tree.CreateTreeTestResultRequest">
<map-to ns-uri="http://argeo.org/projects/slc/schemas"
\r
import java.sql.SQLException;\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.SortedSet;\r
import java.util.TreeSet;\r
\r
+import org.argeo.slc.SlcException;\r
import org.argeo.slc.core.test.tree.ResultAttributes;\r
import org.argeo.slc.core.test.tree.TreeTestResult;\r
import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
import org.hibernate.HibernateException;\r
import org.hibernate.LockMode;\r
import org.hibernate.Session;\r
+import org.hibernate.criterion.DetachedCriteria;\r
import org.springframework.orm.hibernate3.HibernateCallback;\r
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
\r
\r
return list;\r
}\r
+\r
+ @SuppressWarnings("unchecked")\r
+ public List<TreeTestResult> listResults(String collectionId,\r
+ Map<String, String> attributes) {\r
+ List<TreeTestResult> list;\r
+\r
+ if (collectionId == null) {\r
+ if (attributes == null || attributes.size() == 0)\r
+ list = getHibernateTemplate().find("from TreeTestResult");\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ Object[] args = { entry.getKey(), entry.getValue() };\r
+ list = getHibernateTemplate().find(\r
+ "select ttr from TreeTestResult ttr"\r
+ + " where attributes[?]=?", args);\r
+ } else {\r
+ throw new SlcException(\r
+ "Multiple attributes filter are currently not supported.");\r
+ }\r
+ } else {\r
+ if (attributes == null || attributes.size() == 0)\r
+ list = getHibernateTemplate()\r
+ .find(\r
+ "select ttr "\r
+ + " from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
+ + " where ttr in elements(ttrc.results) and ttrc.id=?",\r
+ collectionId);\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ Object[] args = { collectionId, entry.getKey(),\r
+ entry.getValue() };\r
+ list = getHibernateTemplate()\r
+ .find(\r
+ "select ttr from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
+ + " where ttr in elements(ttrc.results) and ttrc.id=?"\r
+ + " and attributes[?]=?", args);\r
+ } else {\r
+ throw new SlcException(\r
+ "Multiple attributes filter are currently not supported.");\r
+ }\r
+ }\r
+ return list;\r
+ }\r
}\r
--- /dev/null
+package org.argeo.slc.core.test.tree;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/** List of results. Used for marshaling. */
+public class TreeTestResultList {
+ private List<TreeTestResult> list = new ArrayList<TreeTestResult>();
+
+ public TreeTestResultList() {
+ super();
+ }
+
+ public TreeTestResultList(List<TreeTestResult> list) {
+ super();
+ this.list = list;
+ }
+
+ public List<TreeTestResult> getList() {
+ return list;
+ }
+
+ public void setList(List<TreeTestResult> list) {
+ this.list = list;
+ }
+
+}
package org.argeo.slc.dao.test.tree;\r
\r
import java.util.List;\r
+import java.util.Map;\r
import java.util.SortedSet;\r
\r
import org.argeo.slc.core.test.tree.ResultAttributes;\r
+import org.argeo.slc.core.test.tree.TreeTestResult;\r
import org.argeo.slc.core.test.tree.TreeTestResultCollection;\r
\r
+/** Collections DAO */\r
public interface TreeTestResultCollectionDao {\r
public void create(TreeTestResultCollection ttrCollection);\r
\r
\r
public TreeTestResultCollection getTestResultCollection(String id);\r
\r
+ /** Lists all collections */\r
public SortedSet<TreeTestResultCollection> listCollections();\r
\r
+ /**\r
+ * Lists only result ids and attributes of the results belonging to these\r
+ * collection, or all results if id is null.\r
+ */\r
public List<ResultAttributes> listResultAttributes(String collectionId);\r
\r
+ /** Lists results filtering based on the arguments. */\r
+ public List<TreeTestResult> listResults(String collectionId,\r
+ Map<String, String> attributes);\r
+\r
+ /** Adds a result to a collection. */\r
public void addResultToCollection(TreeTestResultCollection ttrc,\r
String resultUuid);\r
\r
+ /** Removes a result from a collection. */\r
public void removeResultFromCollection(TreeTestResultCollection ttrc,\r
String resultUuid);\r
\r
import org.argeo.slc.dao.test.TestResultDao;\r
import org.argeo.slc.structure.StructureElement;\r
\r
+/**\r
+ * Adds DAO features specific to tree test result.\r
+ * \r
+ * @see TreeTestResult\r
+ */\r
public interface TreeTestResultDao extends TestResultDao<TreeTestResult> {\r
/** Lists results containing this path */\r
public List<TreeTestResult> listResults(TreeSPath path);\r
\r
+ /** Adds a result part related to this path */\r
public void addResultPart(String testResultId, TreeSPath path,\r
SimpleResultPart resultPart,\r
Map<TreeSPath, StructureElement> relatedElements);\r
\r
+ /** Update attributes */\r
public void updateAttributes(String testResultId,\r
Map<String, String> attributes);\r
}\r