Example #1
0
    def getItemByUniqueAttributes(self,
                                  domainName,
                                  itemName,
                                  itemIdentifier1=None,
                                  itemIdentifier2=None,
                                  derivedFromItemId=None):
        if not domainName:
            raise InvalidRequest("Invalid domain name provided")
        if not itemName:
            raise InvalidRequest("Invalid itemName provided")

        domainName = Encoder.decode(domainName)
        itemName = Encoder.decode(itemName)

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

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

        item = self.itemControllerImpl.getItemByUniqueAttributes(
            domainName, itemName, itemIdentifier1, itemIdentifier2,
            derivedFromItemId)
        response = item.getFullJsonRep()

        self.logger.debug(
            'Returning item info for item in domain %s with name %s: %s' %
            (domainName, itemName, response))
        return response
Example #2
0
    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
Example #3
0
    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()
Example #4
0
    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
Example #5
0
    def packageOptionalPropertyValueVariables(self, tag=None, value=None, units=None, description=None, isUserWriteable=None, isDynamic=None, displayValue=None):
        optionalParameters = {}

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

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

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

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

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

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

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

        return optionalParameters
    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
Example #7
0
    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()
    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
Example #9
0
 def writeFile(self, fileName, **kwargs):
     if 'parentDirectory' not in kwargs:
         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 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()
    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
    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
    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()
Example #14
0
    def getFirstItemRelationship(self, itemId, relationshipTypeName):
        if not itemId:
            raise InvalidRequest("Invalid item id provided")
        if not relationshipTypeName:
            raise InvalidRequest("Invalid relationship type name provided")

        relationshipTypeName = Encoder.decode(relationshipTypeName)

        itemElementRelationshipList = self.itemControllerImpl.getFirstItemRelationship(
            itemId, relationshipTypeName)

        response = self.listToJson(itemElementRelationshipList)
        self.logger.debug(
            'Returning item element relationship list of type: %s for item: %s : %s'
            % (relationshipTypeName, itemId, response))

        return response
Example #15
0
    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
Example #16
0
    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
    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()