X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.support.jcr%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fjcr%2FSlcJcrUtils.java;h=c3cdda7573e421dd7b2408c6775628d8b5fa40c4;hb=7361a299b9077a1960694bab93a53449bd1f7a1f;hp=e4d5d6e6ee768b128d91a4af28df47fb7721ad0a;hpb=3781dcd363f0f6265fae0ac758fd40cf4254ebc9;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java index e4d5d6e6e..c3cdda757 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcJcrUtils.java @@ -64,7 +64,13 @@ public class SlcJcrUtils { Calendar now = new GregorianCalendar(); return SlcJcrConstants.PROCESSES_BASE_PATH + '/' + JcrUtils.dateAsPath(now, true) + uuid; + } + /** Create a new execution result path based on the current time */ + public static String createResultPath(String uuid) { + Calendar now = new GregorianCalendar(); + return SlcJcrConstants.RESULTS_BASE_PATH + '/' + + JcrUtils.dateAsPath(now, true) + uuid; } /** @@ -75,6 +81,12 @@ public class SlcJcrUtils { 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) @@ -82,22 +94,22 @@ public class SlcJcrUtils { ((CharSequence) value).toString()); try { - if (type.equals(PrimitiveUtils.TYPE_STRING)) + if (type.equals(PrimitiveAccessor.TYPE_STRING)) node.setProperty(propertyName, value.toString()); - else if (type.equals(PrimitiveUtils.TYPE_INTEGER)) + else if (type.equals(PrimitiveAccessor.TYPE_INTEGER)) node.setProperty(propertyName, (long) ((Integer) value)); - else if (type.equals(PrimitiveUtils.TYPE_LONG)) + else if (type.equals(PrimitiveAccessor.TYPE_LONG)) node.setProperty(propertyName, ((Long) value)); - else if (type.equals(PrimitiveUtils.TYPE_FLOAT)) + else if (type.equals(PrimitiveAccessor.TYPE_FLOAT)) node.setProperty(propertyName, (double) ((Float) value)); - else if (type.equals(PrimitiveUtils.TYPE_DOUBLE)) + else if (type.equals(PrimitiveAccessor.TYPE_DOUBLE)) node.setProperty(propertyName, ((Double) value)); - else if (type.equals(PrimitiveUtils.TYPE_BOOLEAN)) + 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 " + primitiveAccessor + throw new SlcException("Cannot set primitive of " + type + " as property " + propertyName + " on " + node, e); } }