blob: 51d6630827049ea3eb919993bfbddb5617064eb2 [file]
/*
******************************************************************************
* 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 { MessageService } from '../../services/message.service';
export abstract class ValidationFunc< T > {
public abstract validate( item: T, messageService: MessageService ): boolean;
}
export class EntityValidator< T > {
constructor( private messageService: MessageService,
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;
}
}