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=693389d119fe02bd1ce462c93061a988b7ce18c7;hb=ce8f53763eec2a2b9e15e97f2eaa8468b551ea31;hp=51ea14e98d0d0a24b790da8e70a7d1168fb6d665;hpb=86fc845e533e99358ec3de7182ea0c01bcd1c432;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 51ea14e98..693389d11 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 @@ -1,13 +1,33 @@ +/* + * Copyright (C) 2007-2012 Argeo GmbH + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.argeo.slc.jcr; import java.util.Calendar; import java.util.GregorianCalendar; +import java.util.List; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.Property; import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.nodetype.NodeType; import org.argeo.jcr.JcrUtils; +import org.argeo.jcr.UserJcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.core.execution.PrimitiveAccessor; import org.argeo.slc.core.execution.PrimitiveUtils; @@ -31,23 +51,28 @@ public class SlcJcrUtils implements SlcNames { return buf.toString(); } - /** Module node name based on module name and version */ - public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) { - return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion(); + /** Extracts the path to the related execution module */ + public static String modulePath(String fullFlowPath) { + String[] tokens = fullFlowPath.split("/"); + StringBuffer buf = new StringBuffer(fullFlowPath.length()); + for (int i = 0; i < AGENT_FACTORY_DEPTH + 3; i++) { + if (!tokens[i].equals("")) + buf.append('/').append(tokens[i]); + } + return buf.toString(); } - /** Extracts the execution module name of a flow */ - public static String flowExecutionModuleName(String fullFlowPath) { + /** Extracts the module name from a flow path */ + public static String moduleName(String fullFlowPath) { String[] tokens = fullFlowPath.split("/"); - String moduleNodeName = tokens[AGENT_FACTORY_DEPTH + 2]; - return moduleNodeName.substring(0, moduleNodeName.lastIndexOf('_')); + String moduleName = tokens[AGENT_FACTORY_DEPTH + 2]; + moduleName = moduleName.substring(0, moduleName.indexOf('_')); + return moduleName; } - /** Extracts the execution module version of a flow */ - public static String flowExecutionModuleVersion(String fullFlowPath) { - String[] tokens = fullFlowPath.split("/"); - String moduleNodeName = tokens[AGENT_FACTORY_DEPTH + 2]; - return moduleNodeName.substring(moduleNodeName.lastIndexOf('_') + 1); + /** Module node name based on module name and version */ + public static String getModuleNodeName(ModuleDescriptor moduleDescriptor) { + return moduleDescriptor.getName() + "_" + moduleDescriptor.getVersion(); } /** Extracts the agent factory of a flow */ @@ -62,17 +87,54 @@ public class SlcJcrUtils implements SlcNames { } /** Create a new execution process path based on the current time */ - public static String createExecutionProcessPath(String uuid) { + public static String createExecutionProcessPath(Session session, String uuid) { Calendar now = new GregorianCalendar(); - return SlcJcrConstants.PROCESSES_BASE_PATH + '/' + return getSlcProcessesBasePath(session) + '/' + JcrUtils.dateAsPath(now, true) + uuid; } - /** Create a new execution result path based on the current time */ - public static String createResultPath(String uuid) { + /** Get the base for the user processi. */ + public static String getSlcProcessesBasePath(Session session) { + try { + Node userHome = UserJcrUtils.getUserHome(session); + if (userHome == null) + throw new SlcException("No user home available for " + + session.getUserID()); + return userHome.getPath() + '/' + SlcNames.SLC_SYSTEM + '/' + + SlcNames.SLC_PROCESSES; + } catch (RepositoryException re) { + throw new SlcException( + "Unexpected error while getting Slc Results Base Path.", re); + } + } + + /** + * 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(); - return SlcJcrConstants.RESULTS_BASE_PATH + '/' - + JcrUtils.dateAsPath(now, true) + uuid; + 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 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; } /** @@ -94,10 +156,14 @@ public class SlcJcrUtils implements SlcNames { 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)) @@ -130,9 +196,14 @@ public class SlcJcrUtils implements SlcNames { NodeIterator it = node.getNodes(); while (it.hasNext()) { - Integer childStatus = aggregateTestStatus(it.nextNode()); - if (childStatus > status) - status = childStatus; + Node curr = it.nextNode(); + + // Manually skip aggregated status + if (!SlcNames.SLC_AGGREGATED_STATUS.equals(curr.getName())) { + Integer childStatus = aggregateTestStatus(curr); + if (childStatus > status) + status = childStatus; + } } return status; } catch (Exception e) { @@ -166,7 +237,10 @@ public class SlcJcrUtils implements SlcNames { NodeIterator it = node.getNodes(); while (it.hasNext()) { Node child = it.nextNode(); - aggregateTestMessages(child, messages); + // Manually skip aggregated status + if (!SlcNames.SLC_AGGREGATED_STATUS.equals(child.getName())) { + aggregateTestMessages(child, messages); + } } return messages; } catch (Exception e) { @@ -174,20 +248,8 @@ public class SlcJcrUtils implements SlcNames { + node, e); } } - + /** Prevents instantiation */ private SlcJcrUtils() { - } - - public static void main(String[] args) { - String path = "/slc/agents/vm/default/org.argeo_1.2.3/myPath/myFlow"; - System.out.println("Flow relative path: " + flowRelativePath(path)); - System.out.println("Execution Module Name: " - + flowExecutionModuleName(path)); - System.out.println("Execution Module Version: " - + flowExecutionModuleVersion(path)); - System.out.println("Agent Factory path: " + flowAgentFactoryPath(path)); - } - -} +} \ No newline at end of file