コード例 #1
0
 def __init__(self):
     CdbObjectManager.__init__(self)
     self.itemDbApi = ItemDbApi()
     self.logControllerImpl = LogControllerImpl()
     self.propertyDbApi = PropertyDbApi()
     self.storageUtility = StorageUtility.getInstance()
コード例 #2
0
class ItemControllerImpl(CdbObjectManager):

    CATALOG_ITEM_DOMAIN_NAME = "Catalog"
    INVENTORY_ITEM_DOMAIN_NAME = "Inventory"
    LOCATION_ITEM_DOMAIN_NAME = "LOCATION"

    def __init__(self):
        CdbObjectManager.__init__(self)
        self.itemDbApi = ItemDbApi()
        self.logControllerImpl = LogControllerImpl()
        self.propertyDbApi = PropertyDbApi()
        self.storageUtility = StorageUtility.getInstance()

    def getItemById(self, itemId):
        return self.itemDbApi.getItemById(itemId)

    def getItemByQrId(self, itemQrId):
        return self.itemDbApi.getItemByQrId(itemQrId)

    def getFirstItemRelationship(self, itemId, relationshipTypeName):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        return self.itemDbApi.getFirstItemElementRelationshipList(
            relationshipTypeName, selfElementId)

    def addItemElementRelationshipByQrId(self,
                                         firstItemQrId,
                                         secondItemQrId,
                                         relationshipTypeName,
                                         enteredByUserId,
                                         relationshipDetails=None,
                                         description=None):
        firstItemId = self.itemDbApi.getItemByQrId(firstItemQrId).data['id']
        secondItemId = self.itemDbApi.getItemByQrId(secondItemQrId).data['id']

        return self.__addItemElementRelationship(firstItemId, secondItemId,
                                                 relationshipTypeName,
                                                 enteredByUserId,
                                                 relationshipDetails,
                                                 description)

    def addItemElementRelationship(self,
                                   firstItemId,
                                   secondItemId,
                                   relationshipTypeName,
                                   enteredByUserId,
                                   relationshipDetails=None,
                                   description=None):
        return self.__addItemElementRelationship(firstItemId, secondItemId,
                                                 relationshipTypeName,
                                                 enteredByUserId,
                                                 relationshipDetails,
                                                 description)

    def __addItemElementRelationship(self,
                                     firstItemId,
                                     secondItemId,
                                     relationshipTypeName,
                                     enteredByUserId,
                                     relationshipDetails=None,
                                     description=None):
        firstSelfElement = self.itemDbApi.getSelfElementByItemId(firstItemId)
        firstSelfElementId = firstSelfElement.data['id']
        secondSelfElement = self.itemDbApi.getSelfElementByItemId(secondItemId)
        secondSelfElementId = secondSelfElement.data['id']

        return self.itemDbApi.addValidItemElementRelationship(
            firstSelfElementId, secondSelfElementId, relationshipTypeName,
            enteredByUserId, relationshipDetails, description)

    def getItemByUniqueAttributes(self,
                                  domainName,
                                  itemName,
                                  itemIdentifier1=None,
                                  itemIdentifier2=None,
                                  derivedFromItemId=None):
        domain = self.itemDbApi.getDomainByName(domainName)
        return self.itemDbApi.getItemByUniqueAttributes(
            domain.data['id'], itemName, itemIdentifier1, itemIdentifier2,
            derivedFromItemId)

    def addLogEntryForItemWithQrId(self, qrId, logEntryText, enteredByUserId,
                                   attachmentName, cherryPyData):
        item = self.itemDbApi.getItemByQrId(qrId)

        itemId = item.data['id']
        return self.addLogEntryForItemWithItemId(itemId, logEntryText,
                                                 enteredByUserId,
                                                 attachmentName, cherryPyData)

    def addLogEntryForItemWithItemId(self, itemId, logEntryText,
                                     enteredByUserId, attachmentName,
                                     cherryPyData):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        # Add log entry
        itemElementLog = self.itemDbApi.addItemElementLog(
            selfElementId, logEntryText, enteredByUserId)
        logEntry = itemElementLog.data['log']

        # Check if log has an attachment that needs to be stored
        if attachmentName is not None and len(attachmentName) > 0:
            logId = logEntry.data['id']
            logAttachment = self.logControllerImpl.addLogAttachment(
                logId, attachmentName, None, enteredByUserId, cherryPyData)
            del (logAttachment.data['log'])
            logAttachmentJsonRep = logAttachment.getFullJsonRep()
            logEntry.data['logAttachmentAdded'] = logAttachmentJsonRep

        return logEntry

    def addPropertyImageToItem(self, itemId, imageFileName, enteredByUserId,
                               cherryPyData):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        if self.itemDbApi.verifyPermissionsForWriteToItemElement(
                enteredByUserId, selfElementId):
            storedAttachmentName = self.storageUtility.storePropertyImage(
                cherryPyData, imageFileName)

            propertyValue = self.itemDbApi.addItemElementImageProperty(
                selfElementId, enteredByUserId, storedAttachmentName,
                imageFileName)

            return propertyValue

        return None

    def addPropertyValueForItemWithId(self,
                                      itemId,
                                      propertyTypeName,
                                      enteredByUserId,
                                      tag=None,
                                      value=None,
                                      units=None,
                                      description=None,
                                      isUserWriteable=None,
                                      isDynamic=False,
                                      displayValue=None):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        propertyValueAdded = self.itemDbApi.addItemElementProperty(
            selfElementId,
            propertyTypeName,
            tag,
            value,
            units,
            description,
            enteredByUserId,
            isUserWriteable,
            isDynamic,
            displayValue=displayValue)

        return propertyValueAdded

    def deletePropertyValuesFromItemByItemId(self, itemId, propertyTypeName,
                                             enteredByUserId):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']
        return self.itemDbApi.deleteItemElementProperties(
            selfElementId, propertyTypeName, enteredByUserId)

    def getParentItems(self, itemId):
        return self.itemDbApi.getParentItems(itemId)

    def getItemElementsForItem(self, itemId):
        return self.itemDbApi.getItemElementsByItemId(itemId)

    def getLogEntriesForItemWithQrId(self, qrId):
        item = self.itemDbApi.getItemByQrId(qrId)
        itemId = item.data['id']
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        return self.logControllerImpl.getLogEntriesForItemElement(
            selfElementId)

    def getLogEntriesForItemWithId(self, itemId):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']
        return self.logControllerImpl.getLogEntriesForItemElement(
            selfElementId)

    def getCatalogItems(self):
        return self.itemDbApi.getItemsOfDomain(self.CATALOG_ITEM_DOMAIN_NAME)

    def getLocationItems(self):
        return self.itemDbApi.getItemsOfDomain(self.LOCATION_ITEM_DOMAIN_NAME)

    def getLocationItemsWithoutParents(self):
        return self.itemDbApi.getItemsOfDomainWithoutParents(
            self.LOCATION_ITEM_DOMAIN_NAME)

    def getItemsDerivedFromItemId(self, derivedFromItemId):
        return self.itemDbApi.getItemsDerivedFromItem(derivedFromItemId)

    def getPropertiesForItemId(self, itemId):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        return self.propertyDbApi.getPropertyValueListForItemElementId(
            selfElementId)

    def getDomains(self):
        return self.itemDbApi.getDomains()

    def addItem(self,
                domainName,
                name,
                createdByUserId,
                ownerUserId,
                ownerGroupId,
                itemProjectName=None,
                itemIdentifier1=None,
                itemIdentifier2=None,
                qrId=None,
                description=None,
                isGroupWriteable=True,
                entityTypeNames=None,
                derivedFromItemId=None):
        return self.itemDbApi.addItem(domainName=domainName,
                                      name=name,
                                      createdByUserId=createdByUserId,
                                      ownerUserId=ownerUserId,
                                      ownerGroupId=ownerGroupId,
                                      itemProjectName=itemProjectName,
                                      itemIdentifier1=itemIdentifier1,
                                      itemIdentifier2=itemIdentifier2,
                                      qrId=qrId,
                                      description=description,
                                      isGroupWriteable=isGroupWriteable,
                                      entityTypeNames=entityTypeNames,
                                      derivedFromItemId=derivedFromItemId)

    def getAvailableInventoryItemStatuses(self):
        return self.itemDbApi.getAvailableInventoryItemStatuses()

    def getInventoryItemStatus(self, itemId):
        return self.itemDbApi.getInventoryItemStatus(itemId)

    def updateInventoryItemStatus(self, itemId, statusName, enteredByUserId):
        return self.itemDbApi.updateInventoryItemStatus(
            itemId, statusName, enteredByUserId)
コード例 #3
0
 def __init__(self):
     CdbObjectManager.__init__(self)
     self.itemDbApi = ItemDbApi()
     self.logControllerImpl = LogControllerImpl()
     self.propertyDbApi = PropertyDbApi()
コード例 #4
0
class ItemControllerImpl(CdbObjectManager):

    CATALOG_ITEM_DOMAIN_NAME = "Catalog"
    INVENTORY_ITEM_DOMAIN_NAME = "Inventory"
    LOCATION_ITEM_DOMAIN_NAME = "LOCATION"

    def __init__(self):
        CdbObjectManager.__init__(self)
        self.itemDbApi = ItemDbApi()
        self.logControllerImpl = LogControllerImpl()
        self.propertyDbApi = PropertyDbApi()

    def getItemById(self, itemId):
        return self.itemDbApi.getItemById(itemId)

    def addLogEntryForItemWithQrId(self, qrId, logEntryText, enteredByUserId,
                                   attachmentName, cherryPyData):
        item = self.itemDbApi.getItemByQrId(qrId)

        itemId = item.data['id']
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        # Add log entry
        itemElementLog = self.itemDbApi.addItemElementLog(
            selfElementId, logEntryText, enteredByUserId)
        logEntry = itemElementLog.data['log']

        # Check if log has an attachment that needs to be stored
        if attachmentName is not None and len(attachmentName) > 0:
            logId = logEntry.data['id']
            logAttachment = self.logControllerImpl.addLogAttachment(
                logId, attachmentName, None, enteredByUserId, cherryPyData)
            del (logAttachment.data['log'])
            logAttachmentJsonRep = logAttachment.getFullJsonRep()
            logEntry.data['logAttachmentAdded'] = logAttachmentJsonRep

        return logEntry

    def getLogEntriesForItemWithQrId(self, qrId):
        item = self.itemDbApi.getItemByQrId(qrId)
        itemId = item.data['id']
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        return self.logControllerImpl.getLogEntriesForItemElement(
            selfElementId)

    def getLogEntriesForItemWithId(self, itemId):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']
        return self.logControllerImpl.getLogEntriesForItemElement(
            selfElementId)

    def getCatalogItems(self):
        return self.itemDbApi.getItemsOfDomain(self.CATALOG_ITEM_DOMAIN_NAME)

    def getItemsDerivedFromItemId(self, derivedFromItemId):
        return self.itemDbApi.getItemsDerivedFromItem(derivedFromItemId)

    def getPropertiesForItemId(self, itemId):
        selfElement = self.itemDbApi.getSelfElementByItemId(itemId)
        selfElementId = selfElement.data['id']

        return self.propertyDbApi.getPropertyValueListForItemElementId(
            selfElementId)
コード例 #5
0
 def __init__(self):
     CdbSessionController.__init__(self)
     self.logControllerImpl = LogControllerImpl()
コード例 #6
0
class LogSessionController(CdbSessionController):
    def __init__(self):
        CdbSessionController.__init__(self)
        self.logControllerImpl = LogControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addLogAttachment(self,
                         logId,
                         attachmentName,
                         attachmentDescription=None,
                         **kwargs):
        if not logId:
            raise InvalidRequest("Invalid logId provided")
        if not attachmentName:
            raise InvalidRequest("Invalid attachment name provided")

        attachmentName = Encoder.decode(attachmentName)
        attachmentDescription = Encoder.decode(attachmentDescription)
        cherrypyData = cherrypy.request.body
        sessionUser = self.getSessionUser()
        attachmentAddedByUserId = sessionUser.get('id')

        logAttachmentAdded = self.logControllerImpl.addLogAttachment(
            logId, attachmentName, attachmentDescription,
            attachmentAddedByUserId, cherrypyData)

        response = logAttachmentAdded.getFullJsonRep()
        self.logger.debug(
            'Returning log attachment info for log with id %s: %s' %
            (logId, response))
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def updateLogEntry(self,
                       logId,
                       text=None,
                       effectiveFromDateTime=None,
                       effectiveToDateTime=None,
                       logTopicName=None):
        sessionUser = self.getSessionUser()
        userId = sessionUser.get('id')

        if text is not None:
            text = Encoder.decode(text)

        if effectiveFromDateTime is not None:
            effectiveFromDateTime = Encoder.decode(effectiveFromDateTime)

        if effectiveToDateTime is not None:
            effectiveToDateTime = Encoder.decode(effectiveToDateTime)

        if logTopicName is not None:
            logTopicName = Encoder.decode(logTopicName)

        logObject = self.logControllerImpl.updateLogEntry(
            logId, userId, text, effectiveFromDateTime, effectiveToDateTime,
            logTopicName)

        response = logObject.getFullJsonRep()
        self.logger.debug('Return updated log entry for log with id %s' %
                          logId)
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def deleteLogEntry(self, logId):
        sessionUser = self.getSessionUser()
        userId = sessionUser.get('id')

        self.logControllerImpl.deleteLogEntry(logId, userId)

        return {}