Exemplo 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!'}
Exemplo n.º 2
0
 def deleteApp(self, appData):
     json_re = json.loads(appData)
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_app_name]
     mycollection.delete_one(json_re)
     # need to delete all files as well? Or just leave the files alone
     return {'success': True, 'message': 'Application Deleted!'}
Exemplo n.º 3
0
 def authUser(self, userData):
     json_re = json.loads(userData)
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_userInfo_name]
     res = mycollection.find_one(json_re)
     if res is None:
         return False
     else:
         return True
Exemplo n.º 4
0
 def updateUser(self, userData):
     json_re = json.loads(userData)
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_userInfo_name]
     myquery = {"username": json_re['username']}
     json_re['updatedAt'] = datetime.datetime.utcnow()
     newvalues = {"$set": json_re}
     mycollection.update_one(myquery, newvalues)
     return {'success': True, 'message': 'User Updated!'}
 def getFileList(self, userName, appName):
     json_re = {"username": userName, "appName": appName}
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_files_name]
     res = mycollection.find(json_re)
     docs = []
     for doc in res:
         doc.pop('_id')
         docs.append(doc)
     return json.dumps(docs, default=self.default)
Exemplo n.º 6
0
 def deleteAllAppForUser(self, username):
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_app_name]
     myquery = {"username": username}
     mycollection.delete_many(myquery)
     # need to delete all files as well? Or just leave the files alone
     return {
         'success': True,
         'message': 'All Applications Deleted For User: ' + username
     }
Exemplo n.º 7
0
 def updateApp(self, appData):
     json_re = json.loads(appData)
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_app_name]
     myquery = {
         "username": json_re['username'],
         "appName": json_re['appName']
     }
     json_re['updatedAt'] = datetime.datetime.utcnow()
     newvalues = {"$set": json_re}
     mycollection.update_one(myquery, newvalues)
     return {'success': True, 'message': 'Application Updated!'}
    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!'}
Exemplo n.º 9
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!'}
    def delAllFileForApp(self, userName, appName, folderPath, isUsingCloud):

        if self.str2bool(isUsingCloud):
            self.delAllCloudFilesForApp(userName, appName)
        else:
            self.delAllLocalFilesForApp(userName, appName, folderPath)

        json_re = {"username": userName, "appName": appName}
        mydb = MongoDBService(self.configReader).getDB()
        mycollection = mydb[self.configReader.collection_files_name]
        mycollection.delete_many(json_re)
        return {
            'success': True,
            'message':
            'Files Deleted for: ' + userName + ' , appName: ' + appName
        }
    def delFile(self, userName, appName, fileType, fileName, folderPath,
                isUsingCloud):

        if self.str2bool(isUsingCloud):
            self.delFromCloud(userName, appName, fileType, fileName)
        else:
            self.delFromLocal(userName, appName, fileType, fileName,
                              folderPath)

        json_re = {
            "username": userName,
            "appName": appName,
            "fileType": fileType,
            "fileName": fileName
        }
        mydb = MongoDBService(self.configReader).getDB()
        mycollection = mydb[self.configReader.collection_files_name]
        mycollection.delete_one(json_re)

        return {'success': True, 'message': 'File Deleted!'}
Exemplo n.º 12
0
def connectMongo():
    #mongodb://[username:password@]host1[:port1]
    dbService = MongoDBService(configReader)
    client = dbService.myclient
    print(client.database_names())
    return 'connected and DB names are: ' + ' '.join(client.database_names())
Exemplo n.º 13
0
 def deleteUser(self, userData):
     json_re = json.loads(userData)
     mydb = MongoDBService(self.configReader).getDB()
     mycollection = mydb[self.configReader.collection_userInfo_name]
     mycollection.delete_one(json_re)
     return {'success': True, 'message': 'User Deleted!'}