1 package org
.argeo
.slc
.jcr
;
3 import java
.util
.Calendar
;
4 import java
.util
.GregorianCalendar
;
6 import org
.argeo
.jcr
.JcrUtils
;
7 import org
.argeo
.slc
.deploy
.ModuleDescriptor
;
10 * Utilities around the SLC JCR model. Note that it relies on fixed base paths
11 * (convention over configuration) for optimization purposes.
13 public class SlcJcrUtils
{
14 public final static Integer AGENT_FACTORY_DEPTH
= 3;
16 /** Extracts the path of a flow relative to its execution module */
17 public static String
flowRelativePath(String fullFlowPath
) {
18 String
[] tokens
= fullFlowPath
.split("/");
19 StringBuffer buf
= new StringBuffer(fullFlowPath
.length());
20 for (int i
= AGENT_FACTORY_DEPTH
+ 3; i
< tokens
.length
; i
++) {
21 buf
.append('/').append(tokens
[i
]);
23 return buf
.toString();
26 /** Module node name based on module name and version */
27 public static String
getModuleNodeName(ModuleDescriptor moduleDescriptor
) {
28 return moduleDescriptor
.getName() + "_" + moduleDescriptor
.getVersion();
31 /** Extracts the execution module name of a flow */
32 public static String
flowExecutionModuleName(String fullFlowPath
) {
33 String
[] tokens
= fullFlowPath
.split("/");
34 String moduleNodeName
= tokens
[AGENT_FACTORY_DEPTH
+ 2];
35 return moduleNodeName
.substring(0, moduleNodeName
.lastIndexOf('_'));
38 /** Extracts the execution module version of a flow */
39 public static String
flowExecutionModuleVersion(String fullFlowPath
) {
40 String
[] tokens
= fullFlowPath
.split("/");
41 String moduleNodeName
= tokens
[AGENT_FACTORY_DEPTH
+ 2];
42 return moduleNodeName
.substring(moduleNodeName
.lastIndexOf('_') + 1);
45 /** Extracts the agent factory of a flow */
46 public static String
flowAgentFactoryPath(String fullFlowPath
) {
47 String
[] tokens
= fullFlowPath
.split("/");
48 StringBuffer buf
= new StringBuffer(fullFlowPath
.length());
49 // first token is always empty
50 for (int i
= 1; i
< AGENT_FACTORY_DEPTH
+ 1; i
++) {
51 buf
.append('/').append(tokens
[i
]);
53 return buf
.toString();
56 /** Create a new execution process path based on the current time */
57 public static String
createExecutionProcessPath(String uuid
) {
58 Calendar now
= new GregorianCalendar();
59 return SlcJcrConstants
.PROCESSES_BASE_PATH
+ '/'
60 + JcrUtils
.dateAsPath(now
, true) + uuid
;
64 /** Prevents instantiation */
65 private SlcJcrUtils() {
69 public static void main(String
[] args
) {
70 String path
= "/slc/agents/vm/default/org.argeo_1.2.3/myPath/myFlow";
71 System
.out
.println("Flow relative path: " + flowRelativePath(path
));
72 System
.out
.println("Execution Module Name: "
73 + flowExecutionModuleName(path
));
74 System
.out
.println("Execution Module Version: "
75 + flowExecutionModuleVersion(path
));
76 System
.out
.println("Agent Factory path: " + flowAgentFactoryPath(path
));