]> git.argeo.org Git - gpl/argeo-slc.git/blob - jcr/SlcJcrUtils.java
Prepare next development cycle
[gpl/argeo-slc.git] / jcr / SlcJcrUtils.java
1 package org.argeo.slc.jcr;
2
3 import java.util.Calendar;
4 import java.util.GregorianCalendar;
5
6 import org.argeo.jcr.JcrUtils;
7 import org.argeo.slc.deploy.ModuleDescriptor;
8
9 /**
10 * Utilities around the SLC JCR model. Note that it relies on fixed base paths
11 * (convention over configuration) for optimization purposes.
12 */
13 public class SlcJcrUtils {
14 public final static Integer AGENT_FACTORY_DEPTH = 3;
15
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]);
22 }
23 return buf.toString();
24 }
25
26 /** Module node name based on module name and version */
27 public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) {
28 return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion();
29 }
30
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('_'));
36 }
37
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);
43 }
44
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]);
52 }
53 return buf.toString();
54 }
55
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;
61
62 }
63
64 /** Prevents instantiation */
65 private SlcJcrUtils() {
66
67 }
68
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));
77 }
78
79 }