+ /**
+ * Creates and populates a {@link TreeTestResult} from the related result
+ * node. Meant to simplify migration of legacy applications. This is no
+ * stable API.
+ */
+ public static TreeTestResult nodeToTreeTestResult(Node resultNode) {
+ try {
+ String resultPath = resultNode.getPath();
+ TreeTestResult ttr = new TreeTestResult();
+ // base properties
+ ttr.setUuid(resultNode.getProperty(SLC_UUID).getString());
+ if (resultNode.hasProperty(SLC_COMPLETED))
+ ttr.setCloseDate(resultNode.getProperty(SLC_COMPLETED)
+ .getDate().getTime());
+ // attributes
+ for (PropertyIterator pit = resultNode.getProperties(); pit
+ .hasNext();) {
+ Property p = pit.nextProperty();
+ if (p.getName().indexOf(':') < 0) {
+ ttr.getAttributes().put(p.getName(), p.getString());
+ }
+ }
+
+ QueryManager qm = resultNode.getSession().getWorkspace()
+ .getQueryManager();
+ String statement = "SELECT * FROM [" + SlcTypes.SLC_CHECK
+ + "] WHERE ISDESCENDANTNODE(['" + resultPath + "'])";
+ NodeIterator nit = qm.createQuery(statement, Query.JCR_SQL2)
+ .execute().getNodes();
+ while (nit.hasNext()) {
+ Node checkNode = nit.nextNode();
+ String relPath = checkNode.getPath().substring(
+ resultPath.length());
+ TreeSPath tsp = new TreeSPath(relPath);
+
+ // result part
+ SimpleResultPart srp = new SimpleResultPart();
+ if (checkNode.getProperty(SLC_SUCCESS).getBoolean())
+ srp.setStatus(TestStatus.PASSED);
+ else if (checkNode.hasProperty(SLC_ERROR_MESSAGE))
+ srp.setStatus(TestStatus.ERROR);
+ else
+ srp.setStatus(TestStatus.FAILED);
+ if (checkNode.hasProperty(SLC_MESSAGE))
+ srp.setMessage(checkNode.getProperty(SLC_MESSAGE)
+ .getString());
+ if (!ttr.getResultParts().containsKey(tsp))
+ ttr.getResultParts().put(tsp, new PartSubList());
+ ttr.getResultParts().get(tsp).getParts().add(srp);
+
+ // element
+ SimpleSElement elem = new SimpleSElement();
+ if (checkNode.hasProperty(Property.JCR_TITLE))
+ elem.setLabel(checkNode.getProperty(Property.JCR_TITLE)
+ .getString());
+ else
+ elem.setLabel("");// some legacy code expect it to be set
+ for (NodeIterator tagIt = checkNode.getNodes(); tagIt.hasNext();) {
+ Node tagNode = tagIt.nextNode();
+ elem.getTags().put(
+ tagNode.getProperty(SLC_NAME).getString(),
+ tagNode.getProperty(SLC_VALUE).getString());
+ }
+ ttr.getElements().put(tsp, elem);
+ }
+ return ttr;
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot generate tree test result from "
+ + resultNode, e);
+ }
+ }