+ /**
+ * Create a new execution result path in the user home based on the current
+ * time
+ */
+ public static String createResultPath(Session session, String uuid)
+ throws RepositoryException {
+ Calendar now = new GregorianCalendar();
+ StringBuffer absPath = new StringBuffer(
+ SlcJcrResultUtils.getSlcResultsBasePath(session) + '/');
+ // Remove hours and add title property to the result process path on
+ // request of O. Capillon
+ // return getSlcProcessesBasePath(session) + '/'
+ // + JcrUtils.dateAsPath(now, true) + uuid;
+ String relPath = JcrUtils.dateAsPath(now, false);
+ List<String> names = JcrUtils.tokenize(relPath);
+ for (String name : names) {
+ absPath.append(name + "/");
+ Node node = JcrUtils.mkdirs(session, absPath.toString());
+ try {
+ node.addMixin(NodeType.MIX_TITLE);
+ node.setProperty(Property.JCR_TITLE, name.substring(1));
+ } catch (RepositoryException e) {
+ throw new SlcException(
+ "unable to create execution process path", e);
+ }
+ }
+ return absPath.toString() + uuid;
+ }
+
+ /**
+ * Set the value of the primitive accessor as a JCR property. Does nothing
+ * if the value is null.
+ */
+ public static void setPrimitiveAsProperty(Node node, String propertyName,
+ PrimitiveAccessor primitiveAccessor) {
+ String type = primitiveAccessor.getType();
+ Object value = primitiveAccessor.getValue();
+ setPrimitiveAsProperty(node, propertyName, type, value);
+ }
+
+ /** Map a primitive value to JCR property value. */
+ public static void setPrimitiveAsProperty(Node node, String propertyName,
+ String type, Object value) {
+ if (value == null)
+ return;
+ if (value instanceof CharSequence)
+ value = PrimitiveUtils.convert(type,
+ ((CharSequence) value).toString());
+ if (value instanceof char[])
+ value = new String((char[]) value);
+
+ try {
+ if (type.equals(PrimitiveAccessor.TYPE_STRING))
+ node.setProperty(propertyName, value.toString());
+ else if (type.equals(PrimitiveAccessor.TYPE_PASSWORD))
+ node.setProperty(propertyName, value.toString());
+ else if (type.equals(PrimitiveAccessor.TYPE_INTEGER))
+ node.setProperty(propertyName, (long) ((Integer) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_LONG))
+ node.setProperty(propertyName, ((Long) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_FLOAT))
+ node.setProperty(propertyName, (double) ((Float) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_DOUBLE))
+ node.setProperty(propertyName, ((Double) value));
+ else if (type.equals(PrimitiveAccessor.TYPE_BOOLEAN))
+ node.setProperty(propertyName, ((Boolean) value));
+ else
+ throw new SlcException("Unsupported type " + type);
+ } catch (RepositoryException e) {
+ throw new SlcException("Cannot set primitive of " + type
+ + " as property " + propertyName + " on " + node, e);
+ }
+ }
+
+ /** Aggregates the {@link TestStatus} of this sub-tree. */
+ public static Integer aggregateTestStatus(Node node) {
+ try {
+ Integer status = TestStatus.PASSED;
+ if (node.isNodeType(SlcTypes.SLC_CHECK))
+ if (node.getProperty(SLC_SUCCESS).getBoolean())
+ status = TestStatus.PASSED;
+ else if (node.hasProperty(SLC_ERROR_MESSAGE))
+ status = TestStatus.ERROR;
+ else
+ status = TestStatus.FAILED;