X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2FJcrTestResult.java;h=66b658b750e06dd786c90f3681ab1461b1ab6551;hb=a0a151ee3a0aed29a3cb03d81e35d540ca9fdb03;hp=daeb3249135caad35a12aeabc9eb5cb2f2cd900a;hpb=a66f1580f7f1fcd781917d749eb9b29670f661f5;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 daeb32491..66b658b75 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 @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.jcr; import java.util.Date; @@ -9,6 +24,7 @@ import java.util.UUID; import javax.jcr.Node; import javax.jcr.Property; import javax.jcr.PropertyIterator; +import javax.jcr.Repository; import javax.jcr.Session; import javax.jcr.query.Query; import javax.jcr.query.QueryManager; @@ -22,12 +38,16 @@ 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; + private String resultType = SlcTypes.SLC_TEST_RESULT; /** cached for performance purposes */ private String nodeIdentifier = null; @@ -38,10 +58,11 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { public void init() { try { + session = repository.login(); if (uuid == null) { // create new result uuid = UUID.randomUUID().toString(); - String path = SlcJcrUtils.createResultPath(uuid); + String path = SlcJcrUtils.createResultPath(session, uuid); Node resultNode = JcrUtils.mkdirs(session, path, resultType); resultNode.setProperty(SLC_UUID, uuid); for (String attr : attributes.keySet()) { @@ -73,9 +94,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(); @@ -92,9 +113,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) @@ -172,8 +192,8 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { this.uuid = uuid; } - public void setSession(Session session) { - this.session = session; + public void setRepository(Repository repository) { + this.repository = repository; } public void setResultType(String resultType) { @@ -188,8 +208,8 @@ public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled { this.attributes = attributes; } - public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) { - this.logoutWhenDestroyed = logoutWhenDestroyed; - } + // public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) { + // this.logoutWhenDestroyed = logoutWhenDestroyed; + // } }