def applicationsBy(cls, userEmail): try: objectManager = applicationDatabaseManager.DatabaseManager() user = User.findUserByEmail(userEmail) if user.get('role').get('S') == 'administrator': return objectManager.allApplications() else: return objectManager.applicationsForUser(userEmail) except Exception as e: logger.error('Database error: ' + str(e)) raise DatabaseConnectionFailed("Connection with the database failed, please try again later")
def addApplication(self): self.assertNotDuplicatePetition() item = self.itemToInsert() try: objectManager = applicationDatabaseManager.DatabaseManager() resp = objectManager.dynamoDB().put_item( TableName=objectManager.applicationTable(), Item=item ) return json.loads(item) except Exception as e: logger.error('Database error: ' + str(e)) raise DatabaseConnectionFailed("Connection with the database failed, please try again later")
def cancelApplication(userEmail, appID): try: objectManager = applicationDatabaseManager.DatabaseManager() app = objectManager.findApplicationBy(userEmail, appID) if app is None: raise ValueError('Application #' + appID + ' Does not exist for the current user') else: appID = app['applicationID'] appStatus = app['status'] appFiller = app['filler'] appArea = app['area'] appSupply = app['supply'] app = Application(appFiller, appSupply, appArea) app.ID = appID app.status = appStatus app.cancel() objectManager.cancelApplication(app) except (ValueError, DatabaseConnectionFailed) as e: return e
def rejectApplication(filler, appID, aMotive): try: objectManager = applicationDatabaseManager.DatabaseManager() app = objectManager.findApplicationBy(filler, appID) if app is None: raise ValueError('Application #' + appID + ' Does not exist') else: appID = app['applicationID'] appStatus = app['status'] appFiller = app['filler'] appArea = app['area'] appSupply = app['supply'] app = Application(appFiller, appSupply, appArea, None) app.ID = appID app.status = appStatus app.reject() objectManager.rejectApplication(app, aMotive) except (ValueError, DatabaseConnectionFailed, StatusTransitionFailed) as e: return e
def assertNotDuplicatePetition(self): objectManager = applicationDatabaseManager.DatabaseManager() app = objectManager.findExistingApplication(self.filler, self.supply, self.area, self.drugName) if app is not None: raise ValueError('A similar application is pending, please check again.')