def parseWorkflowXML( self, xml, encoding=None ): """ Pseudo API. """ dom = domParseString( xml ) root = dom.getElementsByTagName( 'dc-workflow' )[ 0 ] workflow_id = _getNodeAttribute( root, 'workflow_id', encoding ) title = _getNodeAttribute( root, 'title', encoding ) state_variable = _getNodeAttribute( root, 'state_variable', encoding ) initial_state = _getNodeAttribute( root, 'initial_state', encoding ) states = _extractStateNodes( root, encoding ) transitions = _extractTransitionNodes( root, encoding ) variables = _extractVariableNodes( root, encoding ) worklists = _extractWorklistNodes( root, encoding ) permissions = _extractPermissionNodes( root, encoding ) scripts = _extractScriptNodes( root, encoding ) return ( workflow_id , title , state_variable , initial_state , states , transitions , variables , worklists , permissions , scripts )
def _extractScriptNodes( root, encoding=None ): result = [] for s_node in root.getElementsByTagName( 'script' ): try: function = _getNodeAttribute( s_node, 'function' ) except ValueError: function = '' try: module = _getNodeAttribute( s_node, 'module' ) except ValueError: module = '' info = { 'script_id' : _getNodeAttribute( s_node, 'script_id' ) , 'meta_type' : _getNodeAttribute( s_node, 'type' , encoding ) , 'function' : function , 'module' : module } filename = _queryNodeAttribute( s_node, 'filename' , None, encoding ) if filename is not None: info[ 'filename' ] = filename result.append( info ) return result
def _extractScriptNodes(root, encoding=None): result = [] for s_node in root.getElementsByTagName('script'): try: function = _getNodeAttribute(s_node, 'function') except ValueError: function = '' try: module = _getNodeAttribute(s_node, 'module') except ValueError: module = '' info = { 'script_id': _getNodeAttribute(s_node, 'script_id'), 'meta_type': _getNodeAttribute(s_node, 'type', encoding), 'function': function, 'module': module } filename = _queryNodeAttribute(s_node, 'filename', None, encoding) if filename is not None: info['filename'] = filename result.append(info) return result
def parseWorkflowXML( self, xml, encoding=None ): """ Pseudo API. """ dom = domParseString( xml ) root = dom.getElementsByTagName( 'dc-workflow' )[ 0 ] workflow_id = _getNodeAttribute( root, 'workflow_id', encoding ) title = _getNodeAttribute( root, 'title', encoding ) state_variable = _getNodeAttribute( root, 'state_variable', encoding ) initial_state = _getNodeAttribute( root, 'initial_state', encoding ) states = _extractStateNodes( root ) transitions = _extractTransitionNodes( root ) variables = _extractVariableNodes( root ) worklists = _extractWorklistNodes( root ) permissions = _extractPermissionNodes( root ) scripts = _extractScriptNodes( root ) return ( workflow_id , title , state_variable , initial_state , states , transitions , variables , worklists , permissions , scripts )
def _extractAliasesNode(parent, encoding=None): result = {} aliases = parent.getElementsByTagName('aliases')[0] for alias in aliases.getElementsByTagName('alias'): alias_from = _getNodeAttribute(alias, 'from', encoding) alias_to = _getNodeAttribute(alias, 'to', encoding) result[alias_from] = alias_to return result
def _extractMatchNode( parent, encoding=None ): nodes = parent.getElementsByTagName( 'match' ) result = {} for node in nodes: name = _getNodeAttribute( node, 'name', encoding ) values = _getNodeAttribute( node, 'values', encoding ) result[ name ] = _SEMICOLON_LIST_SPLITTER.split( values ) return result
def _extractMatchNode(parent, encoding=None): nodes = parent.getElementsByTagName('match') result = {} for node in nodes: name = _getNodeAttribute(node, 'name', encoding) values = _getNodeAttribute(node, 'values', encoding) result[name] = _SEMICOLON_LIST_SPLITTER.split(values) return result
def _extractActionNode( parent, encoding=None ): nodes = parent.getElementsByTagName( 'action' ) assert len( nodes ) <= 1, nodes if len( nodes ) < 1: return { 'name' : '', 'url' : '', 'category' : '' } node = nodes[ 0 ] return { 'name' : _coalesceTextNodeChildren( node, encoding ) , 'url' : _getNodeAttribute( node, 'url', encoding ) , 'category' : _getNodeAttribute( node, 'category', encoding ) }
def _extractVariableNodes( root, encoding=None ): result = [] for v_node in root.getElementsByTagName( 'variable' ): info = { 'variable_id' : _getNodeAttribute( v_node, 'variable_id' , encoding ) , 'description' : _extractDescriptionNode( v_node, encoding ) , 'for_catalog' : _getNodeAttributeBoolean( v_node , 'for_catalog' ) , 'for_status' : _getNodeAttributeBoolean( v_node , 'for_status' ) , 'update_always' : _getNodeAttributeBoolean( v_node , 'update_always' ) , 'default' : _extractDefaultNode( v_node, encoding ) , 'guard' : _extractGuardNode( v_node, encoding ) } result.append( info ) return result
def _extractStateNodes( root, encoding=None ): result = [] for s_node in root.getElementsByTagName( 'state' ): info = { 'state_id' : _getNodeAttribute( s_node, 'state_id', encoding ) , 'title' : _getNodeAttribute( s_node, 'title', encoding ) , 'description' : _extractDescriptionNode( s_node, encoding ) } info[ 'transitions' ] = [ _getNodeAttribute( x, 'transition_id' , encoding ) for x in s_node.getElementsByTagName( 'exit-transition' ) ] info[ 'permissions' ] = permission_map = {} for p_map in s_node.getElementsByTagName( 'permission-map' ): name = _getNodeAttribute( p_map, 'name', encoding ) acquired = _getNodeAttributeBoolean( p_map, 'acquired' ) roles = [ _coalesceTextNodeChildren( x, encoding ) for x in p_map.getElementsByTagName( 'permission-role' ) ] if not acquired: roles = tuple( roles ) permission_map[ name ] = roles info[ 'groups' ] = group_map = [] for g_map in s_node.getElementsByTagName( 'group-map' ): name = _getNodeAttribute( g_map, 'name', encoding ) roles = [ _coalesceTextNodeChildren( x, encoding ) for x in g_map.getElementsByTagName( 'group-role' ) ] group_map.append( ( name, tuple( roles ) ) ) info[ 'variables' ] = var_map = {} for assignment in s_node.getElementsByTagName( 'assignment' ): name = _getNodeAttribute( assignment, 'name', encoding ) type_id = _getNodeAttribute( assignment, 'type', encoding ) value = _coalesceTextNodeChildren( assignment, encoding ) var_map[ name ] = { 'name' : name , 'type' : type_id , 'value' : value } result.append( info ) return result
def _extractStateNodes(root, encoding=None): result = [] for s_node in root.getElementsByTagName('state'): info = { 'state_id': _getNodeAttribute(s_node, 'state_id', encoding), 'title': _getNodeAttribute(s_node, 'title', encoding), 'description': _extractDescriptionNode(s_node, encoding) } info['transitions'] = [ _getNodeAttribute(x, 'transition_id', encoding) for x in s_node.getElementsByTagName('exit-transition') ] info['permissions'] = permission_map = {} for p_map in s_node.getElementsByTagName('permission-map'): name = _getNodeAttribute(p_map, 'name', encoding) acquired = _getNodeAttributeBoolean(p_map, 'acquired') roles = [ _coalesceTextNodeChildren(x, encoding) for x in p_map.getElementsByTagName('permission-role') ] if not acquired: roles = tuple(roles) permission_map[name] = roles info['groups'] = group_map = [] for g_map in s_node.getElementsByTagName('group-map'): name = _getNodeAttribute(g_map, 'name', encoding) roles = [ _coalesceTextNodeChildren(x, encoding) for x in g_map.getElementsByTagName('group-role') ] group_map.append((name, tuple(roles))) info['variables'] = var_map = {} for assignment in s_node.getElementsByTagName('assignment'): name = _getNodeAttribute(assignment, 'name', encoding) type_id = _getNodeAttribute(assignment, 'type', encoding) value = _coalesceTextNodeChildren(assignment, encoding) var_map[name] = {'name': name, 'type': type_id, 'value': value} result.append(info) return result
def _extractTransitionNodes(root, encoding=None): result = [] for t_node in root.getElementsByTagName('transition'): info = { 'transition_id': _getNodeAttribute(t_node, 'transition_id', encoding), 'title': _getNodeAttribute(t_node, 'title', encoding), 'description': _extractDescriptionNode(t_node, encoding), 'new_state': _getNodeAttribute(t_node, 'new_state', encoding), 'trigger': _getNodeAttribute(t_node, 'trigger', encoding), 'before_script': _getNodeAttribute(t_node, 'before_script', encoding), 'after_script': _getNodeAttribute(t_node, 'after_script', encoding), 'action': _extractActionNode(t_node, encoding), 'guard': _extractGuardNode(t_node, encoding) } info['variables'] = var_map = {} for assignment in t_node.getElementsByTagName('assignment'): name = _getNodeAttribute(assignment, 'name', encoding) expr = _coalesceTextNodeChildren(assignment, encoding) var_map[name] = expr result.append(info) return result
def _extractTransitionNodes( root, encoding=None ): result = [] for t_node in root.getElementsByTagName( 'transition' ): info = { 'transition_id' : _getNodeAttribute( t_node, 'transition_id' , encoding ) , 'title' : _getNodeAttribute( t_node, 'title', encoding ) , 'description' : _extractDescriptionNode( t_node, encoding ) , 'new_state' : _getNodeAttribute( t_node, 'new_state' , encoding ) , 'trigger' : _getNodeAttribute( t_node, 'trigger', encoding ) , 'before_script' : _getNodeAttribute( t_node, 'before_script' , encoding ) , 'after_script' : _getNodeAttribute( t_node, 'after_script' , encoding ) , 'action' : _extractActionNode( t_node, encoding ) , 'guard' : _extractGuardNode( t_node, encoding ) } info[ 'variables' ] = var_map = {} for assignment in t_node.getElementsByTagName( 'assignment' ): name = _getNodeAttribute( assignment, 'name', encoding ) expr = _coalesceTextNodeChildren( assignment, encoding ) var_map[ name ] = expr result.append( info ) return result
def _extractRoleNodes(parent, encoding=None): result = [] for r_node in parent.getElementsByTagName('role'): value = _getNodeAttribute(r_node, 'name', encoding) result.append(value) return tuple(result)
def _extractWorklistNodes(root, encoding=None): result = [] for w_node in root.getElementsByTagName('worklist'): info = { 'worklist_id': _getNodeAttribute(w_node, 'worklist_id', encoding), 'title': _getNodeAttribute(w_node, 'title', encoding), 'description': _extractDescriptionNode(w_node, encoding), 'match': _extractMatchNode(w_node, encoding), 'action': _extractActionNode(w_node, encoding), 'guard': _extractGuardNode(w_node, encoding) } result.append(info) return result
def _extractWorklistNodes( root, encoding=None ): result = [] for w_node in root.getElementsByTagName( 'worklist' ): info = { 'worklist_id' : _getNodeAttribute( w_node, 'worklist_id' , encoding ) , 'title' : _getNodeAttribute( w_node, 'title' , encoding ) , 'description' : _extractDescriptionNode( w_node, encoding ) , 'match' : _extractMatchNode( w_node, encoding ) , 'action' : _extractActionNode( w_node, encoding ) , 'guard' : _extractGuardNode( w_node, encoding ) } result.append( info ) return result
def _extractScriptNodes( root, encoding=None ): result = [] for s_node in root.getElementsByTagName( 'script' ): info = { 'script_id' : _getNodeAttribute( s_node, 'script_id' ) , 'meta_type' : _getNodeAttribute( s_node, 'type' , encoding ) } filename = _queryNodeAttribute( s_node, 'filename' , None, encoding ) if filename is not None: info[ 'filename' ] = filename result.append( info ) return result
def _extractScriptNodes(root, encoding=None): result = [] for s_node in root.getElementsByTagName('script'): info = { 'script_id': _getNodeAttribute(s_node, 'script_id'), 'meta_type': _getNodeAttribute(s_node, 'type', encoding) } filename = _queryNodeAttribute(s_node, 'filename', None, encoding) if filename is not None: info['filename'] = filename result.append(info) return result
def _extractPermissionNodes(parent, encoding=None): result = [] for p_node in parent.getElementsByTagName('permission'): name = _getNodeAttribute(p_node, 'name', encoding) roles = _extractRoleNodes(p_node, encoding) acquire = _getNodeAttributeBoolean(p_node, 'acquire') result.append({'name': name, 'roles': roles, 'acquire': acquire}) return tuple(result)
def _extractActionProviderNodes(parent, encoding=None): result = [] for ap_node in parent.getElementsByTagName('action-provider'): id = _getNodeAttribute(ap_node, 'id', encoding) actions = _extractActionNodes(ap_node, encoding) result.append( { 'id': id, 'actions': actions } ) return result
def _extractPermissionNodes(parent, encoding=None): result = [] for p_node in parent.getElementsByTagName('permission'): name = _getNodeAttribute(p_node, 'name', encoding) roles = _extractRoleNodes(p_node, encoding) acquire = _getNodeAttributeBoolean(p_node, 'acquire') result.append( { 'name': name, 'roles': roles, 'acquire': acquire } ) return tuple(result)
def _es(key): return _getNodeAttribute(a_node, key, encoding)