import org.argeo.jcr.JcrUtils;
import org.argeo.slc.SlcException;
+import org.argeo.slc.core.attachment.Attachment;
+import org.argeo.slc.core.attachment.AttachmentsEnabled;
import org.argeo.slc.test.TestResult;
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}. */
-public class JcrTestResult implements TestResult, SlcNames {
+public class JcrTestResult implements TestResult, SlcNames, AttachmentsEnabled {
/** Should only be set for an already existing result. */
private String uuid;
private Session session;
/** cached for performance purposes */
private String nodeIdentifier = null;
+ private Boolean logoutWhenDestroyed = true;
+
+ private Map<String, String> attributes = new HashMap<String, String>();
+
public void init() {
try {
if (uuid == null) {
String path = SlcJcrUtils.createResultPath(uuid);
Node resultNode = JcrUtils.mkdirs(session, path, resultType);
resultNode.setProperty(SLC_UUID, uuid);
+ for (String attr : attributes.keySet()) {
+ String property = attr;
+ // compatibility with legacy applications
+ if ("testCase".equals(attr))
+ property = SLC_TEST_CASE;
+ else if ("testCaseType".equals(attr))
+ property = SLC_TEST_CASE_TYPE;
+ resultNode.setProperty(property, attributes.get(attr));
+ }
session.save();
}
} catch (Exception e) {
}
public void destroy() {
-
+ if (logoutWhenDestroyed)
+ JcrUtils.logoutQuietly(session);
}
public Node getNode() {
JcrUtils.discardUnderlyingSessionQuietly(node);
throw new SlcException("Cannot get close date from " + node, e);
}
+ if (logoutWhenDestroyed)
+ JcrUtils.logoutQuietly(session);
}
public Date getCloseDate() {
}
}
+ public void addAttachment(Attachment attachment) {
+ // TODO implement it
+ }
+
public void setUuid(String uuid) {
this.uuid = uuid;
}
this.resultType = resultType;
}
+ public void setAttributes(Map<String, String> attributes) {
+ if (uuid != null)
+ throw new SlcException(
+ "Attributes cannot be set on an already initialized test result."
+ + " Update the related JCR node directly instead.");
+ this.attributes = attributes;
+ }
+
+ public void setLogoutWhenDestroyed(Boolean logoutWhenDestroyed) {
+ this.logoutWhenDestroyed = logoutWhenDestroyed;
+ }
+
}