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)
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)
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)
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)
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))
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))
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)
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))
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)
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))
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)
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))
def validateUpdate(account_resource): errors = ResourceValidator.validate( account_resource, AccountValidator.FIELDS[ResourceValidator.UPDATE]) return BaseValidator.getValidationMessage(errors)
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)
def validateCreate(image): errors = [] return BaseValidator.getValidationMessage(ImageValidator.checkUniqueness(errors, image))
def validateUpdate(image_resource): errors = ResourceValidator.validate(image_resource, ImageValidator.FIELDS[ResourceValidator.UPDATE]) return BaseValidator.getValidationMessage(errors)
def validateCreate(account): errors = [] return BaseValidator.getValidationMessage(AccountValidator.checkUniqueness(errors, account))
def validateRead(accountId): errors = [] if not PersistenceValidator.checkExists(Account, accountId): errors.append(PersistenceValidator.entityDoesNotExist("Account", "id", accountId)) return BaseValidator.getValidationMessage(errors)
def validateQuery(query): return BaseValidator.getValidationMessage([])