def validateUpdate(viewing_resource):
     errors = ResourceValidator.validate(
         viewing_resource,
         ViewingValidator.FIELDS[ResourceValidator.UPDATE])
     ResourceValidator.checkDate(errors, viewing_resource,
                                 ViewingField.DATE)
     return BaseValidator.getValidationMessage(errors)
 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)
示例#3
0
 def validateUpdate(property_resource):
     errors = ResourceValidator.validate(
         property_resource,
         PropertyValidator.FIELDS[ResourceValidator.UPDATE])
     ResourceValidator.checkInt(errors, property_resource,
                                PropertyField.RENT)
     return BaseValidator.getValidationMessage(errors)
 def validateRead(propertyId):
     errors = []
     if not PersistenceValidator.checkExists(Property, propertyId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", propertyId))
     return BaseValidator.getValidationMessage(errors)
示例#5
0
 def validateReadAll(customerId):
     errors = []
     if not PersistenceValidator.checkExists(Account, customerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", customerId))
     return BaseValidator.getValidationMessage(errors)
 def validateDelete(sessionId):
     errors = []
     if not PersistenceValidator.checkExists(Session, sessionId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Session", "token", sessionId))
     return BaseValidator.getValidationMessage(errors)
示例#7
0
 def validateDelete(rentalId):
     errors = RentalValidator.validateRead(rentalId)
     rental = ReadOnlyAccess.getEntityCopy(Rental, rentalId)
     if Date.after(Date.toDate(rental.end),
                   Date.now()) and rental.status == RentlStatus.CONFIRMED:
         errors.append(PersistenceValidator.entityActive(
             "Rental", rentalId))
     return BaseValidator.getValidationMessage(errors)
示例#8
0
 def validateUpdate(account):
     errors = []
     if PersistenceValidator.checkExists(Account, account.id):
         original = ReadOnlyAccess.getEntityCopy(Account, account.id)
     else:
         original = Account()
         errors.append(PersistenceValidator.entityDoesNotExist("Account", "id", account.id))
     return BaseValidator.getValidationMessage(AccountValidator.checkUniqueness(errors, account, original))
示例#9
0
 def validateUpdate(image):
     errors = []
     if PersistenceValidator.checkExists(Image, image.id):
         original = ReadOnlyAccess.getEntityCopy(Image, image.id)
     else:
         original = Image()
         errors.append(PersistenceValidator.entityDoesNotExist("Image", "id", image.id))
     return BaseValidator.getValidationMessage(ImageValidator.checkUniqueness(errors, image, original))
示例#10
0
 def validateRead(propertyId, imageId):
     errors = []
     if not PersistenceValidator.checkExists(Image, imageId):
         errors.append(PersistenceValidator.entityDoesNotExist("Image", "id", imageId))
     if not PersistenceValidator.checkExists(Property, propertyId):
         errors.append(PersistenceValidator.entityDoesNotExist("Property", "id", propertyId))
     if not ReadOnlyAccess.getEntityCopy(Image, imageId).propertyId == propertyId:
         errors.append(linkedDomainNotFoundError("Property", "Image", propertyId, imageId))
     return BaseValidator.getValidationMessage(errors)
示例#11
0
 def validateUpdate(rental):
     errors = []
     if PersistenceValidator.checkExists(Rental, rental.id):
         original = ReadOnlyAccess.getEntityCopy(Rental, rental.id)
     else:
         original = Rental()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Rental", "id", rental.id))
     return BaseValidator.getValidationMessage(
         RentalValidator.checkUniqueness(errors, rental, original))
示例#12
0
 def validateUpdate(viewing):
     errors = []
     if PersistenceValidator.checkExists(Viewing, viewing.id):
         original = ReadOnlyAccess.getEntityCopy(Viewing, viewing.id)
     else:
         original = Viewing()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Viewing", "id", viewing.id))
     return BaseValidator.getValidationMessage(
         ViewingValidator.checkUniqueness(errors, viewing, original))
 def validateUpdate(ownerId, property):
     errors = []
     if PersistenceValidator.checkExists(Property, property.id):
         original = ReadOnlyAccess.getEntityCopy(Property, property.id)
         PropertyValidator.checkOwner(errors, ownerId, property.id)
     else:
         original = Property()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", property.id))
     return BaseValidator.getValidationMessage(
         PropertyValidator.checkUniqueness(errors, property, original))
 def validateReadAll(ownerId):
     errors = []
     if not PersistenceValidator.checkExists(Account, ownerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", ownerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, ownerId).type == AccountType.OWNER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", ownerId))
     return BaseValidator.getValidationMessage(errors)
 def validateCreate(property):
     errors = []
     if not PersistenceValidator.checkExists(Account, property.ownerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", property.ownerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, property.ownerId).type == AccountType.OWNER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", property.ownerId))
     return BaseValidator.getValidationMessage(
         PropertyValidator.checkUniqueness(errors, property))
 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)
示例#17
0
 def validateCreate(viewing):
     errors = []
     if not PersistenceValidator.checkExists(Account, viewing.customerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", viewing.customerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, viewing.customerId).type == AccountType.CUSTOMER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", viewing.customerId))
     if not PersistenceValidator.checkExists(Property, viewing.propertyId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", viewing.propertyId))
     return BaseValidator.getValidationMessage(
         ViewingValidator.checkUniqueness(errors, viewing.propertyId))
示例#18
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)
示例#19
0
 def validateCreate(rental):
     errors = []
     if not PersistenceValidator.checkExists(Account, rental.customer):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", rental.customer))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, rental.customer).type == AccountType.CUSTOMER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", rental.customer))
     if not PersistenceValidator.checkExists(Property, rental.property):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", rental.property))
     if not PersistenceValidator.checkExists(Property, rental.property):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", rental.property))
     return BaseValidator.getValidationMessage(
         RentalValidator.checkUniqueness(errors, rental))
示例#20
0
 def validateUpdate(account_resource):
     errors = ResourceValidator.validate(
         account_resource,
         AccountValidator.FIELDS[ResourceValidator.UPDATE])
     return BaseValidator.getValidationMessage(errors)
示例#21
0
 def validateUpdate(rental_resource):
     errors = ResourceValidator.validate(rental_resource, RentalValidator.FIELDS[ResourceValidator.UPDATE])
     ResourceValidator.checkDate(errors, rental_resource, RentalField.START)
     ResourceValidator.checkDate(errors, rental_resource, RentalField.END)
     return BaseValidator.getValidationMessage(errors)
示例#22
0
 def validateCreate(image):
     errors = []
     return BaseValidator.getValidationMessage(ImageValidator.checkUniqueness(errors, image))
示例#23
0
 def validateUpdate(image_resource):
     errors = ResourceValidator.validate(image_resource, ImageValidator.FIELDS[ResourceValidator.UPDATE])
     return BaseValidator.getValidationMessage(errors)
示例#24
0
 def validateCreate(account):
     errors = []
     return BaseValidator.getValidationMessage(AccountValidator.checkUniqueness(errors, account))
示例#25
0
 def validateRead(accountId):
     errors = []
     if not PersistenceValidator.checkExists(Account, accountId):
         errors.append(PersistenceValidator.entityDoesNotExist("Account", "id", accountId))
     return BaseValidator.getValidationMessage(errors)
示例#26
0
 def validateQuery(query):
     return BaseValidator.getValidationMessage([])