- /**\r
- * List<TreeTestResult> list;\r
- * \r
- * if (collectionId == null) { if (attributes == null ||\r
- * attributes.size() == 0) list =\r
- * getHibernateTemplate().find("from TreeTestResult"); else if\r
- * (attributes.size() == 1) { Map.Entry<String, String> entry =\r
- * attributes.entrySet() .iterator().next(); Object[] args = {\r
- * entry.getKey(), entry.getValue() }; list =\r
- * getHibernateTemplate().find( "select ttr from TreeTestResult ttr" +\r
- * " where attributes[?]=?", args); } else { throw new SlcException(\r
- * "Multiple attributes filter are currently not supported."); } } else\r
- * { if (attributes == null || attributes.size() == 0) list =\r
- * getHibernateTemplate() .find( "select ttr " +\r
- * " from TreeTestResult ttr, TreeTestResultCollection ttrc " +\r
- * " where ttr in elements(ttrc.results) and ttrc.id=?", collectionId);\r
- * else if (attributes.size() == 1) { Map.Entry<String, String> entry =\r
- * attributes.entrySet() .iterator().next(); Object[] args = {\r
- * collectionId, entry.getKey(), entry.getValue() }; list =\r
- * getHibernateTemplate() .find(\r
- * "select ttr from TreeTestResult ttr, TreeTestResultCollection ttrc "\r
- * + " where ttr in elements(ttrc.results) and ttrc.id=?" +\r
- * " and attributes[?]=?", args); } else { throw new SlcException(\r
- * "Multiple attributes filter are currently not supported."); } }\r
- * return list;\r
- */\r
- return null;\r
+ List<TreeTestResult> list;\r
+\r
+ if (collectionId == null) {\r
+ if (attributes == null || attributes.size() == 0)\r
+ list = asTreeTestResultList(resultNodes(null, null));\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ list = asTreeTestResultList(resultNodes(entry.getKey(), entry\r
+ .getValue()));\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 = asTreeTestResultList(resultNodesInCollection(collectionId));\r
+ else if (attributes.size() == 1) {\r
+ Map.Entry<String, String> entry = attributes.entrySet()\r
+ .iterator().next();\r
+ list = asTreeTestResultList(resultNodesInCollection(\r
+ collectionId, entry.getKey(), entry.getValue()));\r
+ } else {\r
+ throw new SlcException(\r
+ "Multiple attributes filter are currently not supported.");\r
+ }\r
+ }\r
+ return list;\r
+ }\r
+\r
+ // UTILITIES\r
+\r
+ protected NodeIterator resultNodesInCollection(String collectionId,\r
+ String attributeKey, String attributeValue) {\r
+ String queryString = "//testresult[@" + ttrColProp + "='"\r
+ + collectionId + "' and @" + attributeKey + "='"\r
+ + attributeValue + "']";\r
+ return query(queryString);\r
+ }\r
+\r
+ protected NodeIterator resultNodesInCollection(String collectionId) {\r
+ String queryString = "//testresult[@" + ttrColProp + "='"\r
+ + collectionId + "']";\r
+ return query(queryString);\r
+ }\r
+\r
+ protected NodeIterator resultNodes(String attributeKey,\r
+ String attributeValue) {\r
+ String queryString;\r
+ if (attributeKey != null)\r
+ queryString = "//testresult[@" + attributeKey + "='"\r
+ + attributeValue + "']";\r
+ else\r
+ queryString = "//testresult";\r
+ return query(queryString);\r