⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 __init__.py

📁 OpenWFE是一个开放源码的Java工作流引擎。它是一个完整的业务处理管理套件:一个引擎
💻 PY
字号:
## Copyright (c) 2005, John Mettraux, OpenWFE.org# All rights reserved.# # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met:# # . Redistributions of source code must retain the above copyright notice, this#   list of conditions and the following disclaimer.  # # . Redistributions in binary form must reproduce the above copyright notice, #   this list of conditions and the following disclaimer in the documentation #   and/or other materials provided with the distribution.# # . Neither the name of the "OpenWFE" nor the names of its contributors may be#   used to endorse or promote products derived from this software without#   specific prior written permission.# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE.## $Id: __init__.py 2402 2006-03-07 14:30:05Z jmettraux $#"""    A python library for interacting with the worklist REST server    $Id: __init__.py 2402 2006-03-07 14:30:05Z jmettraux $"""import refrom openwfe.rest import RestSession, getSessionfrom openwfe.workitem import codec, StringAttribute#def printFirstLine (xmlData):#    if not xmlData: return#    i = xmlData.find('\n')#    print xmlData[0:i]## WorkSessionclass WorkSession (RestSession):    def __init__ (self, server, port, username, password, discardHistory=0):        """            Instantiates a new WorkSession.        """        self.url = "http://%s:%i/worklist" % (server, port)        self.sessionId = getSession(self.url, username, password)        self.discardHistory = discardHistory    #    # session methods    def getStoreNames (self):        """            This is the old name of the current method which is now            named 'listStores'.            But this method is still operational.        """        return self.listStores()    def listStores (self):        """            Returns a list of Store instances, detailing the stores            available to the user through the session.            Of course, some stores may be read only.        """        r = self._get('listStores')        return codec.decode(r)    def findFlowInstance (self, storeName, workflowInstanceId):        """            Returns a list of workitems matching a given workflowInstanceId.            This id is usually given as the return of the launch() method.        """        return codec.decode(self._get('findFlowInstance', storeName, id=workflowInstanceId))    def getHeaders (self, storeName, limit=1000):        """            Returns the headers that can be found in a store.            Headers are summary of workitem.        """        return codec.decode(self._get('getHeaders', storeName, limit=limit))    def getWorkitem (self, storeName, flowExpressionId):        """            Fetches a workitem from the worklist, but acquires no lock on it.        """        return self._doPost('getWorkitem', storeName, codec.encode(flowExpressionId))    def getAndLockWorkitem (self, storeName, flowExpressionId):        """            Fetches a workitem from the worklist which keeps it locked.            You can then save it, release it or forward it.        """        return self._doPost('getAndLockWorkitem', storeName, codec.encode(flowExpressionId))    def releaseWorkitem (self, storeName, workitem):        """            Tells the worklist that the workitem can be unlocked.            Any change to the workitem is ignored.        """        return self._doPost('releaseWorkitem', storeName, codec.encode(workitem))    def saveWorkitem (self, storeName, workitem):        """            Gives back the workitem to the worklist which will save changes            made to it.        """        #workitem.history = None             # do travel lighter        return self._doPost('saveWorkitem', storeName, codec.encode(workitem))    def forwardWorkitem (self, storeName, workitem):        """            Gives back the workitem to the worklist, which will take care of            saving it and proceeding it to engine in charge so that the            flow will resume.        """        #if self.discardHistory:         #    # do travel lighter        #    workitem.history = None         return self._doPost('forwardWorkitem', storeName, codec.encode(workitem))    def listLaunchables (self):        """            Returns a list of URL pointing to flows or launchitems that the            user of the worksession is authorized to launch.        """        return self._doPost('listLaunchables', None, None)            # patch by Pau Giner Blasco     def launchFlow (self, engineId, launchitem):        """            With this method the user can launch a new instance of a flow            from the worksession on a given engine.            The engineId must be 'registered' in the participant-map            available to the worklist.        """        data = codec.encode(launchitem)        return self._doPost('launchflow', None, data, engineid=engineId)    def delegate (self, storeName, workitem, targetStoreName):        """            Transfers a workitem from one store to the other.             The user must have a 'delegate' right to the target store            (and of course the read and write rights on the source store).            The store must also belong to the worklist, else            an error will be thrown.        """        #workitem.history = None             # do travel lighter        data = codec.encode(workitem)        return self._doPost \            ('delegate', storeName, data, targetstore=targetStoreName)    #    # direct delegation    #    def delegateToParticipant (self, storeName, workitem, targetParticipant):        """            This method allows user to perform 'direct delegation' :             the workitem is dispatched by the worklist to the given            participant (that must be registered in the participant-map            available to the worklist).        """        #workitem.history = None             # do travel lighter        data = codec.encode(workitem)        return self._doPost \            ('delegate', storeName, data, targetparticipant=targetParticipant)    #    # MISC METHODS    def queryStore (self, storeName, query):        """            This method queries all the workitem headers in a store and return            those (headers) that match the query.            Please note that the query addresses the headers and not the            workitem fields !            Beware, the values in query are considered as regular expressions,            not just plain strings !        """        headers = self.getHeaders(storeName)        if not headers or len(headers) < 1: return []        results = []        for header in headers:            headerDoesMatch = 1            for key in query.keys():                regex = query[key]                headerValue = header.attributes.get(StringAttribute(key))                if not headerValue:                     headerDoesMatch = 0                    break                if hasattr(headerValue, 'value'):                    headerValue = headerValue.value                else:                    headerValue = str(headerValue)                regex = re.compile(regex)                if not regex.match(headerValue):                    headerDoesMatch = 0                    break                        if headerDoesMatch: results.append(header)        return results

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -