Esempio n. 1
0
 def createUser(self, userData):
     json_re = json.loads(userData)
     client = MongoDBService(self.configReader)
     if client.isExisting({"username": json_re['username']},
                          self.configReader.collection_userInfo_name):
         return {'success': False, 'message': 'User Already Exists!'}
     mydb = client.getDB()
     mycollection = mydb[self.configReader.collection_userInfo_name]
     time = datetime.datetime.utcnow()
     json_re['createdAt'] = time
     json_re['updatedAt'] = time
     mycollection.insert_one(json_re)
     return {'success': True, 'message': 'New User Created!'}
    def saveFile(self, userName, appName, fileType, fileName, myfile,
                 folderPath, isUsingCloud):
        json_re = {
            "username": userName,
            "appName": appName,
            "fileType": fileType,
            "fileName": fileName,
            "isUsingCloud": isUsingCloud
        }
        client = MongoDBService(self.configReader)
        mydb = client.getDB()
        mycollection = mydb[self.configReader.collection_files_name]
        if client.isExisting(json_re, self.configReader.collection_files_name):
            # update
            myquery = {
                "username": userName,
                "appName": appName,
                "fileType": fileType,
                "fileName": fileName,
                "isUsingCloud": isUsingCloud
            }
            json_re['updatedAt'] = datetime.datetime.utcnow()
            newvalues = {"$set": json_re}
            mycollection.update_one(myquery, newvalues)
        else:
            # save
            time = datetime.datetime.utcnow()
            json_re['createdAt'] = time
            json_re['updatedAt'] = time
            mycollection.insert_one(json_re)

        #previous insertion op should be in the same transaction with following file op
        if self.str2bool(isUsingCloud):
            self.saveToCloud(userName, appName, fileType, fileName, myfile)
        else:
            self.saveToLocal(userName, appName, fileType, fileName, myfile,
                             folderPath)

        return {'success': True, 'message': 'New File Created!'}
Esempio n. 3
0
 def createApp(self, appData):
     json_re = json.loads(appData)
     if json_re['appName'] is None or json_re['username'] is None:
         return {
             'success': False,
             'message': 'Application Name Should Not Be Empty!'
         }
     client = MongoDBService(self.configReader)
     if client.isExisting(
         {
             "username": json_re['username'],
             "appName": json_re['appName']
         }, self.configReader.collection_app_name):
         return {
             'success': False,
             'message': 'Application Name Already Exists!'
         }
     mydb = client.getDB()
     mycollection = mydb[self.configReader.collection_app_name]
     time = datetime.datetime.utcnow()
     json_re['createdAt'] = time
     json_re['updatedAt'] = time
     mycollection.insert_one(json_re)
     return {'success': True, 'message': 'New Application Created!'}