X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;ds=sidebyside;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2FJcrTestResult.java;h=3006266f3ceb6a93c0e42715f5216070663a5213;hb=4e7678886b9f37c7e47896ff0889aa6cafbb3372;hp=f96e88ea7fc090fadfb5488698db9d6d57e5ccf9;hpb=4444b88528fd1ba4de62d47bf885bbe9403d2216;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrTestResult.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrTestResult.java index f96e88ea7..3006266f3 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrTestResult.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/JcrTestResult.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import javax.jcr.Credentials; import javax.jcr.Node; import javax.jcr.Property; import javax.jcr.PropertyIterator; @@ -38,29 +39,34 @@ import org.argeo.slc.test.TestResultPart; import org.argeo.slc.test.TestRun; import org.argeo.slc.test.TestStatus; -/** {@link TestResult} wrapping a JCR node of type {@link SlcTypes#SLC_RESULT}. */ +/** + * {@link TestResult} wrapping a JCR node of type + * {@link SlcTypes#SLC_TEST_RESULT}. + */ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { /** Should only be set for an already existing result. */ private String uuid; private Repository repository; private Session session; - private String resultType = SlcTypes.SLC_RESULT; + /** + * For testing purposes, best practice is to not set them explicitely but + * via other mechanisms such as JAAS or SPring Security. + */ + private Credentials credentials = null; + private String resultType = SlcTypes.SLC_TEST_RESULT; /** cached for performance purposes */ private String nodeIdentifier = null; - private Boolean logoutWhenDestroyed = true; - private Map attributes = new HashMap(); public void init() { try { - session = repository.login(); + session = repository.login(credentials); if (uuid == null) { // create new result uuid = UUID.randomUUID().toString(); - String path = SlcJcrUtils.createResultPath(session.getUserID(), - uuid); + String path = SlcJcrUtils.createResultPath(session, uuid); Node resultNode = JcrUtils.mkdirs(session, path, resultType); resultNode.setProperty(SLC_UUID, uuid); for (String attr : attributes.keySet()) { @@ -81,8 +87,7 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { } public void destroy() { - if (logoutWhenDestroyed) - JcrUtils.logoutQuietly(session); + JcrUtils.logoutQuietly(session); } public Node getNode() { @@ -92,9 +97,9 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { return session.getNodeByIdentifier(nodeIdentifier); } else { QueryManager qm = session.getWorkspace().getQueryManager(); - Query q = qm.createQuery( - "select * from [slc:result] where [slc:uuid]='" + uuid - + "'", Query.JCR_SQL2); + Query q = qm.createQuery("select * from [" + + SlcTypes.SLC_TEST_RESULT + "] where [slc:uuid]='" + + uuid + "'", Query.JCR_SQL2); resultNode = JcrUtils.querySingleNode(q); if (resultNode != null) nodeIdentifier = resultNode.getIdentifier(); @@ -111,9 +116,8 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { public void addResultPart(TestResultPart testResultPart) { Node node = getNode(); try { - // TODO: find a better way to name it by default - String partName = Long.toString(System.currentTimeMillis()); - Node resultPartNode = node.addNode(partName, SlcTypes.SLC_CHECK); + Node resultPartNode = node.addNode(SlcNames.SLC_STATUS, + SlcTypes.SLC_CHECK); resultPartNode.setProperty(SLC_SUCCESS, testResultPart.getStatus() == TestStatus.PASSED); if (testResultPart.getMessage() != null) @@ -140,6 +144,7 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { } } + /** JCR session is NOT logged out */ public void close() { Node node = getNode(); try { @@ -152,8 +157,6 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { JcrUtils.discardUnderlyingSessionQuietly(node); throw new SlcException("Cannot get close date from " + node, e); } - if (logoutWhenDestroyed) - JcrUtils.logoutQuietly(session); } public Date getCloseDate() { @@ -207,8 +210,12 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { this.attributes = attributes; } -// public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) { -// this.logoutWhenDestroyed = logoutWhenDestroyed; -// } + public void setCredentials(Credentials credentials) { + this.credentials = credentials; + } + + // public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) { + // this.logoutWhenDestroyed = logoutWhenDestroyed; + // } }