Source

dataliberation / issues / tigris / data / TigrisIssue.py

# coding: latin-1
'''
Created on 08.04.2010

@author: dirk
'''

import TigrisActivity
import TigrisAttachment
import TigrisIssueMessage

import io.xml
import xml.dom.minidom


class TigrisIssue:
    '''
    A complete Tigris issue with its messages and activities.
    '''
    def __init__(self):
       
        self.messages = []
        self.activities = []
        self.attachments = []
        self.id = ''
        self.desc = ''
        self.status = ''
        self.assigned = ''
        self.type = ''
        self.delta_ts = ''
        self.creation_ts = ''

    def readXML(self, xpath):
        # Parse XML
        dom = xml.dom.minidom.parse(xpath)
        for i in dom.getElementsByTagName('issue'):
            self.parseNode(i)

    def appendNode(self, doc, root):
        e = doc.createElement("issue")
        io.xml.addChildText(doc, e, "issue_id", self.id)
        io.xml.addChildText(doc, e, "short_desc", self.desc)
        io.xml.addChildText(doc, e, "issue_status", self.status)
        io.xml.addChildText(doc, e, "assigned_to", self.assigned)
        io.xml.addChildText(doc, e, "issue_type", self.type)
        io.xml.addChildText(doc, e, "delta_ts", self.delta_ts)
        io.xml.addChildText(doc, e, "creation_ts", self.creation_ts)
        
        for m in self.messages:
            m.appendNode(doc, e)
        for att in self.attachments:
            att.appendNode(doc, e)
        for act in self.activities:
            act.appendNode(doc, e)
        
        root.appendChild(e)
    
    def parseNode(self, i):
        self.id = io.xml.getChildText(i, 'issue_id')
        self.desc = io.xml.getChildText(i, 'short_desc')
        self.status = io.xml.getChildText(i, 'issue_status')
        self.assigned = io.xml.getChildText(i, 'assigned_to')
        self.type = io.xml.getChildText(i, 'issue_type')
        self.delta_ts = io.xml.getChildText(i, 'delta_ts')
        self.creation_ts = io.xml.getChildText(i, 'creation_ts')

        for m in i.getElementsByTagName('long_desc'):            
            tm = TigrisIssueMessage.TigrisIssueMessage()
            tm.parseNode(m)
            self.messages.append(tm)

        for att in i.getElementsByTagName('attachment'):            
            ta = TigrisAttachment.TigrisAttachment()
            ta.parseNode(att)
            self.attachments.append(ta)

        for act in i.getElementsByTagName('activity'):            
            tc = TigrisActivity.TigrisActivity()
            tc.parseNode(act)
            self.activities.append(tc)

    def getLastMessageDate(self):
        d = ''
        for m in self.messages:
            if m.when > d:
                d = m.when
        
        return d
    
    def getLastAttachmentDate(self):
        d = ''
        for a in self.attachments:
            if a.when > d:
                d = a.when
        
        return d

    def getLastActivityDate(self, field=''):
        d = ''
        if field != '':
            for a in self.activities:
                if (a.field == field) and (a.when > d):
                    d = a.when
        else:
            for a in self.activities:
                if a.when > d:
                    d = a.when

        return d

    def getDeltaDate(self):
        d = self.getLastMessageDate()
        n = self.getLastAttachmentDate()
        if n > d:
            d = n
        n = self.getLastActivityDate()
        if n > d:
            d = n
        
        return d
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.