Example #1
0
class PropertySessionController(CdbSessionController):
    def __init__(self):
        CdbController.__init__(self)
        self.propertyControllerImpl = PropertyControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addPropertyValueMetadata(self, propertyValueId, metadataKey,
                                 metadataValue):
        if not propertyValueId:
            raise InvalidRequest("Invalid propertyValueId provided")
        if not metadataKey:
            raise InvalidRequest("Invalid metadataKey provided")
        if not metadataValue:
            raise InvalidRequest("Invalid metadataValue provided")

        metadataValue = Encoder.decode(metadataValue)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        addedMetadata = self.propertyControllerImpl.addPropertyMetadataForPropertyValueId(
            propertyValueId, metadataKey, metadataValue, enteredByUserId)
        response = addedMetadata.getFullJsonRep()

        self.logger.debug(
            'Returning Property Metadata for property value with id %s: %s' %
            (propertyValueId, addedMetadata))
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addPropertyValueMetadataFromDict(self, propertyValueId, metadataDict):
        if not propertyValueId:
            raise InvalidRequest("Invalid propertyValueId provided")
        if not metadataDict:
            raise InvalidRequest("Invalid propertyMetadataDict provided")

        propertyMetadataDictStringRep = Encoder.decode(metadataDict)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        addedUpdatedPropertyMetadata = self.propertyControllerImpl.addPropertyValueMetadataFromDict(
            propertyValueId, propertyMetadataDictStringRep, enteredByUserId)

        response = self.listToJson(addedUpdatedPropertyMetadata)

        self.logger.debug(
            "Returning property metadata for property value with id %s: %s" %
            (propertyValueId, response))

        return response
class ItemSessionController(CdbSessionController):
    def __init__(self):
        CdbSessionController.__init__(self)
        self.itemControllerImpl = ItemControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addLogToItemByQrId(self,
                           qrId,
                           logEntry,
                           attachmentName=None,
                           **kwargs):
        if not qrId:
            raise InvalidRequest("Invalid qrId provided")
        if not logEntry:
            raise InvalidRequest("Log entry must be provided")

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

        logAdded = self.itemControllerImpl.addLogEntryForItemWithQrId(
            qrId, logEntry, enteredByUserId, attachmentName, cherrypyData)

        response = logAdded.getFullJsonRep()
        self.logger.debug('Returning log info for item with qrid %s: %s' %
                          (qrId, response))
        return response
class FileSystemSessionController(CdbSessionController):
    def __init__(self):
        CdbSessionController.__init__(self)
        self.fileSystemControllerImpl = FileSystemControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def writeFile(self, fileName, **kwargs):
        if not kwargs.has_key('parentDirectory'):
            raise InvalidRequest('Missing parent directory.')
        parentDirectory = kwargs.get('parentDirectory')
        encodedFileContent = kwargs.get('encodedFileContent', '')
        fileContent = Encoder.decode(encodedFileContent)
        filePath = '%s/%s' % (parentDirectory, fileName)
        response = '%s' % self.fileSystemControllerImpl.writeFile(
            filePath, fileContent).getFullJsonRep()
        self.logger.debug('Returning: %s' % response)
        return response
 def __init__(self):
     CdbSessionController.__init__(self)
     self.itemControllerImpl = ItemControllerImpl()
     self.propertyControllerImpl = PropertyControllerImpl()
class ItemSessionController(CdbSessionController):
    def __init__(self):
        CdbSessionController.__init__(self)
        self.itemControllerImpl = ItemControllerImpl()
        self.propertyControllerImpl = PropertyControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addLogToItemByQrId(self,
                           qrId,
                           logEntry,
                           attachmentName=None,
                           **kwargs):
        if not qrId:
            raise InvalidRequest("Invalid qrId provided")
        if not logEntry:
            raise InvalidRequest("Log entry must be provided")

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

        logAdded = self.itemControllerImpl.addLogEntryForItemWithQrId(
            qrId, logEntry, enteredByUserId, attachmentName, cherrypyData)

        response = logAdded.getFullJsonRep()
        self.logger.debug('Returning log info for item with qrid %s: %s' %
                          (qrId, response))
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addLogToItemByItemId(self,
                             itemId,
                             logEntry,
                             attachmentName=None,
                             **kwargs):
        if not itemId:
            raise InvalidRequest("Invalid itemId provided")
        if not logEntry:
            raise InvalidRequest("Log entry must be provided")

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

        logAdded = self.itemControllerImpl.addLogEntryForItemWithItemId(
            itemId, logEntry, enteredByUserId, attachmentName, cherrypyData)

        response = logAdded.getFullJsonRep()
        self.logger.debug('Returning log info for item with item id %s: %s' %
                          (itemId, response))
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addPropertyImageToItem(self,
                               itemId,
                               imageFileName,
                               dataEncodedBase64=False):
        if not itemId:
            raise InvalidRequest("Invalid item id provided")
        if not imageFileName:
            raise InvalidRequest("Invalid image file name provided")

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')
        imageFileName = Encoder.decode(imageFileName)
        cherrypyData = cherrypy.request.body

        if dataEncodedBase64:
            cherrypyData = Encoder.decode(cherrypyData.read())

        imagePropertyAdded = self.itemControllerImpl.addPropertyImageToItem(
            itemId, imageFileName, enteredByUserId, cherrypyData)

        return imagePropertyAdded.getFullJsonRep()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addItemElementRelationship(self,
                                   relationshipTypeName,
                                   firstItemId=None,
                                   secondItemId=None,
                                   firstItemQrId=None,
                                   secondItemQrId=None,
                                   relationshipDetails=None,
                                   description=None):
        if not firstItemId and not firstItemQrId:
            raise InvalidRequest("Invalid first item id provided")
        if not secondItemId and not secondItemQrId:
            raise InvalidRequest("Invalid second item id provided")
        if not relationshipTypeName:
            raise InvalidRequest("Invalid relationship type name provided")

        usingQrIds = None
        if firstItemId and secondItemId:
            usingQrIds = False
        elif firstItemQrId and secondItemQrId:
            usingQrIds = True
        else:
            raise InvalidRequest("Must either specify both qrIds or both Ids")

        relationshipTypeName = Encoder.decode(relationshipTypeName)

        if relationshipDetails is not None:
            relationshipDetails = Encoder.decode(relationshipDetails)
        if description is not None:
            description = Encoder.decode(description)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        logMessageStart = "Returning item element relationship between "

        if usingQrIds:
            itemElementRelationship = self.itemControllerImpl.addItemElementRelationshipByQrId(
                firstItemQrId, secondItemQrId, relationshipTypeName,
                enteredByUserId, relationshipDetails, description)

            logMessageStart += "item qr: %s and item qr: %s" % (firstItemQrId,
                                                                secondItemQrId)
        else:
            itemElementRelationship = self.itemControllerImpl.addItemElementRelationship(
                firstItemId, secondItemId, relationshipTypeName,
                enteredByUserId, relationshipDetails, description)

            logMessageStart += "item id: %s and item id: %s" % (firstItemId,
                                                                secondItemId)

        response = itemElementRelationship.getFullJsonRep()

        self.logger.debug("%s of type: %s : %s" %
                          (logMessageStart, relationshipTypeName, response))

        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addPropertyValueToItemByItemId(self,
                                       itemId,
                                       propertyTypeName,
                                       tag=None,
                                       value=None,
                                       displayValue=None,
                                       units=None,
                                       description=None,
                                       isUserWriteable=None,
                                       isDynamic=None):
        if not itemId:
            raise InvalidRequest("Invalid itemId provided")
        if not propertyTypeName:
            raise InvalidRequest("Invalid propertyTypeName provided")

        propertyTypeName = Encoder.decode(propertyTypeName)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        optionalParameters = self.propertyControllerImpl.packageOptionalPropertyValueVariables(
            tag, value, units, description, isUserWriteable, isDynamic,
            displayValue)

        itemElementPropertyValueAdded = self.itemControllerImpl.addPropertyValueForItemWithId(
            itemId, propertyTypeName, enteredByUserId, **optionalParameters)
        propertyValueAdded = itemElementPropertyValueAdded.data[
            'propertyValue']

        response = propertyValueAdded.getFullJsonRep()
        self.logger.debug(
            'Returning new property value created for item with id %s: %s' %
            (itemId, propertyValueAdded))
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def deletePropertyValuesFromItemByItemId(self, itemId, propertyTypeName):
        if not itemId:
            raise InvalidRequest("Invalid itemId provided")
        if not propertyTypeName:
            raise InvalidRequest("Invalid propertyTypeName provided")

        propertyTypeName = Encoder.decode(propertyTypeName)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        deletedPropertyValues = self.itemControllerImpl.deletePropertyValuesFromItemByItemId(
            itemId, propertyTypeName, enteredByUserId)
        response = self.listToJson(deletedPropertyValues)
        return response

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addItem(self,
                domainName,
                name,
                itemProjectName=None,
                ownerUserId=None,
                ownerGroupId=None,
                itemIdentifier1=None,
                itemIdentifier2=None,
                qrId=None,
                description=None,
                isGroupWriteable=None,
                entityTypeNames=None,
                derivedFromItemId=None):
        if not domainName:
            raise InvalidRequest("Invalid domain name provided")
        if not name:
            raise InvalidRequest("Invalid item name provided")

        domainName = Encoder.decode(domainName)
        name = Encoder.decode(name)

        sessionUser = self.getSessionUser()
        createdByUserId = sessionUser.get('id')

        if ownerUserId is None:
            ownerUserId = createdByUserId

        if ownerGroupId is None:
            userGroupList = sessionUser.data['userGroupList']
            if len(userGroupList) > 0:
                ownerGroupId = userGroupList[0].data['id']
            else:
                raise InvalidRequest(
                    "Invalid, current session user is not assigned to any groups... please specify owner group id."
                )

        optionalParameters = {}

        if itemIdentifier1 is not None:
            itemIdentifier1 = Encoder.decode(itemIdentifier1)
            optionalParameters.update({'itemIdentifier1': itemIdentifier1})

        if itemIdentifier2 is not None:
            itemIdentifier2 = Encoder.decode(itemIdentifier2)
            optionalParameters.update({'itemIdentifier2': itemIdentifier2})

        if qrId is not None:
            optionalParameters.update({'qrId': qrId})

        if description is not None:
            description = Encoder.decode(description)
            optionalParameters.update({'description': description})

        if isGroupWriteable is not None:
            isGroupWriteable = eval(isGroupWriteable)
            optionalParameters.update({'isGroupWriteable': isGroupWriteable})

        if entityTypeNames is not None:
            entityTypeNames = Encoder.decode(entityTypeNames)
            if entityTypeNames[0] == '[':
                entityTypeNames = eval(entityTypeNames)
            optionalParameters.update({'entityTypeNames': entityTypeNames})

        if derivedFromItemId is not None:
            optionalParameters.update({'derivedFromItemId': derivedFromItemId})

        if itemProjectName is not None:
            itemProjectName = Encoder.decode(itemProjectName)
            optionalParameters.update({'itemProjectName': itemProjectName})

        response = self.itemControllerImpl.addItem(domainName, name,
                                                   createdByUserId,
                                                   ownerUserId, ownerGroupId,
                                                   **optionalParameters)
        self.logger.debug('Returning new item: %s' % (response))
        return response.getFullJsonRep()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def updateInventoryItemStatus(self, itemId, status):
        if not itemId:
            raise InvalidRequest("Item id must be provided")
        if not status:
            raise InvalidRequest("Status must be provided")

        status = Encoder.decode(status)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        response = self.itemControllerImpl.updateInventoryItemStatus(
            itemId, status, enteredByUserId)
        self.logger.debug("Returning updated status: %s" % (response))

        return response.getFullJsonRep()
 def __init__(self):
     CdbSessionController.__init__(self)
     self.fileSystemControllerImpl = FileSystemControllerImpl()
Example #7
0
 def __init__(self):
     CdbSessionController.__init__(self)
     self.itemElementImplController = ItemElementControllerImpl()
     self.propertyControllerImpl = PropertyControllerImpl()
Example #8
0
class ItemElementSessionController(CdbSessionController):
    def __init__(self):
        CdbSessionController.__init__(self)
        self.itemElementImplController = ItemElementControllerImpl()
        self.propertyControllerImpl = PropertyControllerImpl()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addItemElement(self,
                       parentItemId,
                       itemElementName,
                       containedItemId=None,
                       description=None,
                       ownerUserId=None,
                       ownerGroupId=None,
                       isRequired=None,
                       isGroupWriteable=None):
        sessionUser = self.getSessionUser()
        createdByUserId = sessionUser.get('id')

        if ownerUserId is None:
            ownerUserId = createdByUserId

        if ownerGroupId is None:
            userGroupList = sessionUser.data['userGroupList']
            if len(userGroupList) > 0:
                ownerGroupId = userGroupList[0].data['id']
            else:
                raise InvalidRequest(
                    "Invalid, current session user is not assigned to any groups... please specify owner group id."
                )

        optionalParameters = {}

        itemElementName = Encoder.decode(itemElementName)

        if containedItemId is not None:
            optionalParameters.update({'containedItemId': containedItemId})

        if description is not None:
            description = Encoder.decode(description)
            optionalParameters.update({'description': description})

        if isRequired is not None:
            isRequired = eval(isRequired)
            optionalParameters.update({'isRequired': isRequired})

        if isGroupWriteable is not None:
            isGroupWriteable = eval(isGroupWriteable)
            optionalParameters.update({'isGroupWriteable': isGroupWriteable})

        response = self.itemElementImplController.addItemElement(
            parentItemId, itemElementName, createdByUserId, ownerUserId,
            ownerGroupId, **optionalParameters)
        self.logger.debug('Returning new item element: %s' % (response))
        return response.getFullJsonRep()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def updateItemElement(self,
                          itemElementId,
                          containedItemId=-1,
                          isRequired=-1,
                          name=None,
                          description=None,
                          ownerUserId=None,
                          ownerGroupId=None,
                          isGroupWriteable=None):
        sessionUser = self.getSessionUser()
        lastModifiedUserId = sessionUser.get('id')

        if containedItemId != -1:
            containedItemId = eval(containedItemId)
        if isRequired != -1:
            isRequired = eval(isRequired)
        if name is not None:
            name = Encoder.decode(name)
        if description is not None:
            description = Encoder.decode(description)
        if ownerUserId is not None:
            ownerUserId = eval(ownerUserId)
        if ownerGroupId is not None:
            ownerGroupId = eval(ownerGroupId)
        if isGroupWriteable is not None:
            isGroupWriteable = eval(isGroupWriteable)

        response = self.itemElementImplController.updateItemElement(
            itemElementId, lastModifiedUserId, containedItemId, isRequired,
            name, description, ownerUserId, ownerGroupId, isGroupWriteable)

        self.logger.debug('Returning updated item element: %s' % (response))
        return response.getFullJsonRep()

    @cherrypy.expose
    @CdbSessionController.require(CdbSessionController.isLoggedIn())
    @CdbSessionController.execute
    def addPropertyValueToItemElementById(self,
                                          itemElementId,
                                          propertyTypeName,
                                          tag=None,
                                          value=None,
                                          displayValue=None,
                                          units=None,
                                          description=None,
                                          isUserWriteable=None,
                                          isDynamic=None):
        if not itemElementId:
            raise InvalidRequest("Invalid itemElementId provided")
        if not propertyTypeName:
            raise InvalidRequest("Invalid propertyTypeName provided")

        propertyTypeName = Encoder.decode(propertyTypeName)

        sessionUser = self.getSessionUser()
        enteredByUserId = sessionUser.get('id')

        optionalParameters = self.propertyControllerImpl.packageOptionalPropertyValueVariables(
            tag, value, units, description, isUserWriteable, isDynamic,
            displayValue)

        itemElementPropertyValueAdded = self.itemElementImplController.addPropertyValueForItemElementWithId(
            itemElementId, propertyTypeName, enteredByUserId,
            **optionalParameters)
        propertyValueAdded = itemElementPropertyValueAdded.data[
            'propertyValue']

        response = propertyValueAdded.getFullJsonRep()
        self.logger.debug(
            'Returning new property value created for item element with id %s: %s'
            % (itemElementId, propertyValueAdded))
        return response
Example #9
0
 def __init__(self):
     CdbSessionController.__init__(self)
     self.logControllerImpl = LogControllerImpl()
Example #10
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 {}