📄 __init__.py
字号:
hi.author = author hi.text = text hi.date = currentTimeMillis() hi.host = getfqdn() hi.workflowDefinitionName = \ self.lastExpressionId.workflowDefinitionName hi.workflowDefinitionRevision = \ self.lastExpressionId.workflowDefinitionRevision hi.workflowInstanceId = \ self.lastExpressionId.workflowInstanceId hi.expressionId = \ self.lastExpressionId.expressionId if self.history == None: self.history = [] self.history.append(hi)## FLOW EXPRESSION ID# class FlowExpressionId: """ This class is very important, it helps uniquely identifying a workitem by linking it to the expression that last handled it. """ def __init__ (self): self.initialEngineId = None self.engineId = None self.workflowDefinitionUrl = None self.workflowDefinitionName = None self.workflowDefinitionRevision = None self.workflowInstanceId = -1L self.expressionName = None self.expressionId = -1 self.owfeVersion = None def __hash__ (self): return hash(__str__(self)) def __cmp__ (self, other): if other == None: return 1 return hash(self) - hash(other) def __str__ (self): return '(fei %s %s/%s %s %s %s %s %s %s)' % \ (self.owfeVersion, \ self.engineId, \ self.initialEngineId, \ self.workflowDefinitionUrl, \ self.workflowDefinitionName, \ self.workflowDefinitionRevision, \ self.workflowInstanceId, \ self.expressionName, \ self.expressionId)def strToFei (s): fei = FlowExpressionId() ss = s.split(' ') fei.owfeVersion = ss[2] ssRawEngineId = ss[3].split('/') fei.engineId = ssRawEngineId[0] fei.initialEngineId = ssRawEngineId[1] fei.workflowDefinitionUrl = ss[4] fei.workflowDefinitionName = ss[5] fei.workflowDefinitionRevision = ss[6] fei.workflowInstanceId = ss[7] fei.expressionName = ss[8] fei.expressionId = ss[9] return fei## FILTER#FILTER_TYPE_OPEN = 0FILTER_TYPE_CLOSED = 1class Filter: """ A filter is used by participant expressions to determine which field should be visible / modified by the participant they point to. A client application should enforce those filters. Anyway, if for example a client modifies the content of a read-only field (as determined in the flow definition), the engine will discard this change when the workitem comes back to it. """ def __init__ (self): self.name = None self.type = -1 self.addAllowed = 1 self.removeAllowed = 1 self.entryList = None def isOpen (self): return self.type == FILTER_TYPE_OPEN def _getPermissions (self, fieldName): for entry in self.entryList: if entry.getFieldRegex().matches(fieldName): return entry.permissions.strip() return None def _hasPermission (self, fieldName, permissionChar): for entry in self.entryList: if entry.getFieldRegex().matches(fieldName): return entry.permissions.find(permissionChar) > -1 return 0 def _knowsAbout (self, fieldName): return self._getPermissions(fieldName) != null def allowWrite (self, fieldName): if self.type == FILTER_TYPE_OPEN and not self._knowsAbout(fieldName): return 1 return self._hasPermission(fieldName, 'w') def allowRead (self, fieldName): if self.type == FILTER_TYPE_OPEN and not self._knowsAbout(fieldName): return 1 return self._hasPermission(fieldName, 'r') def allowRemove (self, fieldName): if not self.removeAllowed: return 0 if self.type == FILTER_TYPE_OPEN and not self._knowsAbout(fieldName): return 1 return self._hasPermission(fieldName, 'w')class FilterEntry: """ A filter is a list of FilterEntry """ def __init__ (self): self.fieldRegex = None self.compiledFieldRegex = None self.permissions = None self.attributeClassName = None def getFieldRegex (self): if self.compiledFieldRegex == None: self.compiledFieldRegex = re.compile(self.fieldRegex) return self.compiledFieldRegex## STORE#class Store: """ Models the store info a client can fetch from its worksession """ def __init__ (self): self.name = None self.workitemCount = 0 self.mayRead = 0 self.mayWrite = 0 self.mayDelegate = 0 self.mayBrowse = 0## HISTORY ITEM#class HistoryItem: """ An InFlowWorkitem contains a list of HistoryItem, it constitues the history of the workitem : where it has passed """ def __init__ (self): self.author = None self.date = None self.host = None self.text = None self.workflowDefinitionName = None self.workflowDefinitionRevision = None self.workflowInstanceId = -1L self.expressionId = -1## LAUNCHABLES#class Launchable: """ gathers the info necessary for launching a flow. A client usually obtains a Launchable instance through the worksession. It's used to build a Launchitem and to launch a flow """ def __init__ (self): self.engineId = None self.url = None## EXPRESSIONS#class Expression: """ this class is used to gather information about a flow expression as needed for a control session. """ def __init__ (self): self.id = None self.applyTime = None self.frozenTime = None def __str__ (self): s = '' if self.state == 'frozen': s += 'f' else: s += '-' if not self.applyTime: s += 'u' else: s += '-' s = ('%s %s %s %s %s %s' % \ (s, \ self.id.workflowInstanceId, \ self.id.workflowDefinitionName, \ self.id.workflowDefinitionRevision, \ self.id.expressionName, \ self.id.expressionId)) return s## MISC HELP METHODSdef toStringAttribute (object) : """ Turns whatever into a StringAttribute """ if not object: raise TypeError, "Cannot turn 'None' into a StringAttribute" if isinstance(object, StringAttribute): return object if isinstance(object, AtomicAttribute): return StringAttribute(str(object.value)) return StringAttribute(str(object))## the initial author of the following help methods is Richard Jennings# 2004-02-11#ENCODING = 'latin1'def py2owfe (object): """ contract: convert a python type to an owfe type for string, int, list and dict args, exception for all others. drawback: boolean are integers in python so they become IntAttributes for OpenWFE """ if isinstance(object, Attribute): return object if isinstance(object, DictType): return pdict2odict(object) if isinstance(object, ListType): return plist2olist(object) if isinstance(object, StringType): return StringAttribute(object) if isinstance(object, UnicodeType): return StringAttribute(object) if isinstance(object, IntType): return IntegerAttribute(object) if isinstance(object, LongType): return LongAttribute(object) if isinstance(object, FloatType): return DoubleAttribute(object) else: raise TypeError, "py2owfe:object %s type is not supported" % object.__class__def pdict2odict (pdict): """ contract: convert a python dict object to an owfe dict object for string, int, list and dict types, exception for all others. """ odict = StringMapAttribute() for key in pdict.keys(): k = StringAttribute(key) v = py2owfe(pdict[key]) odict[k] = v return odictdef plist2olist (plist): """ Contract: convert a python list object to an owfe list object for string, int, list and dict types, exception for all others. """ olist = ListAttribute() for item in plist: olist.append(py2owfe(item)) return olistdef owfe2py (object): """ contract: convert an owfe type to a python type for string, int, list and dict args, exception for all others. """ if isinstance(object, StringAttribute): #return object.value.encode(ENCODING) return object.value.encode(getEncoding()) if isinstance(object, AtomicAttribute): return object.value if isinstance(object, ListAttribute): return olist2plist(object) if isinstance(object, StringMapAttribute): return odict2pdict(object) if isinstance(object, MapAttribute): return odict2pdict(object) raise TypeError, "owfe2py:object %s type is not supported" % objectdef odict2pdict (odict): """ contract: convert an owfe dict object to a python dict object for string, int, list and dict types, exception for all others. """ pdict = {} do = odict.data for key in do.keys(): k = owfe2py(key) v = owfe2py(do[key]) pdict[k] = v return pdictdef olist2plist (olist): """ contract: convert an owfe list object to a python list object for string, int, list and dict types, exception for all others. """ plist = [] lo = olist.data for item in lo: #plist += owfe2py(item) plist.append(owfe2py(item)) # as suggested (patch) by Richard Jennings return plist
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -