def validateDelete(ownerId, propertyId):
     errors = []
     if not PersistenceValidator.checkExists(Property, propertyId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", propertyId))
     else:
         PropertyValidator.checkOwner(errors, ownerId, propertyId)
         rentals = ReadOnlyAccess.getEntityListCopy(
             Rental, {"property": propertyId})
         viewings = ReadOnlyAccess.getEntityListCopy(
             Viewing, {"propertyId": propertyId})
         rentals = list(
             filter(
                 lambda x: Date.after(Date.toDate(x.end), Date.now()) and x.
                 status == RentalStatus.CONFIRMED, rentals))
         viewings = list(
             filter(lambda x: Date.after(Date.toDate(x.date), Date.now()),
                    viewings))
         if len(rentals) > 0:
             errors.append(
                 PersistenceValidator.activeSubEntitiesExist(
                     "Property", "Rentals", len(rentals)))
         if len(viewings) > 0:
             errors.append(
                 PersistenceValidator.activeSubEntitiesExist(
                     "Property", "Viewings", len(viewings)))
     return BaseValidator.getValidationMessage(errors)
示例#2
0
 def getAccount(sessionToken):
     session = ReadOnlyAccess.getEntityCopy(Session, sessionToken)
     if session is None:
         return False, None
     if SessionUtility.isExpired(session):
         return False, None
     return True, ReadOnlyAccess.getEntityListCopy(Account, {"username": session.username})[0]
示例#3
0
 def readAll(customerId):
     # Validate in persistence level
     validatorResponse = RentalValidator.validateReadAll(customerId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Read Entities
     searchFilter = {"customer": customerId}
     rentalList = ReadOnlyAccess.getEntityListCopy(Rental, searchFilter)
     # Return Result
     return {FieldKey.SUCCESS: rentalList}
示例#4
0
    def validateDelete(accountId):
        errors = []
        properties = ReadOnlyAccess.getEntityListCopy(Property, {"ownerId": accountId})

        rentals = ReadOnlyAccess.getEntityListCopy(Rental, {"customer": accountId})
        rentals.extend(ReadOnlyAccess.getEntityListCopy(Rental, {"agent": accountId}))
        rentals = list(filter(lambda x: Date.after(Date.toDate(x.end), Date.now()) and x.status == RentalStatus.CONFIRMED, rentals))

        viewings = ReadOnlyAccess.getEntityListCopy(Viewing, {"customerId": accountId})
        viewings = list(filter(lambda x: Date.after(Date.toDate(x.date), Date.now()), rentals))

        if len(properties) > 0:
            errors.append(PersistenceValidator.subEntitiesExist("Account", "Properties", len(properties)))
        if len(rentals) > 0:
            errors.append(PersistenceValidator.activeSubEntitiesExist("Account", "Rentals", len(rentals)))
        if len(viewings) > 0:
            errors.append(PersistenceValidator.activeSubEntitiesExist("Account", "Viewings", len(viewings)))

        return BaseValidator.getValidationMessage(errors)
示例#5
0
 def readAll(propertyId):
     # Validate in persistence level
     validatorResponse = ImageValidator.validateReadAll(propertyId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Read Entities
     searchFilter = {"propertyId": propertyId}
     imageList = ReadOnlyAccess.getEntityListCopy(
         Image, {"propertyId": propertyId})
     # Return Result
     return {FieldKey.SUCCESS: imageList}
示例#6
0
 def readList(customerId):
     # Validate in persistence level
     validatorResponse = ViewingValidator.validateReadAll(customerId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Read Entities
     searchFilter = {"customerId": customerId}
     viewingList = ReadOnlyAccess.getEntityListCopy(Viewing, searchFilter)
     viewingList = list(
         filter(lambda x: Date.after(Date.toDate(x.date), Date.now()),
                viewingList))
     return {FieldKey.SUCCESS: viewingList}
 def validateCreate(username, password):
     errors = []
     accounts = ReadOnlyAccess.getEntityListCopy(Account,
                                                 {"username": username})
     if len(accounts) > 1:
         raise Exception("Multiple Accounts with Username: " + username)
     elif len(accounts) < 1:
         errors.append(SessionValidator.incorrectUsernameOrPassword())
     else:
         credential = ReadOnlyAccess.getEntityCopy(Credential,
                                                   accounts[0].id)
         if credential is None or not PasswordUtility.checkHashedPassword(
                 password, credential.password):
             errors.append(SessionValidator.incorrectUsernameOrPassword())
     return BaseValidator.getValidationMessage(errors)
示例#8
0
Repository.engine = create_engine(
    properties.database_type + '://' + properties.database_username + ':' +
    properties.database_password + '@' + properties.database_host + '/' +
    properties.database_name,
    echo=properties.database_echo)
Repository.Session = sessionmaker(bind=Repository.engine)

# Flask Setup
app = Flask(__name__)
api = Api(app)

# Initialize / Update Repository
Base.metadata.create_all(bind=Repository.engine)

# Create Admin Agent if no Agent Exists
if len(ReadOnlyAccess.getEntityListCopy(Account,
                                        {"type": AccountType.AGENT})) == 0:
    session = Repository.Session()
    # Create the Account object
    account = Account()
    account.id = IdGenerator.generate()
    account.username = properties.admin_username
    account.email = properties.admin_email
    account.type = AccountType.AGENT
    session.add(account)

    # Create the Credential Object
    credential = Credential()
    credential.id = account.id
    credential.password = PasswordUtility.getHashedPassword(
        properties.admin_password)
    session.add(credential)