blob: f5811dc69b04d87840547387bac651db3dda9506 [file] [log] [blame]
/*
******************************************************************************
* Copyright © 2018 PTA GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*
******************************************************************************
*/
import { ToasterMessageService } from '../../services/toaster-message.service';
export abstract class ValidationFunc<T> {
public abstract validate(item: T, messageService: ToasterMessageService): boolean;
}
export class EntityValidator<T> {
constructor(private messageService: ToasterMessageService,
private validationList: ValidationFunc<T>[]) { }
public validateEntity(entity: T, stopOnFirstError: boolean): boolean {
let errorOccured = false;
this.validationList.forEach(validator => {
if (!(errorOccured && stopOnFirstError)) {
errorOccured = !validator.validate(entity, this.messageService);
}
});
return !errorOccured;
}
}