cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncTest Manager - Failure Reasons.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2012-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncfrom testmanager.core.base import ModelDataBase, ModelLogicBase, TMExceptionBase
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass FailureReasonData(ModelDataBase):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Reason Data.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksIdAttr = 'idFailureReason';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idFailureReason = 'FailureReasonData_idFailureReason'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsEffective = 'FailureReasonData_tsEffective'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_tsExpire = 'FailureReasonData_tsExpire'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_uidAuthor = 'FailureReasonData_uidAuthor'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_idFailureCategory = 'FailureReasonData_idFailureCategory'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sShort = 'FailureReasonData_sShort'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_sFull = 'FailureReasonData_sFull'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_iTicket = 'FailureReasonData_iTicket'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ksParam_asUrls = 'FailureReasonData_asUrls'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync kasAllowNullAttributes = [ 'idFailureReason', 'tsEffective', 'tsExpire',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'uidAuthor', 'iTicket', 'asUrls' ]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def __init__(self):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ModelDataBase.__init__(self);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Initialize with defaults.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # See the database for explanations of each of these fields.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync #
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idFailureReason = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idFailureCategory = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sShort = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sFull = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.iTicket = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asUrls = None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def initFromDbRow(self, aoRow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Re-initializes the data with a row from a SELECT * FROM FailureReasons.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns self. Raises exception if the row is None or otherwise invalid.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if aoRow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase('Failure Reason not found.');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idFailureReason = aoRow[0]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsEffective = aoRow[1]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.tsExpire = aoRow[2]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.uidAuthor = aoRow[3]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.idFailureCategory = aoRow[4]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sShort = aoRow[5]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.sFull = aoRow[6]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.iTicket = aoRow[7]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.asUrls = aoRow[8]
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass FailureReasonLogic(ModelLogicBase): # pylint: disable=R0903
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Failure Reason logic.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForListing(self, iStart, cMaxRows, tsNow):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Fetches Failure Category records.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array (list) of FailureReasonData items, empty list if none.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Raises exception on error.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsNow is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (cMaxRows, iStart,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'LIMIT %s OFFSET %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsNow, tsNow, cMaxRows, iStart,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRows.append(FailureReasonData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRows
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def fetchForCombo(self, tsEffective = None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Failure Reasons for a combo box.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of (value [idFailureReason], drop-down-name [sShort],
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync hover-text [sFull]) tuples.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason, sShort, sFull\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY sShort'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsEffective, tsEffective))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getById(self, idFailureReason):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Get Failure Reason data by idFailureReason"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::timestamp\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureReason = %s;', (idFailureReason,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aRows = self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(aRows) not in (0, 1):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise self._oDb.integrityException(
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Found more than one failure reasons with the same credentials. Database structure is corrupted.')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return FailureReasonData().initFromDbRow(aRows[0])
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except IndexError:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getIdsByCategory(self, idFailureCategory, tsEffective=None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of Failure Ressons IDs,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync all the items belong to @param idFailureCategory
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (idFailureCategory,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT idFailureReason\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND idFailureCategory = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsEffective, tsEffective, idFailureCategory))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return self._oDb.fetchAll()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def getAll(self, tsEffective=None):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Gets the list of all Failure Reasons.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns an array of FailureReasonData instances.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if tsEffective is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire > %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsEffective <= %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'ORDER BY idFailureReason DESC'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync , (tsEffective, tsEffective))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet = []
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for aoRow in self._oDb.fetchAll():
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoRet.append(FailureReasonData().initFromDbRow(aoRow))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return aoRet
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def addEntry(self, oFailureReasonData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Add record to database"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record with the same sShort fiels is already exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('SELECT *\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'FROM FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE tsExpire = \'infinity\'::TIMESTAMP\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND sShort = %s\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oFailureReasonData.sShort,))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if len(self._oDb.fetchAll()) != 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise Exception('Record already exist')
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO FailureReasons (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor, idFailureCategory,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sShort, sFull, iTicket, asUrls'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ')\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s)',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (uidAuthor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.idFailureCategory,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.sShort,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.sFull,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.iTicket,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.asUrls))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fCommit:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.commit()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def remove(self, uidAuthor, idFailureReason, fNeedCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE FailureReasons\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureReason = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (uidAuthor, idFailureReason))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Also historize Black List records
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('UPDATE BuildBlackList\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'SET tsExpire = CURRENT_TIMESTAMP,\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'WHERE idFailureReason = %s\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' AND tsExpire = \'infinity\'::TIMESTAMP\n',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (uidAuthor, idFailureReason))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fNeedCommit:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.commit()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def editEntry(self, oFailureReasonData, uidAuthor, fCommit=True):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """Modify database record"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if record exists
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonDataOld = self.getById(oFailureReasonData.idFailureReason)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oFailureReasonDataOld is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise TMExceptionBase(
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'Failure Reason (id: %d) does not exist'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync % oFailureReasonData.idFailureReason)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Check if anything has been changed
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oFailureReasonData.isEqual(oFailureReasonDataOld):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Historize record
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self.remove(
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uidAuthor, oFailureReasonData.idFailureReason, fNeedCommit=False)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Add new record (keeping its ID)
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.execute('INSERT INTO FailureReasons (\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idFailureReason,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' uidAuthor,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' idFailureCategory,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sShort,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' sFull,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' iTicket,'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ' asUrls'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ')\n'
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync 'VALUES (%s, %s, %s, %s, %s, %s, %s)',
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync (oFailureReasonData.idFailureReason,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync uidAuthor,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.idFailureCategory,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.sShort,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.sFull,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.iTicket,
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oFailureReasonData.asUrls
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync ))
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if fCommit:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync self._oDb.commit()
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return True